Skip to content

Commit

Permalink
Add mouse_warping container
Browse files Browse the repository at this point in the history
This option always moves the cursor into the middle of the container if the warp
variable is true in seat_set_focus_warp.

Fixes swaywm#2577
  • Loading branch information
Emantor committed Oct 10, 2018
1 parent 2bd561d commit d704986
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
8 changes: 7 additions & 1 deletion include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ enum focus_wrapping_mode {
WRAP_FORCE
};

enum mouse_warping_mode {
WARP_NO,
WARP_OUTPUT,
WARP_CONTAINER
};

/**
* The configuration struct. The result of loading a config file.
*/
Expand Down Expand Up @@ -366,7 +372,7 @@ struct sway_config {
// Flags
bool focus_follows_mouse;
bool raise_floating;
bool mouse_warping;
enum mouse_warping_mode mouse_warping;
enum focus_wrapping_mode focus_wrapping;
bool active;
bool failed;
Expand Down
8 changes: 5 additions & 3 deletions sway/commands/mouse_warping.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) {
return error;
} else if (strcasecmp(argv[0], "container") == 0) {
config->mouse_warping = WARP_CONTAINER;
} else if (strcasecmp(argv[0], "output") == 0) {
config->mouse_warping = true;
config->mouse_warping = WARP_OUTPUT;
} else if (strcasecmp(argv[0], "none") == 0) {
config->mouse_warping = false;
config->mouse_warping = WARP_NO;
} else {
return cmd_results_new(CMD_FAILURE, "mouse_warping",
"Expected 'mouse_warping output|none'");
"Expected 'mouse_warping output|container|none'");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void config_defaults(struct sway_config *config) {
// Flags
config->focus_follows_mouse = true;
config->raise_floating = true;
config->mouse_warping = true;
config->mouse_warping = WARP_OUTPUT;
config->focus_wrapping = WRAP_YES;
config->validating = false;
config->reloading = false;
Expand Down
8 changes: 4 additions & 4 deletions sway/input/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,6 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
}
}

struct sway_output *last_output = last_workspace ?
last_workspace->output : NULL;
struct sway_output *new_output = new_workspace->output;

if (last_workspace != new_workspace && new_output) {
Expand Down Expand Up @@ -772,7 +770,7 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
}

if (last_focus) {
if (config->mouse_warping && warp && new_output != last_output) {
if (config->mouse_warping && warp) {
double x = 0;
double y = 0;
if (container) {
Expand All @@ -782,9 +780,11 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
x = new_workspace->x + new_workspace->width / 2.0;
y = new_workspace->y + new_workspace->height / 2.0;
}

if (!wlr_output_layout_contains_point(root->output_layout,
new_output->wlr_output, seat->cursor->cursor->x,
seat->cursor->cursor->y)) {
seat->cursor->cursor->y)
|| config->mouse_warping == WARP_CONTAINER) {
wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
cursor_send_pointer_motion(seat->cursor, 0, true);
}
Expand Down
5 changes: 3 additions & 2 deletions sway/sway.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,10 @@ The default colors are:
If _--pango\_markup_ is given, then _mode_ will be interpreted as pango
markup.

*mouse\_warping* output|none
*mouse\_warping* output|container|none
If _output_ is specified, the mouse will be moved to new outputs as you
move focus between them. Default is _output_.
move focus between them. If _container_ is specified, the mouse will be
moved to the middle of the container on switch. Default is _output_.

*no\_focus* <criteria>
Prevents windows matching <criteria> from being focused automatically when
Expand Down

0 comments on commit d704986

Please sign in to comment.