summaryrefslogtreecommitdiffstats
path: root/sway/commands/seat
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/seat')
-rw-r--r--sway/commands/seat/attach.c28
-rw-r--r--sway/commands/seat/cursor.c89
-rw-r--r--sway/commands/seat/fallback.c32
3 files changed, 149 insertions, 0 deletions
diff --git a/sway/commands/seat/attach.c b/sway/commands/seat/attach.c
new file mode 100644
index 00000000..3e771c00
--- /dev/null
+++ b/sway/commands/seat/attach.c
@@ -0,0 +1,28 @@
1#define _XOPEN_SOURCE 700
2#include <string.h>
3#include <strings.h>
4#include "sway/input/input-manager.h"
5#include "sway/commands.h"
6#include "sway/config.h"
7#include "log.h"
8#include "stringop.h"
9
10struct cmd_results *seat_cmd_attach(int argc, char **argv) {
11 struct cmd_results *error = NULL;
12 if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) {
13 return error;
14 }
15 struct seat_config *current_seat_config =
16 config->handler_context.seat_config;
17 if (!current_seat_config) {
18 return cmd_results_new(CMD_FAILURE, "attach", "No seat defined");
19 }
20
21 struct seat_config *new_config = new_seat_config(current_seat_config->name);
22 struct seat_attachment_config *new_attachment = seat_attachment_config_new();
23 new_attachment->identifier = strdup(argv[0]);
24 list_add(new_config->attachments, new_attachment);
25
26 apply_seat_config(new_config);
27 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
28}
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c
new file mode 100644
index 00000000..5dad97f1
--- /dev/null
+++ b/sway/commands/seat/cursor.c
@@ -0,0 +1,89 @@
1#define _XOPEN_SOURCE 700
2#ifdef __linux__
3#include <linux/input-event-codes.h>
4#elif __FreeBSD__
5#include <dev/evdev/input-event-codes.h>
6#endif
7
8#include <strings.h>
9#include <wlr/types/wlr_cursor.h>
10#include "sway/commands.h"
11#include "sway/input/cursor.h"
12
13static struct cmd_results *press_or_release(struct sway_cursor *cursor,
14 char *action, char *button_str, uint32_t time);
15
16static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or "
17 "'cursor <set> <x> <y>' or "
18 "'curor <press|release> <left|right|1|2|3...>'";
19
20struct cmd_results *seat_cmd_cursor(int argc, char **argv) {
21 struct cmd_results *error = NULL;
22 if ((error = checkarg(argc, "cursor", EXPECTED_AT_LEAST, 2))) {
23 return error;
24 }
25 struct sway_seat *seat = config->handler_context.seat;
26 if (!seat) {
27 return cmd_results_new(CMD_FAILURE, "cursor", "No seat defined");
28 }
29
30 struct sway_cursor *cursor = seat->cursor;
31
32 struct timespec now;
33 clock_gettime(CLOCK_MONOTONIC, &now);
34 uint32_t time = now.tv_nsec / 1000;
35
36 if (strcasecmp(argv[0], "move") == 0) {
37 if (argc < 3) {
38 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
39 }
40 int delta_x = strtol(argv[1], NULL, 10);
41 int delta_y = strtol(argv[2], NULL, 10);
42 wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y);
43 cursor_send_pointer_motion(cursor, time);
44 } else if (strcasecmp(argv[0], "set") == 0) {
45 if (argc < 3) {
46 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
47 }
48 // map absolute coords (0..1,0..1) to root container coords
49 float x = strtof(argv[1], NULL) / root_container.width;
50 float y = strtof(argv[2], NULL) / root_container.height;
51 wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y);
52 cursor_send_pointer_motion(cursor, time);
53 } else {
54 if (argc < 2) {
55 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
56 }
57 if ((error = press_or_release(cursor, argv[0], argv[1], time))) {
58 return error;
59 }
60 }
61
62 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
63}
64
65static struct cmd_results *press_or_release(struct sway_cursor *cursor,
66 char *action, char *button_str, uint32_t time) {
67 enum wlr_button_state state;
68 uint32_t button;
69 if (strcasecmp(action, "press") == 0) {
70 state = WLR_BUTTON_PRESSED;
71 } else if (strcasecmp(action, "release") == 0) {
72 state = WLR_BUTTON_RELEASED;
73 } else {
74 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
75 }
76
77 if (strcasecmp(button_str, "left") == 0) {
78 button = BTN_LEFT;
79 } else if (strcasecmp(button_str, "right") == 0) {
80 button = BTN_RIGHT;
81 } else {
82 button = strtol(button_str, NULL, 10);
83 if (button == 0) {
84 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
85 }
86 }
87 dispatch_cursor_button(cursor, time, button, state);
88 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
89}
diff --git a/sway/commands/seat/fallback.c b/sway/commands/seat/fallback.c
new file mode 100644
index 00000000..56feaab5
--- /dev/null
+++ b/sway/commands/seat/fallback.c
@@ -0,0 +1,32 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/config.h"
4#include "sway/commands.h"
5#include "sway/input/input-manager.h"
6
7struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) {
10 return error;
11 }
12 struct seat_config *current_seat_config =
13 config->handler_context.seat_config;
14 if (!current_seat_config) {
15 return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined");
16 }
17 struct seat_config *new_config =
18 new_seat_config(current_seat_config->name);
19
20 if (strcasecmp(argv[0], "true") == 0) {
21 new_config->fallback = 1;
22 } else if (strcasecmp(argv[0], "false") == 0) {
23 new_config->fallback = 0;
24 } else {
25 free_seat_config(new_config);
26 return cmd_results_new(CMD_INVALID, "fallback",
27 "Expected 'fallback <true|false>'");
28 }
29
30 apply_seat_config(new_config);
31 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
32}