关闭窗口时清理对应资源

This commit is contained in:
2025-12-09 09:37:06 +08:00
parent f7a29ce74c
commit ef1f71e92f
2 changed files with 29 additions and 0 deletions

View File

@@ -204,6 +204,23 @@ void client_resize(client_t *client, uint16_t width, uint16_t height) {
width, height); width, height);
} }
void client_unmanage(client_t *client) {
monitor_t *m = client->monitor;
client_detach_list(client);
client_detach_stack(client);
for (tag_t *tag = m->tag_list; tag; tag = tag->next) {
if (tag->mask & client->tags) client_remove_from_tag(client, tag);
}
client_wipe(client);
monitor_arrange(m);
monitor_draw_bar(m);
xcb_flush(wm.xcb_conn);
}
bool client_is_visible(client_t *client) { bool client_is_visible(client_t *client) {
return client->tags & client->monitor->selected_tag->mask; return client->tags & client->monitor->selected_tag->mask;
} }

View File

@@ -139,6 +139,16 @@ static void property_notify(xcb_property_notify_event_t *ev) {
} }
} }
static void destroy_notify(xcb_destroy_notify_event_t *ev) {
client_t *client = client_get_by_window(ev->window);
if (client) client_unmanage(client);
}
static void unmap_notify(xcb_unmap_notify_event_t *ev) {
client_t *client = client_get_by_window(ev->window);
if (client) client_unmanage(client);
}
static void handle_xcb_event(xcb_generic_event_t *event) { static void handle_xcb_event(xcb_generic_event_t *event) {
uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event); uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event);
const char *label = xcb_event_get_label(event_type); const char *label = xcb_event_get_label(event_type);
@@ -157,6 +167,8 @@ static void handle_xcb_event(xcb_generic_event_t *event) {
EVENT(XCB_CONFIGURE_REQUEST, configure_request); EVENT(XCB_CONFIGURE_REQUEST, configure_request);
EVENT(XCB_MAP_REQUEST, map_request); EVENT(XCB_MAP_REQUEST, map_request);
EVENT(XCB_PROPERTY_NOTIFY, property_notify); EVENT(XCB_PROPERTY_NOTIFY, property_notify);
EVENT(XCB_UNMAP_NOTIFY, unmap_notify);
EVENT(XCB_DESTROY_NOTIFY, destroy_notify);
#undef EVENT #undef EVENT
} }