diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-10-21 19:44:23 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-10-21 19:44:23 -0400 |
commit | 15d0739f73b5486653ad4f8e1e50ebbfb1b415af (patch) | |
tree | 49c85672cf9ba8e0fa08994b27b8f37c73be4022 | |
parent | Merge pull request #197 from sce/configure_outputs_during_reload_ (diff) | |
parent | config: Add "seamless_mouse" to decide if pointer crosses output edges. (diff) | |
download | sway-15d0739f73b5486653ad4f8e1e50ebbfb1b415af.tar.gz sway-15d0739f73b5486653ad4f8e1e50ebbfb1b415af.tar.zst sway-15d0739f73b5486653ad4f8e1e50ebbfb1b415af.zip |
Merge pull request #199 from sce/mouse_cross_output_edge_simple
Switch to adjacent output when hitting output edge.
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway.5.txt | 5 | ||||
-rw-r--r-- | sway/commands.c | 10 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/handlers.c | 58 |
5 files changed, 75 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h index 2a8e36fa..56fba691 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -55,6 +55,7 @@ struct sway_config { | |||
55 | bool reloading; | 55 | bool reloading; |
56 | bool reading; | 56 | bool reading; |
57 | bool auto_back_and_forth; | 57 | bool auto_back_and_forth; |
58 | bool seamless_mouse; | ||
58 | 59 | ||
59 | int gaps_inner; | 60 | int gaps_inner; |
60 | int gaps_outer; | 61 | int gaps_outer; |
@@ -112,6 +112,11 @@ Commands | |||
112 | Resizes the currently focused container or view by _amount_. _amount_ can be | 112 | Resizes the currently focused container or view by _amount_. _amount_ can be |
113 | specified as "n px" or "n ppt" or "n px or n ppt". | 113 | specified as "n px" or "n ppt" or "n px or n ppt". |
114 | 114 | ||
115 | **seamless_mouse** <on|off>:: | ||
116 | Change output seamlessly when pointer touches edge of output. Outputs need to | ||
117 | be configured with perfectly aligned adjacent positions for this option to | ||
118 | have any effect. | ||
119 | |||
115 | **set** <name> <value>:: | 120 | **set** <name> <value>:: |
116 | Creates a substitution for _value_ that can be used with $_name_ in other | 121 | Creates a substitution for _value_ that can be used with $_name_ in other |
117 | commands. | 122 | commands. |
diff --git a/sway/commands.c b/sway/commands.c index 7605a36b..a9c20e51 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -410,6 +410,15 @@ static enum cmd_status cmd_focus_follows_mouse(int argc, char **argv) { | |||
410 | return CMD_SUCCESS; | 410 | return CMD_SUCCESS; |
411 | } | 411 | } |
412 | 412 | ||
413 | static enum cmd_status cmd_seamless_mouse(int argc, char **argv) { | ||
414 | if (!checkarg(argc, "seamless_mouse", EXPECTED_EQUAL_TO, 1)) { | ||
415 | return CMD_FAILURE; | ||
416 | } | ||
417 | |||
418 | config->seamless_mouse = (strcasecmp(argv[0], "on") == 0 || strcasecmp(argv[0], "yes") == 0); | ||
419 | return CMD_SUCCESS; | ||
420 | } | ||
421 | |||
413 | static void hide_view_in_scratchpad(swayc_t *sp_view) { | 422 | static void hide_view_in_scratchpad(swayc_t *sp_view) { |
414 | if (sp_view == NULL) { | 423 | if (sp_view == NULL) { |
415 | return; | 424 | return; |
@@ -1139,6 +1148,7 @@ static struct cmd_handler handlers[] = { | |||
1139 | { "reload", cmd_reload }, | 1148 | { "reload", cmd_reload }, |
1140 | { "resize", cmd_resize }, | 1149 | { "resize", cmd_resize }, |
1141 | { "scratchpad", cmd_scratchpad }, | 1150 | { "scratchpad", cmd_scratchpad }, |
1151 | { "seamless_mouse", cmd_seamless_mouse }, | ||
1142 | { "set", cmd_set }, | 1152 | { "set", cmd_set }, |
1143 | { "split", cmd_split }, | 1153 | { "split", cmd_split }, |
1144 | { "splith", cmd_splith }, | 1154 | { "splith", cmd_splith }, |
diff --git a/sway/config.c b/sway/config.c index bce074b9..67f8284c 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -102,6 +102,7 @@ static void config_defaults(struct sway_config *config) { | |||
102 | config->active = false; | 102 | config->active = false; |
103 | config->failed = false; | 103 | config->failed = false; |
104 | config->auto_back_and_forth = false; | 104 | config->auto_back_and_forth = false; |
105 | config->seamless_mouse = true; | ||
105 | config->reading = false; | 106 | config->reading = false; |
106 | 107 | ||
107 | config->gaps_inner = 0; | 108 | config->gaps_inner = 0; |
diff --git a/sway/handlers.c b/sway/handlers.c index cf07bc8b..351d0a0f 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -353,6 +353,64 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
353 | } | 353 | } |
354 | 354 | ||
355 | static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { | 355 | static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) { |
356 | // Switch to adjacent output if touching output edge. | ||
357 | // | ||
358 | // Since this doesn't currently support moving windows between outputs we | ||
359 | // don't do the switch if the pointer is in a mode. | ||
360 | if (config->seamless_mouse && !pointer_state.mode) { | ||
361 | swayc_t *output = swayc_active_output(); | ||
362 | |||
363 | // TODO: This implementation is naïve: We assume all outputs are | ||
364 | // perfectly aligned (ie. only a single output per edge which covers | ||
365 | // the whole edge). | ||
366 | if (origin->x == 0) { // Left edge | ||
367 | for(int i = 0; i < root_container.children->length; ++i) { | ||
368 | swayc_t *c = root_container.children->items[i]; | ||
369 | if (c == output || c->type != C_OUTPUT) { | ||
370 | continue; | ||
371 | } | ||
372 | if (c->y == output->y && c->x + c->width == output->x) { | ||
373 | sway_log(L_DEBUG, "%s is right of %s", output->name, c->name); | ||
374 | workspace_switch(c); | ||
375 | } | ||
376 | } | ||
377 | } else if ((double)origin->x == output->width) { // Right edge | ||
378 | for(int i = 0; i < root_container.children->length; ++i) { | ||
379 | swayc_t *c = root_container.children->items[i]; | ||
380 | if (c == output || c->type != C_OUTPUT) { | ||
381 | continue; | ||
382 | } | ||
383 | if (c->y == output->y && output->x + output->width == c->x) { | ||
384 | sway_log(L_DEBUG, "%s is left of %s", output->name, c->name); | ||
385 | workspace_switch(c); | ||
386 | } | ||
387 | } | ||
388 | } | ||
389 | if (origin->y == 0) { // Top edge | ||
390 | for(int i = 0; i < root_container.children->length; ++i) { | ||
391 | swayc_t *c = root_container.children->items[i]; | ||
392 | if (c == output || c->type != C_OUTPUT) { | ||
393 | continue; | ||
394 | } | ||
395 | if (output->x == c->x && c->y + c->height == output->y) { | ||
396 | sway_log(L_DEBUG, "%s is below %s", output->name, c->name); | ||
397 | workspace_switch(c); | ||
398 | } | ||
399 | } | ||
400 | } else if ((double)origin->y == output->height) { // Bottom edge | ||
401 | for(int i = 0; i < root_container.children->length; ++i) { | ||
402 | swayc_t *c = root_container.children->items[i]; | ||
403 | if (c == output || c->type != C_OUTPUT) { | ||
404 | continue; | ||
405 | } | ||
406 | if (output->x == c->x && output->y + output->height == c->y) { | ||
407 | sway_log(L_DEBUG, "%s is above %s", output->name, c->name); | ||
408 | workspace_switch(c); | ||
409 | } | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | |||
356 | // Update pointer origin | 414 | // Update pointer origin |
357 | pointer_state.delta.x = origin->x - pointer_state.origin.x; | 415 | pointer_state.delta.x = origin->x - pointer_state.origin.x; |
358 | pointer_state.delta.y = origin->y - pointer_state.origin.y; | 416 | pointer_state.delta.y = origin->y - pointer_state.origin.y; |