添加布局算法并在新建窗口时应用规则

This commit is contained in:
2025-08-22 23:01:25 +08:00
parent c3bcb7ddd2
commit 69c69200d8
9 changed files with 248 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
#include "window.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -34,6 +35,28 @@ void set_window_class_instance(xcb_window_t window, const char *class,
free(str);
}
static char broken[] = "broken";
void get_window_class_instance(xcb_window_t window,
window_class_instance_t *class_instance) {
xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_class(conn, window);
xcb_icccm_get_wm_class_reply_t prop;
const char *class = NULL;
const char *instance = NULL;
if (xcb_icccm_get_wm_class_reply(conn, cookie, &prop, NULL)) {
class = prop.class_name;
instance = prop.instance_name;
} else {
class = broken;
instance = broken;
}
strncpy(class_instance->class, class, LENGTH(class_instance->class));
strncpy(class_instance->instance, instance, LENGTH(class_instance->instance));
xcb_icccm_get_wm_class_reply_wipe(&prop);
}
typedef struct visual_t {
uint8_t depth;
xcb_visualtype_t *visual;
@@ -242,9 +265,8 @@ char *get_window_name(xcb_window_t window) {
}
{
const char *broken = "broken";
char *name = ecalloc(strlen(broken) + 1, sizeof(char));
strncpy(name, broken, strlen(broken));
char *name = ecalloc(LENGTH(broken), sizeof(char));
strncpy(name, broken, LENGTH(broken));
return name;
}
}