aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/sway/commands.h2
-rw-r--r--include/sway/config.h8
-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
10 files changed, 36 insertions, 19 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 2877c370..3ed00763 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -153,7 +153,6 @@ sway_cmd cmd_new_window;
153sway_cmd cmd_no_focus; 153sway_cmd cmd_no_focus;
154sway_cmd cmd_output; 154sway_cmd cmd_output;
155sway_cmd cmd_permit; 155sway_cmd cmd_permit;
156sway_cmd cmd_pointer_constraint;
157sway_cmd cmd_popup_during_fullscreen; 156sway_cmd cmd_popup_during_fullscreen;
158sway_cmd cmd_reject; 157sway_cmd cmd_reject;
159sway_cmd cmd_reload; 158sway_cmd cmd_reload;
@@ -268,6 +267,7 @@ sway_cmd seat_cmd_attach;
268sway_cmd seat_cmd_cursor; 267sway_cmd seat_cmd_cursor;
269sway_cmd seat_cmd_fallback; 268sway_cmd seat_cmd_fallback;
270sway_cmd seat_cmd_hide_cursor; 269sway_cmd seat_cmd_hide_cursor;
270sway_cmd seat_cmd_pointer_constraint;
271 271
272sway_cmd cmd_ipc_cmd; 272sway_cmd cmd_ipc_cmd;
273sway_cmd cmd_ipc_events; 273sway_cmd cmd_ipc_events;
diff --git a/include/sway/config.h b/include/sway/config.h
index e63b9895..43ea7778 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -135,6 +135,12 @@ struct seat_attachment_config {
135 // TODO other things are configured here for some reason 135 // TODO other things are configured here for some reason
136}; 136};
137 137
138enum seat_config_allow_constrain {
139 CONSTRAIN_DEFAULT, // the default is currently enabled
140 CONSTRAIN_ENABLE,
141 CONSTRAIN_DISABLE
142};
143
138/** 144/**
139 * Options for multiseat and other misc device configurations 145 * Options for multiseat and other misc device configurations
140 */ 146 */
@@ -143,7 +149,7 @@ struct seat_config {
143 int fallback; // -1 means not set 149 int fallback; // -1 means not set
144 list_t *attachments; // list of seat_attachment configs 150 list_t *attachments; // list of seat_attachment configs
145 int hide_cursor_timeout; 151 int hide_cursor_timeout;
146 bool allow_constrain; 152 enum seat_config_allow_constrain allow_constrain;
147}; 153};
148 154
149enum config_dpms { 155enum config_dpms {
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