diff --git a/patches/movetocardinaldir/README.md b/patches/movetocardinaldir/README.md new file mode 100644 index 0000000..42f0d6c --- /dev/null +++ b/patches/movetocardinaldir/README.md @@ -0,0 +1,18 @@ +### Description + +Add the ability to move floating window according to cardinal direction and center. +If gaps needs to be respected, there's a gap patch that needs to be applied after the main patch. + +``` +|u|i|o| +|j|k|l| +|m|,|.| +``` +For example, with the default keybinding, you can move floating window to the east direction by pressing `MODKEY+LOGO+l`. + +### Download +- [git branch](/markus-langgeng/dwl/src/branch/0.7-movetocardinaldir) +- [0.7 movetocardinaldir](/dwl/dwl-patches/raw/branch/main/patches/movetocardinaldir/movetocardinaldir.patch) and [0.7 movetocardinaldir-gaps](/dwl/dwl-patches/raw/branch/main/patches/movetocardinaldir/movetocardinaldir-gaps.patch) + +### Author +- [markus-langgeng](https://codeberg.org/markus-langgeng) diff --git a/patches/movetocardinaldir/movetocardinaldir-gaps.patch b/patches/movetocardinaldir/movetocardinaldir-gaps.patch new file mode 100644 index 0000000..6012882 --- /dev/null +++ b/patches/movetocardinaldir/movetocardinaldir-gaps.patch @@ -0,0 +1,75 @@ +From ae2c1d54a307bdecd876fc4764ff0f25c3f31a5b Mon Sep 17 00:00:00 2001 +From: markus-langgeng +Date: Wed, 2 Apr 2025 15:27:04 +0700 +Subject: [PATCH] Add movetocardinaldir-gaps + +Respect gaps if gaps patch has been applied before +--- + dwl.c | 28 ++++++++++++++-------------- + 1 file changed, 14 insertions(+), 14 deletions(-) + +diff --git a/dwl.c b/dwl.c +index 919c773..dd5d4c8 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -1939,7 +1939,7 @@ movetocardinaldir(const Arg *arg) + { + Client *c = focustop(selmon); + Monitor *m = selmon; +- unsigned int mx, my, mw, mh, h, w; ++ unsigned int mx, my, mw, mh, h, w, e = m->gaps; + int nx, ny; + + if(!(m && arg && arg->v && c && c->isfloating)) { +@@ -1955,35 +1955,35 @@ movetocardinaldir(const Arg *arg) + + switch (arg->i) { + case DIR_NW: +- nx = mx; +- ny = my; ++ nx = mx + gappx*e; ++ ny = my + gappx*e; + break; + case DIR_N: +- nx = (mw - w) / 2; +- ny = my; ++ nx = (mw - w) / 2 + gappx*e; ++ ny = my + gappx*e; + break; + case DIR_NE: +- nx = mw - w; +- ny = my; ++ nx = mw - w - gappx*e; ++ ny = my + gappx*e; + break; + case DIR_E: +- nx = mx + mw - w; ++ nx = mx + mw - w - gappx*e; + ny = (mh - h) / 2 + my; + break; + case DIR_SE: +- nx = mw - w; +- ny = my + mh - h; ++ nx = mw - w - gappx*e; ++ ny = my + mh - h - gappx*e; + break; + case DIR_S: + nx = (mw - w) / 2 + mx; +- ny = my + mh - h; ++ ny = my + mh - h - gappx*e; + break; + case DIR_SW: +- nx = mx; +- ny = my + mh - h; ++ nx = mx + gappx*e; ++ ny = my + mh - h - gappx*e; + break; + case DIR_W: +- nx = mx; ++ nx = mx + gappx*e; + ny = (mh - h) / 2 + my; + break; + case DIR_C: +-- +2.47.2 + diff --git a/patches/movetocardinaldir/movetocardinaldir.patch b/patches/movetocardinaldir/movetocardinaldir.patch new file mode 100644 index 0000000..49e6688 --- /dev/null +++ b/patches/movetocardinaldir/movetocardinaldir.patch @@ -0,0 +1,124 @@ +From a140619d16c410206289e4b4e9937403626b8d01 Mon Sep 17 00:00:00 2001 +From: markus-langgeng +Date: Wed, 2 Apr 2025 15:13:16 +0700 +Subject: [PATCH] add movetocardinaldir + +Add the ability to move floating windows according to cardinal +direction. +--- + config.def.h | 9 ++++++++ + dwl.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 73 insertions(+) + +diff --git a/config.def.h b/config.def.h +index 22d2171..e9e2010 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -148,6 +148,15 @@ static const Key keys[] = { + { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_u, movetocardinaldir, {.i = DIR_NW} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_i, movetocardinaldir, {.i = DIR_N} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_o, movetocardinaldir, {.i = DIR_NE} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_j, movetocardinaldir, {.i = DIR_W} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_k, movetocardinaldir, {.i = DIR_C} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_l, movetocardinaldir, {.i = DIR_E} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_m, movetocardinaldir, {.i = DIR_SW} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_comma, movetocardinaldir, {.i = DIR_S} }, ++ { MODKEY|WLR_MODIFIER_LOGO, XKB_KEY_period, movetocardinaldir, {.i = DIR_SE} }, + TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0), + TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1), + TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2), +diff --git a/dwl.c b/dwl.c +index cf3ef70..003211c 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -84,6 +84,7 @@ + enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ + enum { XDGShell, LayerShell, X11 }; /* client types */ + enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */ ++enum { DIR_N = 1, DIR_NE, DIR_E, DIR_SE, DIR_S, DIR_SW, DIR_W, DIR_NW, DIR_C }; + #ifdef XWAYLAND + enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, + NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ +@@ -308,6 +309,7 @@ static void motionnotify(uint32_t time, struct wlr_input_device *device, double + double sy, double sx_unaccel, double sy_unaccel); + static void motionrelative(struct wl_listener *listener, void *data); + static void moveresize(const Arg *arg); ++static void movetocardinaldir(const Arg *arg); + static void outputmgrapply(struct wl_listener *listener, void *data); + static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test); + static void outputmgrtest(struct wl_listener *listener, void *data); +@@ -1928,6 +1930,68 @@ moveresize(const Arg *arg) + } + } + ++void ++movetocardinaldir(const Arg *arg) ++{ ++ Client *c = focustop(selmon); ++ Monitor *m = selmon; ++ unsigned int mx, my, mw, mh, h, w; ++ int nx, ny; ++ ++ if(!(m && arg && arg->v && c && c->isfloating)) { ++ return; ++ } ++ ++ mx = c->mon->w.x; ++ my = c->mon->w.y; ++ mw = m->w.width; ++ mh = m->w.height; ++ h = c->geom.height; ++ w = c->geom.width; ++ ++ switch (arg->i) { ++ case DIR_NW: ++ nx = mx; ++ ny = my; ++ break; ++ case DIR_N: ++ nx = (mw - w) / 2; ++ ny = my; ++ break; ++ case DIR_NE: ++ nx = mw - w; ++ ny = my; ++ break; ++ case DIR_E: ++ nx = mx + mw - w; ++ ny = (mh - h) / 2 + my; ++ break; ++ case DIR_SE: ++ nx = mw - w; ++ ny = my + mh - h; ++ break; ++ case DIR_S: ++ nx = (mw - w) / 2 + mx; ++ ny = my + mh - h; ++ break; ++ case DIR_SW: ++ nx = mx; ++ ny = my + mh - h; ++ break; ++ case DIR_W: ++ nx = mx; ++ ny = (mh - h) / 2 + my; ++ break; ++ case DIR_C: ++ nx = (mw - w) / 2 + mx; ++ ny = (mh - h) / 2 + my; ++ break; ++ default: ++ return; ++ } ++ ++ resize(c, (struct wlr_box){ .x = nx, .y = ny, .width = c->geom.width, .height = c->geom.height}, 1); ++} + void + outputmgrapply(struct wl_listener *listener, void *data) + { +-- +2.47.2 +