From 26f2b1aaa4eded77cc2a2ec9529b4216fc8f94da Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 6 Dec 2022 13:53:53 +0100 Subject: Minor reorganization. * schewm.c: Separate more clearly dpy-specific and wm-specific code. --- schewm.c | 165 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 82 insertions(+), 83 deletions(-) (limited to 'schewm.c') diff --git a/schewm.c b/schewm.c index 87cfbab..5f7bc8a 100644 --- a/schewm.c +++ b/schewm.c @@ -469,7 +469,7 @@ windows_query(xcb_window_t root, struct WindowsQueryReply *reply) { } reply->length = 0; int length = xcb_query_tree_children_length(data); - // Assume length is OK, but reply->length hold the length of + // Assume length is OK, but reply->length holds the length of // clients we are really interested in reply->data = calloc(length, sizeof(xcb_window_t)); xcb_window_t *children = xcb_query_tree_children(data); @@ -505,43 +505,6 @@ windows_query_reply_free(struct WindowsQueryReply *reply) { } } -/* - * Window Manager API. - */ -struct Client *wm_find_client(xcb_window_t id); -void wm_erase_client(xcb_window_t id); -bool wm_update_outputs(); -bool wm_has_error(); -bool wm_init(); -void wm_quit(); -void wm_close_client(); -void wm_begin_move_client(); -void wm_begin_resize_client(); -void wm_focus_prev(); -void wm_focus_next(); -void wm_toggle_maximize(); -void wm_toggle_half_left(); -void wm_toggle_half_right(); -void wm_toggle_half_top(); -void wm_toggle_half_bottom(); -void wm_toggle_top_left(); -void wm_toggle_top_right(); -void wm_toggle_bottom_left(); -void wm_toggle_bottom_right(); -void wm_pack_left(); -void wm_pack_right(); -void wm_pack_top(); -void wm_pack_bottom(); -void wm_set_workspace(uint32_t workspace); -void wm_set_focused_client_workspace(uint32_t workspace); -void wm_client_monitor_prev(); -void wm_client_monitor_next(); - -struct Client * -wm_find_client(xcb_window_t id) { - return clients_map_find(wm.clients, id); -} - static void dpy_set_window_state(xcb_window_t window, enum WindowState state) { if (state == WS_NORMAL) { @@ -584,25 +547,8 @@ dpy_set_focus(xcb_window_t window) { xcb_ewmh_set_active_window(dpy.ewmh, dpy.screen_num, window); } -void -wm_erase_client(xcb_window_t id) { - struct Client *client = wm_find_client(id); - if (client == NULL) { - return; - } - - struct Workspace *workspace = &wm.workspaces[client->workspace]; - // Workspace being NULL is a bug! - workspace->ring = client_ring_erase(workspace->ring, client); - clients_map_erase(wm.clients, client); - free(client); - if (!wm.focus) { - dpy_set_focus(XCB_NONE); - } -} - bool -wm_has_error() { +dpy_has_error() { return dpy.has_error || xcb_connection_has_error(dpy.conn) > 0; } @@ -843,7 +789,7 @@ dpy_init(const char *wm_name) { dpy.monitors = NULL; dpy.conn = xcb_connect(NULL, &dpy.screen_num); - if (wm_has_error()) { + if (dpy_has_error()) { return false; } @@ -1440,6 +1386,85 @@ find_monitor(const struct Client *client) { return monitor; } +void +dpy_destroy() { + if (dpy.ewmh) { + xcb_ewmh_connection_wipe(dpy.ewmh); + free(dpy.ewmh); + } + + if (dpy.keysyms) { + xcb_key_symbols_free(dpy.keysyms); + } + + if (!dpy_has_error()) { + xcb_free_cursor(dpy.conn, dpy.fleur_cursor); + xcb_free_cursor(dpy.conn, dpy.sizing_cursor); + xcb_close_font(dpy.conn, dpy.cursor_font); + xcb_set_input_focus( + dpy.conn, + XCB_NONE, + XCB_INPUT_FOCUS_POINTER_ROOT, + XCB_CURRENT_TIME); + dpy_flush(); + } + xcb_disconnect(dpy.conn); +} + +/* + * Window Manager API. + */ +struct Client *wm_find_client(xcb_window_t id); +void wm_erase_client(xcb_window_t id); +bool wm_update_outputs(); +bool wm_has_error(); +bool wm_init(); +void wm_quit(); +void wm_close_client(); +void wm_begin_move_client(); +void wm_begin_resize_client(); +void wm_focus_prev(); +void wm_focus_next(); +void wm_toggle_maximize(); +void wm_toggle_half_left(); +void wm_toggle_half_right(); +void wm_toggle_half_top(); +void wm_toggle_half_bottom(); +void wm_toggle_top_left(); +void wm_toggle_top_right(); +void wm_toggle_bottom_left(); +void wm_toggle_bottom_right(); +void wm_pack_left(); +void wm_pack_right(); +void wm_pack_top(); +void wm_pack_bottom(); +void wm_set_workspace(uint32_t workspace); +void wm_set_focused_client_workspace(uint32_t workspace); +void wm_client_monitor_prev(); +void wm_client_monitor_next(); + +struct Client * +wm_find_client(xcb_window_t id) { + return clients_map_find(wm.clients, id); +} + +void +wm_erase_client(xcb_window_t id) { + struct Client *client = wm_find_client(id); + if (client == NULL) { + return; + } + + struct Workspace *workspace = &wm.workspaces[client->workspace]; + // Workspace being NULL is a bug! + workspace->ring = client_ring_erase(workspace->ring, client); + clients_map_erase(wm.clients, client); + free(client); + if (!wm.focus) { + dpy_set_focus(XCB_NONE); + } +} + void wm_set_focus(struct Client *client) { if (wm.focus != NULL) { @@ -1631,31 +1656,6 @@ wm_quit() { wm.is_running = false; } -void -dpy_destroy() { - if (dpy.ewmh) { - xcb_ewmh_connection_wipe(dpy.ewmh); - free(dpy.ewmh); - } - - if (dpy.keysyms) { - xcb_key_symbols_free(dpy.keysyms); - } - - if (!wm_has_error()) { - xcb_free_cursor(dpy.conn, dpy.fleur_cursor); - xcb_free_cursor(dpy.conn, dpy.sizing_cursor); - xcb_close_font(dpy.conn, dpy.cursor_font); - xcb_set_input_focus( - dpy.conn, - XCB_NONE, - XCB_INPUT_FOCUS_POINTER_ROOT, - XCB_CURRENT_TIME); - dpy_flush(); - } - xcb_disconnect(dpy.conn); -} - void wm_destroy() { free(wm.workspaces); @@ -1679,7 +1679,6 @@ wm_run() { } free(ev); } - wm_destroy(); } -- cgit v1.2.3