diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-01-30 10:42:31 -0500 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-01-30 19:53:59 +0100 |
commit | a6d41254c90c1471326e5df94b939a12844d9be6 (patch) | |
tree | 2b8c8f6efc012284bd438a0ebcfc7f6022e32bc5 | |
parent | Add relative pointer (diff) | |
download | sway-a6d41254c90c1471326e5df94b939a12844d9be6.tar.gz sway-a6d41254c90c1471326e5df94b939a12844d9be6.tar.zst sway-a6d41254c90c1471326e5df94b939a12844d9be6.zip |
Add pointer_constraint command
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/pointer_constraint.c | 51 | ||||
-rw-r--r-- | sway/config/seat.c | 1 | ||||
-rw-r--r-- | sway/input/cursor.c | 5 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway.5.scd | 5 |
8 files changed, 66 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 7672a3fd..2877c370 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -153,6 +153,7 @@ sway_cmd cmd_new_window; | |||
153 | sway_cmd cmd_no_focus; | 153 | sway_cmd cmd_no_focus; |
154 | sway_cmd cmd_output; | 154 | sway_cmd cmd_output; |
155 | sway_cmd cmd_permit; | 155 | sway_cmd cmd_permit; |
156 | sway_cmd cmd_pointer_constraint; | ||
156 | sway_cmd cmd_popup_during_fullscreen; | 157 | sway_cmd cmd_popup_during_fullscreen; |
157 | sway_cmd cmd_reject; | 158 | sway_cmd cmd_reject; |
158 | sway_cmd cmd_reload; | 159 | sway_cmd cmd_reload; |
diff --git a/include/sway/config.h b/include/sway/config.h index d5467a56..e63b9895 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -143,6 +143,7 @@ struct seat_config { | |||
143 | int fallback; // -1 means not set | 143 | int fallback; // -1 means not set |
144 | list_t *attachments; // list of seat_attachment configs | 144 | list_t *attachments; // list of seat_attachment configs |
145 | int hide_cursor_timeout; | 145 | int hide_cursor_timeout; |
146 | bool allow_constrain; | ||
146 | }; | 147 | }; |
147 | 148 | ||
148 | enum config_dpms { | 149 | enum config_dpms { |
diff --git a/sway/commands.c b/sway/commands.c index dd994fa1..425897fb 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -81,6 +81,7 @@ static struct cmd_handler handlers[] = { | |||
81 | { "no_focus", cmd_no_focus }, | 81 | { "no_focus", cmd_no_focus }, |
82 | { "output", cmd_output }, | 82 | { "output", cmd_output }, |
83 | { "popup_during_fullscreen", cmd_popup_during_fullscreen }, | 83 | { "popup_during_fullscreen", cmd_popup_during_fullscreen }, |
84 | { "pointer_constraint", cmd_pointer_constraint }, | ||
84 | { "seat", cmd_seat }, | 85 | { "seat", cmd_seat }, |
85 | { "set", cmd_set }, | 86 | { "set", cmd_set }, |
86 | { "show_marks", cmd_show_marks }, | 87 | { "show_marks", cmd_show_marks }, |
diff --git a/sway/commands/pointer_constraint.c b/sway/commands/pointer_constraint.c new file mode 100644 index 00000000..2dda0776 --- /dev/null +++ b/sway/commands/pointer_constraint.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include <string.h> | ||
2 | #include <wlr/types/wlr_pointer_constraints_v1.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "sway/input/cursor.h" | ||
6 | #include "sway/input/seat.h" | ||
7 | |||
8 | enum operation { | ||
9 | OP_ENABLE, | ||
10 | OP_DISABLE, | ||
11 | OP_ESCAPE, | ||
12 | }; | ||
13 | |||
14 | // pointer_constraint [enable|disable|escape] | ||
15 | struct cmd_results *cmd_pointer_constraint(int argc, char **argv) { | ||
16 | struct cmd_results *error = NULL; | ||
17 | if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) { | ||
18 | return error; | ||
19 | } | ||
20 | |||
21 | enum operation op; | ||
22 | if (strcmp(argv[0], "enable") == 0) { | ||
23 | op = OP_ENABLE; | ||
24 | } else if (strcmp(argv[0], "disable") == 0) { | ||
25 | op = OP_DISABLE; | ||
26 | } else if (strcmp(argv[0], "escape") == 0) { | ||
27 | op = OP_ESCAPE; | ||
28 | } else { | ||
29 | return cmd_results_new(CMD_FAILURE, "Expected enable|disable|escape"); | ||
30 | } | ||
31 | |||
32 | if (op == OP_ESCAPE && config->reading) { | ||
33 | return cmd_results_new(CMD_FAILURE, "Can only escape at runtime."); | ||
34 | } | ||
35 | |||
36 | struct sway_cursor *cursor = config->handler_context.seat->cursor; | ||
37 | struct seat_config *seat_config = seat_get_config(cursor->seat); | ||
38 | switch (op) { | ||
39 | case OP_ENABLE: | ||
40 | seat_config->allow_constrain = true; | ||
41 | break; | ||
42 | case OP_DISABLE: | ||
43 | seat_config->allow_constrain = false; | ||
44 | /* fallthrough */ | ||
45 | case OP_ESCAPE: | ||
46 | sway_cursor_constrain(cursor, NULL); | ||
47 | break; | ||
48 | } | ||
49 | |||
50 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
51 | } | ||
diff --git a/sway/config/seat.c b/sway/config/seat.c index 92dc42e3..541c4f99 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c | |||
@@ -26,6 +26,7 @@ struct seat_config *new_seat_config(const char* name) { | |||
26 | return NULL; | 26 | return NULL; |
27 | } | 27 | } |
28 | seat->hide_cursor_timeout = -1; | 28 | seat->hide_cursor_timeout = -1; |
29 | seat->allow_constrain = true; | ||
29 | 30 | ||
30 | return seat; | 31 | return seat; |
31 | } | 32 | } |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 78e2f695..14c62970 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -1454,6 +1454,11 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) { | |||
1454 | 1454 | ||
1455 | void sway_cursor_constrain(struct sway_cursor *cursor, | 1455 | void sway_cursor_constrain(struct sway_cursor *cursor, |
1456 | struct wlr_pointer_constraint_v1 *constraint) { | 1456 | struct wlr_pointer_constraint_v1 *constraint) { |
1457 | struct seat_config *config = seat_get_config(cursor->seat); | ||
1458 | if (!config->allow_constrain) { | ||
1459 | return; | ||
1460 | } | ||
1461 | |||
1457 | if (cursor->active_constraint == constraint) { | 1462 | if (cursor->active_constraint == constraint) { |
1458 | return; | 1463 | return; |
1459 | } | 1464 | } |
diff --git a/sway/meson.build b/sway/meson.build index 94d5abdb..b3837e21 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -75,6 +75,7 @@ sway_sources = files( | |||
75 | 'commands/nop.c', | 75 | 'commands/nop.c', |
76 | 'commands/output.c', | 76 | 'commands/output.c', |
77 | 'commands/popup_during_fullscreen.c', | 77 | 'commands/popup_during_fullscreen.c', |
78 | 'commands/pointer_constraint.c', | ||
78 | 'commands/reload.c', | 79 | 'commands/reload.c', |
79 | 'commands/rename.c', | 80 | 'commands/rename.c', |
80 | 'commands/resize.c', | 81 | 'commands/resize.c', |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 55de3c9c..e04c5fbf 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -539,6 +539,11 @@ The default colors are: | |||
539 | \* may be used in lieu of a specific output name to configure all outputs. | 539 | \* may be used in lieu of a specific output name to configure all outputs. |
540 | A list of output names may be obtained via *swaymsg -t get_outputs*. | 540 | A list of output names may be obtained via *swaymsg -t get_outputs*. |
541 | 541 | ||
542 | *pointer_constraint* enable|disable|escape | ||
543 | Enables or disables the ability for clients to capture the cursor (enabled | ||
544 | by default). This is primarily useful for video games. The "escape" command | ||
545 | can be used at runtime to escape from a captured client. | ||
546 | |||
542 | *popup_during_fullscreen* smart|ignore|leave_fullscreen | 547 | *popup_during_fullscreen* smart|ignore|leave_fullscreen |
543 | Determines what to do when a fullscreen view opens a dialog. | 548 | Determines what to do when a fullscreen view opens a dialog. |
544 | If _smart_ (the default), the dialog will be displayed. If _ignore_, the | 549 | If _smart_ (the default), the dialog will be displayed. If _ignore_, the |