commit 4e18c2f
shrub
·
2026-08-05 14:38:18 +0000 UTC
parent 999c916
get window title better
5 files changed,
+36,
-39
+0,
-0
+6,
-6
1@@ -76,12 +76,12 @@ static const uint32_t afterstep_inactive_bottom_pixels[] = {
2 };
3
4 static const uint32_t afterstep_inactive_bottom_right_pixels[] = {
5- 0x684b4b4bu, 0x68cfcfcfu, 0x68bfbfbfu, 0x688f8f8fu, 0x683e3e3eu, 0x68000000u, 0xa34b4b4bu, 0x68cfcfcfu,
6- 0x68bfbfbfu, 0x688f8f8fu, 0xa33e3e3eu, 0x51000000u, 0x68cfcfcfu, 0x68cfcfcfu, 0x42bfbfbfu, 0x687f7f7fu,
7- 0xa33e3e3eu, 0x68000000u, 0x68bfbfbfu, 0x42bfbfbfu, 0x689f9f9fu, 0xa35f5f5fu, 0xa33e3e3eu, 0x68000000u,
8- 0x688f8f8fu, 0x687f7f7fu, 0xa35f5f5fu, 0xa35f5f5fu, 0xa33e3e3eu, 0x68000000u, 0xa33e3e3eu, 0xa33e3e3eu,
9- 0xa33e3e3eu, 0xa33e3e3eu, 0xa33e3e3eu, 0x68000000u, 0xa3000000u, 0xa3000000u, 0xa3000000u, 0xa3000000u,
10- 0xa3000000u, 0xa3000000u
11+ 0xff4b4b4bu, 0xffcfcfcfu, 0xffbfbfbfu, 0xff8f8f8fu, 0xff3e3e3eu, 0xff000000u, 0xff4b4b4bu, 0xffcfcfcfu,
12+ 0xffbfbfbfu, 0xff8f8f8fu, 0xff3e3e3eu, 0xff000000u, 0xffcfcfcfu, 0xffcfcfcfu, 0xffbfbfbfu, 0xff7f7f7fu,
13+ 0xff3e3e3eu, 0xff000000u, 0xffbfbfbfu, 0xffbfbfbfu, 0xff9f9f9fu, 0xff5f5f5fu, 0xff3e3e3eu, 0xff000000u,
14+ 0xff8f8f8fu, 0xff7f7f7fu, 0xff5f5f5fu, 0xff5f5f5fu, 0xff3e3e3eu, 0xff000000u, 0xff3e3e3eu, 0xff3e3e3eu,
15+ 0xff3e3e3eu, 0xff3e3e3eu, 0xff3e3e3eu, 0xff000000u, 0xff000000u, 0xff000000u, 0xff000000u, 0xff000000u,
16+ 0xff000000u, 0xff000000u
17 };
18
19 static const struct swc_decor_part afterstep_inactive_top_left = { .width = 6u, .height = 24u, .stride = 24u, .data = afterstep_inactive_top_left_pixels };
+6,
-6
1@@ -76,12 +76,12 @@ static const uint32_t afterstep_bottom_pixels[] = {
2 };
3
4 static const uint32_t afterstep_bottom_right_pixels[] = {
5- 0x684b4b4bu, 0x68cfcfcfu, 0x68bfbfbfu, 0x688f8f8fu, 0x683e3e3eu, 0x68000000u, 0xa34b4b4bu, 0x68cfcfcfu,
6- 0x68bfbfbfu, 0x688f8f8fu, 0xa33e3e3eu, 0x51000000u, 0x68cfcfcfu, 0x68cfcfcfu, 0x42bfbfbfu, 0x687f7f7fu,
7- 0xa33e3e3eu, 0x68000000u, 0x68bfbfbfu, 0x42bfbfbfu, 0x689f9f9fu, 0xa35f5f5fu, 0xa33e3e3eu, 0x68000000u,
8- 0x688f8f8fu, 0x687f7f7fu, 0xa35f5f5fu, 0xa35f5f5fu, 0xa33e3e3eu, 0x68000000u, 0xa33e3e3eu, 0xa33e3e3eu,
9- 0xa33e3e3eu, 0xa33e3e3eu, 0xa33e3e3eu, 0x68000000u, 0xa3000000u, 0xa3000000u, 0xa3000000u, 0xa3000000u,
10- 0xa3000000u, 0xa3000000u
11+ 0xff4b4b4bu, 0xffcfcfcfu, 0xffbfbfbfu, 0xff8f8f8fu, 0xff3e3e3eu, 0xff000000u, 0xff4b4b4bu, 0xffcfcfcfu,
12+ 0xffbfbfbfu, 0xff8f8f8fu, 0xff3e3e3eu, 0xff000000u, 0xffcfcfcfu, 0xffcfcfcfu, 0xffbfbfbfu, 0xff7f7f7fu,
13+ 0xff3e3e3eu, 0xff000000u, 0xffbfbfbfu, 0xffbfbfbfu, 0xff9f9f9fu, 0xff5f5f5fu, 0xff3e3e3eu, 0xff000000u,
14+ 0xff8f8f8fu, 0xff7f7f7fu, 0xff5f5f5fu, 0xff5f5f5fu, 0xff3e3e3eu, 0xff000000u, 0xff3e3e3eu, 0xff3e3e3eu,
15+ 0xff3e3e3eu, 0xff3e3e3eu, 0xff3e3e3eu, 0xff000000u, 0xff000000u, 0xff000000u, 0xff000000u, 0xff000000u,
16+ 0xff000000u, 0xff000000u
17 };
18
19 static const struct swc_decor_part afterstep_top_left = { .width = 6u, .height = 24u, .stride = 24u, .data = afterstep_top_left_pixels };
+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 */