1grab(3)               User Contributed Perl Documentation              grab(3)
2
3
4

NAME

6       grab - Confine pointer and keyboard events to a window sub-tree
7

SYNOPSIS

9       $widget->grab
10
11       $widget->grabOption
12

DESCRIPTION

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

BUGS

89       It took an incredibly complex and gross implementation to produce the
90       simple grab effect described above.  Given the current implementation,
91       it isn't safe for applications to use the Xlib grab facilities at all
92       except through the Tk grab procedures.  If applications try to manipu‐
93       late X's grab mechanisms directly, things will probably break.
94
95       If a single process is managing several different Tk applications, only
96       one of those applications can have a local grab for a given display at
97       any given time.  If the applications are in different processes, this
98       restriction doesn't exist.
99

KEYWORDS

101       grab, keyboard events, pointer events, window
102
103
104
105perl v5.8.8                       2008-02-05                           grab(3)
Impressum