summaryrefslogtreecommitdiff
path: root/schewm.c
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2022-12-09 12:39:18 +0100
committerSamuel Fadel <samuel@nihil.ws>2022-12-09 12:39:18 +0100
commitcd3a1b7749ecfacd0dc47eb32bcae4b23cb439f9 (patch)
treec46e93cb901ad388bb95936d4a100a70f50f3844 /schewm.c
parent6f54084c0ee63f4b341f8f92efbc8b82d3dfa224 (diff)
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
Diffstat (limited to 'schewm.c')
-rw-r--r--schewm.c34
1 files changed, 34 insertions, 0 deletions
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;