From 7a7df4694b5bd491cb1cc738056b8d1d1c32381c Mon Sep 17 00:00:00 2001 From: celso Date: Mon, 17 Jul 2023 19:11:47 -0300 Subject: [PATCH] added movekeyboard patch --- config.def.h | 4 +++ dwm.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/config.def.h b/config.def.h index 24ca1a6..8ae0651 100644 --- a/config.def.h +++ b/config.def.h @@ -89,6 +89,10 @@ static const Key keys[] = { { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, + { MODKEY|ControlMask, XK_l, movekeyboard_x, {.i = 20}}, + { MODKEY|ControlMask, XK_h, movekeyboard_x, {.i = -20}}, + { MODKEY|ControlMask, XK_j, movekeyboard_y, {.i = 20}}, + { MODKEY|ControlMask, XK_k, movekeyboard_y, {.i = -20}}, { MODKEY, XK_Right, viewnext, {0} }, { MODKEY, XK_Left, viewprev, {0} }, { MODKEY|ShiftMask, XK_Right, tagtonext, {0} }, diff --git a/dwm.c b/dwm.c index d5c2738..7f81cdc 100644 --- a/dwm.c +++ b/dwm.c @@ -182,6 +182,8 @@ static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); static void movemouse(const Arg *arg); +static void movekeyboard_x(const Arg *arg); +static void movekeyboard_y(const Arg *arg); static unsigned int nexttag(void); static Client *nexttiled(Client *c); static void pop(Client *c); @@ -1197,6 +1199,92 @@ nexttag(void) return seltag; } +void +movekeyboard_x(const Arg *arg){ + int ocx, ocy, nx, ny; + Client *c; + Monitor *m; + + if (!(c = selmon->sel)) + return; + + if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ + return; + + restack(selmon); + + ocx = c->x; + ocy = c->y; + + nx = ocx + arg->i; + ny = ocy; + + if (abs(selmon->wx - nx) < snap) + nx = selmon->wx; + else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) + nx = selmon->wx + selmon->ww - WIDTH(c); + + if (abs(selmon->wy - ny) < snap) + ny = selmon->wy; + else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) + ny = selmon->wy + selmon->wh - HEIGHT(c); + + if (!c->isfloating) + togglefloating(NULL); + + if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) + resize(c, nx, ny, c->w, c->h, 1); + + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { + sendmon(c, m); + selmon = m; + focus(NULL); + } +} + +void +movekeyboard_y(const Arg *arg){ + int ocx, ocy, nx, ny; + Client *c; + Monitor *m; + + if (!(c = selmon->sel)) + return; + + if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ + return; + + restack(selmon); + + ocx = c->x; + ocy = c->y; + + nx = ocx; + ny = ocy + arg->i; + + if (abs(selmon->wx - nx) < snap) + nx = selmon->wx; + else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) + nx = selmon->wx + selmon->ww - WIDTH(c); + + if (abs(selmon->wy - ny) < snap) + ny = selmon->wy; + else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) + ny = selmon->wy + selmon->wh - HEIGHT(c); + + if (!c->isfloating) + togglefloating(NULL); + + if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) + resize(c, nx, ny, c->w, c->h, 1); + + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { + sendmon(c, m); + selmon = m; + focus(NULL); + } +} + Client * nexttiled(Client *c) {