Add mouse_warp to mark option

This allows to better support certain pop-ups which require focus or they close (like certain password managers).
The popup can be marked and only that window will get mouse_warped.

For example:
```
for_window [title="Enpass Assistant"] {
    move position mouse
    inhibit_idle visible
    urgent enable
    mark --add mouse_me
}

mouse_warping mark mouse_me
```
This commit is contained in:
Kevin Wiesmueller 2024-06-08 17:45:04 -04:00
parent f344e9d5a5
commit d93cc70798
3 changed files with 15 additions and 2 deletions

View file

@ -472,6 +472,7 @@ enum mouse_warping_mode {
WARP_NO, WARP_NO,
WARP_OUTPUT, WARP_OUTPUT,
WARP_CONTAINER, WARP_CONTAINER,
WARP_MARK,
}; };
enum alignment { enum alignment {
@ -537,6 +538,7 @@ struct sway_config {
// Flags // Flags
enum focus_follows_mouse_mode focus_follows_mouse; enum focus_follows_mouse_mode focus_follows_mouse;
enum mouse_warping_mode mouse_warping; enum mouse_warping_mode mouse_warping;
char *mouse_warping_mark_name;
enum focus_wrapping_mode focus_wrapping; enum focus_wrapping_mode focus_wrapping;
bool active; bool active;
bool failed; bool failed;

View file

@ -280,6 +280,11 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws,
// to anyway. // to anyway.
if (config->mouse_warping == WARP_CONTAINER) { if (config->mouse_warping == WARP_CONTAINER) {
cursor_warp_to_container(seat->cursor, new_focus, true); cursor_warp_to_container(seat->cursor, new_focus, true);
} else if (config->mouse_warping == WARP_MARK) {
bool has_warp_mark = container_has_mark(new_focus, config->mouse_warping_mark_name);
if (has_warp_mark) {
cursor_warp_to_container(seat->cursor, new_focus, true);
}
} else { } else {
seat_consider_warp_to_focus(seat); seat_consider_warp_to_focus(seat);
} }

View file

@ -4,7 +4,7 @@
struct cmd_results *cmd_mouse_warping(int argc, char **argv) { struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { if ((error = checkarg(argc, "mouse_warping", EXPECTED_AT_LEAST, 1))) {
return error; return error;
} else if (strcasecmp(argv[0], "container") == 0) { } else if (strcasecmp(argv[0], "container") == 0) {
config->mouse_warping = WARP_CONTAINER; config->mouse_warping = WARP_CONTAINER;
@ -12,9 +12,15 @@ struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
config->mouse_warping = WARP_OUTPUT; config->mouse_warping = WARP_OUTPUT;
} else if (strcasecmp(argv[0], "none") == 0) { } else if (strcasecmp(argv[0], "none") == 0) {
config->mouse_warping = WARP_NO; config->mouse_warping = WARP_NO;
} else if (strcasecmp(argv[0], "mark") == 0) {
config->mouse_warping = WARP_MARK;
if (argc < 2) {
return cmd_results_new(CMD_FAILURE, "Expected an mark name as a second argument");
}
config->mouse_warping_mark_name = argv[1];
} else { } else {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE,
"Expected 'mouse_warping output|container|none'"); "Expected 'mouse_warping output|container|mark|none'");
} }
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }