add more spacing
[personal-kdebase.git] / workspace / krunner / screensaver / xautolock_engine.c
blobd6d0cf5d49d59d8789aba2901dd71d27d8aa559f
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.
29 void
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 */
47 * Have a guess...
49 if (firstCall)
51 firstCall = False;
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
59 * of pointer events.
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);
72 break;
77 if ( rootX == prevRootX
78 && rootY == prevRootY
79 && mask == prevMask)
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
92 * particular).
94 if ( (corner = 0,
95 rootX <= cornerSize && rootX >= 0
96 && rootY <= cornerSize && rootY >= 0)
97 || (corner++,
98 rootX >= WidthOfScreen (screen) - cornerSize - 1
99 && rootY <= cornerSize)
100 || (corner++,
101 rootX <= cornerSize
102 && rootY >= HeightOfScreen (screen) - cornerSize - 1)
103 || (corner++,
104 rootX >= WidthOfScreen (screen) - cornerSize - 1
105 && rootY >= HeightOfScreen (screen) - cornerSize - 1))
107 switch (corners[corner])
109 case ca_forceLock:
110 #if 0
111 xautolock_setTrigger( (useRedelay ? cornerRedelay : cornerDelay) - 1 );
112 #else
113 xautolock_setTrigger( 0 );
114 #endif
115 break;
117 case ca_dontLock:
118 xautolock_resetTriggers ();
120 #ifdef __GNUC__
121 default: ; /* Makes gcc -Wall shut up. */
122 #endif /* __GNUC__ */
126 else
128 #if 0
129 useRedelay = False;
130 #endif
131 prevRootX = rootX;
132 prevRootY = rootY;
133 prevMask = mask;
135 xautolock_resetTriggers ();