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"
25 * Function for querying the idle time from the server.
26 * Only used if the Xscreensaver
27 * extension is present.
30 xautolock_queryIdleTime (Display
* d
)
32 Time idleTime
= 0; /* millisecs since last input event */
34 #ifdef HAVE_XSCREENSAVER
35 if( xautolock_useMit
)
37 static XScreenSaverInfo
* mitInfo
= 0;
38 if (!mitInfo
) mitInfo
= XScreenSaverAllocInfo ();
39 XScreenSaverQueryInfo (d
, DefaultRootWindow (d
), mitInfo
);
40 idleTime
= mitInfo
->idle
;
43 #endif /* HAVE_XSCREENSAVER */
49 if (idleTime
< CHECK_INTERVAL
)
51 xautolock_resetTriggers ();
56 * Function for monitoring pointer movements. This implements the
57 * `corners' feature and as a side effect also tracks pointer
58 * related user activity. The latter actually is only needed when
59 * we're using the DIY mode of operations, but it's much simpler
60 * to do it unconditionally.
63 xautolock_queryPointer (Display
* d
)
65 Window dummyWin
; /* as it says */
66 int dummyInt
; /* as it says */
67 unsigned mask
; /* modifier mask */
68 int rootX
; /* as it says */
69 int rootY
; /* as it says */
70 int corner
; /* corner index */
71 time_t now
; /* as it says */
72 time_t newTrigger
; /* temporary storage */
73 int i
; /* loop counter */
74 static Window root
; /* root window the pointer is on */
75 static Screen
* screen
; /* screen the pointer is on */
76 static unsigned prevMask
= 0; /* as it says */
77 static int prevRootX
= -1; /* as it says */
78 static int prevRootY
= -1; /* as it says */
79 static Bool firstCall
= True
; /* as it says */
87 root
= DefaultRootWindow (d
);
88 screen
= ScreenOfDisplay (d
, DefaultScreen (d
));
92 * Find out whether the pointer has moved. Using XQueryPointer for this
93 * is gross, but it also is the only way never to mess up propagation
96 if (!XQueryPointer (d
, root
, &root
, &dummyWin
, &rootX
, &rootY
,
97 &dummyInt
, &dummyInt
, &mask
))
100 * Pointer has moved to another screen, so let's find out which one.
102 for (i
= -1; ++i
< ScreenCount (d
); )
104 if (root
== RootWindow (d
, i
))
106 screen
= ScreenOfDisplay (d
, i
);
112 if ( rootX
== prevRootX
113 && rootY
== prevRootY
116 xautolock_corner_t
* corners
= xautolock_corners
;
118 * If the pointer has not moved since the previous call and
119 * is inside one of the 4 corners, we act according to the
120 * contents of the "corners" array.
122 * If rootX and rootY are less than zero, don't lock even if
123 * ca_forceLock is set in the upper-left corner. Why? 'cause
124 * on initial server startup, if (and only if) the pointer is
125 * never moved, XQueryPointer() can return values less than
126 * zero (only some servers, Openwindows 2.0 and 3.0 in
130 rootX
<= cornerSize
&& rootX
>= 0
131 && rootY
<= cornerSize
&& rootY
>= 0)
133 rootX
>= WidthOfScreen (screen
) - cornerSize
- 1
134 && rootY
<= cornerSize
)
137 && rootY
>= HeightOfScreen (screen
) - cornerSize
- 1)
139 rootX
>= WidthOfScreen (screen
) - cornerSize
- 1
140 && rootY
>= HeightOfScreen (screen
) - cornerSize
- 1))
144 switch (corners
[corner
])
148 newTrigger
= now
+ (useRedelay
? cornerRedelay
: cornerDelay
) - 1;
154 if (newTrigger
< lockTrigger
)
156 setLockTrigger (newTrigger
- now
);
159 xautolock_setTrigger( newTrigger
);
164 xautolock_resetTriggers ();
167 default: ; /* Makes gcc -Wall shut up. */
168 #endif /* __GNUC__ */
181 xautolock_resetTriggers ();