From b7b08941d5dbb77744939f87c90eee4b9662ea46 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Sun, 24 Nov 2019 22:39:47 +0100 Subject: [PATCH 01/11] Add patch which provides primitive multimonitor functionality With this patch, center and fullscreen will work as expected when using multiple outputs. --- patches/sowm-primitive-multimonitor.patch | 104 ++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 patches/sowm-primitive-multimonitor.patch diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch new file mode 100644 index 0000000..6ab6955 --- /dev/null +++ b/patches/sowm-primitive-multimonitor.patch @@ -0,0 +1,104 @@ +diff --git a/Makefile b/Makefile +index 8573837..72e9542 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,5 +1,5 @@ + CFLAGS+= -std=c99 -Wall -Wextra -pedantic +-LDADD+= -lX11 ++LDADD+= -lX11 -lXinerama + LDFLAGS= + PREFIX?= /usr + BINDIR?= $(PREFIX)/bin +diff --git a/sowm.c b/sowm.c +index 0cc1293..27c51ce 100644 +--- a/sowm.c ++++ b/sowm.c +@@ -4,9 +4,11 @@ + #include + #include + #include ++#include + #include + #include + #include ++#include + + typedef union { + const char** com; +@@ -97,6 +99,7 @@ void notify_enter(XEvent *e) { + + void notify_motion(XEvent *e) { + if (!mouse.subwindow) return; ++ if (cur->f == 1) return; + + while(XCheckTypedEvent(d, MotionNotify, e)); + +@@ -108,6 +111,7 @@ void notify_motion(XEvent *e) { + wy + (mouse.button == 1 ? yd : 0), + ww + (mouse.button == 3 ? xd : 0), + wh + (mouse.button == 3 ? yd : 0)); ++ win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); + } + + void key_press(XEvent *e) { +@@ -172,12 +176,37 @@ void win_kill() { + if (cur) XKillClient(d, cur->w); + } + ++bool coords_in_box (int x, int y, int box_x, int box_y, int box_w, int box_h) { ++ if ((x >= box_x && x < box_x + box_w) && (y >= box_y && y < box_y + box_h)) ++ return true; ++ else ++ return false; ++} ++ + void win_center() { + if (!cur) return; + + win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh); + +- XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); ++ if (XineramaIsActive(d)) { ++ int number_of_monitors; ++ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &number_of_monitors); ++ /* Checking on which monitor the origin of the window is. Technically it ++ * would be better to check for the center of the window, but that is ++ * only relevant in the edge case when a window is displayed on multiple ++ * outputs simultaneously. ++ */ ++ for (int i = 0; i < number_of_monitors; i++) { ++ if (coords_in_box(cur->wx, cur->wy, ++ screen_info[i].x_org, screen_info[i].y_org, ++ screen_info[i].width, screen_info[i].height)) ++ XMoveWindow(d, cur->w, ++ screen_info[i].x_org + ((screen_info[i].width - ww) / 2), ++ screen_info[i].y_org + ((screen_info[i].height - wh) / 2)); ++ } ++ } else ++ XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); ++ win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); + } + + void win_fs() { +@@ -185,8 +214,19 @@ void win_fs() { + + if ((cur->f = cur->f ? 0 : 1)) { + win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); +- XMoveResizeWindow(d, cur->w, 0, 0, sw, sh); +- ++ if (XineramaIsActive(d)) { ++ int number_of_monitors; ++ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &number_of_monitors); ++ for (int i = 0; i < number_of_monitors; i++) { ++ if (coords_in_box(cur->wx, cur->wy, ++ screen_info[i].x_org, screen_info[i].y_org, ++ screen_info[i].width, screen_info[i].height)) ++ XMoveResizeWindow(d, cur->w, ++ screen_info[i].x_org, screen_info[i].y_org, ++ screen_info[i].width, screen_info[i].height); ++ } ++ } else ++ XMoveResizeWindow(d, cur->w, 0, 0, sw, sh); + } else + XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh); + } From 818480983f4518d02f0a3db7705ea2b152ef64ef Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 04:58:46 +0100 Subject: [PATCH 02/11] Check center of window instead of origin. Checking on what monitor the center of a window is, is more intuitive. --- patches/sowm-primitive-multimonitor.patch | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 6ab6955..4d48b0a 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -41,7 +41,7 @@ index 0cc1293..27c51ce 100644 } void key_press(XEvent *e) { -@@ -172,12 +176,37 @@ void win_kill() { +@@ -172,12 +171,32 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } @@ -61,13 +61,8 @@ index 0cc1293..27c51ce 100644 + if (XineramaIsActive(d)) { + int number_of_monitors; + XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &number_of_monitors); -+ /* Checking on which monitor the origin of the window is. Technically it -+ * would be better to check for the center of the window, but that is -+ * only relevant in the edge case when a window is displayed on multiple -+ * outputs simultaneously. -+ */ + for (int i = 0; i < number_of_monitors; i++) { -+ if (coords_in_box(cur->wx, cur->wy, ++ if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), + screen_info[i].x_org, screen_info[i].y_org, + screen_info[i].width, screen_info[i].height)) + XMoveWindow(d, cur->w, @@ -90,7 +85,7 @@ index 0cc1293..27c51ce 100644 + int number_of_monitors; + XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &number_of_monitors); + for (int i = 0; i < number_of_monitors; i++) { -+ if (coords_in_box(cur->wx, cur->wy, ++ if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), + screen_info[i].x_org, screen_info[i].y_org, + screen_info[i].width, screen_info[i].height)) + XMoveResizeWindow(d, cur->w, From 8f1b7c28dfcab59b85ec4cf7b911b71e97a0763d Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 09:50:53 +0100 Subject: [PATCH 03/11] Remove dependency on stdbool.h --- patches/sowm-primitive-multimonitor.patch | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 4d48b0a..c3f9405 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -13,7 +13,7 @@ diff --git a/sowm.c b/sowm.c index 0cc1293..27c51ce 100644 --- a/sowm.c +++ b/sowm.c -@@ -4,9 +4,11 @@ +@@ -4,9 +4,10 @@ #include #include #include @@ -21,7 +21,6 @@ index 0cc1293..27c51ce 100644 #include #include #include -+#include typedef union { const char** com; @@ -45,11 +44,11 @@ index 0cc1293..27c51ce 100644 if (cur) XKillClient(d, cur->w); } -+bool coords_in_box (int x, int y, int box_x, int box_y, int box_w, int box_h) { ++int coords_in_box (int x, int y, int box_x, int box_y, int box_w, int box_h) { + if ((x >= box_x && x < box_x + box_w) && (y >= box_y && y < box_y + box_h)) -+ return true; ++ return 1; + else -+ return false; ++ return 0; +} + void win_center() { From 425ae0f698063faebf34eb659f4689205851d98d Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 13:02:21 +0100 Subject: [PATCH 04/11] Style Whitespace --- patches/sowm-primitive-multimonitor.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index c3f9405..86a91a1 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -17,7 +17,7 @@ index 0cc1293..27c51ce 100644 #include #include #include -+#include ++#include #include #include #include From 216e46284198dbb47436e4fa90f2522778153ef0 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 13:12:06 +0100 Subject: [PATCH 05/11] Simply coords_in_box() --- patches/sowm-primitive-multimonitor.patch | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 86a91a1..ed4b909 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -40,15 +40,12 @@ index 0cc1293..27c51ce 100644 } void key_press(XEvent *e) { -@@ -172,12 +171,32 @@ void win_kill() { +@@ -172,12 +171,29 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } +int coords_in_box (int x, int y, int box_x, int box_y, int box_w, int box_h) { -+ if ((x >= box_x && x < box_x + box_w) && (y >= box_y && y < box_y + box_h)) -+ return 1; -+ else -+ return 0; ++ return ((x >= box_x && x < box_x + box_w) && (y >= box_y && y < box_y + box_h)); +} + void win_center() { From afa8b1871f5a5c2bd4107eacda696b69c793da25 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 13:22:44 +0100 Subject: [PATCH 06/11] Make number_of_monitors global --- patches/sowm-primitive-multimonitor.patch | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index ed4b909..483644a 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -10,10 +10,10 @@ index 8573837..72e9542 100644 PREFIX?= /usr BINDIR?= $(PREFIX)/bin diff --git a/sowm.c b/sowm.c -index 0cc1293..27c51ce 100644 +index 0cc1293..ead3f6c 100644 --- a/sowm.c +++ b/sowm.c -@@ -4,9 +4,10 @@ +@@ -4,6 +4,7 @@ #include #include #include @@ -21,10 +21,16 @@ index 0cc1293..27c51ce 100644 #include #include #include +@@ -48,7 +49,7 @@ static void ws_go(const Arg arg); + static int xerror() { return 0;} - typedef union { - const char** com; -@@ -97,6 +99,7 @@ void notify_enter(XEvent *e) { + static client *list = {0}, *ws_list[10] = {0}, *cur; +-static int ws = 1, sw, sh, wx, wy; ++static int ws = 1, sw, sh, wx, wy, monitors; + static unsigned int ww, wh; + + static Display *d; +@@ -97,6 +98,7 @@ void notify_enter(XEvent *e) { void notify_motion(XEvent *e) { if (!mouse.subwindow) return; @@ -32,7 +38,7 @@ index 0cc1293..27c51ce 100644 while(XCheckTypedEvent(d, MotionNotify, e)); -@@ -108,6 +111,7 @@ void notify_motion(XEvent *e) { +@@ -108,6 +110,7 @@ void notify_motion(XEvent *e) { wy + (mouse.button == 1 ? yd : 0), ww + (mouse.button == 3 ? xd : 0), wh + (mouse.button == 3 ? yd : 0)); @@ -40,7 +46,7 @@ index 0cc1293..27c51ce 100644 } void key_press(XEvent *e) { -@@ -172,12 +171,29 @@ void win_kill() { +@@ -172,12 +175,28 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } @@ -55,9 +61,8 @@ index 0cc1293..27c51ce 100644 - XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); + if (XineramaIsActive(d)) { -+ int number_of_monitors; -+ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &number_of_monitors); -+ for (int i = 0; i < number_of_monitors; i++) { ++ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); ++ for (int i = 0; i < monitors; i++) { + if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), + screen_info[i].x_org, screen_info[i].y_org, + screen_info[i].width, screen_info[i].height)) @@ -71,16 +76,15 @@ index 0cc1293..27c51ce 100644 } void win_fs() { -@@ -185,8 +214,19 @@ void win_fs() { +@@ -185,8 +204,18 @@ void win_fs() { if ((cur->f = cur->f ? 0 : 1)) { win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); - XMoveResizeWindow(d, cur->w, 0, 0, sw, sh); - + if (XineramaIsActive(d)) { -+ int number_of_monitors; -+ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &number_of_monitors); -+ for (int i = 0; i < number_of_monitors; i++) { ++ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); ++ for (int i = 0; i < monitors; i++) { + if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), + screen_info[i].x_org, screen_info[i].y_org, + screen_info[i].width, screen_info[i].height)) From 4867928d5789e6922ad3b0bd663801f95e060407 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 13:37:04 +0100 Subject: [PATCH 07/11] Monitor iterating now in its own function --- patches/sowm-primitive-multimonitor.patch | 63 +++++++++++------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 483644a..61acd7f 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -10,7 +10,7 @@ index 8573837..72e9542 100644 PREFIX?= /usr BINDIR?= $(PREFIX)/bin diff --git a/sowm.c b/sowm.c -index 0cc1293..ead3f6c 100644 +index 0cc1293..40b39dd 100644 --- a/sowm.c +++ b/sowm.c @@ -4,6 +4,7 @@ @@ -30,15 +30,7 @@ index 0cc1293..ead3f6c 100644 static unsigned int ww, wh; static Display *d; -@@ -97,6 +98,7 @@ void notify_enter(XEvent *e) { - - void notify_motion(XEvent *e) { - if (!mouse.subwindow) return; -+ if (cur->f == 1) return; - - while(XCheckTypedEvent(d, MotionNotify, e)); - -@@ -108,6 +110,7 @@ void notify_motion(XEvent *e) { +@@ -108,6 +109,7 @@ void notify_motion(XEvent *e) { wy + (mouse.button == 1 ? yd : 0), ww + (mouse.button == 3 ? xd : 0), wh + (mouse.button == 3 ? yd : 0)); @@ -46,13 +38,35 @@ index 0cc1293..ead3f6c 100644 } void key_press(XEvent *e) { -@@ -172,12 +175,28 @@ void win_kill() { +@@ -172,12 +174,41 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } +int coords_in_box (int x, int y, int box_x, int box_y, int box_w, int box_h) { + return ((x >= box_x && x < box_x + box_w) && (y >= box_y && y < box_y + box_h)); +} ++ ++int multimonitor_center_fs (int fs) { ++ if (XineramaIsActive(d)) { ++ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); ++ for (int i = 0; i < monitors; i++) { ++ if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), ++ screen_info[i].x_org, screen_info[i].y_org, ++ screen_info[i].width, screen_info[i].height)) { ++ if (fs) ++ XMoveResizeWindow(d, cur->w, ++ screen_info[i].x_org, screen_info[i].y_org, ++ screen_info[i].width, screen_info[i].height); ++ else ++ XMoveWindow(d, cur->w, ++ screen_info[i].x_org + ((screen_info[i].width - ww) / 2), ++ screen_info[i].y_org + ((screen_info[i].height - wh) / 2)); ++ } ++ return 0; ++ } ++ } ++ return 1; ++} + void win_center() { if (!cur) return; @@ -60,39 +74,20 @@ index 0cc1293..ead3f6c 100644 win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh); - XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); -+ if (XineramaIsActive(d)) { -+ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); -+ for (int i = 0; i < monitors; i++) { -+ if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), -+ screen_info[i].x_org, screen_info[i].y_org, -+ screen_info[i].width, screen_info[i].height)) -+ XMoveWindow(d, cur->w, -+ screen_info[i].x_org + ((screen_info[i].width - ww) / 2), -+ screen_info[i].y_org + ((screen_info[i].height - wh) / 2)); -+ } -+ } else ++ if (multimonitor_center_fs(0)) + XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); ++ + win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); } void win_fs() { -@@ -185,8 +204,18 @@ void win_fs() { +@@ -185,8 +216,8 @@ void win_fs() { if ((cur->f = cur->f ? 0 : 1)) { win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); - XMoveResizeWindow(d, cur->w, 0, 0, sw, sh); - -+ if (XineramaIsActive(d)) { -+ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); -+ for (int i = 0; i < monitors; i++) { -+ if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), -+ screen_info[i].x_org, screen_info[i].y_org, -+ screen_info[i].width, screen_info[i].height)) -+ XMoveResizeWindow(d, cur->w, -+ screen_info[i].x_org, screen_info[i].y_org, -+ screen_info[i].width, screen_info[i].height); -+ } -+ } else ++ if(multimonitor_center_fs(1)) + XMoveResizeWindow(d, cur->w, 0, 0, sw, sh); } else XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh); From 4dd50e6f4facc0b5908f75b081e65b6d3bb38752 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 13:47:20 +0100 Subject: [PATCH 08/11] Remove coords_in_box() --- patches/sowm-primitive-multimonitor.patch | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 61acd7f..0e1a6d4 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -10,7 +10,7 @@ index 8573837..72e9542 100644 PREFIX?= /usr BINDIR?= $(PREFIX)/bin diff --git a/sowm.c b/sowm.c -index 0cc1293..40b39dd 100644 +index 0cc1293..665b0f8 100644 --- a/sowm.c +++ b/sowm.c @@ -4,6 +4,7 @@ @@ -38,21 +38,16 @@ index 0cc1293..40b39dd 100644 } void key_press(XEvent *e) { -@@ -172,12 +174,41 @@ void win_kill() { +@@ -172,12 +174,36 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } -+int coords_in_box (int x, int y, int box_x, int box_y, int box_w, int box_h) { -+ return ((x >= box_x && x < box_x + box_w) && (y >= box_y && y < box_y + box_h)); -+} -+ +int multimonitor_center_fs (int fs) { + if (XineramaIsActive(d)) { + XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); + for (int i = 0; i < monitors; i++) { -+ if (coords_in_box(cur->wx + (cur->ww / 2), cur->wy + (cur->wh / 2), -+ screen_info[i].x_org, screen_info[i].y_org, -+ screen_info[i].width, screen_info[i].height)) { ++ if ((cur->wx >= screen_info[i].x_org && cur->wx < screen_info[i].x_org + screen_info[i].width) ++ && (cur->wy >= screen_info[i].y_org && cur->wy < screen_info[i].y_org + screen_info[i].height)) { + if (fs) + XMoveResizeWindow(d, cur->w, + screen_info[i].x_org, screen_info[i].y_org, @@ -81,7 +76,7 @@ index 0cc1293..40b39dd 100644 } void win_fs() { -@@ -185,8 +216,8 @@ void win_fs() { +@@ -185,8 +211,8 @@ void win_fs() { if ((cur->f = cur->f ? 0 : 1)) { win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); From c6ff8d06a06fee7e7dce492135c658725b534950 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 13:52:55 +0100 Subject: [PATCH 09/11] Simplify multimonitor_center_fs() --- patches/sowm-primitive-multimonitor.patch | 37 +++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 0e1a6d4..106ed38 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -10,7 +10,7 @@ index 8573837..72e9542 100644 PREFIX?= /usr BINDIR?= $(PREFIX)/bin diff --git a/sowm.c b/sowm.c -index 0cc1293..665b0f8 100644 +index 0cc1293..fa911b0 100644 --- a/sowm.c +++ b/sowm.c @@ -4,6 +4,7 @@ @@ -38,29 +38,28 @@ index 0cc1293..665b0f8 100644 } void key_press(XEvent *e) { -@@ -172,12 +174,36 @@ void win_kill() { +@@ -172,12 +174,35 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } +int multimonitor_center_fs (int fs) { -+ if (XineramaIsActive(d)) { -+ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); -+ for (int i = 0; i < monitors; i++) { -+ if ((cur->wx >= screen_info[i].x_org && cur->wx < screen_info[i].x_org + screen_info[i].width) -+ && (cur->wy >= screen_info[i].y_org && cur->wy < screen_info[i].y_org + screen_info[i].height)) { -+ if (fs) -+ XMoveResizeWindow(d, cur->w, -+ screen_info[i].x_org, screen_info[i].y_org, -+ screen_info[i].width, screen_info[i].height); -+ else -+ XMoveWindow(d, cur->w, -+ screen_info[i].x_org + ((screen_info[i].width - ww) / 2), -+ screen_info[i].y_org + ((screen_info[i].height - wh) / 2)); -+ } -+ return 0; ++ if (!XineramaIsActive(d)) ++ return 1; ++ XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); ++ for (int i = 0; i < monitors; i++) { ++ if ((cur->wx >= screen_info[i].x_org && cur->wx < screen_info[i].x_org + screen_info[i].width) ++ && (cur->wy >= screen_info[i].y_org && cur->wy < screen_info[i].y_org + screen_info[i].height)) { ++ if (fs) ++ XMoveResizeWindow(d, cur->w, ++ screen_info[i].x_org, screen_info[i].y_org, ++ screen_info[i].width, screen_info[i].height); ++ else ++ XMoveWindow(d, cur->w, ++ screen_info[i].x_org + ((screen_info[i].width - ww) / 2), ++ screen_info[i].y_org + ((screen_info[i].height - wh) / 2)); + } + } -+ return 1; ++ return 0; +} + void win_center() { @@ -76,7 +75,7 @@ index 0cc1293..665b0f8 100644 } void win_fs() { -@@ -185,8 +211,8 @@ void win_fs() { +@@ -185,8 +210,8 @@ void win_fs() { if ((cur->f = cur->f ? 0 : 1)) { win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); From 9a634e61340cdafd2f562df136dbcaa83a6e0298 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 17:20:49 +0100 Subject: [PATCH 10/11] Style --- patches/sowm-primitive-multimonitor.patch | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 106ed38..966f2bf 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -10,7 +10,7 @@ index 8573837..72e9542 100644 PREFIX?= /usr BINDIR?= $(PREFIX)/bin diff --git a/sowm.c b/sowm.c -index 0cc1293..fa911b0 100644 +index 0cc1293..e8cbce6 100644 --- a/sowm.c +++ b/sowm.c @@ -4,6 +4,7 @@ @@ -38,13 +38,12 @@ index 0cc1293..fa911b0 100644 } void key_press(XEvent *e) { -@@ -172,12 +174,35 @@ void win_kill() { +@@ -172,12 +174,34 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } +int multimonitor_center_fs (int fs) { -+ if (!XineramaIsActive(d)) -+ return 1; ++ if (!XineramaIsActive(d)) return 1; + XineramaScreenInfo *screen_info = XineramaQueryScreens(d, &monitors); + for (int i = 0; i < monitors; i++) { + if ((cur->wx >= screen_info[i].x_org && cur->wx < screen_info[i].x_org + screen_info[i].width) @@ -75,7 +74,7 @@ index 0cc1293..fa911b0 100644 } void win_fs() { -@@ -185,8 +210,8 @@ void win_fs() { +@@ -185,8 +209,8 @@ void win_fs() { if ((cur->f = cur->f ? 0 : 1)) { win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); From 6b12178131c826c0434aa5c9b3aed385a3917ce0 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Mon, 25 Nov 2019 17:32:07 +0100 Subject: [PATCH 11/11] Double bug fix Fixes bug where loop would continue even after window is configured. Fixes bug where the window origins instead of window center is the relevant coordinates for determining on which monitor a window is displayed. --- patches/sowm-primitive-multimonitor.patch | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/patches/sowm-primitive-multimonitor.patch b/patches/sowm-primitive-multimonitor.patch index 966f2bf..af43e11 100644 --- a/patches/sowm-primitive-multimonitor.patch +++ b/patches/sowm-primitive-multimonitor.patch @@ -10,7 +10,7 @@ index 8573837..72e9542 100644 PREFIX?= /usr BINDIR?= $(PREFIX)/bin diff --git a/sowm.c b/sowm.c -index 0cc1293..e8cbce6 100644 +index 0cc1293..6f858a9 100644 --- a/sowm.c +++ b/sowm.c @@ -4,6 +4,7 @@ @@ -38,7 +38,7 @@ index 0cc1293..e8cbce6 100644 } void key_press(XEvent *e) { -@@ -172,12 +174,34 @@ void win_kill() { +@@ -172,12 +174,35 @@ void win_kill() { if (cur) XKillClient(d, cur->w); } @@ -56,6 +56,7 @@ index 0cc1293..e8cbce6 100644 + XMoveWindow(d, cur->w, + screen_info[i].x_org + ((screen_info[i].width - ww) / 2), + screen_info[i].y_org + ((screen_info[i].height - wh) / 2)); ++ break; + } + } + return 0; @@ -74,7 +75,7 @@ index 0cc1293..e8cbce6 100644 } void win_fs() { -@@ -185,8 +209,8 @@ void win_fs() { +@@ -185,8 +210,8 @@ void win_fs() { if ((cur->f = cur->f ? 0 : 1)) { win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh);