i3 - improved tiling WM


Separate border width for floating windows

Patch status: merged

Patch by Aleksi Blinnikka

Long description:

Floating windows already had their own border style, but the width was
the same for all windows.

The configuration directives 'new_window' and 'new_float' can now be
used simultaneously to have different border widths for floating and
tiled windows.

fixes #1244

To apply this patch, use:
curl http://cr.i3wm.org/patch/547/raw.patch | git am

b/include/config.h

27
@@ -98,6 +98,7 @@ struct Config {
28
     int container_stack_limit;
29
     int container_stack_limit_value;
30
     int default_border_width;
31
+    int default_floating_border_width;
32
 
33
     /** Default orientation for new containers */
34
     int default_orientation;

b/src/con.c

39
@@ -1090,8 +1090,13 @@ Rect con_border_style_rect(Con *con) {
40
     int border_width = con->current_border_width;
41
     DLOG("The border width for con is set to: %d\n", con->current_border_width);
42
     Rect result;
43
-    if (con->current_border_width < 0)
44
-        border_width = config.default_border_width;
45
+    if (con->current_border_width < 0) {
46
+        if (con_is_floating(con)) {
47
+            border_width = config.default_floating_border_width;
48
+        } else {
49
+            border_width = config.default_border_width;
50
+        }
51
+    }
52
     DLOG("Effective border width is set to: %d\n", border_width);
53
     /* Shortcut to avoid calling con_adjacent_borders() on dock containers. */
54
     int border_style = con_border_style(con);

b/src/config.c

59
@@ -255,6 +255,7 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
60
     config.default_border = BS_NORMAL;
61
     config.default_floating_border = BS_NORMAL;
62
     config.default_border_width = logical_px(2);
63
+    config.default_floating_border_width = logical_px(2);
64
     /* Set default_orientation to NO_ORIENTATION for auto orientation. */
65
     config.default_orientation = NO_ORIENTATION;
66
 

b/src/config_directives.c

71
@@ -252,9 +252,6 @@ CFGFUN(workspace_layout, const char *layout) {
72
 }
73
 
74
 CFGFUN(new_window, const char *windowtype, const char *border, const long width) {
75
-    // FIXME: when using new_float *and* new_window with different border
76
-    // types, this breaks because default_border_width gets overwritten.
77
-
78
     int border_style;
79
     int border_width;
80
 
81
@@ -273,12 +270,14 @@ CFGFUN(new_window, const char *windowtype, const char *border, const long width)
82
     }
83
 
84
     if (strcmp(windowtype, "new_window") == 0) {
85
+        DLOG("default tiled border style = %d and border width = %d\n", border_style, border_width);
86
         config.default_border = border_style;
87
+        config.default_border_width = border_width;
88
     } else {
89
+        DLOG("default floating border style = %d and border width = %d\n", border_style, border_width);
90
         config.default_floating_border = border_style;
91
+        config.default_floating_border_width = border_width;
92
     }
93
-
94
-    config.default_border_width = border_width;
95
 }
96
 
97
 CFGFUN(hide_edge_borders, const char *borders) {

b/src/manage.c

102
@@ -430,7 +430,11 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
103
 
104
     if (motif_border_style != BS_NORMAL) {
105
         DLOG("MOTIF_WM_HINTS specifies decorations (border_style = %d)\n", motif_border_style);
106
-        con_set_border_style(nc, motif_border_style, config.default_border_width);
107
+        if (want_floating) {
108
+            con_set_border_style(nc, motif_border_style, config.default_floating_border_width);
109
+        } else {
110
+            con_set_border_style(nc, motif_border_style, config.default_border_width);
111
+        }
112
     }
113
 
114
     /* to avoid getting an UnmapNotify event due to reparenting, we temporarily

b/testcases/t/228-border-widths.t

120
@@ -0,0 +1,91 @@
121
+#!perl
122
+# vim:ts=4:sw=4:expandtab
123
+#
124
+# Please read the following documents before working on tests:
125
+# • http://build.i3wm.org/docs/testsuite.html
126
+#   (or docs/testsuite)
127
+#
128
+# • http://build.i3wm.org/docs/lib-i3test.html
129
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
130
+#
131
+# • http://build.i3wm.org/docs/ipc.html
132
+#   (or docs/ipc)
133
+#
134
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
135
+#   (unless you are already familiar with Perl)
136
+#
137
+# Tests that the border widths can be set separately for floating and
138
+# tiled windows
139
+# Ticket: #1244
140
+# Bug still in: 4.7.2-166-gb69b3fc
141
+
142
+use i3test i3_autostart => 0;
143
+
144
+#####################################################################
145
+# 1: check that the border widths can be different for floating and
146
+# tiled windows
147
+#####################################################################
148
+
149
+my $config = <<EOT;
150
+# i3 config file (v4)
151
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
152
+
153
+new_window pixel 5
154
+new_float pixel 10
155
+EOT
156
+
157
+my $pid = launch_with_config($config);
158
+
159
+my $tmp = fresh_workspace;
160
+
161
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
162
+
163
+my $tilewindow = open_window;
164
+my $floatwindow = open_floating_window;
165
+
166
+my $wscontent = get_ws($tmp);
167
+
168
+my @tiled = @{$wscontent->{nodes}};
169
+ok(@tiled == 1, 'one tiled container opened');
170
+is($tilewindow->rect->width, $tiled[0]->{rect}->{width} - 2*5, 'tiled border width 5');
171
+
172
+my @floating = @{$wscontent->{floating_nodes}};
173
+ok(@floating == 1, 'one floating container opened');
174
+is($floatwindow->rect->width, $floating[0]->{rect}->{width} - 2*10, 'floating border width 10');
175
+
176
+exit_gracefully($pid);
177
+
178
+#####################################################################
179
+# 2: make sure the order can also be reverse
180
+#####################################################################
181
+
182
+$config = <<EOT;
183
+# i3 config file (v4)
184
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
185
+
186
+new_float pixel 7
187
+new_window pixel 3
188
+EOT
189
+
190
+$pid = launch_with_config($config);
191
+
192
+$tmp = fresh_workspace;
193
+
194
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
195
+
196
+$tilewindow = open_window;
197
+$floatwindow = open_floating_window;
198
+
199
+$wscontent = get_ws($tmp);
200
+
201
+@tiled = @{$wscontent->{nodes}};
202
+ok(@tiled == 1, 'one tiled container opened');
203
+is($tilewindow->rect->width, $tiled[0]->{rect}->{width} - 2*3, 'tiled border width 3');
204
+
205
+@floating = @{$wscontent->{floating_nodes}};
206
+ok(@floating == 1, 'one floating container opened');
207
+is($floatwindow->rect->width, $floating[0]->{rect}->{width} - 2*7, 'floating border width 7');
208
+
209
+exit_gracefully($pid);
210
+
211
+done_testing;