Debian Codegraph @

info/gcl-tk/focus.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>focus (GCL TK Manual)</title>
7
8 <meta name="description" content="focus (GCL TK Manual)">
9 <meta name="keywords" content="focus (GCL TK Manual)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents">
15 <link href="Control.html" rel="up" title="Control">
16 <link href="grab.html" rel="next" title="grab">
17 <link href="exit.html" rel="prev" title="exit">
18 <style type="text/css">
19 <!--
20 a.summary-letter {text-decoration: none}
21 blockquote.indentedblock {margin-right: 0em}
22 div.display {margin-left: 3.2em}
23 div.example {margin-left: 3.2em}
24 div.lisp {margin-left: 3.2em}
25 kbd {font-style: oblique}
26 pre.display {font-family: inherit}
27 pre.format {font-family: inherit}
28 pre.menu-comment {font-family: serif}
29 pre.menu-preformatted {font-family: serif}
30 span.nolinebreak {white-space: nowrap}
31 span.roman {font-family: initial; font-weight: normal}
32 span.sansserif {font-family: sans-serif; font-weight: normal}
33 ul.no-bullet {list-style: none}
34 -->
35 </style>
36
37
38 </head>
39
40 <body lang="en">
41 <span id="focus"></span><div class="header">
42 <p>
43 Next: <a href="grab.html" accesskey="n" rel="next">grab</a>, Previous: <a href="exit.html" accesskey="p" rel="prev">exit</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> &nbsp; [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
44 </div>
45 <hr>
46 <span id="focus-1"></span><h3 class="section">3.6 focus</h3>
47
48 <p>focus \- Direct keyboard events to a particular window
49 </p><span id="Synopsis-20"></span><h4 class="unnumberedsubsec">Synopsis</h4>
50 <br><p><b>focus</b><!-- /@w --><br>
51 <br><b>focus&nbsp;</b><i>window</i><!-- /@w --><br>
52 <b>focus </b><i>option</i><span class="roman"> ?</span><i>arg arg ...</i>?
53 </p>
54 <span id="Description-17"></span><h4 class="unnumberedsubsec">Description</h4>
55
56 <p>The <b>focus</b> command is used to manage the Tk input focus.
57 At any given time, one window in an application is designated as
58 the focus window for that application; any key press or key release
59 events directed to any window in the application will be redirected
60 instead to the focus window. If there is no focus window for an
61 application then keyboard events are discarded.
62 Typically, windows that are prepared to deal with the focus
63 (e.g. entries and other widgets that display editable text) will
64 claim the focus when mouse button 1 is pressed in them.
65 When an application is created its main window is initially given
66 the focus.
67 </p>
68 <p>The <b>focus</b> command can take any of the following forms:
69 </p>
70 <dl compact="compact">
71 <dt><b>focus</b></dt>
72 <dd><p>If invoked with no arguments, <b>focus</b> returns the path name of
73 the current focus window, or <b>none</b> if there is no focus window.
74 </p></dd>
75 <dt><b>focus </b><i>window</i></dt>
76 <dd><p>If invoked with a single argument consisting of a window&rsquo;s path
77 name, <b>focus</b> sets the input focus to that window.
78 The return value is an empty string.
79 </p></dd>
80 <dt><b>focus :default </b><span class="roman">?</span><i>window</i>?</dt>
81 <dd><p>If <i>window</i> is specified, it becomes the default focus window
82 (the window that receives the focus whenever the focus window is
83 deleted) and the command returns an empty string.
84 If <i>window</i> isn&rsquo;t specified, the command returns the path name
85 of the current default focus window, or <b>none</b> if there is no
86 default.
87 <i>Window</i><span class="roman"> may be specified as </span><b>none</b> to clear its existing
88 value.
89 The default window is initially <b>none</b>.
90 </p></dd>
91 <dt><b>focus :none</b></dt>
92 <dd><p>Clears the focus window, so that keyboard input to this application
93 will be discarded.
94 </p>
95 </dd>
96 </dl>
97 <span id="g_t_0022Focus-Events_0022"></span><h4 class="unnumberedsubsec">&quot;Focus Events&quot;</h4>
98
99 <p>Tk&rsquo;s model of the input focus is different than X&rsquo;s model, and the
100 focus window set with the <b>focus</b> command is not usually the
101 same as the X focus window.
102 Tk never explicitly changes the official X focus window.
103 It waits for the window manager to direct the X input focus to
104 and from the application&rsquo;s top-level windows, and it intercepts
105 <b>FocusIn</b><span class="roman"> and </span><b>FocusOut</b> events coming from the X
106 server to detect these changes.
107 All of the focus events received from X are discarded by Tk; they
108 never reach the application.
109 Instead, Tk generates a different stream of <b>FocusIn</b> and
110 <b>FocusOut</b> for the application.
111 This means that <b>FocusIn</b> and
112 and <b>FocusOut</b> events seen by the application will not obey the
113 conventions described in the documentation for Xlib.
114 </p>
115 <p>Tk applications receive two kinds of <b>FocusIn</b><span class="roman"> and </span><b>FocusOut</b>
116 events, which can be distinguished by their <i>detail</i> fields.
117 Events with a <i>detail</i><span class="roman"> of </span><b>NotifyAncestor</b> are directed
118 to the current focus window when it becomes active or inactive.
119 A window is the active focus whenever two conditions are
120 simultaneously true: (a) the window is the focus window for its
121 application, and (b) some top-level window in the application has
122 received the X focus.
123 When this happens Tk generates a <b>FocusIn</b> event for the focus
124 window with detail <b>NotifyAncestor</b>.
125 When a window loses the active focus (either because the window manager
126 removed the focus from the application or because the focus window changed
127 within the application) then it receives a <b>FocusOut</b> event
128 with detail <b>NotifyAncestor</b>.
129 </p>
130 <p>The events described above are directed to the application&rsquo;s focus
131 window regardless of which top-level window within the application
132 has received the focus.
133 The second kind of focus event is provided for applications that
134 need to know which particular top-level window has the X focus.
135 Tk generates <b>FocusIn</b><span class="roman"> and </span><b>FocusOut</b> events with detail
136 <b>NotifyVirtual</b> for top-level windows whenever they receive or
137 lose the X focus.
138 These events are generated regardless of which window in the
139 application has the Tk input focus.
140 They do not imply that keystrokes will be directed to the window
141 that receives the event; they simply indicate which top-level
142 window is active as far as the window manager is concerned.
143 If a top-level window is also the application&rsquo;s focus window,
144 then it will receive both <b>NotifyVirtual</b><span class="roman"> and </span><b>NotifyAncestor</b>
145 events when it receives or loses the X focus.
146 </p>
147 <p>Tk does not generate the hierarchical chains of <b>FocusIn</b> and
148 <b>FocusOut</b> events described in the Xlib documentation (e.g.
149 a window can get a <b>FocusIn</b><span class="roman"> or </span><b>FocusOut</b> event without
150 all of its ancestors getting events too).
151 Furthermore, the <i>mode</i> field in focus events is always
152 <b>NotifyNormal</b> and the only values ever present in the
153 <i>detail</i><span class="roman"> field are </span><b>NotifyAncestor</b><span class="roman"> and </span><b>NotifyVirtual</b>.
154 </p>
155 <span id="Keywords-20"></span><h4 class="unnumberedsubsec">Keywords</h4>
156 <p>events, focus, keyboard, top-level, window manager
157 </p><hr>
158 <div class="header">
159 <p>
160 Next: <a href="grab.html" accesskey="n" rel="next">grab</a>, Previous: <a href="exit.html" accesskey="p" rel="prev">exit</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> &nbsp; [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
161 </div>
162
163
164
165 </body>
166 </html>