From cd3a1b7749ecfacd0dc47eb32bcae4b23cb439f9 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Fri, 9 Dec 2022 12:39:18 +0100 Subject: Implemented focus prev/next; cleanup on Scheme side. * schewm.c: Implemented focus prev/next and minor helper func * main.scm and wm.scm: Added focus prev/next calls to C --- schewm.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'schewm.c') diff --git a/schewm.c b/schewm.c index 4a3811a..0129888 100644 --- a/schewm.c +++ b/schewm.c @@ -1934,6 +1934,40 @@ wm_destroy() { dpy_destroy(); } +void +wm_raise_and_center_cursor(struct Client *client) { + dpy_raise_window(client->id); + dpy_center_cursor_client(client); +} + +void +wm_focus_other(bool is_next) { + struct Client *focused = wm.focus; + if (focused == NULL) { + // No current focus, pick first client from the ring + focused = wm.workspaces[wm.cur_workspace].ring; + } else { + // We have focus, pick next/prev + focused = is_next ? focused->next : focused->prev; + } + if (focused == NULL) { + return; + } + + wm_raise_and_center_cursor(focused); + wm_set_focus(focused); +} + +void +wm_focus_prev() { + wm_focus_other(false); +} + +void +wm_focus_next() { + wm_focus_other(true); +} + static uint8_t ev_type(const xcb_generic_event_t *ev) { return ev->response_type & ~0x80; -- cgit v1.2.3