1 /*****************************************************************************
3 * Authors: Michel Eyckmans (MCE) & Stefan De Troch (SDT)
5 * Content: This file is part of version 2.x of xautolock. It implements
6 * the program's core functions.
8 * Please send bug reports etc. to eyckmans@imec.be.
10 * --------------------------------------------------------------------------
12 * Copyright 1990,1992-1999,2001-2002 by Stefan De Troch and Michel Eyckmans.
14 * Versions 2.0 and above of xautolock are available under version 2 of the
15 * GNU GPL. Earlier versions are available under other conditions. For more
16 * information, see the License file.
18 *****************************************************************************/
20 #include "xautolock_c.h"
23 * Function for monitoring pointer movements. This implements the
24 * `corners' feature and as a side effect also tracks pointer
25 * related user activity. The latter actually is only needed when
26 * we're using the DIY mode of operations, but it's much simpler
27 * to do it unconditionally.
30 xautolock_queryPointer (Display
* d
)
32 Window dummyWin
; /* as it says */
33 int dummyInt
; /* as it says */
34 unsigned mask
; /* modifier mask */
35 int rootX
; /* as it says */
36 int rootY
; /* as it says */
37 int corner
; /* corner index */
38 int i
; /* loop counter */
39 static Window root
; /* root window the pointer is on */
40 static Screen
* screen
; /* screen the pointer is on */
41 static unsigned prevMask
= 0; /* as it says */
42 static int prevRootX
= -1; /* as it says */
43 static int prevRootY
= -1; /* as it says */
44 static Bool firstCall
= True
; /* as it says */
52 root
= DefaultRootWindow (d
);
53 screen
= ScreenOfDisplay (d
, DefaultScreen (d
));
57 * Find out whether the pointer has moved. Using XQueryPointer for this
58 * is gross, but it also is the only way never to mess up propagation
61 if (!XQueryPointer (d
, root
, &root
, &dummyWin
, &rootX
, &rootY
,
62 &dummyInt
, &dummyInt
, &mask
))
65 * Pointer has moved to another screen, so let's find out which one.
67 for (i
= -1; ++i
< ScreenCount (d
); )
69 if (root
== RootWindow (d
, i
))
71 screen
= ScreenOfDisplay (d
, i
);
77 if ( rootX
== prevRootX
81 xautolock_corner_t
* corners
= xautolock_corners
;
83 * If the pointer has not moved since the previous call and
84 * is inside one of the 4 corners, we act according to the
85 * contents of the "corners" array.
87 * If rootX and rootY are less than zero, don't lock even if
88 * ca_forceLock is set in the upper-left corner. Why? 'cause
89 * on initial server startup, if (and only if) the pointer is
90 * never moved, XQueryPointer() can return values less than
91 * zero (only some servers, Openwindows 2.0 and 3.0 in
95 rootX
<= cornerSize
&& rootX
>= 0
96 && rootY
<= cornerSize
&& rootY
>= 0)
98 rootX
>= WidthOfScreen (screen
) - cornerSize
- 1
99 && rootY
<= cornerSize
)
102 && rootY
>= HeightOfScreen (screen
) - cornerSize
- 1)
104 rootX
>= WidthOfScreen (screen
) - cornerSize
- 1
105 && rootY
>= HeightOfScreen (screen
) - cornerSize
- 1))
107 switch (corners
[corner
])
111 xautolock_setTrigger( (useRedelay
? cornerRedelay
: cornerDelay
) - 1 );
113 xautolock_setTrigger( 0 );
118 xautolock_resetTriggers ();
121 default: ; /* Makes gcc -Wall shut up. */
122 #endif /* __GNUC__ */
135 xautolock_resetTriggers ();