Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / workspace / krunner / xautolock_engine.c
blob3f23db8b7474aecee03cdd1fe2ae2e6ce4edfec8
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"
22 #include <time.h>
25 * Function for querying the idle time from the server.
26 * Only used if the Xscreensaver
27 * extension is present.
29 void
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;
42 else
43 #endif /* HAVE_XSCREENSAVER */
45 d = d; /* shut up */
46 return; /* DIY */
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.
62 void
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 */
82 * Have a guess...
84 if (firstCall)
86 firstCall = False;
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
94 * of pointer events.
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);
107 break;
112 if ( rootX == prevRootX
113 && rootY == prevRootY
114 && mask == prevMask)
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
127 * particular).
129 if ( (corner = 0,
130 rootX <= cornerSize && rootX >= 0
131 && rootY <= cornerSize && rootY >= 0)
132 || (corner++,
133 rootX >= WidthOfScreen (screen) - cornerSize - 1
134 && rootY <= cornerSize)
135 || (corner++,
136 rootX <= cornerSize
137 && rootY >= HeightOfScreen (screen) - cornerSize - 1)
138 || (corner++,
139 rootX >= WidthOfScreen (screen) - cornerSize - 1
140 && rootY >= HeightOfScreen (screen) - cornerSize - 1))
142 now = time (0);
144 switch (corners[corner])
146 case ca_forceLock:
147 #if 0
148 newTrigger = now + (useRedelay ? cornerRedelay : cornerDelay) - 1;
149 #else
150 newTrigger = now;
151 #endif
153 #if 0
154 if (newTrigger < lockTrigger)
156 setLockTrigger (newTrigger - now);
158 #else
159 xautolock_setTrigger( newTrigger );
160 #endif
161 break;
163 case ca_dontLock:
164 xautolock_resetTriggers ();
166 #ifdef __GNUC__
167 default: ; /* Makes gcc -Wall shut up. */
168 #endif /* __GNUC__ */
172 else
174 #if 0
175 useRedelay = False;
176 #endif
177 prevRootX = rootX;
178 prevRootY = rootY;
179 prevMask = mask;
181 xautolock_resetTriggers ();