commit 047c3d2

0uppy  ·  2026-05-09 14:01:24 +0000 UTC
parent 2576651
slgro 1.3 - Added optional window decoration (titlebars) support (Very broken and unstable for now)
1 files changed,  +67, -8
+67, -8
  1@@ -1,6 +1,7 @@
  2 #include <signal.h>
  3 #include <stdio.h>
  4 #include <stdlib.h>
  5+#include <string.h>
  6 #include <unistd.h>
  7 #include <sys/wait.h>
  8 
  9@@ -28,6 +29,8 @@ static void on_win_entered(void* data);
 10 static void setup(void);
 11 static void setup_binds(void);
 12 static void sync_window_visibility(void);
 13+static void apply_decor(struct client* c, bool active);
 14+static const char* decorstring(struct client* c, char* buf, size_t size);
 15 
 16 #define WHEN_PRESSED(state) \
 17 	do { if ((state) != WL_KEYBOARD_KEY_STATE_PRESSED) return; } while (0)
 18@@ -67,6 +70,57 @@ static void adjust_geom(struct client *c, int dx, int dy, int dw, int dh)
 19 	swc_window_set_geometry(c->win, &geom);
 20 }
 21 
 22+static const char* decorstring(struct client* c, char* buf, size_t size)
 23+{
 24+    char path[64];
 25+    FILE* fp;
 26+    pid_t pid;
 27+    size_t len;
 28+
 29+    if (!c || !buf || size == 0)
 30+        return NULL;
 31+
 32+    pid = swc_window_get_pid(c->win);
 33+    if (pid <= 0)
 34+        return NULL;
 35+
 36+    snprintf(path, sizeof(path), "/proc/%lld/comm", (long long)pid);
 37+    fp = fopen(path, "r");
 38+    if (!fp)
 39+        return NULL;
 40+
 41+    if (!fgets(buf, (int)size, fp)) {
 42+        fclose(fp);
 43+        return NULL;
 44+    }
 45+
 46+    fclose(fp);
 47+    len = strcspn(buf, "\n");
 48+    buf[len] = '\0';
 49+    return buf[0] ? buf : NULL;
 50+}
 51+
 52+static void apply_decor(struct client* c, bool active)
 53+{
 54+    char process_name[256];
 55+    const char* title;
 56+    struct swc_decor decor;
 57+
 58+    if (!c)
 59+        return;
 60+
 61+    if (c->fullscreen) {
 62+        swc_window_set_decor(c->win, NULL);
 63+        return;
 64+    }
 65+
 66+    decor = cfg.decor;
 67+    title = decorstring(c, process_name, sizeof(process_name));
 68+    if (title)
 69+        decor.title.string = title;
 70+    swc_window_set_decor(c->win, &decor);
 71+}
 72+
 73 struct wm wm;
 74 const struct swc_manager manager = {
 75 	.new_screen = new_screen, .new_window = new_window, .new_device = new_device,
 76@@ -86,15 +140,17 @@ static struct client* get_focus_candidate(struct screen* s) {
 77 
 78 static void focus(struct client* c)
 79 {
 80-	if (wm.sel_client && wm.sel_client != c) {
 81-		swc_window_set_border(wm.sel_client->win, cfg.border_col_normal, cfg.border_width, 0, 0);
 82-	}
 83-	if (c) {
 84-		swc_window_set_border(c->win, cfg.border_col_active, cfg.border_width, 0, 0);
 85-	}
 86+    if (wm.sel_client && wm.sel_client != c) {
 87+        swc_window_set_border(wm.sel_client->win, cfg.border_col_normal, cfg.border_width, 0, 0);
 88+        apply_decor(wm.sel_client, false);
 89+    }
 90+    if (c) {
 91+        swc_window_set_border(c->win, cfg.border_col_active, cfg.border_width, 0, 0);
 92+        apply_decor(c, true);
 93+    }
 94 
 95-	swc_window_focus(c ? c->win : NULL);
 96-	wm.sel_client = c;
 97+    swc_window_focus(c ? c->win : NULL);
 98+    wm.sel_client = c;
 99 }
100 
101 static struct client* first_client(struct screen* s)
102@@ -274,6 +330,7 @@ void fullscreen(void* data, uint32_t time, uint32_t value, uint32_t state)
103 	if (c->fullscreen) {
104 		c->fullscreen = false;
105 		swc_window_set_stacked(c->win);
106+        apply_decor(c, true);        
107 
108 		if (c->w > 0 && c->h > 0) {
109 			geom = (struct swc_rectangle){ c->x, c->y, c->w, c->h };
110@@ -292,6 +349,7 @@ void fullscreen(void* data, uint32_t time, uint32_t value, uint32_t state)
111 	}
112 
113 	c->fullscreen = true;
114+    apply_decor(c, true);
115 	swc_window_set_fullscreen(c->win, c->scr->scr);
116 }
117 
118@@ -383,6 +441,7 @@ void new_window(struct swc_window* win)
119 	wl_list_insert(&wm.clients, &c->link);
120 	swc_window_set_handler(win, &window_handler, c);
121 	swc_window_set_stacked(win);
122+    apply_decor(c, false);
123 
124 	int32_t cx = 0, cy = 0;
125 	if (swc_cursor_position(&cx, &cy))