X11::Protocol::ChooseWindow -- user click to choose window
use X11::Protocol::ChooseWindow; my $client_window = X11::Protocol::ChooseWindow->choose (X => $X);
This spot of code lets the user click on a toplevel window to choose it, in a similar style to the
The choose is implemented in a similar way to the
xwininfo etc programs. It consists of
GrabPointer() on the root window, wait for a
ButtonRelease from the user, get the frame window from the
ButtonPress event, then the client window under there from
KeyPress events are not used and they go to the focus window in the usual way. This can be good in a command line program since it lets the user press
SIGINT) in an
xterm or similar. Perhaps in the future there could be an option to watch for
Esc to cancel or some such.
A virtual root per
X11::Protocol::WM is used if present. This helps
ChooseWindow work with
amiwm and similar virtual root window managers.
choose() is in class method style with the intention of perhaps in the future having objects of type
X11::Protocol::ChooseWindow holding state and advanced by events supplied by an external main loop.
$window = X11::Protocol::ChooseWindow->choose (key=>value,...)
Read a user button press to choose a toplevel window. The key/value options are as follows,
X => X11::Protocol object display => string ":0:0" etc screen => integer, eg. 0 root => XID of root window time => integer server timestamp event => hashref of event initiating the choose cursor => XID of cursor cursor_glyph => integer glyph for cursor font cursor_name => string name from cursor font
displaygives the server, or the default is to open the
X11::Protocolobject is usual, but sometimes it can make sense to open a new connection just to choose.
screengives the root window to choose on, or the default is the current screen of
$X, which in turn defaults to the screen part of the display name. If there's a window manager virtual root then that's automatically used as necessary.
timeor the time field in
eventis a server timestamp for the
GrabPointer(). This guards against stealing a grab from another client if badly lagged. Omitted or
CurrentTime. In a command line program there might be no initiating event, making
CurrentTimeall that's possible.
cursoretc is the mouse pointer cursor to show during the choose, as a visual indication to the user. The default is a "crosshair".
cursor_glyphare from the usual cursor font. See X11::CursorFont for available names. For example perhaps the "exchange" cursor to choose a window for some sort of swap or flip,
$window = X11::Protocol::ChooseWindow->choose (X => $X, cursor_name => "exchange");
cursorXID can be created by any client as usual. Don't forget to flush if creating a cursor from one connection, so it's ready for use from another.
"Inter-Client Communication Conventions Manual" section "WM_STATE Property" for notes on using
WM_STATE to identify client windows.
Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2017, 2019 Kevin Ryde
X11-Protocol-Other is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
X11-Protocol-Other is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.