summaryrefslogtreecommitdiff
path: root/patches/option-mirror-layout-palsmo.patch
blob: efad604ddf6409aa143c39ad16b601185adff167 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Author: palsmo
Date: 2025-09-04
Description: add mirror layout option
Commit Version: 591c550 (Merge pull request #227 from dehroox/main)

Add 'mirror_layout' configuration option to flip master-stack layout.
When enabled, master window stays on the right side instead of the default left,
and resize controls are reversed to maintain intuitive behavior.
---
 src/defs.h   |  1 +
 src/parser.c |  3 +++
 src/sxwm.c   | 40 ++++++++++++++++++++++++++++++++++------
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/src/defs.h b/src/defs.h
index 27d16fd..592ba47 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -104,6 +104,7 @@ typedef struct {
 	Bool new_win_focus;
 	Bool warp_cursor;
 	Bool new_win_master;
+    Bool mirror_layout;
 	Binding binds[MAX_ITEMS];
 	char **should_float[MAX_ITEMS];
 	char **start_fullscreen[MAX_ITEMS];
diff --git a/src/parser.c b/src/parser.c
index 6bfaeeb..ba19028 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -496,6 +496,9 @@ found:
 		else if (!strcmp(key, "new_win_master")) {
 			cfg->new_win_master = !strcmp(rest, "true") ? True : False;
 		}
+        else if (!strcmp(key, "mirror_layout")) {
+            cfg->mirror_layout = !strcmp(rest, "true") ? True : False;
+        }
 		else if (!strcmp(key, "open_in_workspace")) {
 			char *mid = strchr(rest, ':');
 			if (!mid) {
diff --git a/src/sxwm.c b/src/sxwm.c
index 843b133..ce0cb1c 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -1427,6 +1427,7 @@ void init_defaults(void)
 	default_config.new_win_focus = True;
 	default_config.warp_cursor = True;
 	default_config.new_win_master = False;
+    default_config.mirror_layout = False;

 	/*
 	if (backup_binds) {
@@ -1861,9 +1862,17 @@ void resize_master_add(void)
 	int m = focused ? focused->mon : 0;
 	float *mw = &user_config.master_width[m];

-	if (*mw < MF_MAX - 0.001f) {
-		*mw += ((float)user_config.resize_master_amt / 100);
+	if (user_config.mirror_layout) {
+		if (*mw < MF_MAX + 0.001f) {
+			*mw -= ((float)user_config.resize_master_amt / 100);
+		}
 	}
+	else {
+		if (*mw < MF_MAX - 0.001f) {
+			*mw += ((float)user_config.resize_master_amt / 100);
+		}
+ 	}
+
 	tile();
 	update_borders();
 }
@@ -1874,9 +1883,17 @@ void resize_master_sub(void)
 	int m = focused ? focused->mon : 0;
 	float *mw = &user_config.master_width[m];

-	if (*mw > MF_MIN + 0.001f) {
-		*mw -= ((float)user_config.resize_master_amt / 100);
+	if (user_config.mirror_layout) {
+		if (*mw > MF_MIN - 0.001f) {
+			*mw += ((float)user_config.resize_master_amt / 100);
+		}
 	}
+	else {
+		if (*mw > MF_MIN + 0.001f) {
+			*mw -= ((float)user_config.resize_master_amt / 100);
+		}
+ 	}
+
 	tile();
 	update_borders();
 }
@@ -2426,11 +2443,22 @@ void tile(void)
 		int master_width = (n_tileable > 1) ? (int)(tile_width * master_frac) : tile_width;
 		int stack_width = (n_tileable > 1) ? (tile_width - master_width - gaps) : 0;

+		int master_x, stack_x;
+		if (user_config.mirror_layout) {
+			master_x = tile_x + stack_width + (n_tileable > 1 ? gaps : 0);
+			stack_x = tile_x;
+		}
+		else {
+			master_x = tile_x;
+			stack_x = tile_x + master_width + gaps;
+		}
+
+
 		{
 			Client *c = tileable[0];
 			int border_width = 2 * user_config.border_width;
 			XWindowChanges wc = {
-				.x = tile_x,
+				.x = master_x,
 				.y = tile_y,
 				.width = MAX(1, master_width - border_width),
 				.height = MAX(1, tile_height - border_width),
@@ -2528,7 +2556,7 @@ void tile(void)
 		for (int i = 1; i < n_tileable; i++) {
 			Client *c = tileable[i];
 			XWindowChanges wc = {
-				.x = tile_x + master_width + gaps,
+				.x = stack_x,
 				.y = stack_y,
 				.width = MAX(1, stack_width - (2 * user_config.border_width)),
 				.height = MAX(1, heights_final[i] - (2 * user_config.border_width)),
--
2.51.0