Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust position of container mouse warp #8071

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions include/sway/commands.h
Expand Up @@ -155,6 +155,7 @@ sway_cmd cmd_mark;
sway_cmd cmd_max_render_time;
sway_cmd cmd_mode;
sway_cmd cmd_mouse_warping;
sway_cmd cmd_mouse_warping_position;
sway_cmd cmd_move;
sway_cmd cmd_new_float;
sway_cmd cmd_new_window;
Expand Down
9 changes: 9 additions & 0 deletions include/sway/config.h
Expand Up @@ -461,6 +461,14 @@ enum mouse_warping_mode {
WARP_CONTAINER,
};

enum mouse_warping_position {
WARP_POS_CENTER,
WARP_POS_TOPLEFT,
WARP_POS_TOPRIGHT,
WARP_POS_BOTLEFT,
WARP_POS_BOTRIGHT,
};

enum alignment {
ALIGN_LEFT,
ALIGN_CENTER,
Expand Down Expand Up @@ -524,6 +532,7 @@ struct sway_config {
// Flags
enum focus_follows_mouse_mode focus_follows_mouse;
enum mouse_warping_mode mouse_warping;
enum mouse_warping_position mouse_warping_position;
enum focus_wrapping_mode focus_wrapping;
bool active;
bool failed;
Expand Down
4 changes: 3 additions & 1 deletion include/sway/input/cursor.h
Expand Up @@ -127,7 +127,9 @@ void cursor_set_image_surface(struct sway_cursor *cursor,
struct wl_client *client);

void cursor_warp_to_container(struct sway_cursor *cursor,
struct sway_container *container, bool force);
struct sway_container *container,
enum mouse_warping_position pos,
bool force);

void cursor_warp_to_workspace(struct sway_cursor *cursor,
struct sway_workspace *workspace);
Expand Down
1 change: 1 addition & 0 deletions sway/commands.c
Expand Up @@ -76,6 +76,7 @@ static const struct cmd_handler handlers[] = {
{ "input", cmd_input },
{ "mode", cmd_mode },
{ "mouse_warping", cmd_mouse_warping },
{ "mouse_warping_position", cmd_mouse_warping_position },
{ "new_float", cmd_new_float },
{ "new_window", cmd_new_window },
{ "no_focus", cmd_no_focus },
Expand Down
2 changes: 1 addition & 1 deletion sway/commands/focus.c
Expand Up @@ -279,7 +279,7 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws,
// `seat_consider_warp_to_focus` would decide not to warp, but we need
// to anyway.
if (config->mouse_warping == WARP_CONTAINER) {
cursor_warp_to_container(seat->cursor, new_focus, true);
cursor_warp_to_container(seat->cursor, new_focus, config->mouse_warping_position, true);
} else {
seat_consider_warp_to_focus(seat);
}
Expand Down
20 changes: 20 additions & 0 deletions sway/commands/mouse_warping.c
Expand Up @@ -19,3 +19,23 @@ struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL);
}

struct cmd_results *cmd_mouse_warping_position(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "mouse_warping_position", EXPECTED_EQUAL_TO, 1))) {
return error;
} else if (strcasecmp(argv[0], "center") == 0) {
config->mouse_warping_position = WARP_POS_CENTER;
} else if (strcasecmp(argv[0], "topleft") == 0) {
config->mouse_warping_position = WARP_POS_TOPLEFT;
} else if (strcasecmp(argv[0], "topright") == 0) {
config->mouse_warping_position = WARP_POS_TOPRIGHT;
} else if (strcasecmp(argv[0], "bottomleft") == 0) {
config->mouse_warping_position = WARP_POS_BOTLEFT;
} else if (strcasecmp(argv[0], "bottomright") == 0) {
config->mouse_warping_position = WARP_POS_BOTRIGHT;
} else {
return cmd_results_new(CMD_FAILURE,
"Expected 'mouse_warping_position center|topleft|topright|bottomleft|bottomright");
}
return cmd_results_new(CMD_SUCCESS, NULL);
}
1 change: 1 addition & 0 deletions sway/config.c
Expand Up @@ -270,6 +270,7 @@ static void config_defaults(struct sway_config *config) {
// Flags
config->focus_follows_mouse = FOLLOWS_YES;
config->mouse_warping = WARP_OUTPUT;
config->mouse_warping_position = WARP_POS_CENTER;
config->focus_wrapping = WRAP_YES;
config->validating = false;
config->reloading = false;
Expand Down
26 changes: 25 additions & 1 deletion sway/input/cursor.c
Expand Up @@ -1162,7 +1162,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
* false. If container is NULL, returns without doing anything.
*/
void cursor_warp_to_container(struct sway_cursor *cursor,
struct sway_container *container, bool force) {
struct sway_container *container,
enum mouse_warping_position pos,
bool force) {
if (!container) {
return;
}
Expand All @@ -1174,9 +1176,31 @@ void cursor_warp_to_container(struct sway_cursor *cursor,
return;
}

// Initialize to center
double x = container->pending.x + container->pending.width / 2.0;
double y = container->pending.y + container->pending.height / 2.0;

switch (pos) {
case WARP_POS_CENTER:
// Already initialized above
break;
case WARP_POS_TOPLEFT:
x = container->pending.x;
y = container->pending.y;
break;
case WARP_POS_TOPRIGHT:
x = container->pending.x + container->pending.width;
y = container->pending.y;
break;
case WARP_POS_BOTLEFT:
x = container->pending.x;
y = container->pending.y + container->pending.height;
break;
case WARP_POS_BOTRIGHT:
x = container->pending.x + container->pending.width;
y = container->pending.y + container->pending.height;
break;
}
wlr_cursor_warp(cursor->cursor, NULL, x, y);
cursor_unhide(cursor);
}
Expand Down
2 changes: 1 addition & 1 deletion sway/input/seat.c
Expand Up @@ -1552,7 +1552,7 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) {
}

if (focus->type == N_CONTAINER) {
cursor_warp_to_container(seat->cursor, focus->sway_container, false);
cursor_warp_to_container(seat->cursor, focus->sway_container, config->mouse_warping_position, false);
} else {
cursor_warp_to_workspace(seat->cursor, focus->sway_workspace);
}
Expand Down
7 changes: 6 additions & 1 deletion sway/sway.5.scd
Expand Up @@ -791,7 +791,12 @@ The default colors are:
*mouse_warping* output|container|none
If _output_ is specified, the mouse will be moved to new outputs as you
move focus between them. If _container_ is specified, the mouse will be
moved to the middle of the container on switch. Default is _output_.
moved into the container on switch. The mouse warp position can be adjusted
with *mouse_warping_position*. Default is _output_.

*mouse_warping_position* center|topleft|topright|bottomleft|bottomright
Which corner of the container to move the mouse to when mouse warping occurs.
Default is _center_.

*no_focus* <criteria>
Prevents windows matching <criteria> from being focused automatically when
Expand Down