aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/seat
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/commands/seat
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/commands/seat')
-rw-r--r--sway/commands/seat/pointer_constraint.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/sway/commands/seat/pointer_constraint.c b/sway/commands/seat/pointer_constraint.c
new file mode 100644
index 00000000..3890ebde
--- /dev/null
+++ b/sway/commands/seat/pointer_constraint.c
@@ -0,0 +1,58 @@
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
8enum operation {
9 OP_ENABLE,
10 OP_DISABLE,
11 OP_ESCAPE,
12};
13
14// pointer_constraint [enable|disable|escape]
15struct cmd_results *seat_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 if (!config->handler_context.seat_config) {
21 return cmd_results_new(CMD_FAILURE, "No seat defined");
22 }
23
24 enum operation op;
25 if (strcmp(argv[0], "enable") == 0) {
26 op = OP_ENABLE;
27 } else if (strcmp(argv[0], "disable") == 0) {
28 op = OP_DISABLE;
29 } else if (strcmp(argv[0], "escape") == 0) {
30 op = OP_ESCAPE;
31 } else {
32 return cmd_results_new(CMD_FAILURE, "Expected enable|disable|escape");
33 }
34
35 if (op == OP_ESCAPE && config->reading) {
36 return cmd_results_new(CMD_FAILURE, "Can only escape at runtime.");
37 }
38
39 struct seat_config *seat_config = config->handler_context.seat_config;
40 switch (op) {
41 case OP_ENABLE:
42 seat_config->allow_constrain = CONSTRAIN_ENABLE;
43 break;
44 case OP_DISABLE:
45 seat_config->allow_constrain = CONSTRAIN_DISABLE;
46 /* fallthrough */
47 case OP_ESCAPE:;
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 }
55 break;
56 }
57 return cmd_results_new(CMD_SUCCESS, NULL);
58}