summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRick Console <rick@rickconsole.com>2025-06-05 19:10:15 -0400
committerRick Console <rick@rickconsole.com>2025-06-05 19:10:15 -0400
commit787416e6a3cead68472619a42385c58b23b51d81 (patch)
tree7cad4e55bfaad08ee5c753da510c3859f48ec2f4 /src
parent443a8ca4581b3e93a2d4a96f4acf7a4f9c5afa18 (diff)
added monitor switching
Diffstat (limited to 'src')
-rw-r--r--src/config.h5
-rw-r--r--src/defs.h2
-rw-r--r--src/sxwm.c72
3 files changed, 78 insertions, 1 deletions
diff --git a/src/config.h b/src/config.h
index 7c42764..b67b771 100644
--- a/src/config.h
+++ b/src/config.h
@@ -13,6 +13,9 @@ const Binding binds[] = {
{Mod4Mask, XK_j, {.fn = focus_next}, TYPE_FUNC},
{Mod4Mask, XK_k, {.fn = focus_prev}, TYPE_FUNC},
+ {Mod4Mask, XK_comma, {.fn = focus_prev_monitor}, TYPE_FUNC},
+ {Mod4Mask, XK_period, {.fn = focus_next_monitor}, TYPE_FUNC},
+
{Mod4Mask | ShiftMask, XK_j, {.fn = move_master_next}, TYPE_FUNC},
{Mod4Mask | ShiftMask, XK_k, {.fn = move_master_prev}, TYPE_FUNC},
@@ -53,4 +56,4 @@ const Binding binds[] = {
{Mod4Mask | ShiftMask, XK_8, {.ws = 7}, TYPE_MWKSP},
{Mod4Mask, XK_9, {.ws = 8}, TYPE_CWKSP},
{Mod4Mask | ShiftMask, XK_9, {.ws = 8}, TYPE_MWKSP},
-}; \ No newline at end of file
+};
diff --git a/src/defs.h b/src/defs.h
index 53c7c6a..9bba4be 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -107,6 +107,8 @@ extern void close_focused(void);
extern void dec_gaps(void);
extern void focus_next(void);
extern void focus_prev(void);
+extern void focus_next_monitor(void);
+extern void focus_prev_monitor(void);
extern void inc_gaps(void);
extern void move_master_next(void);
extern void move_master_prev(void);
diff --git a/src/sxwm.c b/src/sxwm.c
index bc6f922..63c0a24 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -343,6 +343,78 @@ void focus_prev(void)
update_borders();
}
+void focus_next_monitor(void)
+{
+ if (monsn <= 1) {
+ return; /* only one monitor, nothing to switch to */
+ }
+
+ int current_mon = focused ? focused->mon : 0;
+ int target_mon = (current_mon + 1) % monsn;
+
+ /* find the first window on the target monitor in current workspace */
+ Client *target_client = NULL;
+ for (Client *c = workspaces[current_ws]; c; c = c->next) {
+ if (c->mon == target_mon && c->mapped && !c->fullscreen) {
+ target_client = c;
+ break;
+ }
+ }
+
+ if (target_client) {
+ /* focus the window on target monitor */
+ focused = target_client;
+ XSetInputFocus(dpy, focused->win, RevertToPointerRoot, CurrentTime);
+ XRaiseWindow(dpy, focused->win);
+ if (user_config.warp_cursor) {
+ warp_cursor(focused);
+ }
+ update_borders();
+ } else {
+ /* no windows on target monitor, just move cursor to center */
+ int center_x = mons[target_mon].x + mons[target_mon].w / 2;
+ int center_y = mons[target_mon].y + mons[target_mon].h / 2;
+ XWarpPointer(dpy, None, root, 0, 0, 0, 0, center_x, center_y);
+ XSync(dpy, False);
+ }
+}
+
+void focus_prev_monitor(void)
+{
+ if (monsn <= 1) {
+ return; /* only one monitor, nothing to switch to */
+ }
+
+ int current_mon = focused ? focused->mon : 0;
+ int target_mon = (current_mon - 1 + monsn) % monsn;
+
+ /* find the first window on the target monitor in current workspace */
+ Client *target_client = NULL;
+ for (Client *c = workspaces[current_ws]; c; c = c->next) {
+ if (c->mon == target_mon && c->mapped && !c->fullscreen) {
+ target_client = c;
+ break;
+ }
+ }
+
+ if (target_client) {
+ /* focus the window on target monitor */
+ focused = target_client;
+ XSetInputFocus(dpy, focused->win, RevertToPointerRoot, CurrentTime);
+ XRaiseWindow(dpy, focused->win);
+ if (user_config.warp_cursor) {
+ warp_cursor(focused);
+ }
+ update_borders();
+ } else {
+ /* no windows on target monitor, just move cursor to center */
+ int center_x = mons[target_mon].x + mons[target_mon].w / 2;
+ int center_y = mons[target_mon].y + mons[target_mon].h / 2;
+ XWarpPointer(dpy, None, root, 0, 0, 0, 0, center_x, center_y);
+ XSync(dpy, False);
+ }
+}
+
int get_monitor_for(Client *c)
{
int cx = c->x + c->w / 2, cy = c->y + c->h / 2;