pass window regions to given program as stdin

This commit is contained in:
sewn 2023-07-23 08:13:52 +03:00 committed by Stachelbeere1248
parent 71dd023220
commit a559b2f6fe
2 changed files with 29 additions and 0 deletions

View file

@ -127,6 +127,7 @@ static const Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
{ MODKEY, XKB_KEY_p, spawn, {.v = menucmd} }, { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
{ MODKEY, XKB_KEY_r, regions, SHCMD("grim -g \"$(slurp)\"") },
{ MODKEY, XKB_KEY_j, focusstack, {.i = +1} }, { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} }, { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} }, { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },

28
dwl.c
View file

@ -355,6 +355,7 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface, static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny); Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
static void regions(const Arg *arg);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
@ -3054,6 +3055,33 @@ zoom(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void
regions(const Arg *arg)
{
int pipefd[2];
Client *c;
Monitor *m;
if (pipe(pipefd) == -1)
return;
if (fork() == 0) {
close(pipefd[1]);
dup2(pipefd[0], STDIN_FILENO);
close(pipefd[0]);
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
die("dwl: execvp %s failed:", ((char **)arg->v)[0]);
}
close(pipefd[0]);
wl_list_for_each(m, &mons, link)
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, m))
dprintf(pipefd[1], "%d,%d %dx%d\n",
c->geom.x, c->geom.y, c->geom.width, c->geom.height);
close(pipefd[1]);
}
#ifdef XWAYLAND #ifdef XWAYLAND
void void
activatex11(struct wl_listener *listener, void *data) activatex11(struct wl_listener *listener, void *data)