int handle_map_request_event(void *data, xcb_connection_t *c, xcb_map_request_event_t *event) { xcb_get_window_attributes_cookie_t win_attrs_cookie; xcb_get_window_attributes_reply_t *win_attrs_reply; win_attrs_cookie = xcb_get_window_attributes_unchecked(c, event->window); win_attrs_reply = xcb_get_window_attributes_reply(c, win_attrs_cookie, NULL); if (!win_attrs_reply) { fprintf(stderr, "map request: failed to get window attributes\n"); return -1; } if (win_attrs_reply->override_redirect) { fprintf(stderr, "map request: window has override redirect set - ignoring map request\n"); return 0; } client_t *client = NULL; client = find_client(event->window); if (!client) client = manage_window(event->window); xcb_map_window(c, event->window); run_arrange_hook(); free(win_attrs_reply); return 0; }
/* * Go through all existing windows (if the window manager is restarted) and manage them * */ void manage_existing_windows(xcb_window_t root) { xcb_query_tree_reply_t *reply; int i, len; xcb_window_t *children; xcb_get_window_attributes_cookie_t *cookies; /* Get the tree of windows whose parent is the root window (= all) */ if ((reply = xcb_query_tree_reply(conn, xcb_query_tree(conn, root), 0)) == NULL) return; len = xcb_query_tree_children_length(reply); cookies = smalloc(len * sizeof(*cookies)); /* Request the window attributes for every window */ children = xcb_query_tree_children(reply); for (i = 0; i < len; ++i) cookies[i] = xcb_get_window_attributes(conn, children[i]); /* Call manage_window with the attributes for every window */ for (i = 0; i < len; ++i) manage_window(children[i], cookies[i], true); free(reply); free(cookies); }
void schedule_window(xcb_window_t win) { coordinates_t loc; uint8_t override_redirect = 0; xcb_get_window_attributes_reply_t *wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, win), NULL); if (wa != NULL) { override_redirect = wa->override_redirect; free(wa); } if (override_redirect || locate_window(win, &loc)) { return; } /* ignore pending windows */ for (pending_rule_t *pr = pending_rule_head; pr != NULL; pr = pr->next) { if (pr->win == win) { return; } } rule_consequence_t *csq = make_rule_conquence(); apply_rules(win, csq); if (!schedule_rules(win, csq)) { manage_window(win, csq, -1); free(csq); } }