记录 property_notify 和 client_message 事件中的 xcb atom 名称

This commit is contained in:
2025-09-30 16:21:22 +08:00
parent b40f499e7b
commit bec2162890
3 changed files with 26 additions and 2 deletions

View File

@@ -135,6 +135,7 @@ typedef enum atom_t {
atom_zswm_client_info, /* 自定义属性,用于存储所在 monitor 和 tags */ atom_zswm_client_info, /* 自定义属性,用于存储所在 monitor 和 tags */
} atom_t; } atom_t;
xcb_atom_t get_xcb_atom(atom_t atom); xcb_atom_t get_xcb_atom(atom_t atom);
char *get_xcb_atom_name(xcb_atom_t atom);
bool send_event(xcb_window_t window, atom_t atom); bool send_event(xcb_window_t window, atom_t atom);
typedef enum wm_state_t { typedef enum wm_state_t {
wm_state_withdrawn = 0, wm_state_withdrawn = 0,

View File

@@ -926,8 +926,10 @@ void focus_in(focus_in_event_t *event) {
} }
void property_notify(property_notify_event_t *event) { void property_notify(property_notify_event_t *event) {
logger("window: 0x%x state: %u, atom: %u\n", event->window, event->state, char *atom_name = get_xcb_atom_name(event->xcb_atom);
event->xcb_atom); logger("window: 0x%x state: %u, atom: %u, atom name: %s\n", event->window,
event->state, event->xcb_atom, atom_name);
free(atom_name);
if (event->state == property_delete) return; if (event->state == property_delete) return;
client_t *c = get_client_of_window(event->window); client_t *c = get_client_of_window(event->window);
@@ -956,6 +958,10 @@ void property_notify(property_notify_event_t *event) {
} }
void client_message(client_message_event_t *event) { void client_message(client_message_event_t *event) {
char *atom_name = get_xcb_atom_name(event->message_type);
logger("client message: message type: %s\n", atom_name);
free(atom_name);
client_t *c = get_client_of_window(event->window); client_t *c = get_client_of_window(event->window);
if (!c) return; if (!c) return;

View File

@@ -111,6 +111,23 @@ xcb_atom_t get_xcb_atom(atom_t atom) {
return atom_map[atom].xcb_atom; return atom_map[atom].xcb_atom;
} }
/**
* @brief 获取 xcb atom 名称
* @returns xcb atom 对应的名称,使用后记得用 free 释放
*/
char *get_xcb_atom_name(xcb_atom_t atom) {
xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(conn, atom);
xcb_get_atom_name_reply_t *reply =
xcb_get_atom_name_reply(conn, cookie, NULL);
int length = xcb_get_atom_name_name_length(reply);
char *name_buffer = ecalloc(1, length + 1);
const char *name = xcb_get_atom_name_name(reply);
strncpy(name_buffer, name, length);
free(reply);
return name_buffer;
}
bool send_event(xcb_window_t window, atom_t atom) { bool send_event(xcb_window_t window, atom_t atom) {
if (atom < 0 || atom >= LENGTH(atom_map)) return false; if (atom < 0 || atom >= LENGTH(atom_map)) return false;