riodraw: upgrading patch to include rio-spawning of windows

This commit is contained in:
bakkeby 2021-02-16 10:26:49 +01:00
parent 009b84cbdc
commit f5bbd9b4c3
4 changed files with 130 additions and 39 deletions

View File

@ -53,7 +53,12 @@ static int floatposgrid_x = 5; /* float grid columns */
static int floatposgrid_y = 5; /* float grid rows */
#endif // FLOATPOS_PATCH
#if RIODRAW_PATCH
static const char slopstyle[] = "-t 0 -c 0.92,0.85,0.69,0.3"; /* do NOT define -f (format) here */
static const char slopspawnstyle[] = "-t 0 -c 0.92,0.85,0.69,0.3 -o"; /* do NOT define -f (format) here */
static const char slopresizestyle[] = "-t 0 -c 0.92,0.85,0.69,0.3"; /* do NOT define -f (format) here */
static const int riodraw_borders = 0; /* 0 or 1, indicates whether the area drawn using slop includes the window borders */
#if SWALLOW_PATCH
static const int riodraw_matchpid = 1; /* 0 or 1, indicates whether to match the PID of the client that was spawned with riospawn */
#endif // SWALLOW_PATCH
#endif // RIODRAW_PATCH
#if BAR_STATUSPADDING_PATCH
static const int horizpadbar = 2; /* horizontal padding for statusbar */
@ -757,6 +762,11 @@ static Key keys[] = {
#endif // KEYMODES_PATCH
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
#if RIODRAW_PATCH
{ MODKEY|ControlMask, XK_p, riospawnsync, {.v = dmenucmd } },
{ MODKEY|ControlMask, XK_Return, riospawn, {.v = termcmd } },
{ MODKEY, XK_s, rioresize, {0} },
#endif // RIODRAW_PATCH
{ MODKEY, XK_b, togglebar, {0} },
#if FOCUSMASTER_PATCH
{ MODKEY|ControlMask, XK_space, focusmaster, {0} },
@ -777,9 +787,6 @@ static Key keys[] = {
#if SWAPFOCUS_PATCH && PERTAG_PATCH
{ MODKEY, XK_s, swapfocus, {.i = -1 } },
#endif // SWAPFOCUS_PATCH
#if RIODRAW_PATCH
{ MODKEY|ControlMask, XK_s, riodraw, {0} },
#endif // RIODRAW_PATCH
#if SWITCHCOL_PATCH
{ MODKEY, XK_v, switchcol, {0} },
#endif // SWITCHCOL_PATCH

51
dwm.c
View File

@ -614,6 +614,9 @@ static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void sigchld(int unused);
static void spawn(const Arg *arg);
#if RIODRAW_PATCH
static pid_t spawncmd(const Arg *arg);
#endif // RIODRAW_PATCH
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void togglebar(const Arg *arg);
@ -684,6 +687,10 @@ static int ignore_warp = 0; // force skip warp in some situations, e.g. dragmfac
#endif // WARP_PATCH
static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0;
#if RIODRAW_PATCH
static int riodimensions[4] = { -1, -1, -1, -1 };
static pid_t riopid = 0;
#endif // RIODRAW_PATCH
static void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress,
#if COMBO_PATCH || BAR_HOLDBAR_PATCH
@ -2293,6 +2300,16 @@ manage(Window w, XWindowAttributes *wa)
c->mon->sel = c;
#if SWALLOW_PATCH
if (!(term && swallow(term, c))) {
#if RIODRAW_PATCH
if (riopid && (!riodraw_matchpid || isdescprocess(riopid, c->pid))) {
if (riodimensions[3] != -1)
rioposition(c, riodimensions[0], riodimensions[1], riodimensions[2], riodimensions[3]);
else {
killclient(&((Arg) { .v = c }));
return;
}
}
#endif // RIODRAW_PATCH
arrange(c->mon);
#if BAR_WINTITLEACTIONS_PATCH
if (!HIDDEN(c))
@ -2302,6 +2319,16 @@ manage(Window w, XWindowAttributes *wa)
#endif // BAR_WINTITLEACTIONS_PATCH
}
#else
#if RIODRAW_PATCH
if (riopid) {
if (riodimensions[3] != -1)
rioposition(c, riodimensions[0], riodimensions[1], riodimensions[2], riodimensions[3]);
else {
killclient(&((Arg) { .v = c }));
return;
}
}
#endif // RIODRAW_PATCH
arrange(c->mon);
#if BAR_WINTITLEACTIONS_PATCH
if (!HIDDEN(c))
@ -3556,9 +3583,23 @@ sigchld(int unused)
#endif // COOL_AUTOSTART_PATCH
}
#if RIODRAW_PATCH
void
spawn(const Arg *arg)
{
spawncmd(arg);
}
pid_t
spawncmd(const Arg *arg)
#else
void
spawn(const Arg *arg)
#endif // RIODRAW_PATCH
{
#if RIODRAW_PATCH
pid_t pid;
#endif // RIODRAW_PATCH
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
char *cmd = NULL;
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
@ -3583,7 +3624,12 @@ spawn(const Arg *arg)
}
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
if (fork() == 0) {
#if RIODRAW_PATCH
if ((pid = fork()) == 0)
#else
if (fork() == 0)
#endif // RIODRAW_PATCH
{
if (dpy)
close(ConnectionNumber(dpy));
#if SPAWNCMD_PATCH
@ -3629,6 +3675,9 @@ spawn(const Arg *arg)
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
free(cmd);
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
#if RIODRAW_PATCH
return pid;
#endif // RIODRAW_PATCH
}
void

View File

@ -1,21 +1,15 @@
/* drag out an area using slop and resize the selected window to it. */
void
riodraw(const Arg *arg)
int
riodraw(Client *c, const char slopstyle[])
{
char str[100];
int i;
char str[100];
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");
@ -25,7 +19,7 @@ riodraw(const Arg *arg)
pclose(fp);
if (strlen(strout) < 6)
return;
return 0;
for (i = 0; i < strlen(strout); i++){
if (!firstchar) {
@ -37,36 +31,73 @@ riodraw(const Arg *arg)
if (strout[i] != 'x')
tmpstring[strlen(tmpstring)] = strout[i];
else {
dimensions[counter] = atoi(tmpstring);
riodimensions[counter] = atoi(tmpstring);
counter++;
memset(tmpstring,0,strlen(tmpstring));
}
}
x = dimensions[0];
y = dimensions[1];
width = dimensions[2];
height = dimensions[3];
if (riodimensions[0] <= -40 || riodimensions[1] <= -40 || riodimensions[2] <= 50 || riodimensions[3] <= 50) {
riodimensions[3] = -1;
return 0;
}
if (!selmon->sel)
return;
if (c) {
rioposition(c, riodimensions[0], riodimensions[1], riodimensions[2], riodimensions[3]);
return 0;
}
c = selmon->sel;
return 1;
}
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, NULL);
selmon = m;
focus(NULL);
}
void
rioposition(Client *c, int x, int y, int w, int h)
{
Monitor *m;
if ((m = recttomon(x, y, w, h)) && m != c->mon) {
detach(c);
detachstack(c);
c->mon = m;
c->tags = m->tagset[m->seltags];
attach(c);
attachstack(c);
selmon = m;
focus(c);
}
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));
c->isfloating = 1;
if (riodraw_borders)
resizeclient(c, x, y, w - (c->bw * 2), h - (c->bw * 2));
else
resizeclient(c, x - c->bw, y - c->bw, w, h);
drawbar(c->mon);
arrange(c->mon);
riodimensions[3] = -1;
riopid = 0;
}
/* drag out an area using slop and resize the selected window to it */
void
rioresize(const Arg *arg)
{
Client *c = (arg && arg->v ? (Client*)arg->v : selmon->sel);
if (c)
riodraw(c, slopresizestyle);
}
/* Spawn a new window and drag out an area using slop to position it while the window is
* initialising in the background. */
void
riospawn(const Arg *arg)
{
riopid = spawncmd(arg);
riodraw(NULL, slopspawnstyle);
}
void
riospawnsync(const Arg *arg)
{
if (riodraw(NULL, slopspawnstyle))
riopid = spawncmd(arg);
}

View File

@ -1 +1,5 @@
static void riodraw(const Arg *arg);
static int riodraw(Client *c, const char slopstyle[]);
static void rioposition(Client *c, int x, int y, int w, int h);
static void rioresize(const Arg *arg);
static void riospawn(const Arg *arg);
static void riospawnsync(const Arg *arg);