aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/seat
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-01-31 22:58:52 -0500
committerBrian Ashworth <bosrsf04@gmail.com>2019-01-31 22:58:52 -0500
commitebe5399ed6bfa59f5f5d289bf3d46b08f60787b3 (patch)
treeca0bff9d26283b0fa790855e7379e8da2e89166b /sway/commands/seat
parent204e1f47122d5a48865802dd1fb94fe0f05c2401 (diff)
downloadsway-ebe5399ed6bfa59f5f5d289bf3d46b08f60787b3.tar.xz
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 @@
+#include <string.h>
+#include <wlr/types/wlr_pointer_constraints_v1.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/input/cursor.h"
+#include "sway/input/seat.h"
+
+enum operation {
+ OP_ENABLE,
+ OP_DISABLE,
+ OP_ESCAPE,
+};
+
+// pointer_constraint [enable|disable|escape]
+struct cmd_results *seat_cmd_pointer_constraint(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->handler_context.seat_config) {
+ return cmd_results_new(CMD_FAILURE, "No seat defined");
+ }
+
+ enum operation op;
+ if (strcmp(argv[0], "enable") == 0) {
+ op = OP_ENABLE;
+ } else if (strcmp(argv[0], "disable") == 0) {
+ op = OP_DISABLE;
+ } else if (strcmp(argv[0], "escape") == 0) {
+ op = OP_ESCAPE;
+ } else {
+ return cmd_results_new(CMD_FAILURE, "Expected enable|disable|escape");
+ }
+
+ if (op == OP_ESCAPE && config->reading) {
+ return cmd_results_new(CMD_FAILURE, "Can only escape at runtime.");
+ }
+
+ struct seat_config *seat_config = config->handler_context.seat_config;
+ switch (op) {
+ case OP_ENABLE:
+ seat_config->allow_constrain = CONSTRAIN_ENABLE;
+ break;
+ case OP_DISABLE:
+ seat_config->allow_constrain = CONSTRAIN_DISABLE;
+ /* fallthrough */
+ case OP_ESCAPE:;
+ bool wildcard = !strcmp(seat_config->name, "*");
+ struct sway_seat *seat = NULL;
+ wl_list_for_each(seat, &server.input->seats, link) {
+ if (wildcard || !strcmp(seat->wlr_seat->name, seat_config->name)) {
+ sway_cursor_constrain(seat->cursor, NULL);
+ }
+ }
+ break;
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL);
+}