dwm-tiledmove-20231210-b731.diff (2197B)
1 From 427c5fef13676179621949f0a8a4036e49d4b74e Mon Sep 17 00:00:00 2001 2 From: Niki <> 3 Date: Sun, 10 Dec 2023 00:29:59 +0000 4 Subject: [PATCH] The function `movemouse` now doesn't force clients to be 5 floating. 6 7 Tiling clients when moved will swap with any existing clients that 8 overlap with the cursor, and snap to other monitors. 9 --- 10 dwm.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 11 1 file changed, 53 insertions(+), 3 deletions(-) 12 13 diff --git a/dwm.c b/dwm.c 14 index d12be2d..b1023e0 100644 15 --- a/dwm.c 16 +++ b/dwm.c 17 @@ -1189,11 +1189,60 @@ movemouse(const Arg *arg) 18 ny = selmon->wy; 19 else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) 20 ny = selmon->wy + selmon->wh - HEIGHT(c); 21 - if (!c->isfloating && selmon->lt[selmon->sellt]->arrange 22 - && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) 23 - togglefloating(NULL); 24 if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) 25 resize(c, nx, ny, c->w, c->h, 1); 26 + else if (selmon->lt[selmon->sellt]->arrange || !c->isfloating) { 27 + if ((m = recttomon(ev.xmotion.x_root, ev.xmotion.y_root, 1, 1)) != selmon) { 28 + sendmon(c, m); 29 + selmon = m; 30 + focus(NULL); 31 + } 32 + 33 + Client *cc = c->mon->clients; 34 + while (1) { 35 + if (cc == 0) break; 36 + if( 37 + cc != c && !cc->isfloating && ISVISIBLE(cc) && 38 + ev.xmotion.x_root > cc->x && 39 + ev.xmotion.x_root < cc->x + cc->w && 40 + ev.xmotion.y_root > cc->y && 41 + ev.xmotion.y_root < cc->y + cc->h ) { 42 + break; 43 + } 44 + 45 + cc = cc->next; 46 + } 47 + 48 + if (cc) { 49 + Client *cl1, *cl2, ocl1; 50 + 51 + if (!selmon->lt[selmon->sellt]->arrange) return; 52 + 53 + cl1 = c; 54 + cl2 = cc; 55 + ocl1 = *cl1; 56 + strcpy(cl1->name, cl2->name); 57 + cl1->win = cl2->win; 58 + cl1->x = cl2->x; 59 + cl1->y = cl2->y; 60 + cl1->w = cl2->w; 61 + cl1->h = cl2->h; 62 + 63 + cl2->win = ocl1.win; 64 + strcpy(cl2->name, ocl1.name); 65 + cl2->x = ocl1.x; 66 + cl2->y = ocl1.y; 67 + cl2->w = ocl1.w; 68 + cl2->h = ocl1.h; 69 + 70 + selmon->sel = cl2; 71 + 72 + c = cc; 73 + focus(c); 74 + 75 + arrange(cl1->mon); 76 + } 77 + } 78 break; 79 } 80 } while (ev.type != ButtonRelease); 81 -- 82 2.43.0 83