aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-02-03 16:26:59 -0500
committerB. Watson <urchlay@slackware.uk>2024-02-03 16:26:59 -0500
commit484a141ecb3e57ca925ab652a049b0c5b4c783c5 (patch)
tree5bcac2cb17af4342f97c2bb8a6f4b3d807045a79
parentf9dc28ec5d5f5dcaad24a62378e2f47795373a34 (diff)
downloadxdeadzone-484a141ecb3e57ca925ab652a049b0c5b4c783c5.tar.gz
Use a switch in the event loop, clean up debug output.
-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;
}
}