diff options
author | choc <notchoc@proton.me> | 2023-09-15 10:36:21 +0800 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2025-02-12 17:41:44 -0600 |
commit | fb6e9304479ca3e578db697fa0e46770ccc039de (patch) | |
tree | ea6afc69da66cd2522c9c3939acbffea4441144b /dwl.c | |
parent | 46453af601d7007951caafce80148ed7ede3de3d (diff) | |
download | dwl-fb6e9304479ca3e578db697fa0e46770ccc039de.tar.gz dwl-fb6e9304479ca3e578db697fa0e46770ccc039de.tar.bz2 dwl-fb6e9304479ca3e578db697fa0e46770ccc039de.zip |
implement swallow
Diffstat (limited to '')
-rw-r--r-- | dwl.c | 114 |
1 files changed, 108 insertions, 6 deletions
@@ -119,8 +119,9 @@ typedef struct { } Gesture; typedef struct Monitor Monitor; -typedef struct { - /* Must keep this field first */ +typedef struct Client Client; +struct Client { + /* Must keep these three elements in this order */ unsigned int type; /* XDGShell or X11* */ Monitor *mon; @@ -156,10 +157,12 @@ 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 */ enum wp_tearing_control_v1_presentation_hint tearing_hint; -} Client; + pid_t pid; + Client *swallowing, *swallowedby; +}; typedef struct { struct wl_list link; @@ -256,6 +259,8 @@ typedef struct { const char *title; uint32_t tags; int isfloating; + int isterm; + int noswallow; int monitor; } Rule; @@ -424,6 +429,10 @@ 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 int regex_match(const char *pattern, const char *str); +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 pid_t child_pid = -1; @@ -579,10 +588,14 @@ applyrules(Client *c) appid = client_get_appid(c); title = client_get_title(c); + c->pid = client_get_pid(c); + for (r = rules; r < END(rules); r++) { if ((!r->title || regex_match(r->title, title)) && (!r->id || regex_match(r->id, appid))) { c->isfloating = r->isfloating; + c->isterm = r->isterm; + c->noswallow = r->noswallow; newtags |= r->tags; i = 0; wl_list_for_each(m, &mons, link) { @@ -591,6 +604,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); } @@ -2096,6 +2124,63 @@ handlenewtearinghint(struct wl_listener *listener, void *data) wl_list_insert(&tearing_controllers, &controller->link); } +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) { @@ -3490,15 +3575,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); |