Created
December 21, 2023 23:19
-
-
Save p4p1/bd6bea1dc3fe5136e540274e6ddfa36a to your computer and use it in GitHub Desktop.
📠📠📠📠
This file contains 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
/* A dwm patch for integrated gestures */ | |
diff -up a/dwm.c b/dwm.c | |
--- a/dwm.c 2023-12-22 00:16:20.949995056 +0100 | |
+++ b/dwm.c 2023-12-22 00:15:28.729807679 +0100 | |
@@ -149,6 +149,7 @@ static void arrangemon(Monitor *m); | |
static void attach(Client *c); | |
static void attachstack(Client *c); | |
static void buttonpress(XEvent *e); | |
+static void buttonrelease(XEvent *e); | |
static void checkotherwm(void); | |
static void cleanup(void); | |
static void cleanupmon(Monitor *mon); | |
@@ -243,8 +244,15 @@ static int bh; /* bar heig | |
static int lrpad; /* sum of left and right padding for text */ | |
static int (*xerrorxlib)(Display *, XErrorEvent *); | |
static unsigned int numlockmask = 0; | |
+static int current_tag = 0; | |
+static int start_x = -1, end_x = -1; | |
+static int start_y = -1, end_y = -1; | |
+static int swiping = 0; | |
+#define SWIPE_THRESHOLD 20 | |
+#define SWIPE_ZONE 100 | |
static void (*handler[LASTEvent]) (XEvent *) = { | |
[ButtonPress] = buttonpress, | |
+ [ButtonRelease] = buttonrelease, | |
[ClientMessage] = clientmessage, | |
[ConfigureRequest] = configurerequest, | |
[ConfigureNotify] = configurenotify, | |
@@ -424,6 +432,12 @@ buttonpress(XEvent *e) | |
Monitor *m; | |
XButtonPressedEvent *ev = &e->xbutton; | |
+ if ((e->xbutton.x < SWIPE_ZONE) || (e->xbutton.x > (sw - SWIPE_ZONE)) || | |
+ (e->xbutton.y < SWIPE_ZONE) || (e->xbutton.y > (sh - SWIPE_ZONE))) { | |
+ start_x = e->xbutton.x; | |
+ start_y = e->xbutton.y; | |
+ swiping = 1; | |
+ } | |
click = ClkRootWin; | |
/* focus monitor if necessary */ | |
if ((m = wintomon(ev->window)) && m != selmon) { | |
@@ -458,6 +472,14 @@ buttonpress(XEvent *e) | |
} | |
void | |
+buttonrelease(XEvent *e) | |
+{ | |
+ start_x = end_x = -1; | |
+ start_y = end_y = -1; | |
+ swiping = 0; | |
+} | |
+ | |
+void | |
checkotherwm(void) | |
{ | |
xerrorxlib = XSetErrorHandler(xerrorstart); | |
@@ -1132,6 +1154,34 @@ motionnotify(XEvent *e) | |
Monitor *m; | |
XMotionEvent *ev = &e->xmotion; | |
+ if (swiping) { | |
+ end_x = e->xmotion.x; | |
+ end_y = e->xmotion.y; | |
+ | |
+ if (end_x - start_x <= -SWIPE_THRESHOLD) { | |
+ swiping = 0; | |
+ end_x = start_x = end_y = start_y = -1; | |
+ if (current_tag < 9) { | |
+ Arg abc = {.ui = (1 << (current_tag))}; | |
+ view(&abc); | |
+ } | |
+ } else if (end_x - start_x >= SWIPE_THRESHOLD) { | |
+ swiping = 0; | |
+ end_x = start_x = end_y = start_y = -1; | |
+ if (current_tag > 1) { | |
+ Arg abc = {.ui = (1 << (current_tag - 2))}; | |
+ view(&abc); | |
+ } | |
+ } else if (end_y - start_y <= -SWIPE_THRESHOLD) { | |
+ printf("bottom to top\n"); | |
+ swiping = 0; | |
+ end_x = start_x = end_y = start_y = -1; | |
+ } else if (end_y - start_y >= SWIPE_THRESHOLD) { | |
+ printf("top to bottom\n"); | |
+ swiping = 0; | |
+ end_x = start_x = end_y = start_y = -1; | |
+ } | |
+ } | |
if (ev->window != root) | |
return; | |
if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { | |
@@ -1606,7 +1656,7 @@ setup(void) | |
wa.cursor = cursor[CurNormal]->cursor; | |
wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask | |
|ButtonPressMask|PointerMotionMask|EnterWindowMask | |
- |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask; | |
+ |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|ButtonReleaseMask; | |
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); | |
XSelectInput(dpy, root, wa.event_mask); | |
grabkeys(); | |
@@ -2053,6 +2103,8 @@ updatewmhints(Client *c) | |
void | |
view(const Arg *arg) | |
{ | |
+ current_tag = 0; | |
+ while (((arg->ui >> current_tag++) & 1) == 0); | |
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) | |
return; | |
selmon->seltags ^= 1; /* toggle sel tagset */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment