aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-26 12:20:32 +0100
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-29 17:41:33 +0100
commit78ca6197697d4f07eddf0c544daff85603adab90 (patch)
treee499ab901ab3371d5860e36db086ea8b46e8227e
parentinput_state: Extract 'pointer_position_set' function from handlers. (diff)
downloadsway-78ca6197697d4f07eddf0c544daff85603adab90.tar.gz
sway-78ca6197697d4f07eddf0c544daff85603adab90.tar.zst
sway-78ca6197697d4f07eddf0c544daff85603adab90.zip
commands: Learn mouse_warping.
Place mouse at center of focused view when changing to a workspace on a different output, if option is enabled. (This replicates existing i3 option.) This can be triggered in multiple ways: A) via `workspace <name>` which changes output B) via `focus <direction>` which changes output C) via `focus output <name>` which (obviously) changes output
-rw-r--r--include/commands.h1
-rw-r--r--include/input_state.h1
-rw-r--r--sway.5.txt4
-rw-r--r--sway/commands.c34
-rw-r--r--sway/focus.c26
-rw-r--r--sway/input_state.c7
6 files changed, 64 insertions, 9 deletions
diff --git a/include/commands.h b/include/commands.h
index 8e53c74d..f6777930 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -2,6 +2,7 @@
2#define _SWAY_COMMANDS_H 2#define _SWAY_COMMANDS_H
3#include <stdbool.h> 3#include <stdbool.h>
4#include <json-c/json.h> 4#include <json-c/json.h>
5#include <wlc/wlc.h>
5#include "config.h" 6#include "config.h"
6 7
7 8
diff --git a/include/input_state.h b/include/input_state.h
index dd5d71a8..52759052 100644
--- a/include/input_state.h
+++ b/include/input_state.h
@@ -66,6 +66,7 @@ extern struct pointer_state {
66} pointer_state; 66} pointer_state;
67 67
68void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); 68void pointer_position_set(struct wlc_origin *new_origin, bool force_focus);
69void center_pointer_on(swayc_t *view);
69 70
70// on button release unset mode depending on the button. 71// on button release unset mode depending on the button.
71// on button press set mode conditionally depending on the button 72// on button press set mode conditionally depending on the button
diff --git a/sway.5.txt b/sway.5.txt
index dad55c5f..27735db6 100644
--- a/sway.5.txt
+++ b/sway.5.txt
@@ -102,6 +102,10 @@ Commands
102 Moves the focused container to the workspace identified by _name_. 102 Moves the focused container to the workspace identified by _name_.
103 _name_ may be a special workspace name. See **workspace**. 103 _name_ may be a special workspace name. See **workspace**.
104 104
105**mouse_warping** <output|none>::
106 When _output_: place mouse at center of newly focused window when changing
107 output. When _none_: don't move mouse.
108
105**output** <name> <resolution|res WIDTHxHEIGHT> <position|pos X,Y>:: 109**output** <name> <resolution|res WIDTHxHEIGHT> <position|pos X,Y>::
106 Configures the specified output. It will use the given resolution and be 110 Configures the specified output. It will use the given resolution and be
107 arranged at the given position in the layout tree. You may omit either of 111 arranged at the given position in the layout tree. You may omit either of
diff --git a/sway/commands.c b/sway/commands.c
index 441b6fd7..00a4d1b0 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -21,6 +21,7 @@
21#include "handlers.h" 21#include "handlers.h"
22#include "sway.h" 22#include "sway.h"
23#include "resize.h" 23#include "resize.h"
24#include "input_state.h"
24 25
25typedef struct cmd_results *sway_cmd(int argc, char **argv); 26typedef struct cmd_results *sway_cmd(int argc, char **argv);
26 27
@@ -45,6 +46,7 @@ static sway_cmd cmd_kill;
45static sway_cmd cmd_layout; 46static sway_cmd cmd_layout;
46static sway_cmd cmd_log_colors; 47static sway_cmd cmd_log_colors;
47static sway_cmd cmd_mode; 48static sway_cmd cmd_mode;
49static sway_cmd cmd_mouse_warping;
48static sway_cmd cmd_move; 50static sway_cmd cmd_move;
49static sway_cmd cmd_output; 51static sway_cmd cmd_output;
50static sway_cmd cmd_reload; 52static sway_cmd cmd_reload;
@@ -383,9 +385,13 @@ static struct cmd_results *cmd_focus(int argc, char **argv) {
383 } else if (!workspace_switch(swayc_active_workspace_for(output))) { 385 } else if (!workspace_switch(swayc_active_workspace_for(output))) {
384 return cmd_results_new(CMD_FAILURE, "focus output", 386 return cmd_results_new(CMD_FAILURE, "focus output",
385 "Switching to workspace on output '%s' was blocked", argv[1]); 387 "Switching to workspace on output '%s' was blocked", argv[1]);
386 } else { 388 } else if (config->mouse_warping) {
387 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 389 swayc_t *focused = get_focused_view(output);
390 if (focused && focused->type == C_VIEW) {
391 center_pointer_on(focused);
392 }
388 } 393 }
394 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
389 } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) { 395 } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
390 return error; 396 return error;
391 } 397 }
@@ -528,6 +534,20 @@ static struct cmd_results *cmd_mode(int argc, char **argv) {
528 return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL); 534 return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL);
529} 535}
530 536
537static struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
538 struct cmd_results *error = NULL;
539 if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) {
540 return error;
541 } else if (strcasecmp(argv[0], "output") == 0) {
542 config->mouse_warping = true;
543 } else if (strcasecmp(argv[0], "none") == 0) {
544 config->mouse_warping = false;
545 } else {
546 return cmd_results_new(CMD_FAILURE, "mouse_warping", "Expected 'mouse_warping output|none'");
547 }
548 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
549}
550
531static struct cmd_results *cmd_move(int argc, char **argv) { 551static struct cmd_results *cmd_move(int argc, char **argv) {
532 struct cmd_results *error = NULL; 552 struct cmd_results *error = NULL;
533 if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); 553 if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file.");
@@ -1165,7 +1185,16 @@ static struct cmd_results *cmd_workspace(int argc, char **argv) {
1165 ws = workspace_create(argv[0]); 1185 ws = workspace_create(argv[0]);
1166 } 1186 }
1167 } 1187 }
1188 swayc_t *old_output = swayc_active_output();
1168 workspace_switch(ws); 1189 workspace_switch(ws);
1190 swayc_t *new_output = swayc_active_output();
1191
1192 if (config->mouse_warping && old_output != new_output) {
1193 swayc_t *focused = get_focused_view(ws);
1194 if (focused && focused->type == C_VIEW) {
1195 center_pointer_on(focused);
1196 }
1197 }
1169 } else { 1198 } else {
1170 if (strcasecmp(argv[1], "output") == 0) { 1199 if (strcasecmp(argv[1], "output") == 0) {
1171 if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) { 1200 if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) {
@@ -1217,6 +1246,7 @@ static struct cmd_handler handlers[] = {
1217 { "layout", cmd_layout }, 1246 { "layout", cmd_layout },
1218 { "log_colors", cmd_log_colors }, 1247 { "log_colors", cmd_log_colors },
1219 { "mode", cmd_mode }, 1248 { "mode", cmd_mode },
1249 { "mouse_warping", cmd_mouse_warping },
1220 { "move", cmd_move }, 1250 { "move", cmd_move },
1221 { "output", cmd_output }, 1251 { "output", cmd_output },
1222 { "reload", cmd_reload }, 1252 { "reload", cmd_reload },
diff --git a/sway/focus.c b/sway/focus.c
index 1aa7579b..7f0b1599 100644
--- a/sway/focus.c
+++ b/sway/focus.c
@@ -4,6 +4,8 @@
4#include "log.h" 4#include "log.h"
5#include "workspace.h" 5#include "workspace.h"
6#include "layout.h" 6#include "layout.h"
7#include "config.h"
8#include "input_state.h"
7 9
8bool locked_container_focus = false; 10bool locked_container_focus = false;
9bool locked_view_focus = false; 11bool locked_view_focus = false;
@@ -49,14 +51,24 @@ static void update_focus(swayc_t *c) {
49} 51}
50 52
51bool move_focus(enum movement_direction direction) { 53bool move_focus(enum movement_direction direction) {
52 swayc_t *view = get_focused_container(&root_container); 54 swayc_t *old_view = get_focused_container(&root_container);
53 view = get_swayc_in_direction(view, direction); 55 swayc_t *new_view = get_swayc_in_direction(old_view, direction);
54 if (view) { 56 if (!new_view) {
55 if (direction == MOVE_PARENT) { 57 return false;
56 return set_focused_container(view); 58 } else if (direction == MOVE_PARENT) {
57 } else { 59 return set_focused_container(new_view);
58 return set_focused_container(get_focused_view(view)); 60 } else if (config->mouse_warping) {
61 swayc_t *old_op = old_view->type == C_OUTPUT ?
62 old_view : swayc_parent_by_type(old_view, C_OUTPUT);
63 swayc_t *focused = get_focused_view(new_view);
64 if (set_focused_container(focused)) {
65 if (old_op != swayc_active_output() && focused && focused->type == C_VIEW) {
66 center_pointer_on(focused);
67 }
68 return true;
59 } 69 }
70 } else {
71 return set_focused_container(get_focused_view(new_view));
60 } 72 }
61 return false; 73 return false;
62} 74}
diff --git a/sway/input_state.c b/sway/input_state.c
index bd46a5ac..ee3dc7cf 100644
--- a/sway/input_state.c
+++ b/sway/input_state.c
@@ -185,6 +185,13 @@ void pointer_position_set(struct wlc_origin *new_origin, bool force_focus) {
185 wlc_pointer_set_origin(new_origin); 185 wlc_pointer_set_origin(new_origin);
186} 186}
187 187
188void center_pointer_on(swayc_t *view) {
189 struct wlc_origin new_origin;
190 new_origin.x = view->x + view->width/2;
191 new_origin.y = view->y + view->height/2;
192 pointer_position_set(&new_origin, true);
193}
194
188// Mode set left/right click 195// Mode set left/right click
189 196
190static void pointer_mode_set_left(void) { 197static void pointer_mode_set_left(void) {