Compare commits

...

4 Commits

2 changed files with 43 additions and 8 deletions

View File

@@ -28,9 +28,9 @@ static void client_attach_list(client_t *client) {
}
static void client_detach_list(client_t *client) {
for (client_t **c = &wm.client_list; *c && *c != client; c = &(*c)->next) {
*c = client->next;
}
client_t **tc = nullptr;
for (tc = &wm.client_list; *tc && *tc != client; tc = &(*tc)->next);
*tc = client->next;
}
static void client_attach_stack(client_t *client) {
@@ -67,10 +67,16 @@ static void client_add_to_tag(client_t *client, tag_t *tag) {
}
static void client_remove_from_tag(client_t *client, tag_t *tag) {
for (task_in_tag_t **task = &tag->task_list; *task; task = &(*task)->next) {
if ((*task)->client != client) continue;
p_delete(task);
task_in_tag_t **task = &tag->task_list;
while (*task) {
if ((*task)->client == client) {
task_in_tag_t *t = *task;
*task = (*task)->next;
p_delete(&t);
continue;
}
task = &(*task)->next;
}
}
@@ -148,7 +154,7 @@ void client_manage(xcb_window_t window,
const xcb_params_cw_t params = {
.event_mask = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE |
XCB_EVENT_MASK_PROPERTY_CHANGE |
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
};
xcb_aux_change_window_attributes(wm.xcb_conn, window, XCB_CW_EVENT_MASK,
&params);
@@ -198,6 +204,23 @@ void client_resize(client_t *client, uint16_t width, uint16_t 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) {
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) {
uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event);
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_MAP_REQUEST, map_request);
EVENT(XCB_PROPERTY_NOTIFY, property_notify);
EVENT(XCB_UNMAP_NOTIFY, unmap_notify);
EVENT(XCB_DESTROY_NOTIFY, destroy_notify);
#undef EVENT
}