aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-31 22:58:52 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-31 22:58:52 -0500
commitebe5399ed6bfa59f5f5d289bf3d46b08f60787b3 (patch)
treeca0bff9d26283b0fa790855e7379e8da2e89166b /sway
parentRebase #1636 against current master (diff)
downloadsway-ebe5399ed6bfa59f5f5d289bf3d46b08f60787b3.tar.gz
sway-ebe5399ed6bfa59f5f5d289bf3d46b08f60787b3.tar.zst
sway-ebe5399ed6bfa59f5f5d289bf3d46b08f60787b3.zip
pointer_constraint: change to a seat subcommand
This changes the `pointer_constraint` command to be a subcommand of seat to allow for per-seat settings. The current implementation that is not a seat subcommand will only operate on the current seat and will segfault in the config due to `config->handler_context.seat` only being set at runtime. This also allows for the wildcard identifier to be used to alter the pointer constraint settings on all seats and allows for the setting to be merged with the rest of the seat config.
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/seat.c1
-rw-r--r--sway/commands/seat/pointer_constraint.c (renamed from sway/commands/pointer_constraint.c)23
-rw-r--r--sway/config/seat.c6
-rw-r--r--sway/input/cursor.c2
-rw-r--r--sway/meson.build2
-rw-r--r--sway/sway-input.5.scd5
-rw-r--r--sway/sway.5.scd5
8 files changed, 28 insertions, 17 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 425897fb..dd994fa1 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -81,7 +81,6 @@ 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 },
85 { "seat", cmd_seat }, 84 { "seat", cmd_seat },
86 { "set", cmd_set }, 85 { "set", cmd_set },
87 { "show_marks", cmd_show_marks }, 86 { "show_marks", cmd_show_marks },
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 69000b57..81bb5f5d 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -11,6 +11,7 @@ static struct cmd_handler seat_handlers[] = {
11 { "cursor", seat_cmd_cursor }, 11 { "cursor", seat_cmd_cursor },
12 { "fallback", seat_cmd_fallback }, 12 { "fallback", seat_cmd_fallback },
13 { "hide_cursor", seat_cmd_hide_cursor }, 13 { "hide_cursor", seat_cmd_hide_cursor },
14 { "pointer_constraint", seat_cmd_pointer_constraint },
14}; 15};
15 16
16struct cmd_results *cmd_seat(int argc, char **argv) { 17struct cmd_results *cmd_seat(int argc, char **argv) {
diff --git a/sway/commands/pointer_constraint.c b/sway/commands/seat/pointer_constraint.c
index 2dda0776..3890ebde 100644
--- a/sway/commands/pointer_constraint.c
+++ b/sway/commands/seat/pointer_constraint.c
@@ -12,11 +12,14 @@ enum operation {
12}; 12};
13 13
14// pointer_constraint [enable|disable|escape] 14// pointer_constraint [enable|disable|escape]
15struct cmd_results *cmd_pointer_constraint(int argc, char **argv) { 15struct cmd_results *seat_cmd_pointer_constraint(int argc, char **argv) {
16 struct cmd_results *error = NULL; 16 struct cmd_results *error = NULL;
17 if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) { 17 if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) {
18 return error; 18 return error;
19 } 19 }
20 if (!config->handler_context.seat_config) {
21 return cmd_results_new(CMD_FAILURE, "No seat defined");
22 }
20 23
21 enum operation op; 24 enum operation op;
22 if (strcmp(argv[0], "enable") == 0) { 25 if (strcmp(argv[0], "enable") == 0) {
@@ -33,19 +36,23 @@ struct cmd_results *cmd_pointer_constraint(int argc, char **argv) {
33 return cmd_results_new(CMD_FAILURE, "Can only escape at runtime."); 36 return cmd_results_new(CMD_FAILURE, "Can only escape at runtime.");
34 } 37 }
35 38
36 struct sway_cursor *cursor = config->handler_context.seat->cursor; 39 struct seat_config *seat_config = config->handler_context.seat_config;
37 struct seat_config *seat_config = seat_get_config(cursor->seat);
38 switch (op) { 40 switch (op) {
39 case OP_ENABLE: 41 case OP_ENABLE:
40 seat_config->allow_constrain = true; 42 seat_config->allow_constrain = CONSTRAIN_ENABLE;
41 break; 43 break;
42 case OP_DISABLE: 44 case OP_DISABLE:
43 seat_config->allow_constrain = false; 45 seat_config->allow_constrain = CONSTRAIN_DISABLE;
44 /* fallthrough */ 46 /* fallthrough */
45 case OP_ESCAPE: 47 case OP_ESCAPE:;
46 sway_cursor_constrain(cursor, NULL); 48 bool wildcard = !strcmp(seat_config->name, "*");
49 struct sway_seat *seat = NULL;
50 wl_list_for_each(seat, &server.input->seats, link) {
51 if (wildcard || !strcmp(seat->wlr_seat->name, seat_config->name)) {
52 sway_cursor_constrain(seat->cursor, NULL);
53 }
54 }
47 break; 55 break;
48 } 56 }
49
50 return cmd_results_new(CMD_SUCCESS, NULL); 57 return cmd_results_new(CMD_SUCCESS, NULL);
51} 58}
diff --git a/sway/config/seat.c b/sway/config/seat.c
index 541c4f99..04a44e3a 100644
--- a/sway/config/seat.c
+++ b/sway/config/seat.c
@@ -26,7 +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 seat->allow_constrain = CONSTRAIN_DEFAULT;
30 30
31 return seat; 31 return seat;
32} 32}
@@ -143,6 +143,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
143 if (source->hide_cursor_timeout != -1) { 143 if (source->hide_cursor_timeout != -1) {
144 dest->hide_cursor_timeout = source->hide_cursor_timeout; 144 dest->hide_cursor_timeout = source->hide_cursor_timeout;
145 } 145 }
146
147 if (source->allow_constrain != CONSTRAIN_DEFAULT) {
148 dest->allow_constrain = source->allow_constrain;
149 }
146} 150}
147 151
148struct seat_config *copy_seat_config(struct seat_config *seat) { 152struct seat_config *copy_seat_config(struct seat_config *seat) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index e51d3e38..106b1910 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -1458,7 +1458,7 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) {
1458void sway_cursor_constrain(struct sway_cursor *cursor, 1458void sway_cursor_constrain(struct sway_cursor *cursor,
1459 struct wlr_pointer_constraint_v1 *constraint) { 1459 struct wlr_pointer_constraint_v1 *constraint) {
1460 struct seat_config *config = seat_get_config(cursor->seat); 1460 struct seat_config *config = seat_get_config(cursor->seat);
1461 if (!config->allow_constrain) { 1461 if (config->allow_constrain == CONSTRAIN_DISABLE) {
1462 return; 1462 return;
1463 } 1463 }
1464 1464
diff --git a/sway/meson.build b/sway/meson.build
index b3837e21..293a4ed2 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -75,7 +75,6 @@ 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',
79 'commands/reload.c', 78 'commands/reload.c',
80 'commands/rename.c', 79 'commands/rename.c',
81 'commands/resize.c', 80 'commands/resize.c',
@@ -85,6 +84,7 @@ sway_sources = files(
85 'commands/seat/cursor.c', 84 'commands/seat/cursor.c',
86 'commands/seat/fallback.c', 85 'commands/seat/fallback.c',
87 'commands/seat/hide_cursor.c', 86 'commands/seat/hide_cursor.c',
87 'commands/seat/pointer_constraint.c',
88 'commands/set.c', 88 'commands/set.c',
89 'commands/show_marks.c', 89 'commands/show_marks.c',
90 'commands/smart_borders.c', 90 'commands/smart_borders.c',
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
index 4b14ef14..88b4347a 100644
--- a/sway/sway-input.5.scd
+++ b/sway/sway-input.5.scd
@@ -172,6 +172,11 @@ in their own "seat").
172 disables hiding the cursor. The minimal timeout is 100 and any value less 172 disables hiding the cursor. The minimal timeout is 100 and any value less
173 than that (aside from 0), will be increased to 100. 173 than that (aside from 0), will be increased to 100.
174 174
175*seat* <name> pointer_constraint enable|disable|escape
176 Enables or disables the ability for clients to capture the cursor (enabled
177 by default) for the seat. This is primarily useful for video games. The
178 "escape" command can be used at runtime to escape from a captured client.
179
175# SEE ALSO 180# SEE ALSO
176 181
177*sway*(5) *sway-output*(5) 182*sway*(5) *sway-output*(5)
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 1ffb0e50..fd0a22dc 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -552,11 +552,6 @@ The default colors are:
552 \* may be used in lieu of a specific output name to configure all outputs. 552 \* may be used in lieu of a specific output name to configure all outputs.
553 A list of output names may be obtained via *swaymsg -t get_outputs*. 553 A list of output names may be obtained via *swaymsg -t get_outputs*.
554 554
555*pointer_constraint* enable|disable|escape
556 Enables or disables the ability for clients to capture the cursor (enabled
557 by default). This is primarily useful for video games. The "escape" command
558 can be used at runtime to escape from a captured client.
559
560*popup_during_fullscreen* smart|ignore|leave_fullscreen 555*popup_during_fullscreen* smart|ignore|leave_fullscreen
561 Determines what to do when a fullscreen view opens a dialog. 556 Determines what to do when a fullscreen view opens a dialog.
562 If _smart_ (the default), the dialog will be displayed. If _ignore_, the 557 If _smart_ (the default), the dialog will be displayed. If _ignore_, the