Created
February 10, 2021 23:13
-
-
Save jzbor/23cda60ef460fc38037016a364316345 to your computer and use it in GitHub Desktop.
[PATCH] Adding rio-like drawing (requires slop; backported from instantWM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 94a52292929bffe9723178601a542fbb118dccc1 Mon Sep 17 00:00:00 2001 | |
From: jzbor <jzbor@posteo.net> | |
Date: Wed, 10 Feb 2021 23:38:41 +0100 | |
Subject: [PATCH] Adding rio-like drawing (requires slop; backported from instantWM) | |
--- | |
config.def.h | 2 ++ | |
dwm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
2 files changed, 81 insertions(+) | |
diff --git a/config.def.h b/config.def.h | |
index 1c0b587..cc9e851 100644 | |
--- a/config.def.h | |
+++ b/config.def.h | |
@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ | |
static const unsigned int snap = 32; /* snap pixel */ | |
static const int showbar = 1; /* 0 means no bar */ | |
static const int topbar = 1; /* 0 means bottom bar */ | |
+static const char slopstyle[] = "-t 0 -c 0.92,0.85,0.69,0.3"; /* do NOT define -f (format) here */ | |
static const char *fonts[] = { "monospace:size=10" }; | |
static const char dmenufont[] = "monospace:size=10"; | |
static const char col_gray1[] = "#222222"; | |
@@ -94,6 +95,7 @@ static Key keys[] = { | |
TAGKEYS( XK_8, 7) | |
TAGKEYS( XK_9, 8) | |
{ MODKEY|ShiftMask, XK_q, quit, {0} }, | |
+ { MODKEY, XK_s, riodraw, {0} }, | |
}; | |
/* button definitions */ | |
diff --git a/dwm.c b/dwm.c | |
index 4465af1..8be1fdf 100644 | |
--- a/dwm.c | |
+++ b/dwm.c | |
@@ -192,6 +192,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact); | |
static void resizeclient(Client *c, int x, int y, int w, int h); | |
static void resizemouse(const Arg *arg); | |
static void restack(Monitor *m); | |
+static void riodraw(const Arg *arg); | |
static void run(void); | |
static void scan(void); | |
static int sendevent(Client *c, Atom proto); | |
@@ -1369,6 +1370,84 @@ restack(Monitor *m) | |
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | |
} | |
+// drag out an area using slop and resize the selected window to it. | |
+void | |
+riodraw(const Arg *arg) { | |
+ char str[100]; | |
+ int i; | |
+ char strout[100]; | |
+ int dimensions[4]; | |
+ int width, height, x, y; | |
+ char tmpstring[30] = {0}; | |
+ char slopcmd[100] = "slop -f x%xx%yx%wx%hx "; | |
+ int firstchar = 0; | |
+ int counter = 0; | |
+ Monitor *m; | |
+ Client *c; | |
+ | |
+ if (!selmon->sel) | |
+ return; | |
+ strcat(slopcmd, slopstyle); | |
+ FILE *fp = popen(slopcmd, "r"); | |
+ | |
+ while (fgets(str, 100, fp) != NULL) { | |
+ strcat(strout, str); | |
+ } | |
+ | |
+ pclose(fp); | |
+ | |
+ if (strlen(strout) < 6) { | |
+ return; | |
+ } | |
+ | |
+ | |
+ for (i = 0; i < strlen(strout); i++){ | |
+ if(!firstchar) { | |
+ if (strout[i] == 'x') { | |
+ firstchar = 1; | |
+ } | |
+ continue; | |
+ } | |
+ | |
+ if (strout[i] != 'x') { | |
+ tmpstring[strlen(tmpstring)] = strout[i]; | |
+ } else { | |
+ dimensions[counter] = atoi(tmpstring); | |
+ counter++; | |
+ memset(tmpstring,0,strlen(tmpstring)); | |
+ } | |
+ } | |
+ | |
+ x = dimensions[0]; | |
+ y = dimensions[1]; | |
+ width = dimensions[2]; | |
+ height = dimensions[3]; | |
+ | |
+ if (!selmon->sel) | |
+ return; | |
+ | |
+ c = selmon->sel; | |
+ | |
+ if (width > 50 && height > 50 && x > -40 && y > -40 && width < selmon->mw + 40 && height < selmon->mh + 40 && | |
+ (abs(c->w - width) > 20 || abs(c->h - height) > 20 || abs(c->x - x) > 20 || abs(c->y - y) > 20)) { | |
+ if ((m = recttomon(x, y, width, height)) != selmon) { | |
+ sendmon(c, m); | |
+ unfocus(selmon->sel, 0); | |
+ selmon = m; | |
+ focus(NULL); | |
+ } | |
+ | |
+ if (!c->isfloating) | |
+ togglefloating(NULL); | |
+ resizeclient(c, x, y, width - (c->bw * 2), height - (c->bw * 2)); | |
+ arrange(selmon); | |
+ } else { | |
+ fprintf(stderr, "error %s", strout); | |
+ } | |
+ memset(tmpstring,0,strlen(tmpstring)); | |
+} | |
+ | |
+ | |
void | |
run(void) | |
{ | |
-- | |
2.30.0 | |
You can resize and move a window by drawing out the rectangle it should cover.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, sorry for the trouble but can you explain me what this patch does.