applied swallow patch

This commit is contained in:
Aaro Koivukangas
2024-11-22 21:15:48 +02:00
parent 92408d9a59
commit 0a92b6b804
3 changed files with 123 additions and 8 deletions
+107 -5
View File
@@ -106,7 +106,8 @@ typedef struct {
typedef struct Pertag Pertag;
typedef struct Monitor Monitor;
typedef struct {
typedef struct Client Client;
struct Client {
/* Must keep these three elements in this order */
unsigned int type; /* XDGShell or X11* */
struct wlr_box geom; /* layout-relative, includes border */
@@ -141,9 +142,11 @@ typedef struct {
#endif
unsigned int bw;
uint32_t tags;
int isfloating, isurgent, isfullscreen;
int isfloating, isurgent, isfullscreen, isterm, noswallow;
uint32_t resize; /* configure serial of a pending resize */
} Client;
pid_t pid;
Client *swallowing, *swallowedby;
};
typedef struct {
struct wl_list link;
@@ -240,6 +243,8 @@ typedef struct {
const char *title;
uint32_t tags;
int isfloating;
int isterm;
int noswallow;
int monitor;
} Rule;
@@ -377,6 +382,10 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
static Client *termforwin(Client *w);
static void swallow(Client *c, Client *w);
/* variables */
static const char broken[] = "broken";
@@ -499,10 +508,14 @@ applyrules(Client *c)
if (!(title = client_get_title(c)))
title = broken;
c->pid = client_get_pid(c);
for (r = rules; r < END(rules); r++) {
if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id))) {
c->isfloating = r->isfloating;
c->isterm = r->isterm;
c->noswallow = r->noswallow;
newtags |= r->tags;
i = 0;
wl_list_for_each(m, &mons, link) {
@@ -511,6 +524,21 @@ applyrules(Client *c)
}
}
}
if (!c->noswallow && !client_is_float_type(c)
&& !c->surface.xdg->initial_commit) {
Client *p = termforwin(c);
if (p) {
c->swallowedby = p;
p->swallowing = c;
wl_list_remove(&c->link);
wl_list_remove(&c->flink);
swallow(c, p);
wl_list_remove(&p->link);
wl_list_remove(&p->flink);
mon = p->mon;
newtags = p->tags;
}
}
setmon(c, mon, newtags);
}
@@ -1778,6 +1806,63 @@ handlesig(int signo)
}
}
pid_t
getparentprocess(pid_t p)
{
unsigned int v = 0;
FILE *f;
char buf[256];
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
if (!(f = fopen(buf, "r")))
return 0;
fscanf(f, "%*u %*s %*c %u", &v);
fclose(f);
return (pid_t)v;
}
int
isdescprocess(pid_t p, pid_t c)
{
while (p != c && c != 0)
c = getparentprocess(c);
return (int)c;
}
Client *
termforwin(Client *w)
{
Client *c;
if (!w->pid || w->isterm || w->noswallow)
return NULL;
wl_list_for_each(c, &fstack, flink)
if (c->isterm && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
return c;
return NULL;
}
void
swallow(Client *c, Client *w)
{
c->bw = w->bw;
c->isfloating = w->isfloating;
c->isurgent = w->isurgent;
c->isfullscreen = w->isfullscreen;
c->tags = w->tags;
c->geom = w->geom;
wl_list_insert(&w->link, &c->link);
wl_list_insert(&w->flink, &c->flink);
wlr_scene_node_set_enabled(&w->scene->node, 0);
wlr_scene_node_set_enabled(&c->scene->node, 1);
}
void
incnmaster(const Arg *arg)
{
@@ -3070,15 +3155,32 @@ unmapnotify(struct wl_listener *listener, void *data)
grabc = NULL;
}
if (c->swallowedby)
swallow(c->swallowedby, c);
if (client_is_unmanaged(c)) {
if (c == exclusive_focus) {
exclusive_focus = NULL;
focusclient(focustop(selmon), 1);
}
} else {
wl_list_remove(&c->link);
if (!c->swallowing)
wl_list_remove(&c->link);
setmon(c, NULL, 0);
wl_list_remove(&c->flink);
if (!c->swallowing)
wl_list_remove(&c->flink);
}
if (c->swallowedby) {
c->swallowedby->prev = c->geom;
setfullscreen(c->swallowedby, c->isfullscreen);
c->swallowedby->swallowing = NULL;
c->swallowedby = NULL;
}
if (c->swallowing) {
c->swallowing->swallowedby = NULL;
c->swallowing = NULL;
}
wlr_scene_node_destroy(&c->scene->node);