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/548/raw.patch | git am

b/debian/control

32
@@ -15,7 +15,7 @@ Build-Depends: debhelper (>= 7.0.50~),
33
                docbook-xml,
34
                pkg-config,
35
                libev-dev (>= 1:4.04),
36
-               libyajl-dev,
37
+               libyajl-dev (>= 2.0.4),
38
                libpcre3-dev,
39
                libstartup-notification0-dev (>= 0.10),
40
                libcairo2-dev,

b/docs/userguide

45
@@ -810,6 +810,22 @@ focus_follows_mouse <yes|no>
46
 focus_follows_mouse no
47
 ----------------------
48
 
49
+=== Focus follows mouse
50
+
51
+By default, mouse cursor is warped to center of the destination
52
+screen/workspace when switching to a different monitor. This option allows
53
+disabling mouse cursor warping entirely.
54
+
55
+*Syntax*:
56
+----------------------
57
+mouse_warping <yes|no>
58
+----------------------
59
+
60
+*Example*:
61
+----------------
62
+mouse_warping no
63
+----------------
64
+
65
 === Popups during fullscreen mode
66
 
67
 When you are in fullscreen mode, some applications still open popup windows

b/include/config.h

72
@@ -108,6 +108,11 @@ struct Config {
73
      * It is not planned to add any different focus models. */
74
     bool disable_focus_follows_mouse;
75
 
76
+    /** By default, mouse cursor is warped to center of the destination
77
+     * screen/workspace when switching focus to a different monitor.
78
+     * This option allows disabling mouse cursor warping entirely. */
79
+    bool disable_mouse_warping;
80
+
81
     /** Remove borders if they are adjacent to the screen edge.
82
      * This is useful if you are reaching scrollbar on the edge of the
83
      * screen or do not want to waste a single pixel of displayspace.

b/include/config_directives.h

88
@@ -46,6 +46,7 @@ CFGFUN(default_orientation, const char *orientation);
89
 CFGFUN(workspace_layout, const char *layout);
90
 CFGFUN(workspace_back_and_forth, const char *value);
91
 CFGFUN(focus_follows_mouse, const char *value);
92
+CFGFUN(mouse_warping, const char *value);
93
 CFGFUN(force_focus_wrapping, const char *value);
94
 CFGFUN(force_xinerama, const char *value);
95
 CFGFUN(fake_outputs, const char *outputs);

b/parser-specs/config.spec

100
@@ -32,6 +32,7 @@ state INITIAL:
101
   'for_window'                             -> FOR_WINDOW
102
   'assign'                                 -> ASSIGN
103
   'focus_follows_mouse'                    -> FOCUS_FOLLOWS_MOUSE
104
+  'mouse_warping'                          -> MOUSE_WARPING
105
   'force_focus_wrapping'                   -> FORCE_FOCUS_WRAPPING
106
   'force_xinerama', 'force-xinerama'       -> FORCE_XINERAMA
107
   'workspace_auto_back_and_forth'          -> WORKSPACE_BACK_AND_FORTH
108
@@ -172,6 +173,11 @@ state FOCUS_FOLLOWS_MOUSE:
109
   value = word
110
       -> call cfg_focus_follows_mouse($value)
111
 
112
+# mouse_warping bool
113
+state MOUSE_WARPING:
114
+  value = word
115
+      -> call cfg_mouse_warping($value)
116
+
117
 # force_focus_wrapping
118
 state FORCE_FOCUS_WRAPPING:
119
   value = word

b/src/config_directives.c

124
@@ -299,6 +299,10 @@ CFGFUN(focus_follows_mouse, const char *value) {
125
     config.disable_focus_follows_mouse = !eval_boolstr(value);
126
 }
127
 
128
+CFGFUN(mouse_warping, const char *value) {
129
+    config.disable_mouse_warping = !eval_boolstr(value);
130
+}
131
+
132
 CFGFUN(force_xinerama, const char *value) {
133
     config.force_xinerama = eval_boolstr(value);
134
 }

b/src/x.c

139
@@ -1142,7 +1142,7 @@ void x_set_i3_atoms(void) {
140
  */
141
 void x_set_warp_to(Rect *rect)
142
 {
143
-    if (!config.disable_focus_follows_mouse)
144
+    if (!config.disable_focus_follows_mouse && !config.disable_mouse_warping)
145
         warp_to = rect;
146
 }
147
 

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

152
@@ -310,6 +310,24 @@ is(parser_calls($config),
153
    'focus_follows_mouse ok');
154
 
155
 ################################################################################
156
+# mouse_warping
157
+################################################################################
158
+
159
+$config = <<'EOT';
160
+mouse_warping yes
161
+mouse_warping no
162
+EOT
163
+
164
+$expected = <<'EOT';
165
+cfg_mouse_warping(yes)
166
+cfg_mouse_warping(no)
167
+EOT
168
+
169
+is(parser_calls($config),
170
+   $expected,
171
+   'mouse_warping ok');
172
+
173
+################################################################################
174
 # force_display_urgency_hint
175
 ################################################################################
176
 
177
@@ -413,7 +431,7 @@ client.focused          #4c7899 #285577 #ffffff #2e9ef4
178
 EOT
179
 
180
 my $expected_all_tokens = <<'EOT';
181
-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'
182
+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'
183
 EOT
184
 
185
 my $expected_end = <<'EOT';

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

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