commit 7c33428
shrub
·
2026-08-05 14:38:18 +0000 UTC
parent 999c916
get window title better
1 files changed,
+24,
-27
+24,
-27
1@@ -16,12 +16,13 @@
2
3 static void focus(struct client* c);
4 static void apply_decor(struct client* c, bool active);
5-static const char* decorstring(struct client* c, char* buf, size_t size);
6+static const char* decorstring(struct client* c);
7 static struct client* first_client(struct screen* s);
8 static bool is_ws_client(const struct client* c, const struct screen* s);
9 static void on_screen_destroy(void* data);
10 static void on_win_destroy(void* data);
11 static void on_win_entered(void* data);
12+static void on_win_metadata_changed(void* data);
13 static void setup(void);
14 static void setup_binds(void);
15 static void sync_window_visibility(void);
16@@ -31,7 +32,10 @@ const struct swc_manager manager = {
17 .new_screen = new_screen, .new_window = new_window, .new_device = new_device,
18 };
19 struct swc_window_handler window_handler = {
20- .destroy = on_win_destroy, .entered = on_win_entered,
21+ .destroy = on_win_destroy,
22+ .title_changed = on_win_metadata_changed,
23+ .app_id_changed = on_win_metadata_changed,
24+ .entered = on_win_entered,
25 };
26 struct swc_screen_handler screen_handler = {
27 .destroy = on_screen_destroy,
28@@ -63,7 +67,6 @@ static void focus(struct client* c)
29
30 static void apply_decor(struct client* c, bool active)
31 {
32- char process_name[256];
33 const char* title;
34 struct swc_decor decor;
35
36@@ -78,40 +81,24 @@ static void apply_decor(struct client* c, bool active)
37 decor = cfg.decor;
38 decor.parts = active ? &afterstep_parts : &afterstep_inactive_parts;
39 decor.title.color = active ? 0xffffffff : 0xffc0c0c0;
40- title = decorstring(c, process_name, sizeof(process_name));
41+ title = decorstring(c);
42 if (title)
43 decor.title.string = title;
44 swc_window_set_decor(c->win, &decor);
45 }
46
47-static const char* decorstring(struct client* c, char* buf, size_t size)
48+static const char* decorstring(struct client* c)
49 {
50- char path[64];
51- FILE* fp;
52- pid_t pid;
53- size_t len;
54-
55- if (!c || !buf || size == 0)
56- return NULL;
57-
58- pid = swc_window_get_pid(c->win);
59- if (pid <= 0)
60+ if (!c || !c->win)
61 return NULL;
62
63- snprintf(path, sizeof(path), "/proc/%lld/comm", (long long)pid);
64- fp = fopen(path, "r");
65- if (!fp)
66- return NULL;
67+ if (c->win->title && c->win->title[0])
68+ return c->win->title;
69
70- if (!fgets(buf, (int)size, fp)) {
71- fclose(fp);
72- return NULL;
73- }
74+ if (c->win->app_id && c->win->app_id[0])
75+ return c->win->app_id;
76
77- fclose(fp);
78- len = strcspn(buf, "\n");
79- buf[len] = '\0';
80- return buf[0] ? buf : NULL;
81+ return NULL;
82 }
83
84 static struct client* first_client(struct screen* s)
85@@ -188,6 +175,16 @@ static void on_win_entered(void* data)
86 focus(c);
87 }
88
89+static void on_win_metadata_changed(void* data)
90+{
91+ struct client* c = data;
92+
93+ if (!c)
94+ return;
95+
96+ apply_decor(c, c == wm.sel_client);
97+}
98+
99 static void setup(void)
100 {
101 /* display */