summaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2019-01-30 10:42:31 -0500
committerLibravatar emersion <contact@emersion.fr>2019-01-30 19:53:59 +0100
commita6d41254c90c1471326e5df94b939a12844d9be6 (patch)
tree2b8c8f6efc012284bd438a0ebcfc7f6022e32bc5 /sway/commands
parentAdd relative pointer (diff)
downloadsway-a6d41254c90c1471326e5df94b939a12844d9be6.tar.gz
sway-a6d41254c90c1471326e5df94b939a12844d9be6.tar.zst
sway-a6d41254c90c1471326e5df94b939a12844d9be6.zip
Add pointer_constraint command
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/pointer_constraint.c51
1 files changed, 51 insertions, 0 deletions
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
8enum operation {
9 OP_ENABLE,
10 OP_DISABLE,
11 OP_ESCAPE,
12};
13
14// pointer_constraint [enable|disable|escape]
15struct 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}