summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorProsperousPotato <ProsperousPotato@users.noreply.github.com>2025-10-07 21:54:33 +0100
committerProsperousPotato <ProsperousPotato@users.noreply.github.com>2025-10-07 21:54:33 +0100
commit2baf22a0d59a19172d975a5b08bbe99184d2ac86 (patch)
tree5d633eb225ec278ea5d5932961ca06710ea8b17f
parent07c18addcc64c7d98799dc83f03f35183a4ca49b (diff)
add move/resize windows with keyboard shortcuts
-rw-r--r--config.h31
-rw-r--r--config.mk2
-rw-r--r--dwm.c64
3 files changed, 92 insertions, 5 deletions
diff --git a/config.h b/config.h
index db1793d..c74cd04 100644
--- a/config.h
+++ b/config.h
@@ -7,7 +7,7 @@
/* appearance */
static const unsigned int borderpx = 3; /* border pixel of windows */
static const unsigned int snap = 12; /* snap pixel */
-static const int refreshrate = 240;
+static const int refreshrate = 120;
static const int swallowfloating = 1; /* 1 means swallow floating windows by default */
static const int mouse_default = 0; /* 1 means enable mouse by default */
static const char col_gray1[] = "#000000";
@@ -21,7 +21,6 @@ static const char *colors[][4] = {
static const char *const autostart[] = {
/* program arguments options null terminator */
-// "st", "-c stfloat -e", "htop", NULL,
"xhidecursor", "", "", NULL,
NULL
};
@@ -83,8 +82,8 @@ static const Key keys[] = {
{ Mod1Mask, XK_space, spawn, SHCMD(TERMINAL" -c stfloat") },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
- { MODKEY, XK_i, incnmaster, {.i = +1 } },
- { MODKEY, XK_u, incnmaster, {.i = -1 } },
+ { MODKEY, XK_minus, incnmaster, {.i = +1 } },
+ { MODKEY, XK_equal, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.01} },
{ MODKEY, XK_l, setmfact, {.f = +0.01} },
{ Mod1Mask, XK_Tab, zoom, {0} },
@@ -117,6 +116,7 @@ static const Key keys[] = {
{ Mod1Mask, XK_Escape, spawn, SHCMD(TERMINAL" -c stfloat -e htop") },
{ MODKEY, XK_x, spawn, SHCMD("xkill") },
{ MODKEY, XK_w, spawn, SHCMD(BROWSER) },
+
#ifdef __linux__
{ MODKEY, XK_s, spawn, SHCMD("steam") },
{ MODKEY|ShiftMask, XK_s, spawn, SHCMD("pkill -9 steam") },
@@ -129,6 +129,7 @@ static const Key keys[] = {
#ifdef __OpenBSD__
{ Mod1Mask, XK_t, spawn, SHCMD(TERMINAL" -c stfloat -e gnuwatch -n 1 transmission-remote -l") },
#endif
+
{ 0, XF86XK_MonBrightnessUp, spawn, SHCMD("xbacklight -inc 10") },
{ 0, XF86XK_MonBrightnessDown, spawn, SHCMD("xbacklight -dec 10") },
{ MODKEY, XK_Print, spawn, SHCMD("maimpick") },
@@ -140,6 +141,28 @@ static const Key keys[] = {
{ MODKEY|ShiftMask, XK_q, search, {.i = 2} },
{ MODKEY, XK_o, togglemouse, {0} },
+
+ { MODKEY, XK_KP_Down, moveresize, {.v = "0x 15y 0w 0h" } },
+ { MODKEY, XK_KP_Up, moveresize, {.v = "0x -15y 0w 0h" } },
+ { MODKEY, XK_KP_Right, moveresize, {.v = "15x 0y 0w 0h" } },
+ { MODKEY, XK_KP_Left, moveresize, {.v = "-15x 0y 0w 0h" } },
+ { MODKEY, XK_KP_Begin, togglefloating, {0} },
+ { MODKEY|ShiftMask, XK_KP_Begin, togglefullscr, {0} },
+
+ { MODKEY, XK_KP_Home, moveresize, {.v = "-15x -15y 0w 0h" } }, /* Diagonal Left && Up */
+ { MODKEY, XK_KP_Prior, moveresize, {.v = "15x -15y 0w 0h" } }, /* Diagonal Right && Up */
+ { MODKEY, XK_KP_End, moveresize, {.v = "-15x 15y 0w 0h" } }, /* Diagonal Left && Down */
+ { MODKEY, XK_KP_Next, moveresize, {.v = "15x 15y 0w 0h" } }, /* Diagonal Right && Down */
+
+ { MODKEY|ShiftMask, XK_KP_Down, moveresize, {.v = "0x 0y 0w 15h" } },
+ { MODKEY|ShiftMask, XK_KP_Up, moveresize, {.v = "0x 0y 0w -15h" } },
+ { MODKEY|ShiftMask, XK_KP_Right, moveresize, {.v = "0x 0y 15w 0h" } },
+ { MODKEY|ShiftMask, XK_KP_Left, moveresize, {.v = "0x 0y -15w 0h" } },
+
+ { MODKEY|ShiftMask, XK_KP_Home, moveresize, {.v = "0x 0y -15w -15h" } }, /* Diagonal Left && Up */
+ { MODKEY|ShiftMask, XK_KP_Prior, moveresize, {.v = "0x 0y 15w -15h" } }, /* Diagonal Right && Up */
+ { MODKEY|ShiftMask, XK_KP_End, moveresize, {.v = "0x 0y -15w 15h" } }, /* Diagonal Left && Down */
+ { MODKEY|ShiftMask, XK_KP_Next, moveresize, {.v = "0x 0y 15w 15h" } }, /* Diagonal Right && Down */
};
/* button definitions */
diff --git a/config.mk b/config.mk
index e655d03..d9903cb 100644
--- a/config.mk
+++ b/config.mk
@@ -28,7 +28,7 @@ LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-r
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
-CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -O3 -march=native ${INCS} ${CPPFLAGS}
+CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -O3 -march=native -mtune=native ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
# Solaris
diff --git a/dwm.c b/dwm.c
index 07623a5..769bddf 100644
--- a/dwm.c
+++ b/dwm.c
@@ -186,6 +186,7 @@ static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
+static void moveresize(const Arg *arg);
static void movemouse(const Arg *arg);
static Client *nexttiled(Client *c);
static void pop(Client *c);
@@ -1127,6 +1128,69 @@ motionnotify(XEvent *e)
}
void
+moveresize(const Arg *arg) {
+ Client *c;
+ c = selmon->sel;
+ int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh;
+ char xAbs, yAbs, wAbs, hAbs;
+ int msx, msy, dx, dy, nmx, nmy;
+ unsigned int dui;
+ Window dummy;
+
+ if (!c || !arg)
+ return;
+ if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
+ return;
+ if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8)
+ return;
+
+ nw = c->w + w;
+ if (wAbs == 'W')
+ nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw;
+
+ nh = c->h + h;
+ if (hAbs == 'H')
+ nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw;
+
+ nx = c->x + x;
+ if (xAbs == 'X') {
+ if (x < selmon->mx)
+ nx = selmon->mx;
+ else if (x > selmon->mx + selmon->mw)
+ nx = selmon->mx + selmon->mw - nw - 2 * c->bw;
+ else
+ nx = x;
+ }
+
+ ny = c->y + y;
+ if (yAbs == 'Y') {
+ if (y < selmon->my)
+ ny = selmon->my;
+ else if (y > selmon->my + selmon->mh)
+ ny = selmon->my + selmon->mh - nh - 2 * c->bw;
+ else
+ ny = y;
+ }
+
+ ox = c->x;
+ oy = c->y;
+ ow = c->w;
+ oh = c->h;
+
+ XRaiseWindow(dpy, c->win);
+ Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui);
+ resize(c, nx, ny, nw, nh, True);
+
+ if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy)
+ {
+ nmx = c->x - ox + c->w - ow;
+ nmy = c->y - oy + c->h - oh;
+ if ((msx + nmx) > c->x && (msy + nmy) > c->y)
+ XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy);
+ }
+}
+
+void
movemouse(const Arg *arg)
{
int x, y, ocx, ocy, nx, ny;