aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xdeadzone.c120
1 files changed, 70 insertions, 50 deletions
diff --git a/xdeadzone.c b/xdeadzone.c
index be0ab92..2b38b5e 100644
--- a/xdeadzone.c
+++ b/xdeadzone.c
@@ -245,57 +245,77 @@ int main(int argc, char **argv) {
DBG(printf("awaiting events...\n"));
while(1) {
XNextEvent(d, &ev);
- if(ev.type == VisibilityNotify) {
- XRaiseWindow(d, w);
- XFlush(d);
- }
-
- if(!normal_window && ev.type == ConfigureNotify) {
- XMoveResizeWindow(d, w, x, y, width, height);
- XFlush(d);
- }
- if(ev.type == EnterNotify && !ctrl_and_mod(ev.xcrossing.state)) {
- Window dummy;
- int real_x, real_y;
- XGetWindowAttributes(d, w, &w_attr);
- XTranslateCoordinates(d, w, DefaultRootWindow(d), 0, 0, &real_x, &real_y, &dummy);
-
- DBG(printf("Got EnterNotify, real_x %d, real_y %d, height %d, width %d\n", real_x, real_y, w_attr.height, w_attr.width));
-
- /* Where do we warp the pointer to?
- It would be better if we had a way to find out
- the previous pointer position, so we could know which
- direction it's moving. But, in the specific (but usual) case
- of deadzones in the corner of the screen, the dumb logic
- below is good enough. */
-
- new_x = ev.xcrossing.x_root;
- new_y = ev.xcrossing.y_root;
-
- if(w_attr.height < root_attr.height) {
- /* window is less than full height of the screen, warp vertically */
- if(w_attr.y == 0)
- new_y = real_y + w_attr.height; /* it's at the top, warp down. */
- else
- new_y = real_y - 1; /* it's not at the top, warp up */
- } else {
- /* window *is* full height of the screen, have to warp horizonally */
- if(w_attr.x == 0)
- new_x = real_x + w_attr.width; /* it's at the left edge, warp right */
- else
- new_x = real_x - 1; /* it's not at the left edge, warp left */
- }
-
- DBG(printf(" old X/Y were %d, %d, new X/Y are %d, %d\n",
- ev.xcrossing.x_root, ev.xcrossing.y_root, new_x, new_y));
-
- XWarpPointer(d,
- None,
- DefaultRootWindow(d),
- 0, 0, 0, 0,
- new_x,
- new_y);
+ switch(ev.type) {
+ case VisibilityNotify:
+ /* always on top (even in normal window mode) */
+ XRaiseWindow(d, w);
+ XFlush(d);
+ break;
+
+ case ConfigureNotify:
+ if(!normal_window) {
+ /* this shouldn't be needed, but some WMs might allow moving/resizing
+ the window even though it's override_redirect */
+ XMoveResizeWindow(d, w, x, y, width, height);
+ XFlush(d);
+ }
+ break;
+
+ case EnterNotify: /* meat and potatoes here */
+ if(!ctrl_and_mod(ev.xcrossing.state)) {
+ Window dummy;
+ int real_x, real_y;
+
+ XGetWindowAttributes(d, w, &w_attr);
+ XTranslateCoordinates(d, w, DefaultRootWindow(d), 0, 0, &real_x, &real_y, &dummy);
+
+ DBG(printf("Got EnterNotify, real_x %d, real_y %d, height %d, width %d\n", real_x, real_y, w_attr.height, w_attr.width));
+
+ /* Where do we warp the pointer to?
+ It would be better if we had a way to find out
+ the previous pointer position, so we could know which
+ direction it's moving. But, in the specific (but usual) case
+ of deadzones in the corner of the screen, the dumb logic
+ below is good enough. */
+
+ new_x = ev.xcrossing.x_root;
+ new_y = ev.xcrossing.y_root;
+
+ if(w_attr.height < root_attr.height) {
+ /* window is less than full height of the screen, warp vertically */
+ if(w_attr.y == 0)
+ new_y = real_y + w_attr.height; /* it's at the top, warp down. */
+ else
+ new_y = real_y - 1; /* it's not at the top, warp up */
+ } else {
+ /* window *is* full height of the screen, have to warp horizonally */
+ if(w_attr.x == 0)
+ new_x = real_x + w_attr.width; /* it's at the left edge, warp right */
+ else
+ new_x = real_x - 1; /* it's not at the left edge, warp left */
+ }
+
+ DBG(printf(" old X/Y were %d, %d; new X/Y are %d, %d\n",
+ ev.xcrossing.x_root, ev.xcrossing.y_root, new_x, new_y));
+
+ XWarpPointer(d,
+ None,
+ DefaultRootWindow(d),
+ 0, 0, 0, 0,
+ new_x,
+ new_y);
+ }
+ break;
+
+ case MapNotify:
+ case ReparentNotify:
+ /* ignore these */
+ break;
+
+ default:
+ DBG(printf("got an unexpected XEvent type %d\n", ev.type));
+ break;
}
}