Last active
January 7, 2024 22:39
-
-
Save ortango/7fc896f5b70be56839375745ac502de2 to your computer and use it in GitHub Desktop.
allow pointer action w/o mod key on window borders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/events.c b/src/events.c | |
index 8c9468a..14cfc3b 100644 | |
--- a/src/events.c | |
+++ b/src/events.c | |
@@ -386,11 +386,13 @@ void button_press(xcb_generic_event_t *evt) | |
bool pfm = pointer_follows_monitor; | |
pointer_follows_focus = false; | |
pointer_follows_monitor = false; | |
- replay = !grab_pointer(ACTION_FOCUS) || !swallow_first_click; | |
+ replay = !grab_pointer(ACTION_FOCUS, false) || !swallow_first_click; | |
pointer_follows_focus = pff; | |
pointer_follows_monitor = pfm; | |
+ } else if (cleaned_mask(e->state) == XCB_NONE) { | |
+ replay = !grab_pointer(pointer_actions[i], true); | |
} else { | |
- grab_pointer(pointer_actions[i]); | |
+ grab_pointer(pointer_actions[i], false); | |
} | |
} | |
xcb_allow_events(dpy, replay ? XCB_ALLOW_REPLAY_POINTER : XCB_ALLOW_SYNC_POINTER, e->time); | |
diff --git a/src/pointer.c b/src/pointer.c | |
index a0c5026..5a1b94e 100644 | |
--- a/src/pointer.c | |
+++ b/src/pointer.c | |
@@ -35,6 +35,7 @@ | |
#include "events.h" | |
#include "window.h" | |
#include "pointer.h" | |
+#include "geometry.h" | |
uint16_t num_lock; | |
uint16_t caps_lock; | |
@@ -63,6 +64,8 @@ void window_grab_buttons(xcb_window_t win) | |
} | |
if (pointer_actions[i] != ACTION_NONE) { | |
window_grab_button(win, BUTTONS[i], pointer_modifier); | |
+ //grab for border actions | |
+ window_grab_button(win, BUTTONS[i], XCB_NONE); | |
} | |
} | |
} | |
@@ -203,7 +206,7 @@ resize_handle_t get_handle(node_t *n, xcb_point_t pos, pointer_action_t pac) | |
return rh; | |
} | |
-bool grab_pointer(pointer_action_t pac) | |
+bool grab_pointer(pointer_action_t pac, bool border_only) | |
{ | |
xcb_window_t win = XCB_NONE; | |
xcb_point_t pos; | |
@@ -234,7 +237,22 @@ bool grab_pointer(pointer_action_t pac) | |
} | |
if (loc.node->client->state == STATE_FULLSCREEN) { | |
- return true; | |
+ return !border_only; | |
+ } | |
+ | |
+ if (border_only) { | |
+ bool the_only_window = !loc.monitor->prev && !loc.monitor->next && loc.desktop->root->client; | |
+ if ((borderless_monocle && loc.desktop->layout == LAYOUT_MONOCLE && IS_TILED(loc.node->client)) | |
+ || (borderless_singleton && the_only_window)) { | |
+ return false; | |
+ } | |
+ unsigned int bw = loc.node->client->border_width; | |
+ xcb_rectangle_t rect = get_rectangle(NULL, NULL, loc.node); | |
+ rect.x = rect.x + bw; | |
+ rect.y = rect.y + bw; | |
+ if (is_inside(pos, rect)) { | |
+ return false; | |
+ } | |
} | |
xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(dpy, xcb_grab_pointer(dpy, 0, root, XCB_EVENT_MASK_BUTTON_RELEASE|XCB_EVENT_MASK_BUTTON_MOTION, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_CURRENT_TIME), NULL); | |
diff --git a/src/pointer.h b/src/pointer.h | |
index ba88cfd..c8ecf6a 100644 | |
--- a/src/pointer.h | |
+++ b/src/pointer.h | |
@@ -43,7 +43,7 @@ void grab_buttons(void); | |
void ungrab_buttons(void); | |
int16_t modfield_from_keysym(xcb_keysym_t keysym); | |
resize_handle_t get_handle(node_t *n, xcb_point_t pos, pointer_action_t pac); | |
-bool grab_pointer(pointer_action_t pac); | |
+bool grab_pointer(pointer_action_t pac, bool border_only); | |
void track_pointer(coordinates_t loc, pointer_action_t pac, xcb_point_t pos); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment