i3 - improved tiling WM


Add configuration option for disabling mouse warping

Patch status: superseded

Patch by Atte Peltomaki

Long description:

This patch fixes ticket #780 by adding a new configuration option
"mouse_warping [yes|no]".

When mouse warping is disabled, mouse cursor does not jump to middle of current
screen when changing workspaces on multiple monitors. This introduces a
"special" cursor state, where focus is in one window and cursor on another.
Useful for eg. scrolling a web page with mouse wheel while typing into another
window on keyboard.

fixes #780

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

b/docs/userguide

31
@@ -810,6 +810,22 @@ focus_follows_mouse <yes|no>
32
 focus_follows_mouse no
33
 ----------------------
34
 
35
+=== Focus follows mouse
36
+
37
+By default, mouse cursor is warped to center of the destination
38
+screen/workspace when switching to a different monitor. This option allows
39
+disabling mouse cursor warping entirely.
40
+
41
+*Syntax*:
42
+----------------------
43
+mouse_warping <yes|no>
44
+----------------------
45
+
46
+*Example*:
47
+----------------
48
+mouse_warping no
49
+----------------
50
+
51
 === Popups during fullscreen mode
52
 
53
 When you are in fullscreen mode, some applications still open popup windows

b/include/config.h

58
@@ -108,6 +108,11 @@ struct Config {
59
      * It is not planned to add any different focus models. */
60
     bool disable_focus_follows_mouse;
61
 
62
+    /** By default, mouse cursor is warped to center of the destination
63
+     * screen/workspace when switching focus to a different monitor.
64
+     * This option allows disabling mouse cursor warping entirely. */
65
+    bool disable_mouse_warping;
66
+
67
     /** Remove borders if they are adjacent to the screen edge.
68
      * This is useful if you are reaching scrollbar on the edge of the
69
      * screen or do not want to waste a single pixel of displayspace.

b/include/config_directives.h

74
@@ -46,6 +46,7 @@ CFGFUN(default_orientation, const char *orientation);
75
 CFGFUN(workspace_layout, const char *layout);
76
 CFGFUN(workspace_back_and_forth, const char *value);
77
 CFGFUN(focus_follows_mouse, const char *value);
78
+CFGFUN(mouse_warping, const char *value);
79
 CFGFUN(force_focus_wrapping, const char *value);
80
 CFGFUN(force_xinerama, const char *value);
81
 CFGFUN(fake_outputs, const char *outputs);

b/parser-specs/config.spec

86
@@ -32,6 +32,7 @@ state INITIAL:
87
   'for_window'                             -> FOR_WINDOW
88
   'assign'                                 -> ASSIGN
89
   'focus_follows_mouse'                    -> FOCUS_FOLLOWS_MOUSE
90
+  'mouse_warping'                          -> MOUSE_WARPING
91
   'force_focus_wrapping'                   -> FORCE_FOCUS_WRAPPING
92
   'force_xinerama', 'force-xinerama'       -> FORCE_XINERAMA
93
   'workspace_auto_back_and_forth'          -> WORKSPACE_BACK_AND_FORTH
94
@@ -172,6 +173,11 @@ state FOCUS_FOLLOWS_MOUSE:
95
   value = word
96
       -> call cfg_focus_follows_mouse($value)
97
 
98
+# mouse_warping bool
99
+state MOUSE_WARPING:
100
+  value = word
101
+      -> call cfg_mouse_warping($value)
102
+
103
 # force_focus_wrapping
104
 state FORCE_FOCUS_WRAPPING:
105
   value = word

b/src/config_directives.c

110
@@ -299,6 +299,10 @@ CFGFUN(focus_follows_mouse, const char *value) {
111
     config.disable_focus_follows_mouse = !eval_boolstr(value);
112
 }
113
 
114
+CFGFUN(mouse_warping, const char *value) {
115
+    config.disable_mouse_warping = !eval_boolstr(value);
116
+}
117
+
118
 CFGFUN(force_xinerama, const char *value) {
119
     config.force_xinerama = eval_boolstr(value);
120
 }

b/src/x.c

125
@@ -1142,7 +1142,7 @@ void x_set_i3_atoms(void) {
126
  */
127
 void x_set_warp_to(Rect *rect)
128
 {
129
-    if (!config.disable_focus_follows_mouse)
130
+    if (!config.disable_focus_follows_mouse && !config.disable_mouse_warping)
131
         warp_to = rect;
132
 }
133
 

b/testcases/t/201-config-parser.t

138
@@ -310,6 +310,24 @@ is(parser_calls($config),
139
    'focus_follows_mouse ok');
140
 
141
 ################################################################################
142
+# mouse_warping
143
+################################################################################
144
+
145
+$config = <<'EOT';
146
+mouse_warping yes
147
+mouse_warping no
148
+EOT
149
+
150
+$expected = <<'EOT';
151
+cfg_mouse_warping(yes)
152
+cfg_mouse_warping(no)
153
+EOT
154
+
155
+is(parser_calls($config),
156
+   $expected,
157
+   'mouse_warping ok');
158
+
159
+################################################################################
160
 # force_display_urgency_hint
161
 ################################################################################
162
 
163
@@ -413,7 +431,7 @@ client.focused          #4c7899 #285577 #ffffff #2e9ef4
164
 EOT
165
 
166
 my $expected_all_tokens = <<'EOT';
167
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
168
+ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'mouse_warping', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
169
 EOT
170
 
171
 my $expected_end = <<'EOT';

b/testcases/t/518-mouse-warping.t

177
@@ -0,0 +1,54 @@
178
+#!/perl
179
+# vim:ts=4:sw=4:expandtab
180
+#
181
+# Please read the following documents before working on tests:
182
+# • http://build.i3wm.org/docs/testsuite.html
183
+#   (or docs/testsuite)
184
+#
185
+# • http://build.i3wm.org/docs/lib-i3test.html
186
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
187
+#
188
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
189
+#   (unless you are already familiar with Perl)
190
+#
191
+# Ticket: #780
192
+
193
+use i3test i3_autostart => 0;
194
+
195
+# Ensure the pointer is at (0, 0) so that we really start on the first
196
+# (the left) workspace.
197
+$x->root->warp_pointer(0, 0);
198
+
199
+my $config = <<EOT;
200
+# i3 config file (v4)
201
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
202
+fake-outputs 1024x768+0+0,1024x768+1024+0
203
+mouse_warping no
204
+EOT
205
+my $pid = launch_with_config($config);
206
+
207
+my $i3 = i3(get_socket_path());
208
+
209
+######################################################
210
+# Open one workspace with one window on both outputs #
211
+######################################################
212
+
213
+# Open window on workspace 1, left output
214
+is(focused_ws, '1', 'starting with focus on workspace 1');
215
+open_window;
216
+
217
+# Open window on workspace 2, right output
218
+cmd 'focus output right';
219
+is(focused_ws, '2', 'moved focus to workspace 2');
220
+open_window;
221
+
222
+# If mouse_warping is disabled, the pointer has not moved from
223
+# position (0, 0) when focus was switched to workspace 2
224
+$x->root->warp_pointer(0, 0);
225
+
226
+# Ensure focus is still on workspace 2
227
+is(focused_ws, '2', 'warped mouse cursor to (0, 0), focus still in workspace 2');
228
+
229
+# Exit gracefully
230
+exit_gracefully($pid);
231
+done_testing;