diff options
Diffstat (limited to 'schewm.c')
-rw-r--r-- | schewm.c | 67 |
1 files changed, 64 insertions, 3 deletions
@@ -432,7 +432,6 @@ static struct { uint16_t inner_border_width, outer_border_width, magnet_border_width; int16_t offset_x, offset_y; uint16_t offset_width, offset_height; - uint32_t pointer_motion_interval; struct { uint32_t focused, unfocused, unkillable, empty, outer; } colors; @@ -469,7 +468,6 @@ static struct { struct Client *focus; struct ClientsMap *clients; struct Workspace *workspaces; - struct xcb_connection_t *conn; generic_event_handler_t events[XCB_NO_OPERATION]; } wm; @@ -598,6 +596,34 @@ dpy_has_error() { return dpy.has_error || xcb_connection_has_error(dpy.conn) > 0; } +bool +dpy_is_protocol_supported(xcb_window_t window, xcb_atom_t atom) { + xcb_get_property_cookie_t cookie = + xcb_icccm_get_wm_protocols_unchecked( + dpy.conn, + window, + dpy.ewmh->WM_PROTOCOLS); + xcb_icccm_get_wm_protocols_reply_t protocols; + uint8_t reply = xcb_icccm_get_wm_protocols_reply( + dpy.conn, + cookie, + &protocols, + NULL); + if (!reply) { + return false; + } + + bool is_supported = false; + for (uint32_t i = 0; i < protocols.atoms_len; i++) { + if (protocols.atoms[i] == atom) { + is_supported = true; + break; + } + } + xcb_icccm_get_wm_protocols_reply_wipe(&protocols); + return is_supported; +} + struct Monitor * dpy_find_monitor(xcb_randr_output_t id) { if (dpy.monitors == NULL) { @@ -617,6 +643,12 @@ dpy_find_monitor(xcb_randr_output_t id) { return NULL; } +bool +dpy_should_update_outputs(const xcb_generic_event_t *event) { + return dpy.has_randr + && event->response_type == dpy.randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY; +} + static bool dpy_update_output(xcb_randr_output_t output, xcb_timestamp_t timestamp, @@ -1482,6 +1514,13 @@ dpy_destroy() { xcb_key_symbols_free(dpy.keysyms); } + struct Monitor *monitor = dpy.monitors; + while (dpy.monitors != NULL) { + dpy.monitors = monitor_ring_erase(dpy.monitors, monitor); + free(monitor); + monitor = dpy.monitors; + } + if (!dpy_has_error()) { xcb_free_cursor(dpy.conn, dpy.fleur_cursor); xcb_free_cursor(dpy.conn, dpy.sizing_cursor); @@ -1505,7 +1544,7 @@ bool wm_update_outputs(); bool wm_has_error(); bool wm_init(); void wm_quit(); -void wm_close_client(); +void wm_focus_close(); void wm_begin_move_client(); void wm_begin_resize_client(); void wm_focus_prev(); @@ -1935,6 +1974,28 @@ wm_destroy() { } void +wm_close(struct Client *client) { + if (client->is_unkillable) { + return; + } + + if (dpy_is_protocol_supported(client->id, dpy.delete_window_atom)) { + dpy_send_window_message(client->id, dpy.delete_window_atom); + } else { + dpy_kill_window(client->id); + } +} + +void +wm_focus_close() { + if (wm.focus == NULL) { + return; + } + + wm_close(wm.focus); +} + +void wm_raise_and_center_cursor(struct Client *client) { dpy_raise_window(client->id); dpy_center_cursor_client(client); |