summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config4
-rw-r--r--include/config.h2
-rw-r--r--sway/commands.c17
-rw-r--r--sway/config.c2
-rw-r--r--sway/input_state.c93
-rw-r--r--sway/sway.5.txt6
6 files changed, 100 insertions, 24 deletions
diff --git a/config b/config
index bd9b980b..2bb37f4f 100644
--- a/config
+++ b/config
@@ -32,7 +32,9 @@ set $menu dmenu_run
32 # Drag floating windows by holding down $mod and left mouse button. 32 # Drag floating windows by holding down $mod and left mouse button.
33 # Resize them with right mouse button + $mod. 33 # Resize them with right mouse button + $mod.
34 # Despite the name, also works for non-floating windows. 34 # Despite the name, also works for non-floating windows.
35 floating_modifier $mod 35 # Change normal to inverse to use left mouse button for resizing and right
36 # mouse button for dragging.
37 floating_modifier $mod normal
36 38
37 # reload the configuration file 39 # reload the configuration file
38 bindsym $mod+Shift+c reload 40 bindsym $mod+Shift+c reload
diff --git a/include/config.h b/include/config.h
index 81d4cd20..4019f479 100644
--- a/include/config.h
+++ b/include/config.h
@@ -109,6 +109,8 @@ struct sway_config {
109 struct sway_mode *current_mode; 109 struct sway_mode *current_mode;
110 struct bar_config bar; 110 struct bar_config bar;
111 uint32_t floating_mod; 111 uint32_t floating_mod;
112 uint32_t dragging_key;
113 uint32_t resizing_key;
112 enum swayc_layouts default_orientation; 114 enum swayc_layouts default_orientation;
113 enum swayc_layouts default_layout; 115 enum swayc_layouts default_layout;
114 116
diff --git a/sway/commands.c b/sway/commands.c
index 8a087af8..205798ec 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -375,14 +375,14 @@ static struct cmd_results *cmd_floating(int argc, char **argv) {
375 375
376static struct cmd_results *cmd_floating_mod(int argc, char **argv) { 376static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
377 struct cmd_results *error = NULL; 377 struct cmd_results *error = NULL;
378 if ((error = checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1))) { 378 if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) {
379 return error; 379 return error;
380 } 380 }
381 int i, j; 381 int i, j;
382 list_t *split = split_string(argv[0], "+"); 382 list_t *split = split_string(argv[0], "+");
383 config->floating_mod = 0; 383 config->floating_mod = 0;
384 384
385 // set modifer keys 385 // set modifier keys
386 for (i = 0; i < split->length; ++i) { 386 for (i = 0; i < split->length; ++i) {
387 for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { 387 for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) {
388 if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { 388 if (strcasecmp(modifiers[j].name, split->items[i]) == 0) {
@@ -395,6 +395,19 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
395 error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]); 395 error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]);
396 return error; 396 return error;
397 } 397 }
398
399 if (argc >= 2) {
400 if (strcasecmp("inverse", argv[1]) == 0) {
401 config->dragging_key = M_RIGHT_CLICK;
402 config->resizing_key = M_LEFT_CLICK;
403 } else if (strcasecmp("normal", argv[1]) == 0) {
404 config->dragging_key = M_LEFT_CLICK;
405 config->resizing_key = M_RIGHT_CLICK;
406 } else {
407 error = cmd_results_new(CMD_INVALID, "floating_modifier", "Invalid definition %s", argv[1]);
408 return error;
409 }
410 }
398 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 411 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
399} 412}
400 413
diff --git a/sway/config.c b/sway/config.c
index 7e3c3149..6c22556f 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -101,6 +101,8 @@ static void config_defaults(struct sway_config *config) {
101 list_add(config->modes, config->current_mode); 101 list_add(config->modes, config->current_mode);
102 102
103 config->floating_mod = 0; 103 config->floating_mod = 0;
104 config->dragging_key = M_LEFT_CLICK;
105 config->resizing_key = M_RIGHT_CLICK;
104 config->default_layout = L_NONE; 106 config->default_layout = L_NONE;
105 config->default_orientation = L_NONE; 107 config->default_orientation = L_NONE;
106 // Flags 108 // Flags
diff --git a/sway/input_state.c b/sway/input_state.c
index 88506c92..24678f71 100644
--- a/sway/input_state.c
+++ b/sway/input_state.c
@@ -194,8 +194,16 @@ void center_pointer_on(swayc_t *view) {
194 194
195// Mode set left/right click 195// Mode set left/right click
196 196
197static void pointer_mode_set_left(void) { 197static void pointer_mode_set_dragging(void) {
198 set_initial_view(pointer_state.left.view); 198 switch (config->dragging_key) {
199 case M_LEFT_CLICK:
200 set_initial_view(pointer_state.left.view);
201 break;
202 case M_RIGHT_CLICK:
203 set_initial_view(pointer_state.right.view);
204 break;
205 }
206
199 if (initial.ptr->is_floating) { 207 if (initial.ptr->is_floating) {
200 pointer_state.mode = M_DRAGGING | M_FLOATING; 208 pointer_state.mode = M_DRAGGING | M_FLOATING;
201 } else { 209 } else {
@@ -208,8 +216,15 @@ static void pointer_mode_set_left(void) {
208 } 216 }
209} 217}
210 218
211static void pointer_mode_set_right(void) { 219static void pointer_mode_set_resizing(void) {
212 set_initial_view(pointer_state.right.view); 220 switch (config->resizing_key) {
221 case M_LEFT_CLICK:
222 set_initial_view(pointer_state.left.view);
223 break;
224 case M_RIGHT_CLICK:
225 set_initial_view(pointer_state.right.view);
226 break;
227 }
213 // Setup locking information 228 // Setup locking information
214 int midway_x = initial.ptr->x + initial.ptr->width/2; 229 int midway_x = initial.ptr->x + initial.ptr->width/2;
215 int midway_y = initial.ptr->y + initial.ptr->height/2; 230 int midway_y = initial.ptr->y + initial.ptr->height/2;
@@ -233,15 +248,19 @@ void pointer_mode_set(uint32_t button, bool condition) {
233 // switch on drag/resize mode 248 // switch on drag/resize mode
234 switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) { 249 switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) {
235 case M_DRAGGING: 250 case M_DRAGGING:
236 // end drag mode when left click is unpressed 251 // end drag mode when 'dragging' click is unpressed
237 if (!pointer_state.left.held) { 252 if (config->dragging_key == M_LEFT_CLICK && !pointer_state.left.held) {
253 pointer_state.mode = 0;
254 } else if (config->dragging_key == M_RIGHT_CLICK && !pointer_state.right.held) {
238 pointer_state.mode = 0; 255 pointer_state.mode = 0;
239 } 256 }
240 break; 257 break;
241 258
242 case M_RESIZING: 259 case M_RESIZING:
243 // end resize mode when right click is unpressed 260 // end resize mode when 'resizing' click is unpressed
244 if (!pointer_state.right.held) { 261 if (config->resizing_key == M_LEFT_CLICK && !pointer_state.left.held) {
262 pointer_state.mode = 0;
263 } else if (config->resizing_key == M_RIGHT_CLICK && !pointer_state.right.held) {
245 pointer_state.mode = 0; 264 pointer_state.mode = 0;
246 } 265 }
247 break; 266 break;
@@ -255,19 +274,27 @@ void pointer_mode_set(uint32_t button, bool condition) {
255 274
256 // Set mode depending on current button press 275 // Set mode depending on current button press
257 switch (button) { 276 switch (button) {
258 // Start dragging mode 277 // Start left-click mode
259 case M_LEFT_CLICK: 278 case M_LEFT_CLICK:
260 // if button release dont do anything 279 // if button release dont do anything
261 if (pointer_state.left.held) { 280 if (pointer_state.left.held) {
262 pointer_mode_set_left(); 281 if (config->dragging_key == M_LEFT_CLICK) {
282 pointer_mode_set_dragging();
283 } else if (config->resizing_key == M_LEFT_CLICK) {
284 pointer_mode_set_resizing();
285 }
263 } 286 }
264 break; 287 break;
265 288
266 // Start resize mode 289 // Start right-click mode
267 case M_RIGHT_CLICK: 290 case M_RIGHT_CLICK:
268 // if button release dont do anyhting 291 // if button release dont do anyhting
269 if (pointer_state.right.held) { 292 if (pointer_state.right.held) {
270 pointer_mode_set_right(); 293 if (config->dragging_key == M_RIGHT_CLICK) {
294 pointer_mode_set_dragging();
295 } else if (config->resizing_key == M_RIGHT_CLICK) {
296 pointer_mode_set_resizing();
297 }
271 } 298 }
272 break; 299 break;
273 } 300 }
@@ -287,8 +314,17 @@ void pointer_mode_update(void) {
287 switch (pointer_state.mode) { 314 switch (pointer_state.mode) {
288 case M_FLOATING | M_DRAGGING: 315 case M_FLOATING | M_DRAGGING:
289 // Update position 316 // Update position
290 dx -= pointer_state.left.x; 317 switch (config->resizing_key) {
291 dy -= pointer_state.left.y; 318 case M_LEFT_CLICK:
319 dx -= pointer_state.left.x;
320 dy -= pointer_state.left.y;
321 break;
322 case M_RIGHT_CLICK:
323 dx -= pointer_state.right.x;
324 dy -= pointer_state.right.y;
325 break;
326 }
327
292 if (initial.x + dx != initial.ptr->x) { 328 if (initial.x + dx != initial.ptr->x) {
293 initial.ptr->x = initial.x + dx; 329 initial.ptr->x = initial.x + dx;
294 } 330 }
@@ -299,9 +335,19 @@ void pointer_mode_update(void) {
299 break; 335 break;
300 336
301 case M_FLOATING | M_RESIZING: 337 case M_FLOATING | M_RESIZING:
302 dx -= pointer_state.right.x; 338 switch (config->resizing_key) {
303 dy -= pointer_state.right.y; 339 case M_LEFT_CLICK:
304 initial.ptr = pointer_state.right.view; 340 dx -= pointer_state.left.x;
341 dy -= pointer_state.left.y;
342 initial.ptr = pointer_state.left.view;
343 break;
344 case M_RIGHT_CLICK:
345 dx -= pointer_state.right.x;
346 dy -= pointer_state.right.y;
347 initial.ptr = pointer_state.right.view;
348 break;
349 }
350
305 if (lock.left) { 351 if (lock.left) {
306 if (initial.w + dx > min_sane_w) { 352 if (initial.w + dx > min_sane_w) {
307 initial.ptr->width = initial.w + dx; 353 initial.ptr->width = initial.w + dx;
@@ -341,8 +387,17 @@ void pointer_mode_update(void) {
341 break; 387 break;
342 388
343 case M_TILING | M_RESIZING: 389 case M_TILING | M_RESIZING:
344 dx -= pointer_state.right.x; 390 switch (config->resizing_key) {
345 dy -= pointer_state.right.y; 391 case M_LEFT_CLICK:
392 dx -= pointer_state.left.x;
393 dy -= pointer_state.left.y;
394 break;
395 case M_RIGHT_CLICK:
396 dx -= pointer_state.right.x;
397 dy -= pointer_state.right.y;
398 break;
399 }
400
346 // resize if we can 401 // resize if we can
347 if (initial.horiz.ptr) { 402 if (initial.horiz.ptr) {
348 if (lock.left) { 403 if (lock.left) {
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 24467d22..c3736d01 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -41,10 +41,12 @@ Commands
41**floating** <enable|disable|toggle>:: 41**floating** <enable|disable|toggle>::
42 Make focused view floating, non-floating, or the opposite of what it is now. 42 Make focused view floating, non-floating, or the opposite of what it is now.
43 43
44**floating_modifier** <modifier>:: 44**floating_modifier** <modifier> [normal|inverse]::
45 When the _modifier_ key is held down, you may use left click to drag floating 45 When the _modifier_ key is held down, you may use left click to drag floating
46 windows, and right click to resize them. Unlike i3, this modifier may also be 46 windows, and right click to resize them. Unlike i3, this modifier may also be
47 used to resize and move windows that are tiled. 47 used to resize and move windows that are tiled. With the _inverse_ mode
48 enabled, left click is used for resizing and right click for dragging. The
49 mode paramenter is optional and defaults to _normal_ if it isn't defined.
48 50
49**focus** <direction>:: 51**focus** <direction>::
50 Direction may be one of _up_, _down_, _left_, _right_, or _parent_. The 52 Direction may be one of _up_, _down_, _left_, _right_, or _parent_. The