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/config.def.h b/config.def.h index 18a553f..1a44983 100644 --- a/config.def.h +++ b/config.def.h @@ -930,6 +930,12 @@ static const Key keys[] = { { MODKEY, XK_Up, focusdir, {.i = 2 } }, // up { 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 @@ -1037,8 +1043,8 @@ static const Key keys[] = { { MODKEY|Mod4Mask, XK_backslash, shiftviewclients, { .i = +1 } }, #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 { MODKEY|Mod4Mask|ShiftMask, XK_Left, shiftswaptags, { .i = -1 } }, @@ -1144,8 +1150,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 { MODKEY|ShiftMask, XK_F1, tagall, {.v = "F1"} }, @@ -1184,8 +1190,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|Mod4Mask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, { MODKEY|Mod4Mask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, { MODKEY|Mod4Mask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, 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 90cedf9..410f9b9 100644 --- a/patches.def.h +++ b/patches.def.h @@ -908,6 +908,12 @@ */ #define PERTAGBAR_PATCH 0 +/* 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 + */ +#define PLACEDIR_PATCH 0 + /* This patch lets you change the position of a client in the stack using the mouse. * https://github.com/bakkeby/patches/wiki/placemouse */