diff options
author | Samuel Fadel <samuel@nihil.ws> | 2022-12-18 13:34:54 +0100 |
---|---|---|
committer | Samuel Fadel <samuel@nihil.ws> | 2022-12-18 13:34:54 +0100 |
commit | c33bba0db6e5c0d439a8aa5a1eb3a8a4ebcf03cf (patch) | |
tree | 554c8b793db509311aa0360ed825a91c5c40f19b | |
parent | ec2ecf9085d1c001b803d27261ecf7ae3fe6d298 (diff) |
WM reconfiguration code.
* main.scm: Added wm-reconifgure call to set initial config
* wm.scm: Added wiring to call C code for reconfiguration
* schewm.c: bugfix in ev_unmap_notify(); new wm_reconfigure() function
-rw-r--r-- | main.scm | 1 | ||||
-rw-r--r-- | schewm.c | 89 | ||||
-rw-r--r-- | wm.scm | 37 |
3 files changed, 112 insertions, 15 deletions
@@ -74,6 +74,7 @@ (,(make-shift-key "o") . ,wm-client-monitor-next))) (when (wm-init) + (wm-reconfigure config) (wm-grab-keys wm-keybindings) (wm-set-key-press-handler! (lambda (mod keysym) @@ -600,7 +600,7 @@ callbacks_map_free(struct CallbacksMap *map) { free(map); } -static struct { +static struct Config { uint16_t inner_border_width, outer_border_width, magnet_border_width; int16_t offset_x, offset_y; uint16_t offset_width, offset_height; @@ -2103,6 +2103,12 @@ wm_fit_client(struct Client *client) { } void +wm_update_client_monitor(struct Client *client) { + client->monitor = find_monitor(client); + wm_fit_client(client); +} + +void wm_handle_state(struct Client *client, xcb_atom_t atom, uint32_t action) { // `state' holds what the atom wants to tell us about what to do enum WindowState state = WS_NORMAL; @@ -2219,8 +2225,7 @@ manage_client_maybe_reposition(xcb_window_t window, bool set_position) { client->y = p.y - client->height / 2; dpy_update_window_position(client); } - client->monitor = find_monitor(client); - wm_fit_client(client); + wm_update_client_monitor(client); clients_map_add(wm.clients, client); if (client->state == WS_NORMAL) { dpy_draw_unfocused_borders(client); @@ -2321,6 +2326,64 @@ wm_destroy() { } void +wm_reconfigure(uint16_t inner_border_width, + uint16_t outer_border_width, + uint16_t magnet_border_width, + int16_t offset_x, + int16_t offset_y, + uint16_t offset_width, + uint16_t offset_height, + uint32_t focused, + uint32_t unfocused, + uint32_t unkillable, + uint32_t empty, + uint32_t outer) { + cfg.inner_border_width = inner_border_width; + cfg.outer_border_width = outer_border_width; + cfg.magnet_border_width = magnet_border_width; + cfg.offset_x = offset_x; + cfg.offset_width = offset_width; + cfg.offset_height = offset_height; + cfg.colors.focused = focused; + cfg.colors.unfocused = unfocused; + cfg.colors.unkillable = unkillable; + cfg.colors.empty = empty; + cfg.colors.outer = outer; + + // Set new window border of ALL clients + for (uint32_t workspace = 0; workspace < wm.num_workspaces; workspace++) { + struct Client *client = wm.workspaces[workspace].ring; + if (client == NULL) { + continue; + } + + for (;;) { + dpy_set_window_border_width(client->id); + wm_fit_client(client); + + client = client->next; + if (client == wm.workspaces[workspace].ring) { + break; + } + } + } + + // Redraw borders of clients from current workspace only + struct Client *client = wm.workspaces[wm.cur_workspace].ring; + if (client == NULL) { + return; + } + + for (;;) { + dpy_draw_borders(client, wm.focus == client); + client = client->next; + if (client == wm.workspaces[wm.cur_workspace].ring) { + break; + } + } +} + +void wm_close(struct Client *client) { if (client->is_unkillable) { return; @@ -2764,13 +2827,7 @@ ev_configure_request(xcb_generic_event_t *generic_ev) { } wm_apply_size_hints(client); dpy_update_window_geometry(client); - - // Update the client monitor accordingly - struct Monitor *monitor = find_monitor(client); - if (monitor != NULL && client->monitor != monitor) { - client->monitor = monitor; - } - wm_fit_client(client); + wm_update_client_monitor(client); // TODO: do we need this? // dpy_draw_borders(client, wm.focus->id == client->id); @@ -2910,7 +2967,6 @@ ev_unmap_notify(xcb_generic_event_t *generic_ev) { struct Client *client = wm_find_client(ev->window); if (client == NULL || wm.workspaces[wm.cur_workspace].ring == NULL - || wm.workspaces[wm.cur_workspace].ring->id == ev->window || client->state == WS_ICONIFIED) { /* * For unknown clients, clients not in our current workspace, @@ -2921,15 +2977,18 @@ ev_unmap_notify(xcb_generic_event_t *generic_ev) { } bool should_ignore = true; - struct Client *ring_ptr = wm.workspaces[wm.cur_workspace].ring->next; - while (ring_ptr != wm.workspaces[wm.cur_workspace].ring) { - if (ring_ptr->id == ev->window) { + struct Client *ring_client = wm.workspaces[wm.cur_workspace].ring; + for (;;) { + if (ring_client->id == ev->window) { // We found the client, now we must handle the unmapping should_ignore = false; break; } + ring_client = ring_client->next; + if (ring_client == wm.workspaces[wm.cur_workspace].ring) { + break; + } } - if (should_ignore) { return; } @@ -4,6 +4,7 @@ #:use-module (system foreign) #:export (wm-init make-config + wm-reconfigure make-key make-shift-key wm-grab-keys @@ -88,6 +89,42 @@ (define wm-run (schewm-func void "wm_run" '())) +(define c/parse-color + (schewm-func uint32 "parse_color" (list '*))) + +(define (parse-color s) + (c/parse-color (string->pointer s))) + +(define c/wm-reconfigure + (schewm-func void + "wm_reconfigure" + (list uint16 + uint16 + uint16 + int16 + int16 + uint16 + uint16 + uint32 + uint32 + uint32 + uint32 + uint32))) + +(define (wm-reconfigure config) + (c/wm-reconfigure (config-inner-border-width config) + (config-outer-border-width config) + (config-magnet-border-width config) + (config-offset-x config) + (config-offset-y config) + (config-offset-width config) + (config-offset-height config) + (parse-color (config-focused-color config)) + (parse-color (config-unfocused-color config)) + (parse-color (config-unkillable-color config)) + (parse-color (config-empty-color config)) + (parse-color (config-outer-color config)))) + (define wm-focus-prev (schewm-func void "wm_focus_prev" '())) |