| 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>grab (GCL TK Manual)</title> |
| 7 |
|
| 8 |
<meta name="description" content="grab (GCL TK Manual)"> |
| 9 |
<meta name="keywords" content="grab (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="tk_002dlistbox_002dsingle_002dselect.html" rel="next" title="tk-listbox-single-select"> |
| 17 |
<link href="focus.html" rel="prev" title="focus"> |
| 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="grab"></span><div class="header"> |
| 42 |
<p> |
| 43 |
Next: <a href="tk_002dlistbox_002dsingle_002dselect.html" accesskey="n" rel="next">tk-listbox-single-select</a>, Previous: <a href="focus.html" accesskey="p" rel="prev">focus</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 44 |
</div> |
| 45 |
<hr> |
| 46 |
<span id="grab-1"></span><h3 class="section">3.7 grab</h3> |
| 47 |
|
| 48 |
<p>grab \- Confine pointer and keyboard events to a window sub-tree |
| 49 |
</p><span id="Synopsis-21"></span><h4 class="unnumberedsubsec">Synopsis</h4> |
| 50 |
<br><p><b>grab </b><span class="roman">?</span><b>:global</b><span class="roman">? </span><i>window</i><!-- /@w --><br> |
| 51 |
<b>grab </b><i>option </i><span class="roman">?arg arg </span>...? |
| 52 |
</p> |
| 53 |
<span id="Description-18"></span><h4 class="unnumberedsubsec">Description</h4> |
| 54 |
|
| 55 |
<p>This command implements simple pointer and keyboard grabs for Tk. |
| 56 |
Tk’s grabs are different than the grabs |
| 57 |
described in the Xlib documentation. |
| 58 |
When a grab is set for a particular window, Tk restricts all pointer |
| 59 |
events to the grab window and its descendants in Tk’s window hierarchy. |
| 60 |
Whenever the pointer is within the grab window’s subtree, the pointer |
| 61 |
will behave exactly the same as if there had been no grab at all |
| 62 |
and all events will be reported in the normal fashion. |
| 63 |
When the pointer is outside <i>window</i>’s tree, button presses and |
| 64 |
releases and |
| 65 |
mouse motion events are reported to <i>window</i>, and window entry |
| 66 |
and window exit events are ignored. |
| 67 |
The grab subtree “owns” the pointer: |
| 68 |
windows outside the grab subtree will be visible on the screen |
| 69 |
but they will be insensitive until the grab is released. |
| 70 |
The tree of windows underneath the grab window can include top-level |
| 71 |
windows, in which case all of those top-level windows |
| 72 |
and their descendants will continue to receive mouse events |
| 73 |
during the grab. |
| 74 |
</p> |
| 75 |
<p>Two forms of grabs are possible: local and global. |
| 76 |
A local grab affects only the grabbing application: events will |
| 77 |
be reported to other applications as if the grab had never occurred. |
| 78 |
Grabs are local by default. |
| 79 |
A global grab locks out all applications on the screen, |
| 80 |
so that only the given subtree of the grabbing application will be |
| 81 |
sensitive to pointer events (mouse button presses, mouse button releases, |
| 82 |
pointer motions, window entries, and window exits). |
| 83 |
During global grabs the window manager will not receive pointer |
| 84 |
events either. |
| 85 |
</p> |
| 86 |
<p>During local grabs, keyboard events (key presses and key releases) |
| 87 |
are delivered as usual: the window |
| 88 |
manager controls which application receives keyboard events, and |
| 89 |
if they are sent to any window in the grabbing application then they are |
| 90 |
redirected to the focus window. |
| 91 |
During a global grab Tk grabs the keyboard so that all keyboard events |
| 92 |
are always sent to the grabbing application. |
| 93 |
The <b>focus</b> command is still used to determine which window in the |
| 94 |
application receives the keyboard events. |
| 95 |
The keyboard grab is released when the grab is released. |
| 96 |
</p> |
| 97 |
<p>Grabs apply to particular displays. If an application has windows |
| 98 |
on multiple displays then it can establish a separate grab on each |
| 99 |
display. |
| 100 |
The grab on a particular display affects only the windows on |
| 101 |
that display. |
| 102 |
It is possible for different applications on a single display to have |
| 103 |
simultaneous local grabs, but only one application can have a global |
| 104 |
grab on a given display at once. |
| 105 |
</p> |
| 106 |
<p>The <b>grab</b> command can take any of the following forms: |
| 107 |
</p> |
| 108 |
<dl compact="compact"> |
| 109 |
<dt><b>grab </b><span class="roman">?</span><b>:global</b><span class="roman">? </span><i>window</i></dt> |
| 110 |
<dd><p>Same as <b>grab :set</b>, described below. |
| 111 |
</p></dd> |
| 112 |
<dt><b>grab :current </b><span class="roman">?</span><i>window</i>?</dt> |
| 113 |
<dd><p>If <i>window</i> is specified, returns the name of the current grab |
| 114 |
window in this application for <i>window</i>’s display, or an empty |
| 115 |
string if there is no such window. |
| 116 |
If <i>window</i> is omitted, the command returns a list whose elements |
| 117 |
are all of the windows grabbed by this application for all displays, |
| 118 |
or an empty string if the application has no grabs. |
| 119 |
</p></dd> |
| 120 |
<dt><b>grab :release </b><i>window</i></dt> |
| 121 |
<dd><p>Releases the grab on <i>window</i> if there is one, otherwise does |
| 122 |
nothing. Returns an empty string. |
| 123 |
</p></dd> |
| 124 |
<dt><b>grab :set </b><span class="roman">?</span><b>:global</b><span class="roman">? </span><i>window</i></dt> |
| 125 |
<dd><p>Sets a grab on <i>window</i><span class="roman">. If </span><b>:global</b> is specified then the |
| 126 |
grab is global, otherwise it is local. |
| 127 |
If a grab was already in effect for this application on |
| 128 |
<i>window</i>’s display then it is automatically released. |
| 129 |
If there is already a grab on <i>window</i> and it has the same |
| 130 |
global/local form as the requested grab, then the command |
| 131 |
does nothing. Returns an empty string. |
| 132 |
</p></dd> |
| 133 |
<dt><b>grab :status </b><i>window</i></dt> |
| 134 |
<dd><p>Returns <b>none</b><span class="roman"> if no grab is currently set on </span><i>window</i>, |
| 135 |
<b>local</b><span class="roman"> if a local grab is set on </span><i>window</i>, and |
| 136 |
<b>global</b> if a global grab is set. |
| 137 |
</p> |
| 138 |
</dd> |
| 139 |
</dl> |
| 140 |
<span id="Bugs-2"></span><h4 class="unnumberedsubsec">Bugs</h4> |
| 141 |
|
| 142 |
<p>It took an incredibly complex and gross implementation to produce |
| 143 |
the simple grab effect described above. |
| 144 |
Given the current implementation, it isn’t safe for applications |
| 145 |
to use the Xlib grab facilities at all except through the Tk grab |
| 146 |
procedures. |
| 147 |
If applications try to manipulate X’s grab mechanisms directly, |
| 148 |
things will probably break. |
| 149 |
</p> |
| 150 |
<p>If a single process is managing several different Tk applications, |
| 151 |
only one of those applications can have a local grab for a given |
| 152 |
display at any given time. If the applications are in different |
| 153 |
processes, this restriction doesn’t exist. |
| 154 |
</p> |
| 155 |
<span id="Keywords-21"></span><h4 class="unnumberedsubsec">Keywords</h4> |
| 156 |
<p>grab, keyboard events, pointer events, window |
| 157 |
</p><hr> |
| 158 |
<div class="header"> |
| 159 |
<p> |
| 160 |
Next: <a href="tk_002dlistbox_002dsingle_002dselect.html" accesskey="n" rel="next">tk-listbox-single-select</a>, Previous: <a href="focus.html" accesskey="p" rel="prev">focus</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 161 |
</div> |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
</body> |
| 166 |
</html> |