This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sowm-primitive-multimonitor.patch
105 lines (94 loc) · 3.22 KB
/
sowm-primitive-multimonitor.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
diff --git a/Makefile b/Makefile
index 6a840ae..eb66fab 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ config.h:
cp config.def.h config.h
sowm: sowm.o
- $(CC) $(LDFLAGS) -O3 -o $@ $+ -lX11
+ $(CC) $(LDFLAGS) -O3 -o $@ $+ -lX11 -lXinerama
install: all
install -Dm755 sowm $(DESTDIR)$(BINDIR)/sowm
diff --git a/sowm.c b/sowm.c
index 793826c..3934f9c 100644
--- a/sowm.c
+++ b/sowm.c
@@ -4,6 +4,7 @@
#include <X11/XF86keysym.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
+#include <X11/extensions/Xinerama.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
@@ -11,7 +12,7 @@
#include "sowm.h"
static client *list = {0}, *ws_list[10] = {0}, *cur;
-static int ws = 1, sw, sh, wx, wy, numlock = 0;
+static int ws = 1, sw, sh, wx, wy, numlock = 0, monitors;
static unsigned int ww, wh;
static Display *d;
@@ -60,6 +61,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) {
@@ -124,11 +126,37 @@ void win_kill(const Arg arg) {
if (cur) XKillClient(d, cur->w);
}
+int multimonitor_action (int action) { // action = 0 -> center; action = 1 -> fs
+ if (!XineramaIsActive(d)) return 1;
+ XineramaScreenInfo *si = XineramaQueryScreens(d, &monitors);
+ for (int i = 0; i < monitors; i++) {
+ if ((cur->wx + (cur->ww/2) >= (unsigned int)si[i].x_org
+ && cur->wx + (cur->ww/2) < (unsigned int)si[i].x_org + si[i].width)
+ && ( cur->wy + (cur->wh/2) >= (unsigned int)si[i].y_org
+ && cur->wy + (cur->wh/2) < (unsigned int)si[i].y_org + si[i].height)) {
+ if (action)
+ XMoveResizeWindow(d, cur->w,
+ si[i].x_org, si[i].y_org,
+ si[i].width, si[i].height);
+ else
+ XMoveWindow(d, cur->w,
+ si[i].x_org + ((si[i].width - ww)/2),
+ si[i].y_org + ((si[i].height -wh)/2));
+ break;
+ }
+ }
+ return 0;
+}
+
void win_center(const Arg arg) {
if (!cur) return;
win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh);
- XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2);
+
+ if (multimonitor_action(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(const Arg arg) {
@@ -136,8 +164,9 @@ void win_fs(const Arg arg) {
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 (multimonitor_action(1))
+ XMoveResizeWindow(d, cur->w, 0, 0, sw, sh);
} else
XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh);
}
diff --git a/sowm.h b/sowm.h
index 750b297..f679715 100644
--- a/sowm.h
+++ b/sowm.h
@@ -32,6 +32,8 @@ typedef struct client {
Window w;
} client;
+int multimonitor_action(int action);
+
void button_press(XEvent *e);
void button_release(XEvent *e);
void configure_request(XEvent *e);