Debian Codegraph @

GUITest.pm

raw
1 # X11::GUITest ($Id: GUITest.pm 253 2026-08-19 22:37:51Z ctrondlp $)
2 #
3 # Copyright (c) 2003-2026 Dennis K. Paulsen, All Rights Reserved.
4 # Email: [email protected]
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http\://www.gnu.org/licenses>.
18 #
19 #
20
21 =head1 NAME
22
23 X11::GUITest - Provides GUI testing/interaction routines.
24
25 =head1 VERSION
26
27 0.29
28
29 Updates are made available at the following sites:
30
31 http\://sourceforge.net/projects/x11guitest
32 http\://www.cpan.org
33
34 Please consult 'Changes' for the list of changes between
35 module revisions.
36
37 =head1 DESCRIPTION
38
39 This Perl package is intended to facilitate the testing of GUI applications
40 by means of user emulation. It can be used to test/interact with GUI
41 applications; which have been built upon the X library or toolkits
42 (i.e., GTK+, Xt, Qt, Motif, etc.) that "wrap" the X library's functionality.
43
44 A basic recorder (x11guirecord) is also available, and can be found in
45 the source code repository.
46
47 =head1 DEPENDENCIES
48
49 An X server with the XTest extensions enabled. This seems to be the
50 norm. If it is not enabled, it usually can be by modifying the X
51 server configuration (i.e., XF86Config).
52
53 This module talks to the X server via the standard DISPLAY environment
54 variable, exactly like any other X11 client. By default DISPLAY is
55 usually ":0.0" (the local machine). To target a different X server --
56 for example, one on a remote host -- set DISPLAY before running your
57 script:
58
59 export DISPLAY=<hostname-or-ipaddress>:<display>.<screen>
60
61 Under most circumstances, xhost will also need to be run on the remote
62 host to permit the connection.
63
64 DISPLAY only helps if there is an actual X11 server to point it at. This
65 module requires a real X11 server -- either a native X11 session, or
66 XWayland running as an X11 compatibility layer inside a Wayland session.
67 It cannot function under a pure Wayland session with no XWayland present.
68 See WAYLAND NOTES below for how to diagnose and work around this on a
69 Wayland desktop.
70
71 There is a known incompatibility between the XTest and Xinerama extensions,
72 which causes the XTestFakeMotionEvent() function to misbehave when the
73 Xinerama (X server) extension is active. MoveMouseAbs() has an alternate,
74 XWarpPointer()-based implementation for this case, but it is not enabled by
75 default -- it requires rebuilding with the X11_GUITEST_USING_XINERAMA
76 preprocessor macro defined *in addition to* this module's other defines (a
77 DEFINE= override on the command line replaces the whole value, it does not
78 add to it):
79
80 perl Makefile.PL DEFINE="-DNDEBUG -DX11_GUITEST_ALT_L_FALLBACK_META_L -DX11_GUITEST_USING_XINERAMA"
81 make
82 make install
83
84 Only do this if Xinerama is actually active on the target X server;
85 otherwise leave the module at its default build.
86
87 The optional x11guirecord recorder utility (see 'recorder/' and
88 INSTALLATION below) additionally requires the X server's RECORD extension.
89 This is separate from XTest, and while common, isn't guaranteed to be
90 present/enabled on every X server -- particularly minimal or older
91 commercial X implementations.
92
93 =head1 INSTALLATION
94
95 perl Makefile.PL
96 make
97 make test
98 make install
99
100 # If "make install" fails with a permissions error, see INSTALLATION
101 # NOTES below.
102
103 # If the build has errors, you may need to install the following dependencies:
104 # libxt-dev, libxtst-dev
105
106 # If you'd like to install the recorder, use these steps:
107 cd recorder
108 ./autogen.sh
109 ./configure
110 make
111 make install
112 x11guirecord --help
113
114 # See INSTALLATION NOTES below if this "make install" fails with a
115 # permissions error too.
116
117 # The recorder has its own build-time dependencies, separate from the
118 # above:
119 # autoconf, automake (needed to run autogen.sh)
120 # popt development files (e.g. popt-devel, libpopt-dev)
121 # libX11, libXtst development files, if not already installed
122 # for the main module above
123 #
124 # GNU gettext (libintl.h) is optional -- if it isn't found, the recorder
125 # builds without translation support rather than failing. This is
126 # relevant mainly on AIX and HP-UX, which don't provide GNU gettext
127 # natively.
128
129 =head1 INSTALLATION NOTES
130
131 C<make install> writes into your Perl's installation directories (e.g.
132 C<site_perl> under F</usr/lib/perl5> or F</usr/local>). If that location
133 isn't writable by your user -- the common case for a system Perl -- rerun
134 the last step as C<sudo make install>. Perl setups that install to a
135 user-writable location instead (C<local::lib>, perlbrew, plenv, etc.)
136 normally don't need C<sudo>. If you're not sure which applies, try plain
137 C<make install> first and only add C<sudo> if it fails with a permissions
138 error.
139
140 The same applies to the recorder's C<make install> step.
141
142 =head1 SYNOPSIS
143
144 For additional examples, please look under the 'eg/'
145 sub-directory from the installation folder.
146
147 use X11::GUITest qw/
148 StartApp
149 WaitWindowViewable
150 SendKeys
151 /;
152
153 # Start gedit application
154 # Note: The interface for this example application keeps changing.
155 StartApp('gedit');
156
157 # Wait for application window to come up and become viewable.
158 my ($GEditWinId) = WaitWindowViewable('Untitled Document 1');
159 if (!$GEditWinId) {
160 die("Couldn't find gedit window in time!");
161 }
162
163 # Send text to it
164 SendKeys("Hello, how are you?\n");
165
166 # Close Application (Alt-f, q).
167 SendKeys('%(f)q');
168
169 # Handle gedit's Question window if it comes up when closing. Wait
170 # at most 5 seconds for it.
171 if (WaitWindowViewable('Question', undef, 5)) {
172 # Don't Save (Alt-n)
173 SendKeys('%(n)');
174 }
175
176 =head1 WAYLAND NOTES
177
178 Even under XWayland, be aware that Wayland's per-application isolation
179 model prevents synthetic input (sent via the XTest extension, which this
180 module relies on) from reaching native Wayland clients -- only
181 X11/XWayland-rooted windows will respond to it. This is a deliberate
182 security property of the Wayland protocol, not a bug, and there is no
183 compile-time or runtime workaround. See
184 https://www.linuxteck.com/x11-vs-wayland/ for background on the X11 vs.
185 Wayland input model.
186
187 On a Wayland session (check with 'echo $XDG_SESSION_TYPE'), most
188 applications default to running as native Wayland clients, invisible to
189 this module no matter what DISPLAY is set to. Forcing a specific
190 application through XWayland instead is usually enough to fix that.
191 Which environment variable to set depends on the GUI toolkit the target
192 application is built with:
193
194 Toolkit Variable to set Example
195 ------- --------------- -------
196 GTK (GNOME, etc.) GDK_BACKEND=x11 GDK_BACKEND=x11 gedit &
197 Qt / KDE Plasma QT_QPA_PLATFORM=xcb QT_QPA_PLATFORM=xcb dolphin &
198
199 Two gotchas that can make this appear not to work, regardless of toolkit:
200
201 =over 8
202
203 =item *
204
205 Many apps use single-instance activation (GTK's GApplication or KDE's
206 KDBusService, both implemented over D-Bus). If the application is already
207 running, a new invocation with the variable set just signals the existing
208 (Wayland) process to open a window -- it does not start a new, X11-backed
209 process. Fully quit the application first (i.e., confirm no process is
210 running), then relaunch it.
211
212 =item *
213
214 Flatpak-packaged applications (increasingly the default for some apps on
215 Fedora) do not automatically inherit environment variables from the host
216 shell. Use 'flatpak run --env=GDK_BACKEND=x11 <app-id>' (substitute
217 QT_QPA_PLATFORM=xcb for Qt/KDE apps) instead of GDK_BACKEND=x11 <app> &,
218 and use 'flatpak list --app' to find the app id if it's not obvious from
219 the command name.
220
221 =back
222
223 If neither works, or you need this reliably for many applications, the
224 more robust fix is a session-level one: log out and choose an X11 session
225 at the login screen, if your desktop still offers one -- e.g. "GNOME on
226 Xorg" or "Plasma (X11)" (some recent GNOME/Fedora releases have deprecated
227 or removed that option).
228
229 =cut
230
231 package X11::GUITest;
232
233 use strict;
234 use warnings;
235 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
236
237 require Exporter;
238 require DynaLoader;
239 #require AutoLoader;
240
241 @ISA = qw(Exporter DynaLoader);
242 # Items to export into callers namespace by default. Note: do not export
243 # names by default without a very good reason. Use EXPORT_OK instead.
244 # Do not simply export all your public functions/methods/constants.
245 @EXPORT = qw(
246
247 );
248
249 @EXPORT_OK = qw(
250 ClickMouseButton
251 ClickWindow
252 DefaultScreen
253 FindWindowLike
254 GetChildWindows
255 GetEventSendDelay
256 GetInputFocus
257 GetKeySendDelay
258 GetMousePos
259 GetParentWindow
260 GetRootWindow
261 GetScreenDepth
262 GetScreenRes
263 GetWindowFromPoint
264 GetWindowName
265 GetWindowPid
266 GetWindowPos
267 GetWindowsFromPid
268 IconifyWindow
269 IsChild
270 IsKeyPressed
271 IsMouseButtonPressed
272 IsWindow
273 IsWindowCursor
274 IsWindowViewable
275 LowerWindow
276 MoveMouseAbs
277 MoveWindow
278 PressKey
279 PressMouseButton
280 PressReleaseKey
281 QSfSK
282 QuoteStringForSendKeys
283 RaiseWindow
284 ReleaseKey
285 ReleaseMouseButton
286 ResizeWindow
287 RunApp
288 ScreenCount
289 SendKeys
290 SetEventSendDelay
291 SetInputFocus
292 SetKeySendDelay
293 SetWindowName
294 StartApp
295 UnIconifyWindow
296 WaitSeconds
297 WaitWindowClose
298 WaitWindowLike
299 WaitWindowViewable
300 );
301
302 # Tags (\:ALL, etc.)
303 %EXPORT_TAGS = (
304 'ALL' => \@EXPORT_OK,
305 'CONST' => [qw(DEF_WAIT M_LEFT M_MIDDLE M_RIGHT M_UP M_DOWN M_BTN1 M_BTN2 M_BTN3 M_BTN4 M_BTN5 XC_X_CURSOR XC_ARROW XC_BASED_ARROW_DOWN XC_BASED_ARROW_UP XC_BOAT XC_BOGOSITY XC_BOTTOM_LEFT_CORNER XC_BOTTOM_RIGHT_CORNER XC_BOTTOM_SIDE XC_BOTTOM_TEE XC_BOX_SPIRAL XC_CENTER_PTR XC_CIRCLE XC_CLOCK XC_COFFEE_MUG XC_CROSS XC_CROSS_REVERSE XC_CROSSHAIR XC_DIAMOND_CROSS XC_DOT XC_DOTBOX XC_DOUBLE_ARROW XC_DRAFT_LARGE XC_DRAFT_SMALL XC_DRAPED_BOX XC_EXCHANGE XC_FLEUR XC_GOBBLER XC_GUMBY XC_HAND1 XC_HAND2 XC_HEART XC_ICON XC_IRON_CROSS XC_LEFT_PTR XC_LEFT_SIDE XC_LEFT_TEE XC_LEFTBUTTON XC_LL_ANGLE XC_LR_ANGLE XC_MAN XC_MIDDLEBUTTON XC_MOUSE XC_PENCIL XC_PIRATE XC_PLUS XC_QUESTION_ARROW XC_RIGHT_PTR XC_RIGHT_SIDE XC_RIGHT_TEE XC_RIGHTBUTTON XC_RTL_LOGO XC_SAILBOAT XC_SB_DOWN_ARROW XC_SB_H_DOUBLE_ARROW XC_SB_LEFT_ARROW XC_SB_RIGHT_ARROW XC_SB_UP_ARROW XC_SB_V_DOUBLE_ARROW XC_SHUTTLE XC_SIZING XC_SPIDER XC_SPRAYCAN XC_STAR XC_TARGET XC_TCROSS XC_TOP_LEFT_ARROW XC_TOP_LEFT_CORNER XC_TOP_RIGHT_CORNER XC_TOP_SIDE XC_TOP_TEE XC_TREK XC_UL_ANGLE XC_UMBRELLA XC_UR_ANGLE XC_WATCH XC_XTERM)],
306 );
307
308 Exporter::export_ok_tags(keys %EXPORT_TAGS);
309
310 $VERSION = '0.29';
311
312 # Module Constants
313 sub DEF_WAIT() { 10; }
314 # Mouse Buttons
315 sub M_BTN1() { 1; }
316 sub M_BTN2() { 2; }
317 sub M_BTN3() { 3; }
318 sub M_BTN4() { 4; }
319 sub M_BTN5() { 5; }
320 sub M_LEFT() { M_BTN1; }
321 sub M_MIDDLE() { M_BTN2; }
322 sub M_RIGHT() { M_BTN3; }
323 sub M_UP() { M_BTN4; }
324 sub M_DOWN() { M_BTN5; }
325 # Cursors
326 sub XC_X_CURSOR() { 0 };
327 sub XC_ARROW() { 2 };
328 sub XC_BASED_ARROW_DOWN() { 4 };
329 sub XC_BASED_ARROW_UP() { 6 };
330 sub XC_BOAT() { 8 };
331 sub XC_BOGOSITY() { 10 };
332 sub XC_BOTTOM_LEFT_CORNER() { 12 };
333 sub XC_BOTTOM_RIGHT_CORNER() { 14 };
334 sub XC_BOTTOM_SIDE() { 16 };
335 sub XC_BOTTOM_TEE() { 18 };
336 sub XC_BOX_SPIRAL() { 20 };
337 sub XC_CENTER_PTR() { 22 };
338 sub XC_CIRCLE() { 24 };
339 sub XC_CLOCK() { 26 };
340 sub XC_COFFEE_MUG() { 28 };
341 sub XC_CROSS() { 30 };
342 sub XC_CROSS_REVERSE() { 32 };
343 sub XC_CROSSHAIR() { 34 };
344 sub XC_DIAMOND_CROSS() { 36 };
345 sub XC_DOT() { 38 };
346 sub XC_DOTBOX() { 40 };
347 sub XC_DOUBLE_ARROW() { 42 };
348 sub XC_DRAFT_LARGE() { 44 };
349 sub XC_DRAFT_SMALL() { 46 };
350 sub XC_DRAPED_BOX() { 48 };
351 sub XC_EXCHANGE() { 50 };
352 sub XC_FLEUR() { 52 };
353 sub XC_GOBBLER() { 54 };
354 sub XC_GUMBY() { 56 };
355 sub XC_HAND1() { 58 };
356 sub XC_HAND2() { 60 };
357 sub XC_HEART() { 62 };
358 sub XC_ICON() { 64 };
359 sub XC_IRON_CROSS() { 66 };
360 sub XC_LEFT_PTR() { 68 };
361 sub XC_LEFT_SIDE() { 70 };
362 sub XC_LEFT_TEE() { 72 };
363 sub XC_LEFTBUTTON() { 74 };
364 sub XC_LL_ANGLE() { 76 };
365 sub XC_LR_ANGLE() { 78 };
366 sub XC_MAN() { 80 };
367 sub XC_MIDDLEBUTTON() { 82 };
368 sub XC_MOUSE() { 84 };
369 sub XC_PENCIL() { 86 };
370 sub XC_PIRATE() { 88 };
371 sub XC_PLUS() { 90 };
372 sub XC_QUESTION_ARROW() { 92 };
373 sub XC_RIGHT_PTR() { 94 };
374 sub XC_RIGHT_SIDE() { 96 };
375 sub XC_RIGHT_TEE() { 98 };
376 sub XC_RIGHTBUTTON() { 100 };
377 sub XC_RTL_LOGO() { 102 };
378 sub XC_SAILBOAT() { 104 };
379 sub XC_SB_DOWN_ARROW() { 106 };
380 sub XC_SB_H_DOUBLE_ARROW() { 108 };
381 sub XC_SB_LEFT_ARROW() { 110 };
382 sub XC_SB_RIGHT_ARROW() { 112 };
383 sub XC_SB_UP_ARROW() { 114 };
384 sub XC_SB_V_DOUBLE_ARROW() { 116 };
385 sub XC_SHUTTLE() { 118 };
386 sub XC_SIZING() { 120 };
387 sub XC_SPIDER() { 122 };
388 sub XC_SPRAYCAN() { 124 };
389 sub XC_STAR() { 126 };
390 sub XC_TARGET() { 128 };
391 sub XC_TCROSS() { 130 };
392 sub XC_TOP_LEFT_ARROW() { 132 };
393 sub XC_TOP_LEFT_CORNER() { 134 };
394 sub XC_TOP_RIGHT_CORNER() { 136 };
395 sub XC_TOP_SIDE() { 138 };
396 sub XC_TOP_TEE() { 140 };
397 sub XC_TREK() { 142 };
398 sub XC_UL_ANGLE() { 144 };
399 sub XC_UMBRELLA() { 146 };
400 sub XC_UR_ANGLE() { 148 };
401 sub XC_WATCH() { 150 };
402 sub XC_XTERM() { 152 };
403
404 # Module Variables
405
406
407 bootstrap X11::GUITest $VERSION;
408
409 =head1 FUNCTIONS
410
411 Parameters enclosed within [] are optional.
412
413 If there are multiple optional parameters available for a function
414 and you would like to specify the last one, for example, you can
415 utilize undef for those parameters you don't specify.
416
417 REGEX in the documentation below denotes an item that is treated as
418 a regular expression. For example, the regex "^OK$" would look for
419 an exact match for the word OK.
420
421
422 =over 8
423
424 =item FindWindowLike TITLEREGEX [, WINDOWIDSTARTUNDER]
425
426 Finds the window Ids of the windows matching the specified title regex.
427 Optionally one can specify the window to start under; which would allow
428 one to constrain the search to child windows of that window.
429
430 An array of window Ids is returned for the matches found. An empty
431 array is returned if no matches were found.
432
433 my @WindowIds = FindWindowLike('gedit');
434 # Only worry about first window found
435 my ($WindowId) = FindWindowLike('gedit');
436
437 =back
438
439 =cut
440
441 my $FindWindowLikeAux =
442 sub {
443 my $titlerx = shift;
444 my $start = shift;
445 my $winname = '';
446 my @wins = ();
447
448 # Match the starting window???
449 $winname = GetWindowName($start);
450 if (defined $winname && $winname =~ /$titlerx/i) {
451 push @wins, $start;
452 }
453
454 # Match a child window?
455 foreach my $child (GetChildWindows($start)) {
456 $winname = GetWindowName($child);
457 if (defined $winname && $winname =~ /$titlerx/i) {
458 push @wins, $child;
459 }
460 }
461 return(@wins);
462 };
463
464 sub FindWindowLike {
465 my $titlerx = shift;
466 my $start = shift;
467
468 if (defined $start) {
469 return &$FindWindowLikeAux($titlerx, $start);
470 }
471 else {
472 my @wins = ();
473 for (my $i = ScreenCount() - 1; $i >= 0 ; --$i) {
474 push @wins, &$FindWindowLikeAux($titlerx,
475 GetRootWindow($i));
476 }
477 return(@wins);
478 }
479 }
480
481
482 =over 8
483
484 =item WaitWindowLike TITLEREGEX [, WINDOWIDSTARTUNDER] [, MAXWAITINSECONDS]
485
486 Waits for a window to come up that matches the specified title regex.
487 Optionally one can specify the window to start under; which would allow
488 one to constrain the search to child windows of that window.
489
490 One can optionally specify an alternative wait amount in seconds. A
491 window will keep being looked for that matches the specified title regex
492 until this amount of time has been reached. The default amount is defined
493 in the DEF_WAIT constant available through the \:CONST export tag.
494
495 If a window is going to be manipulated by input, WaitWindowViewable is the
496 more robust solution to utilize.
497
498 An array of window Ids is returned for the matches found. An empty
499 array is returned if no matches were found.
500
501 my @WindowIds = WaitWindowLike('gedit');
502 # Only worry about first window found
503 my ($WindowId) = WaitWindowLike('gedit');
504
505 WaitWindowLike('gedit') or die("gedit window not found!");
506
507 =back
508
509 =cut
510
511 sub WaitWindowLike {
512 my $titlerx = shift;
513 my $start = shift;
514 my $wait = shift;
515 $wait = DEF_WAIT unless defined $wait;
516
517 require Time::HiRes;
518 my $end_time = Time::HiRes::time() + $wait;
519
520 while (1) {
521 my @found = FindWindowLike($titlerx, $start);
522 if (@found) {
523 return @found; # return actual matches
524 }
525
526 my $remaining = $end_time - Time::HiRes::time();
527 last if $remaining <= 0;
528
529 # Avoid bogging down the system, but don't oversleep the requested
530 # timeout (fractional seconds are supported).
531 my $delay = $remaining < 1 ? $remaining : 1;
532 select(undef, undef, undef, $delay);
533 }
534
535 # Nothing found
536 return ();
537 }
538
539
540 =over 8
541
542 =item WaitWindowViewable TITLEREGEX [, WINDOWIDSTARTUNDER] [, MAXWAITINSECONDS]
543
544 Similar to WaitWindow, but only recognizes windows that are viewable. When GUI
545 applications are started, their window isn't necessarily viewable yet, let alone
546 available for input, so this function is very useful.
547
548 Likewise, this function will only return an array of the matching window Ids for
549 those windows that are viewable. An empty array is returned if no matches were
550 found.
551
552 =back
553
554 =cut
555
556 sub WaitWindowViewable {
557 my $titlerx = shift;
558 my $start = shift;
559 my $wait = shift;
560 $wait = DEF_WAIT unless defined $wait;
561 my @wins = ();
562
563 require Time::HiRes;
564 my $end_time = Time::HiRes::time() + $wait;
565
566 while (1) {
567 # Find windows, but recognize only those that are viewable
568 foreach my $win (FindWindowLike($titlerx, $start)) {
569 if (IsWindowViewable($win)) {
570 push @wins, $win;
571 }
572 }
573 if (@wins) {
574 return(@wins);
575 }
576
577 my $remaining = $end_time - Time::HiRes::time();
578 last if $remaining <= 0;
579
580 # Avoid bogging down the system, but don't oversleep the requested
581 # timeout (fractional seconds are supported).
582 my $delay = $remaining < 1 ? $remaining : 1;
583 select(undef, undef, undef, $delay);
584 }
585
586 # Nothing
587 return(@wins);
588 }
589
590
591 =over 8
592
593 =item WaitWindowClose WINDOWID [, MAXWAITINSECONDS]
594
595 Waits for the specified window to close.
596
597 One can optionally specify an alternative wait amount in seconds. The
598 window will keep being checked to see if it has closed until this amount
599 of time has been reached. The default amount is defined in the DEF_WAIT
600 constant available through the \:CONST export tag.
601
602 zero is returned if window is not gone, non-zero if it is gone.
603
604 =back
605
606 =cut
607
608 sub WaitWindowClose {
609 my $win = shift;
610 my $wait = shift;
611 $wait = DEF_WAIT unless defined $wait;
612
613 require Time::HiRes;
614 my $end_time = Time::HiRes::time() + $wait;
615
616 while (1) {
617 if (not IsWindow($win)) {
618 # Success, window isn't recognized
619 return(1);
620 }
621
622 my $remaining = $end_time - Time::HiRes::time();
623 last if $remaining <= 0;
624
625 # Check approximately twice per second, without exceeding the
626 # requested timeout.
627 my $delay = $remaining < 0.50 ? $remaining : 0.50;
628 select(undef, undef, undef, $delay);
629 }
630
631 # Failure
632 return(0);
633 }
634
635 =over 8
636
637 =item WaitSeconds SECONDS
638
639 Pauses execution for the specified amount of seconds.
640
641 WaitSeconds(0.5); # Wait 1/2 second
642 WaitSeconds(3); # Wait 3 seconds
643
644 =back
645
646 =cut
647
648 sub WaitSeconds {
649 select(undef, undef, undef, shift);
650 }
651
652 =over 8
653
654 =item ClickWindow WINDOWID [, X Offset] [, Y Offset] [, Button]
655
656 Clicks on the specified window with the mouse.
657
658 Optionally one can specify the X offset and Y offset. By default,
659 the top left corner of the window is clicked on, with these two
660 parameters one can specify a different position to be clicked on.
661
662 One can also specify an alternative button. The default button is
663 M_LEFT, but M_MIDDLE and M_RIGHT may be specified too. Also,
664 you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3,
665 M_BTN4, M_BTN5. These are all available through the \:CONST export
666 tag.
667
668 zero is returned on failure, non-zero for success
669
670 =back
671
672 =cut
673
674 sub ClickWindow {
675 my $win = shift;
676 my $x_offset = shift || 0;
677 my $y_offset = shift || 0;
678 my $button = shift || M_LEFT;
679
680 my ($x, $y, $scr);
681 ($x, $y, undef, undef, undef, $scr) = GetWindowPos($win);
682 if (!defined($x) or !defined($y)) {
683 return(0);
684 }
685 if (!MoveMouseAbs($x + $x_offset, $y + $y_offset, $scr)) {
686 return(0);
687 }
688 if (!ClickMouseButton($button)) {
689 return(0);
690 }
691 return(1);
692 }
693
694 =over 8
695
696 =item GetWindowsFromPid PID
697
698 Returns a list of window ids discovered for the specified process id (pid).
699
700 undef is returned on error.
701
702 =back
703
704 =cut
705
706 sub GetWindowsFromPid {
707 my $pid = shift;
708 my @wins = ();
709
710 if (!defined($pid) || $pid !~ /^\d+$/ || $pid <= 0) {
711 return(undef);
712 }
713
714 my @all_wins = FindWindowLike('.*');
715 foreach my $aw (@all_wins) {
716 my $aw_pid = GetWindowPid($aw);
717 if ($aw_pid == $pid) {
718 push @wins, $aw;
719 }
720 }
721 return(@wins);
722 }
723
724 =over 8
725
726 =item GetWindowFromPoint X, Y [, SCREEN]
727
728 Returns the window that is at the specified point. If no screen is given, it
729 is taken from the value given when opening the X display.
730
731 zero is returned if there are no matches (i.e., off screen).
732
733 =back
734
735 =cut
736
737 sub GetWindowFromPoint {
738 my $x = shift;
739 my $y = shift;
740 my $scr = shift;
741 my $lastmatch = 0;
742
743 if ( ! defined $scr) {
744 $scr = DefaultScreen();
745 }
746
747 # Note: Windows are returned in current stacking order, therefore
748 # the last match should be the top-most window.
749 foreach my $win ( GetChildWindows(GetRootWindow($scr)) ) {
750 my ($w_x1, $w_y1, $w_w, $w_h, $w_b) = GetWindowPos($win);
751 # Is window position invalid?
752 if (!defined $w_x1) {
753 next;
754 }
755 my $w_x2 = ($w_x1 + $w_w + ($w_b << 1));
756 my $w_y2 = ($w_y1 + $w_h + ($w_b << 1));
757 # Does window match our point?
758 if ($x >= $w_x1 && $x < $w_x2 && $y >= $w_y1 && $y < $w_y2) {
759 $lastmatch = $win;
760 }
761 }
762 return($lastmatch);
763 }
764
765
766 =over 8
767
768 =item IsChild PARENTWINDOWID, WINDOWID
769
770 Determines if the specified window is a child of the
771 specified parent.
772
773 zero is returned for false, non-zero for true.
774
775 =back
776
777 =cut
778
779 sub IsChild {
780 my $parent = shift;
781 my $win = shift;
782
783 foreach my $child ( GetChildWindows($parent) ) {
784 if ($child == $win && $child != $parent) {
785 return(1);
786 }
787 }
788 return(0);
789 }
790
791
792 =over 8
793
794 =item QuoteStringForSendKeys STRING
795
796 Quotes {} characters in the specified string that would be interpreted
797 as having special meaning if sent to SendKeys directly. This function
798 would be useful if you had a text file in which you wanted to use each
799 line of the file as input to the SendKeys function, but didn't want
800 any special interpretation of the characters in the file.
801
802 Returns the quoted string, undef is returned on error.
803
804 # Quote ~, %, etc. as {~}, {%}, etc for literal use in SendKeys.
805 SendKeys( QuoteStringForSendKeys('Hello: ~%^(){}+#') );
806 SendKeys( QSfSK('#+#') );
807
808 The international AltGr key - modifier character (&) is not escaped by
809 this function. Escape this character manually ("{&}"), if used/needed.
810
811 =back
812
813 =cut
814
815 sub QuoteStringForSendKeys {
816 my $str = shift;
817 if (!defined($str)) {
818 return(undef);
819 }
820
821 # Quote {} special characters (^, %, (, {, etc.)
822 $str =~ s/(\^|\%|\+|\~|\(|\)|\{|\})/\{$1\}/gm;
823
824 return($str);
825 }
826
827 sub QSfSK {
828 return QuoteStringForSendKeys(shift);
829 }
830
831 =over 8
832
833 =item StartApp COMMANDLINE
834
835 Starts a program directly using exec. This function returns after
836 checking that the child process remains running. Useful for starting GUI
837 /applications and then going on to work with them.
838
839 zero is returned on failure, non-zero for success
840
841 StartApp('gedit');
842
843 Environment variable assignments (e.g. GDK_BACKEND=x11, may be needed to
844 force a GTK application through XWayland instead of native Wayland -- see
845 DEPENDENCIES above) can be prefixed onto COMMANDLINE, provided the whole
846 thing is passed as a single string:
847
848 StartApp('GDK_BACKEND=x11 gedit'); # Works.
849 StartApp('GDK_BACKEND=x11', 'gedit'); # Does NOT work.
850
851 =back
852
853 =cut
854
855 sub StartApp {
856 my @cmd = @_;
857 my $pid = fork;
858 if ($pid) {
859 use POSIX qw(WNOHANG);
860 sleep 1;
861 waitpid($pid, WNOHANG) != $pid
862 and kill(0, $pid) == 1
863 and return $pid;
864 } elsif (defined $pid) {
865 use POSIX qw(_exit);
866 # Execute the supplied argument list directly; no shell is invoked.
867 exec @cmd or _exit(1);
868 }
869 return;
870 }
871
872
873 =over 8
874
875 =item RunApp COMMANDLINE
876
877 Uses the shell to execute a program until its completion.
878
879 Return value will be application specific, however -1 is returned
880 to indicate a failure in starting the program.
881
882 RunApp('/work/myapp');
883
884 =back
885
886 =cut
887
888 sub RunApp {
889 my $cmdline = shift;
890 return( system($cmdline) );
891 }
892
893
894 =over 8
895
896 =item ClickMouseButton BUTTON
897
898 Clicks the specified mouse button. Available mouse buttons
899 are: M_LEFT, M_MIDDLE, M_RIGHT, M_DOWN, M_UP. Also, you could
900 use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3,
901 M_BTN4, M_BTN5. These are all available through the \:CONST
902 export tag.
903
904 zero is returned on failure, non-zero for success.
905
906 =back
907
908 =cut
909
910 sub ClickMouseButton {
911 my $button = shift;
912
913 if (!PressMouseButton($button) ||
914 !ReleaseMouseButton($button)) {
915 return(0);
916 }
917 return(1);
918 }
919
920 # Subroutine: INIT
921 # Description: Used to initialize the underlying mechanisms
922 # that this package utilizes.
923 # Note: Perl idiom not to return values for this subroutine.
924 sub INIT {
925 if (!defined($ENV{'AUTOMATED_TESTING'}) || $ENV{'AUTOMATED_TESTING'} ne 1) {
926 InitGUITest();
927 }
928 }
929
930 # Subroutine: END
931 # Description: Used to deinitialize the underlying mechanisms
932 # that this package utilizes.
933 # Note: Perl idiom not to return values for this subroutine.
934 sub END {
935 DeInitGUITest();
936 }
937
938 =over 8
939
940 =item DefaultScreen
941
942 Returns the screen number specified in the X display value used to open the
943 display.
944
945 Leverages the Xlib macro of the same name.
946
947 =back
948
949 =cut
950
951 =over 8
952
953 =item ScreenCount
954
955 Returns the number of screens in the X display specified when opening it.
956
957 Leverages the Xlib macro of the same name.
958
959 =back
960
961 =cut
962
963 =over 8
964
965 =item SetEventSendDelay DELAYINMILLISECONDS
966
967 Sets the milliseconds of delay between events being sent to the
968 X display. It is usually not a good idea to set this to 0.
969
970 Please note that this delay will also affect SendKeys.
971
972 Returns the old delay amount in milliseconds.
973
974 =back
975
976 =cut
977
978 =over 8
979
980 =item GetEventSendDelay
981
982 Returns the current event sending delay amount in milliseconds.
983
984 =back
985
986 =cut
987
988 =over 8
989
990 =item SetKeySendDelay DELAYINMILLISECONDS
991
992 Sets the milliseconds of delay between keystrokes.
993
994 Returns the old delay amount in milliseconds.
995
996 =back
997
998 =cut
999
1000 =over 8
1001
1002 =item GetKeySendDelay
1003
1004 Returns the current keystroke sending delay amount in milliseconds.
1005
1006 =back
1007
1008 =cut
1009
1010 =over 8
1011
1012 =item GetWindowName WINDOWID
1013
1014 Returns the window name for the specified window Id. undef
1015 is returned if name could not be obtained.
1016
1017 # Return the name of the window that has the input focus.
1018 my $WinName = GetWindowName(GetInputFocus());
1019
1020 =back
1021
1022 =cut
1023
1024 =over 8
1025
1026 =item GetWindowPid WINDOWID
1027
1028 Returns the process id (pid) associated with the specified
1029 window. 0 is returned if the pid is not available.
1030
1031 # Return the pid of the window that has the input focus.
1032 my $pid = GetWindowPid(GetInputFocus());
1033
1034 =back
1035
1036 =cut
1037
1038 =over 8
1039
1040 =item SetWindowName WINDOWID, NAME
1041
1042 Sets the window name for the specified window Id.
1043
1044 zero is returned on failure, non-zero for success.
1045
1046 =back
1047
1048 =cut
1049
1050 =over 8
1051
1052 =item GetRootWindow [SCREEN]
1053
1054 Returns the Id of the root window of the screen. This is the top/root level
1055 window that all other windows are under. If no screen is given, it is taken
1056 from the value given when opening the X display.
1057
1058 =back
1059
1060 =cut
1061
1062 =over 8
1063
1064 =item GetChildWindows WINDOWID
1065
1066 Returns an array of the child windows for the specified
1067 window Id. If it detects that the window hierarchy
1068 is in transition, it will wait half a second and try
1069 again.
1070
1071 =back
1072
1073 =cut
1074
1075 =over 8
1076
1077 =item MoveMouseAbs X, Y [, SCREEN]
1078
1079 Moves the mouse cursor to the specified absolute position in the optionally
1080 given screen. If no screen is given, it is taken from the value given when
1081 opening the X display.
1082
1083 Zero is returned on failure, non-zero for success.
1084
1085 =back
1086
1087 =cut
1088
1089 =over 8
1090
1091 =item GetMousePos
1092
1093 Returns an array containing the position and the screen (number) of the mouse
1094 cursor.
1095
1096 my ($x, $y, $scr_num) = GetMousePos();
1097
1098 =back
1099
1100 =cut
1101
1102 =over 8
1103
1104 =item PressMouseButton BUTTON
1105
1106 Presses the specified mouse button. Available mouse buttons
1107 are: M_LEFT, M_MIDDLE, M_RIGHT, M_DOWN, M_UP. Also, you could
1108 use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4,
1109 M_BTN5. These are all available through the \:CONST export tag.
1110
1111 zero is returned on failure, non-zero for success.
1112
1113 =back
1114
1115 =cut
1116
1117 =over 8
1118
1119 =item ReleaseMouseButton BUTTON
1120
1121 Releases the specified mouse button. Available mouse buttons
1122 are: M_LEFT, M_MIDDLE, M_RIGHT, M_DOWN, M_UP. Also, you could
1123 use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4,
1124 M_BTN5. These are all available through the \:CONST export tag.
1125
1126 zero is returned on failure, non-zero for success.
1127
1128 =back
1129
1130 =cut
1131
1132 =over 8
1133
1134 =item SendKeys KEYS
1135
1136 Sends keystrokes to the window that has the input focus.
1137
1138 The keystrokes to send are those specified in KEYS parameter. Some characters
1139 have special meaning, they are:
1140
1141 Modifier Keys:
1142 ^ CTRL
1143 % ALT
1144 + SHIFT
1145 # META
1146 & ALTGR
1147
1148 Other Keys:
1149 ~ ENTER
1150 \n ENTER
1151 \t TAB
1152 ( and ) MODIFIER GROUPING
1153 { and } QUOTE / ESCAPE CHARACTERS
1154
1155 Simply, one can send a text string like so:
1156
1157 SendKeys('Hello, how are you today?');
1158
1159 Parenthesis allow a modifier to work on one or more characters. For example:
1160
1161 SendKeys('%(f)q'); # Alt-f, then press q
1162 SendKeys('%(fa)^(m)'); # Alt-f, Alt-a, Ctrl-m
1163 SendKeys('+(abc)'); # Uppercase ABC using shift modifier
1164 SendKeys('^(+(l))'); # Ctrl-Shift-l
1165 SendKeys('+'); # Press shift
1166
1167 Braces are used to quote special characters, for utilizing aliased key
1168 names, or for special functionality. Multiple characters can be specified
1169 in a brace by space delimiting the entries. Characters can be repeated using
1170 a number that is space delimited after the preceding key.
1171
1172 Quote Special Characters
1173
1174 SendKeys('{{}'); # {
1175 SendKeys('{+}'); # +
1176 SendKeys('{#}'); # #
1177
1178 You can also use QuoteStringForSendKeys (QSfSK) to perform quoting.
1179
1180 Aliased Key Names
1181
1182 SendKeys('{BAC}'); # Backspace
1183 SendKeys('{F1 F2 F3}'); # F1, F2, F3
1184 SendKeys('{TAB 3}'); # Press TAB 3 times
1185 SendKeys('{SPC 3 a b c}'); # Space 3 times, a, b, c
1186
1187 Special Functionality
1188
1189 # Pause execution for 500 milliseconds
1190 SendKeys('{PAUSE 500}');
1191
1192 Combinations
1193
1194 SendKeys('abc+(abc){TAB PAUSE 500}'); # a, b, c, A, B, C, Tab, Pause 500
1195 SendKeys('+({a b c})'); # A, B, C
1196
1197 The following abbreviated key names are currently recognized within a brace set. If you
1198 don't see the desired key, you can still use the unabbreviated name for the key. If you
1199 are unsure of this name, utilize the xev (X event view) tool, press the key you
1200 want and look at the tools output for the name of that key. Names that are in the list
1201 below can be utilized regardless of case. Ones that aren't in this list are going to be
1202 case sensitive and also not abbreviated. For example, using 'xev' you will find that the
1203 name of the backspace key is BackSpace, so you could use {BackSpace} in place of {bac}
1204 if you really wanted to.
1205
1206 Name Action
1207 -------------------
1208 BAC BackSpace
1209 BS BackSpace
1210 BKS BackSpace
1211 BRE Break
1212 CAN Cancel
1213 CAP Caps_Lock
1214 DEL Delete
1215 DOWN Down
1216 END End
1217 ENT Return
1218 ESC Escape
1219 F1 F1
1220 ... ...
1221 F12 F12
1222 HEL Help
1223 HOM Home
1224 INS Insert
1225 LAL Alt_L
1226 LMA Meta_L
1227 LCT Control_L
1228 LEF Left
1229 LSH Shift_L
1230 LSK Super_L
1231 MNU Menu
1232 NUM Num_Lock
1233 PGD Page_Down
1234 PGU Page_Up
1235 PRT Print
1236 RAL Alt_R
1237 RMA Meta_R
1238 RCT Control_R
1239 RIG Right
1240 RSH Shift_R
1241 RSK Super_R
1242 SCR Scroll_Lock
1243 SPA Space
1244 SPC Space
1245 TAB Tab
1246 UP Up
1247
1248 zero is returned on failure, non-zero for success. For configurations (Xvfb)
1249 that don't support Alt_Left, Meta_Left is automatically used in its place.
1250
1251 =back
1252
1253 =cut
1254
1255 =over 8
1256
1257 =item PressKey KEY
1258
1259 Presses the specified key.
1260
1261 One can utilize the abbreviated key names from the table
1262 listed above as outlined in the following example:
1263
1264 # Alt-n
1265 PressKey('LAL'); # Left Alt
1266 PressKey('n');
1267 ReleaseKey('n');
1268 ReleaseKey('LAL');
1269
1270 # Uppercase a
1271 PressKey('LSH'); # Left Shift
1272 PressKey('a');
1273 ReleaseKey('a');
1274 ReleaseKey('LSH');
1275
1276 The ReleaseKey calls in the above example are there to set
1277 both key states back.
1278
1279 zero is returned on failure, non-zero for success.
1280
1281 =back
1282
1283 =cut
1284
1285 =over 8
1286
1287 =item ReleaseKey KEY
1288
1289 Releases the specified key. Normally follows a PressKey call.
1290
1291 One can utilize the abbreviated key names from the table
1292 listed above.
1293
1294 ReleaseKey('n');
1295
1296 zero is returned on failure, non-zero for success.
1297
1298 =back
1299
1300 =cut
1301
1302 =over 8
1303
1304 =item PressReleaseKey KEY
1305
1306 Presses and releases the specified key.
1307
1308 One can utilize the abbreviated key names from the table
1309 listed above.
1310
1311 PressReleaseKey('n');
1312
1313 This function is affected by the key send delay.
1314
1315 zero is returned on failure, non-zero for success.
1316
1317 =back
1318
1319 =cut
1320
1321 =over 8
1322
1323 =item IsKeyPressed KEY
1324
1325 Determines if the specified key is currently being pressed.
1326
1327 You can specify such things as 'bac' or the unabbreviated form 'BackSpace' as
1328 covered in the SendKeys information. Brace forms such as '{bac}' are
1329 unsupported. A '{' is taken literally and letters are case sensitive.
1330
1331 if (IsKeyPressed('esc')) { # Is Escape pressed?
1332 if (IsKeyPressed('a')) { # Is a pressed?
1333 if (IsKeyPressed('A')) { # Is A pressed?
1334
1335 Returns non-zero for true, zero for false.
1336
1337 =back
1338
1339 =cut
1340
1341 =over 8
1342
1343 =item IsMouseButtonPressed BUTTON
1344
1345 Determines if the specified mouse button is currently being pressed.
1346
1347 Available mouse buttons are: M_LEFT, M_MIDDLE, M_RIGHT. Also, you
1348 could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3,
1349 M_BTN4, M_BTN5. These are all available through the \:CONST export
1350 tag.
1351
1352 if (IsMouseButtonPressed(M_LEFT)) { # Is left button pressed?
1353
1354 Returns non-zero for true, zero for false.
1355
1356 =back
1357
1358 =cut
1359
1360 =over 8
1361
1362 =item IsWindow WINDOWID
1363
1364 zero is returned if the specified window Id is not for something
1365 that can be recognized as a window. non-zero is returned if it
1366 looks like a window.
1367
1368 =back
1369
1370 =cut
1371
1372 =over 8
1373
1374 =item IsWindowViewable WINDOWID
1375
1376 zero is returned if the specified window Id is for a window that
1377 isn't viewable. non-zero is returned if the window is viewable.
1378
1379 =back
1380
1381 =cut
1382
1383 =over 8
1384
1385 =item IsWindowCursor WINDOWID, CURSOR
1386
1387 Determines if the specified window has the specified cursor.
1388
1389 zero is returned for false, non-zero for true.
1390
1391 The following cursors are available through the \:CONST export tag.
1392
1393 Name
1394 -------------------
1395 XC_NUM_GLYPHS
1396 XC_X_CURSOR
1397 XC_ARROW
1398 XC_BASED_ARROW_DOWN
1399 XC_BASED_ARROW_UP
1400 XC_BOAT
1401 XC_BOGOSITY
1402 XC_BOTTOM_LEFT_CORNER
1403 XC_BOTTOM_RIGHT_CORNER
1404 XC_BOTTOM_SIDE
1405 XC_BOTTOM_TEE
1406 XC_BOX_SPIRAL
1407 XC_CENTER_PTR
1408 XC_CIRCLE
1409 XC_CLOCK
1410 XC_COFFEE_MUG
1411 XC_CROSS
1412 XC_CROSS_REVERSE
1413 XC_CROSSHAIR
1414 XC_DIAMOND_CROSS
1415 XC_DOT
1416 XC_DOTBOX
1417 XC_DOUBLE_ARROW
1418 XC_DRAFT_LARGE
1419 XC_DRAFT_SMALL
1420 XC_DRAPED_BOX
1421 XC_EXCHANGE
1422 XC_FLEUR
1423 XC_GOBBLER
1424 XC_GUMBY
1425 XC_HAND1
1426 XC_HAND2
1427 XC_HEART
1428 XC_ICON
1429 XC_IRON_CROSS
1430 XC_LEFT_PTR
1431 XC_LEFT_SIDE
1432 XC_LEFT_TEE
1433 XC_LEFTBUTTON
1434 XC_LL_ANGLE
1435 XC_LR_ANGLE
1436 XC_MAN
1437 XC_MIDDLEBUTTON
1438 XC_MOUSE
1439 XC_PENCIL
1440 XC_PIRATE
1441 XC_PLUS
1442 XC_QUESTION_ARROW
1443 XC_RIGHT_PTR
1444 XC_RIGHT_SIDE
1445 XC_RIGHT_TEE
1446 XC_RIGHTBUTTON
1447 XC_RTL_LOGO
1448 XC_SAILBOAT
1449 XC_SB_DOWN_ARROW
1450 XC_SB_H_DOUBLE_ARROW
1451 XC_SB_LEFT_ARROW
1452 XC_SB_RIGHT_ARROW
1453 XC_SB_UP_ARROW
1454 XC_SB_V_DOUBLE_ARROW
1455 XC_SHUTTLE
1456 XC_SIZING
1457 XC_SPIDER
1458 XC_SPRAYCAN
1459 XC_STAR
1460 XC_TARGET
1461 XC_TCROSS
1462 XC_TOP_LEFT_ARROW
1463 XC_TOP_LEFT_CORNER
1464 XC_TOP_RIGHT_CORNER
1465 XC_TOP_SIDE
1466 XC_TOP_TEE
1467 XC_TREK
1468 XC_UL_ANGLE
1469 XC_UMBRELLA
1470 XC_UR_ANGLE
1471 XC_WATCH
1472 XC_XTERM
1473
1474 =back
1475
1476 =cut
1477
1478 =over 8
1479
1480 =item MoveWindow WINDOWID, X, Y
1481
1482 Moves the window to the specified location.
1483
1484 zero is returned on failure, non-zero for success.
1485
1486 =back
1487
1488 =cut
1489
1490 =over 8
1491
1492 =item ResizeWindow WINDOWID, WIDTH, HEIGHT
1493
1494 Resizes the window to the specified size.
1495
1496 zero is returned on failure, non-zero for success.
1497
1498 =back
1499
1500 =cut
1501
1502 =over 8
1503
1504 =item IconifyWindow WINDOWID
1505
1506 Minimizes (Iconifies) the specified window.
1507
1508 zero is returned on failure, non-zero for success.
1509
1510 =back
1511
1512 =cut
1513
1514 =over 8
1515
1516 =item UnIconifyWindow WINDOWID
1517
1518 Unminimizes (UnIconifies) the specified window.
1519
1520 zero is returned on failure, non-zero for success.
1521
1522 =back
1523
1524 =cut
1525
1526 =over 8
1527
1528 =item RaiseWindow WINDOWID
1529
1530 Raises the specified window to the top of the stack, so
1531 that no other windows cover it.
1532
1533 zero is returned on failure, non-zero for success.
1534
1535 =back
1536
1537 =cut
1538
1539 =over 8
1540
1541 =item LowerWindow WINDOWID
1542
1543 Lowers the specified window to the bottom of the stack, so
1544 other existing windows will cover it.
1545
1546 zero is returned on failure, non-zero for success.
1547
1548 =back
1549
1550 =cut
1551
1552 =over 8
1553
1554 =item GetInputFocus
1555
1556 Returns the window that currently has the input focus.
1557
1558 =back
1559
1560 =cut
1561
1562 =over 8
1563
1564 =item SetInputFocus WINDOWID
1565
1566 Sets the specified window to be the one that has the input focus.
1567
1568 zero is returned on failure, non-zero for success.
1569
1570 =back
1571
1572 =cut
1573
1574 =over 8
1575
1576 =item GetWindowPos WINDOWID
1577
1578 Returns an array containing the position information for the specified
1579 window. It also returns size information (including border width) and the
1580 number of the screen where the window resides.
1581
1582 my ($x, $y, $width, $height, $borderWidth, $screen) =
1583 GetWindowPos(GetRootWindow());
1584
1585 =back
1586
1587 =cut
1588
1589 =over 8
1590
1591 =item GetParentWindow WINDOWID
1592
1593 Returns the parent of the specified window.
1594
1595 zero is returned if parent couldn't be determined (i.e., root window).
1596
1597 =back
1598
1599 =cut
1600
1601 =over 8
1602
1603 =item GetScreenDepth [SCREEN]
1604
1605 Returns the color depth for the screen. If no screen is specified, it is taken
1606 from the value given when opening the X display. If the screen (number) is
1607 invalid, -1 will be returned.
1608
1609 Value is represented as bits, i.e. 16.
1610
1611 my $depth = GetScreenDepth();
1612
1613 =back
1614
1615 =cut
1616
1617 =over 8
1618
1619 =item GetScreenRes [SCREEN]
1620
1621 Returns the screen resolution. If no screen is specified, it is taken from the
1622 value given when opening the X display. If the screen (number) is invalid, the
1623 returned list will be empty.
1624
1625 my ($x, $y) = GetScreenRes();
1626
1627 =back
1628
1629 =cut
1630
1631 =head1 OTHER DOCUMENTATION
1632
1633
1634 =begin html
1635
1636 <p>
1637 <a href='../Changes'>Module Changes</a><br>
1638 <a href='CodingStyle'>Coding-Style Guidelines</a><br>
1639 <a href='../ToDo'>ToDo List</a><br>
1640 <a href='Copying'>Copy of the GPL License</a><br>
1641 </p>
1642
1643 =end html
1644
1645
1646 =begin text
1647
1648 Available under the docs sub-directory.
1649 CodingStyle (Coding-Style Guidelines)
1650 Copying (Copy of the GPL License)
1651
1652 =end text
1653
1654 =begin man
1655
1656 Not installed.
1657
1658 =end man
1659
1660
1661 =head1 COPYRIGHT
1662
1663 Copyright(c) 2003-2026 Dennis K. Paulsen, All Rights Reserved. This
1664 program is free software; you can redistribute it and/or modify it
1665 under the terms of the GNU General Public License.
1666
1667 =head1 AUTHOR
1668
1669 Dennis K. Paulsen <[email protected]> (Iowa USA)
1670
1671 =head1 CONTRIBUTORS
1672
1673 Paulo E. Castro <pauloedgarcastro tata gmail.com>
1674
1675 =head1 CREDITS
1676
1677 Thanks to everyone; including those specifically mentioned below for patches,
1678 suggestions, etc.:
1679
1680 David Dick
1681 Alexey Tourbin
1682 Richard Clamp
1683 Gustav Larsson
1684 Nelson D. Caro
1685
1686 =cut
1687
1688
1689 # Autoload methods go after __END__, and are processed by the autosplit program.
1690
1691 # Return success
1692 1;
1693 __END__