1grab(n)                      Tk Built-In Commands                      grab(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       grab - Confine pointer and keyboard events to a window sub-tree
9

SYNOPSIS

11       grab ?-global? window
12
13       grab option ?arg arg ...?
14_________________________________________________________________
15
16

DESCRIPTION

18       This command implements simple pointer and keyboard grabs for Tk.  Tk's
19       grabs are different than the grabs described in the Xlib documentation.
20       When  a  grab  is set for a particular window, Tk restricts all pointer
21       events to the grab window and its descendants in Tk's window hierarchy.
22       Whenever  the  pointer is within the grab window's subtree, the pointer
23       will behave exactly the same as if there had been no grab  at  all  and
24       all events will be reported in the normal fashion.  When the pointer is
25       outside window's tree, button presses and  releases  and  mouse  motion
26       events  are reported to window, and window entry and window exit events
27       are ignored. The grab subtree “owns” the pointer: windows  outside  the
28       grab subtree will be visible on the screen but they will be insensitive
29       until the grab is released.  The tree of windows  underneath  the  grab
30       window  can  include top-level windows, in which case all of those top-
31       level windows and their descendants  will  continue  to  receive  mouse
32       events during the grab.
33
34       Two  forms  of  grabs  are  possible:   local and global.  A local grab
35       affects only the grabbing application:   events  will  be  reported  to
36       other  applications as if the grab had never occurred.  Grabs are local
37       by default.  A global grab locks out all applications on the screen, so
38       that  only the given subtree of the grabbing application will be sensi‐
39       tive to pointer events (mouse button presses,  mouse  button  releases,
40       pointer  motions,  window  entries,  and  window exits).  During global
41       grabs the window manager will not receive pointer events either.
42
43       During local grabs, keyboard events (key presses and key releases)  are
44       delivered  as  usual:   the  window  manager controls which application
45       receives keyboard events, and if they are sent to  any  window  in  the
46       grabbing  application  then  they  are  redirected to the focus window.
47       During a global grab Tk grabs the keyboard so that all keyboard  events
48       are  always  sent  to  the  grabbing application.  The focus command is
49       still used to determine which window in the  application  receives  the
50       keyboard  events.   The  keyboard  grab  is  released  when the grab is
51       released.
52
53       Grabs apply to particular displays.  If an application has  windows  on
54       multiple  displays  then  it can establish a separate grab on each dis‐
55       play.  The grab on a particular display affects  only  the  windows  on
56       that  display.   It  is possible for different applications on a single
57       display to have simultaneous local grabs, but only one application  can
58       have a global grab on a given display at once.
59
60       The grab command can take any of the following forms:
61
62       grab ?-global? window
63              Same as grab set, described below.
64
65       grab current ?window?
66              If  window  is  specified,  returns the name of the current grab
67              window in this application for window's  display,  or  an  empty
68              string  if  there  is no such window.  If window is omitted, the
69              command returns a list whose elements are  all  of  the  windows
70              grabbed by this application for all displays, or an empty string
71              if the application has no grabs.
72
73       grab release window
74              Releases the grab on window if  there  is  one,  otherwise  does
75              nothing.  Returns an empty string.
76
77       grab set ?-global? window
78              Sets a grab on window.  If -global is specified then the grab is
79              global, otherwise it is local.  If a grab was already in  effect
80              for  this  application  on window's display then it is automati‐
81              cally released.  If there is already a grab on window and it has
82              the  same global/local form as the requested grab, then the com‐
83              mand does nothing.  Returns an empty string.
84
85       grab status window
86              Returns none if no grab is currently set on window, local  if  a
87              local grab is set on window, and global if a global grab is set.
88

WARNING

90       It  is  very  easy  to  use global grabs to render a display completely
91       unusable (e.g. by setting a grab on a widget which does not respond  to
92       events  and  not providing any mechanism for releasing the grab).  Take
93       extreme care when using them!
94

BUGS

96       It took an incredibly complex and gross implementation to  produce  the
97       simple  grab effect described above.  Given the current implementation,
98       it is not safe for applications to use the Xlib grab facilities at  all
99       except  through the Tk grab procedures.  If applications try to manipu‐
100       late X's grab mechanisms directly, things will probably break.
101
102       If a single process is managing several different Tk applications, only
103       one  of those applications can have a local grab for a given display at
104       any given time.  If the applications are in different  processes,  this
105       restriction does not exist.
106

EXAMPLE

108       Set  a grab so that only one button may be clicked out of a group.  The
109       other buttons are unresponsive to the mouse until the middle button  is
110       clicked.
111              pack [button .b1 -text "Click me! #1" -command {destroy .b1}]
112              pack [button .b2 -text "Click me! #2" -command {destroy .b2}]
113              pack [button .b3 -text "Click me! #3" -command {destroy .b3}]
114              grab .b2
115
116

KEYWORDS

118       grab, keyboard events, pointer events, window
119
120
121
122Tk                                                                     grab(n)
Impressum