beetlebug▾
/

grab

Keeps the pointer events of the application in one widget and its descendants.

grab ?-global? WINDOW
grab SUBCOMMAND ?ARG ...?

Description

While a widget has the grab, a pointer event over a widget outside its tree goes to the grab widget. A dialog uses a grab so that a click on the main window does not reach the widgets of the main window. The application has at most one grab, and a new grab replaces the old one. The grab ends when its widget is destroyed.

grab WINDOW is the same as grab set WINDOW. ztk has local grabs only. -global is accepted and gives a local grab, because a program cannot take the pointer of other programs on Wayland. grab status gives global for such a grab. event generate is not affected by a grab.

Subcommands

SubcommandDescription
grab setGives the grab to a widget.
grab releaseEnds the grab of a widget.
grab currentGives the widget with the grab.
grab statusGives the grab status of a widget: none, local, or global.

Examples

# The click is over `.main`, and it goes to the grab widget `.dlg`.
% frame .dlg -width 20 -height 20
> frame .main -width 20 -height 20
> pack .dlg .main
> update
> bind .dlg <1> {lappend ::got dlg}
> bind .main <1> {lappend ::got main}
> grab .dlg
> set ::got {}
> ztk::inject . press 1 5 25
> ztk::inject . release 1 5 25
> update
> set got
dlg

% grab release .dlg
> set ::got {}
> ztk::inject . press 1 5 25
> ztk::inject . release 1 5 25
> update
> set got
main

Errors

% grab
wrong # args: should be "grab ?-global? window" or "grab option ?arg ...?"
-errorcode NONE

% grab bogus
bad option "bogus": must be current, release, set, or status
-errorcode NONE

% grab .nope
bad window path name ".nope"
-errorcode NONE

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also