aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/seat/pointer_constraint.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/seat/pointer_constraint.c')
-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}