diff --git a/README.md b/README.md index 38741c0..2fd4bf1 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 ### Changelog: +2024-01-31 - Added the placedir patch + 2023-12-22 - Added the do-not-die-on-color-allocation-failure patch 2023-12-01 - Added the sendmoncenter patch @@ -601,6 +603,9 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 - [pertag](https://dwm.suckless.org/patches/pertag/) - adds nmaster, mfact, layouts and more per tag rather than per monitor + - [placedir](https://github.com/bakkeby/patches/wiki/placedir) + - allows tiled windows to be moved in any direction (up, down, left, right) + - [placemouse](https://github.com/bakkeby/patches/wiki/placemouse) - lets the user change the position of a client in the stack using the mouse. diff --git a/README.org b/README.org index e7b6420..244da90 100644 --- a/README.org +++ b/README.org @@ -123,6 +123,7 @@ - [[#only-one-rule-match][Only One Rule Match]] - [[#only-quit-on-empty][Only Quit On Empty]] - [[#per-tag][Per Tag]] + - [[#place-direction][Place Direction]] - [[#place-mouse][Place Mouse]] - [[#push][Push]] - [[#renamed-scratchpads][Renamed Scratchpads]] @@ -306,6 +307,8 @@ Browsing patches? There is a [[https://coggle.it/diagram/X9IiSSM6PTWOM9Wz][map o ** Changelog +2024-01-31 - Added the placedir patch + 2023-12-22 - Added the do-not-die-on-color-allocation-failure patch 2023-12-01 - Added the sendmoncenter patch @@ -835,6 +838,9 @@ Browsing patches? There is a [[https://coggle.it/diagram/X9IiSSM6PTWOM9Wz][map o - [[https://dwm.suckless.org/patches/pertag/][pertag]] - adds nmaster, mfact, layouts and more per tag rather than per monitor + - [[https://github.com/bakkeby/patches/wiki/placedir][placedir]] + - allows tiled windows to be moved in any direction (up, down, left, right) + - [[https://github.com/bakkeby/patches/wiki/placemouse][placemouse]] - lets the user change the position of a client in the stack using the mouse. @@ -2541,6 +2547,16 @@ This controls whether or not to also store bar position on a per tag basis, or l #define PERTAGBAR_PATCH 0 #+END_SRC +*** Place Direction + +Similar to the focusdir patch this patch allow users to move a window in any direction in the tiled stack (up, down, left, right). + +https://github.com/bakkeby/patches/wiki/placedir + +#+BEGIN_SRC c :tangle patches.def.h +#define PLACEDIR_PATCH 0 +#+END_SRC + *** Place Mouse This patch lets you change the position of a client in the stack using the mouse. @@ -4848,6 +4864,13 @@ static const Key keys[] = { { MODKEY, XK_Down, focusdir, {.i = 3 } }, // down #endif // FOCUSDIR_PATCH + #if PLACEDIR_PATCH + { MODKEY|ControlMask, XK_Left, placedir, {.i = 0 } }, // left + { MODKEY|ControlMask, XK_Right, placedir, {.i = 1 } }, // right + { MODKEY|ControlMask, XK_Up, placedir, {.i = 2 } }, // up + { MODKEY|ControlMask, XK_Down, placedir, {.i = 3 } }, // down + #endif // PLACEDIR_PATCH + #if SWAPFOCUS_PATCH && PERTAG_PATCH { MODKEY, XK_s, swapfocus, {.i = -1 } }, #endif // SWAPFOCUS_PATCH @@ -4978,8 +5001,8 @@ static const Key keys[] = { #endif // SHIFTVIEW_CLIENTS_PATCH #if SHIFTBOTH_PATCH - { MODKEY|ControlMask, XK_Left, shiftboth, { .i = -1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoleft - { MODKEY|ControlMask, XK_Right, shiftboth, { .i = +1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoright + { MODKEY|ControlMask, XK_Left, shiftboth, { .i = -1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoleft placedir + { MODKEY|ControlMask, XK_Right, shiftboth, { .i = +1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoright placedir #endif // SHIFTBOTH_PATCH #if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH @@ -5117,8 +5140,8 @@ static const Key keys[] = { { MODKEY, XK_Right, viewtoright, {0} }, // note keybinding conflict with focusdir { MODKEY|ShiftMask, XK_Left, tagtoleft, {0} }, // note keybinding conflict with shifttag { MODKEY|ShiftMask, XK_Right, tagtoright, {0} }, // note keybinding conflict with shifttag - { MODKEY|ControlMask, XK_Left, tagandviewtoleft, {0} }, - { MODKEY|ControlMask, XK_Right, tagandviewtoright, {0} }, + { MODKEY|ControlMask, XK_Left, tagandviewtoleft, {0} }, // note keybinding conflict with placedir + { MODKEY|ControlMask, XK_Right, tagandviewtoright, {0} }, // note keybinding conflict with placedir #endif // FOCUSADJACENTTAG_PATCH #if TAGALL_PATCH @@ -5163,8 +5186,8 @@ static const Key keys[] = { #if BAR_TAGGRID_PATCH { MODKEY|ControlMask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_VIEW } }, { MODKEY|ControlMask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_VIEW } }, - { MODKEY|ControlMask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_VIEW } }, - { MODKEY|ControlMask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_VIEW } }, + { MODKEY|ControlMask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_VIEW } }, // note keybinding conflict with placedir + { MODKEY|ControlMask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_VIEW } }, // note keybinding conflict with placedir { MODKEY|Mod1Mask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, { MODKEY|Mod1Mask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, { MODKEY|Mod1Mask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, diff --git a/config.def.h b/config.def.h index 77469e5..5d3cb60 100644 --- a/config.def.h +++ b/config.def.h @@ -973,6 +973,13 @@ static const Key keys[] = { { MODKEY, XK_Down, focusdir, {.i = 3 } }, // down #endif // FOCUSDIR_PATCH + #if PLACEDIR_PATCH + { MODKEY|ControlMask, XK_Left, placedir, {.i = 0 } }, // left + { MODKEY|ControlMask, XK_Right, placedir, {.i = 1 } }, // right + { MODKEY|ControlMask, XK_Up, placedir, {.i = 2 } }, // up + { MODKEY|ControlMask, XK_Down, placedir, {.i = 3 } }, // down + #endif // PLACEDIR_PATCH + #if SWAPFOCUS_PATCH && PERTAG_PATCH { MODKEY, XK_s, swapfocus, {.i = -1 } }, #endif // SWAPFOCUS_PATCH @@ -1103,8 +1110,8 @@ static const Key keys[] = { #endif // SHIFTVIEW_CLIENTS_PATCH #if SHIFTBOTH_PATCH - { MODKEY|ControlMask, XK_Left, shiftboth, { .i = -1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoleft - { MODKEY|ControlMask, XK_Right, shiftboth, { .i = +1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoright + { MODKEY|ControlMask, XK_Left, shiftboth, { .i = -1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoleft placedir + { MODKEY|ControlMask, XK_Right, shiftboth, { .i = +1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoright placedir #endif // SHIFTBOTH_PATCH #if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH @@ -1242,8 +1249,8 @@ static const Key keys[] = { { MODKEY, XK_Right, viewtoright, {0} }, // note keybinding conflict with focusdir { MODKEY|ShiftMask, XK_Left, tagtoleft, {0} }, // note keybinding conflict with shifttag { MODKEY|ShiftMask, XK_Right, tagtoright, {0} }, // note keybinding conflict with shifttag - { MODKEY|ControlMask, XK_Left, tagandviewtoleft, {0} }, - { MODKEY|ControlMask, XK_Right, tagandviewtoright, {0} }, + { MODKEY|ControlMask, XK_Left, tagandviewtoleft, {0} }, // note keybinding conflict with placedir + { MODKEY|ControlMask, XK_Right, tagandviewtoright, {0} }, // note keybinding conflict with placedir #endif // FOCUSADJACENTTAG_PATCH #if TAGALL_PATCH @@ -1288,8 +1295,8 @@ static const Key keys[] = { #if BAR_TAGGRID_PATCH { MODKEY|ControlMask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_VIEW } }, { MODKEY|ControlMask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_VIEW } }, - { MODKEY|ControlMask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_VIEW } }, - { MODKEY|ControlMask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_VIEW } }, + { MODKEY|ControlMask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_VIEW } }, // note keybinding conflict with placedir + { MODKEY|ControlMask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_VIEW } }, // note keybinding conflict with placedir { MODKEY|Mod1Mask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, { MODKEY|Mod1Mask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, { MODKEY|Mod1Mask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, diff --git a/patch/alttab.c b/patch/alttab.c index f6775d8..59e6dd9 100644 --- a/patch/alttab.c +++ b/patch/alttab.c @@ -21,7 +21,7 @@ alttab() /* redraw tab */ XRaiseWindow(dpy, alttabwin); - drawtab(ntabs, 0, m); + drawalttab(ntabs, 0, m); } void @@ -66,7 +66,7 @@ alttabend() } void -drawtab(int nwins, int first, Monitor *m) +drawalttab(int nwins, int first, Monitor *m) { Client *c; int i, h; @@ -178,7 +178,7 @@ alttabstart(const Arg *arg) i++; } - drawtab(ntabs, 1, m); + drawalttab(ntabs, 1, m); struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 }; diff --git a/patch/alttab.h b/patch/alttab.h index 2951d04..07fed28 100644 --- a/patch/alttab.h +++ b/patch/alttab.h @@ -1,5 +1,5 @@ #include -static void drawtab(int nwins, int first, Monitor *m); +static void drawalttab(int nwins, int first, Monitor *m); static void alttabstart(const Arg *arg); static void alttabend(); diff --git a/patch/include.c b/patch/include.c index 8b58e6a..239e7db 100644 --- a/patch/include.c +++ b/patch/include.c @@ -208,6 +208,9 @@ #if PERTAG_PATCH #include "pertag.c" #endif +#if PLACEDIR_PATCH +#include "placedir.c" +#endif #if PLACEMOUSE_PATCH #include "placemouse.c" #endif diff --git a/patch/include.h b/patch/include.h index 726dfc0..4255b36 100644 --- a/patch/include.h +++ b/patch/include.h @@ -207,6 +207,9 @@ #if PERTAG_PATCH #include "pertag.h" #endif +#if PLACEDIR_PATCH +#include "placedir.h" +#endif #if PLACEMOUSE_PATCH #include "placemouse.h" #endif diff --git a/patch/placedir.c b/patch/placedir.c new file mode 100644 index 0000000..6fdfd63 --- /dev/null +++ b/patch/placedir.c @@ -0,0 +1,96 @@ +void +placedir(const Arg *arg) +{ + Client *s = selmon->sel, *f = NULL, *c, *next, *fprior, *sprior; + + if (!s || s->isfloating) + return; + + unsigned int score = -1; + unsigned int client_score; + int dist; + int dirweight = 20; + + next = s->next; + if (!next) + next = s->mon->clients; + for (c = next; c != s; c = next) { + + next = c->next; + if (!next) + next = s->mon->clients; + + if (!ISVISIBLE(c)) // || HIDDEN(c) + continue; + + switch (arg->i) { + case 0: // left + dist = s->x - c->x - c->w; + client_score = + dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) + + abs(s->y - c->y); + break; + case 1: // right + dist = c->x - s->x - s->w; + client_score = + dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) + + abs(c->y - s->y); + break; + case 2: // up + dist = s->y - c->y - c->h; + client_score = + dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) + + abs(s->x - c->x); + break; + default: + case 3: // down + dist = c->y - s->y - s->h; + client_score = + dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) + + abs(c->x - s->x); + break; + } + + if (((arg->i == 0 || arg->i == 2) && client_score <= score) || client_score < score) { + score = client_score; + f = c; + } + } + + if (f && f != s) { + for (fprior = f->mon->clients; fprior && fprior->next != f; fprior = fprior->next); + for (sprior = s->mon->clients; sprior && sprior->next != s; sprior = sprior->next); + + if (s == fprior) { + next = f->next; + if (sprior) + sprior->next = f; + else + f->mon->clients = f; + f->next = s; + s->next = next; + } else if (f == sprior) { + next = s->next; + if (fprior) + fprior->next = s; + else + s->mon->clients = s; + s->next = f; + f->next = next; + } else { // clients are not adjacent to each other + next = f->next; + f->next = s->next; + s->next = next; + if (fprior) + fprior->next = s; + else + s->mon->clients = s; + if (sprior) + sprior->next = f; + else + f->mon->clients = f; + } + + arrange(f->mon); + } +} diff --git a/patch/placedir.h b/patch/placedir.h new file mode 100644 index 0000000..a2c864a --- /dev/null +++ b/patch/placedir.h @@ -0,0 +1 @@ +static void placedir(const Arg *arg); diff --git a/patches.def.h b/patches.def.h index b8e6f3d..682413d 100644 --- a/patches.def.h +++ b/patches.def.h @@ -241,6 +241,8 @@ #define PERTAGBAR_PATCH 0 +#define PLACEDIR_PATCH 0 + #define PLACEMOUSE_PATCH 1 #define PUSH_PATCH 0