summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h3
-rw-r--r--include/sway/input/cursor.h2
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/seat.c2
-rw-r--r--sway/commands/seat/cursor.c89
-rw-r--r--sway/input/cursor.c2
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.txt7
-rw-r--r--swaybar/bar.c70
-rw-r--r--swaybar/ipc.c4
10 files changed, 149 insertions, 32 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index bc5d5412..dbebaa49 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -204,8 +204,9 @@ sway_cmd input_cmd_xkb_options;
204sway_cmd input_cmd_xkb_rules; 204sway_cmd input_cmd_xkb_rules;
205sway_cmd input_cmd_xkb_variant; 205sway_cmd input_cmd_xkb_variant;
206 206
207sway_cmd seat_cmd_fallback;
208sway_cmd seat_cmd_attach; 207sway_cmd seat_cmd_attach;
208sway_cmd seat_cmd_fallback;
209sway_cmd seat_cmd_cursor;
209 210
210sway_cmd cmd_ipc_cmd; 211sway_cmd cmd_ipc_cmd;
211sway_cmd cmd_ipc_events; 212sway_cmd cmd_ipc_events;
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index daf7d4ee..fcd94437 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -30,5 +30,7 @@ struct sway_cursor {
30void sway_cursor_destroy(struct sway_cursor *cursor); 30void sway_cursor_destroy(struct sway_cursor *cursor);
31struct sway_cursor *sway_cursor_create(struct sway_seat *seat); 31struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time); 32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time);
33void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
34 uint32_t button, enum wlr_button_state state);
33 35
34#endif 36#endif
diff --git a/sway/commands.c b/sway/commands.c
index 55929659..54d84450 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -203,6 +203,7 @@ static struct cmd_handler input_handlers[] = {
203// must be in order for the bsearch 203// must be in order for the bsearch
204static struct cmd_handler seat_handlers[] = { 204static struct cmd_handler seat_handlers[] = {
205 { "attach", seat_cmd_attach }, 205 { "attach", seat_cmd_attach },
206 { "cursor", seat_cmd_cursor },
206 { "fallback", seat_cmd_fallback }, 207 { "fallback", seat_cmd_fallback },
207}; 208};
208 209
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 819b769c..5916015f 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -40,6 +40,8 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
40 struct cmd_results *res; 40 struct cmd_results *res;
41 if (strcasecmp("attach", argv[1]) == 0) { 41 if (strcasecmp("attach", argv[1]) == 0) {
42 res = seat_cmd_attach(argc_new, argv_new); 42 res = seat_cmd_attach(argc_new, argv_new);
43 } else if (strcasecmp("cursor", argv[1]) == 0) {
44 res = seat_cmd_cursor(argc_new, argv_new);
43 } else if (strcasecmp("fallback", argv[1]) == 0) { 45 } else if (strcasecmp("fallback", argv[1]) == 0) {
44 res = seat_cmd_fallback(argc_new, argv_new); 46 res = seat_cmd_fallback(argc_new, argv_new);
45 } else { 47 } else {
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/input/cursor.c b/sway/input/cursor.c
index 0df01504..15a61cbf 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -166,7 +166,7 @@ static void handle_cursor_motion_absolute(
166 cursor_send_pointer_motion(cursor, event->time_msec); 166 cursor_send_pointer_motion(cursor, event->time_msec);
167} 167}
168 168
169static void dispatch_cursor_button(struct sway_cursor *cursor, 169void dispatch_cursor_button(struct sway_cursor *cursor,
170 uint32_t time_msec, uint32_t button, enum wlr_button_state state) { 170 uint32_t time_msec, uint32_t button, enum wlr_button_state state) {
171 struct wlr_surface *surface = NULL; 171 struct wlr_surface *surface = NULL;
172 double sx, sy; 172 double sx, sy;
diff --git a/sway/meson.build b/sway/meson.build
index d0730296..9e55e335 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -47,6 +47,7 @@ sway_sources = files(
47 'commands/resize.c', 47 'commands/resize.c',
48 'commands/seat.c', 48 'commands/seat.c',
49 'commands/seat/attach.c', 49 'commands/seat/attach.c',
50 'commands/seat/cursor.c',
50 'commands/seat/fallback.c', 51 'commands/seat/fallback.c',
51 'commands/set.c', 52 'commands/set.c',
52 'commands/split.c', 53 'commands/split.c',
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 59c3295a..03975349 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -328,6 +328,13 @@ The default colors are:
328 the named seat, and _}_ on its own line will close the block. 328 the named seat, and _}_ on its own line will close the block.
329 See **sway-input**(5) for details. 329 See **sway-input**(5) for details.
330 330
331**seat** <seat_name> cursor <move|set> <x> <y>::
332 Move cursor relatively to current position or set to absolute screen position.
333 A value of 0 causes the axis to be ignored in both commands.
334
335**seat** <seat_name> cursor <press|release> <left|right|1|2|3...>::
336 Simulate press of mouse button specified by left, right, or numerical code.
337
331**kill**:: 338**kill**::
332 Kills (force-closes) the currently-focused container and all of its children. 339 Kills (force-closes) the currently-focused container and all of its children.
333 340
diff --git a/swaybar/bar.c b/swaybar/bar.c
index f1a701b9..d51c4ec7 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -264,6 +264,19 @@ struct wl_output_listener output_listener = {
264 .scale = output_scale, 264 .scale = output_scale,
265}; 265};
266 266
267static bool bar_uses_output(struct swaybar *bar, size_t output_index) {
268 if (bar->config->all_outputs) {
269 return true;
270 }
271 struct config_output *coutput;
272 wl_list_for_each(coutput, &bar->config->outputs, link) {
273 if (coutput->index == output_index) {
274 return true;
275 }
276 }
277 return false;
278}
279
267static void handle_global(void *data, struct wl_registry *registry, 280static void handle_global(void *data, struct wl_registry *registry,
268 uint32_t name, const char *interface, uint32_t version) { 281 uint32_t name, const char *interface, uint32_t version) {
269 struct swaybar *bar = data; 282 struct swaybar *bar = data;
@@ -278,19 +291,22 @@ static void handle_global(void *data, struct wl_registry *registry,
278 bar->shm = wl_registry_bind(registry, name, 291 bar->shm = wl_registry_bind(registry, name,
279 &wl_shm_interface, 1); 292 &wl_shm_interface, 1);
280 } else if (strcmp(interface, wl_output_interface.name) == 0) { 293 } else if (strcmp(interface, wl_output_interface.name) == 0) {
281 static size_t index = 0; 294 static size_t output_index = 0;
282 struct swaybar_output *output = 295 if (bar_uses_output(bar, output_index)) {
283 calloc(1, sizeof(struct swaybar_output)); 296 struct swaybar_output *output =
284 output->bar = bar; 297 calloc(1, sizeof(struct swaybar_output));
285 output->output = wl_registry_bind(registry, name, 298 output->bar = bar;
286 &wl_output_interface, 3); 299 output->output = wl_registry_bind(registry, name,
287 wl_output_add_listener(output->output, &output_listener, output); 300 &wl_output_interface, 3);
288 output->scale = 1; 301 wl_output_add_listener(output->output, &output_listener, output);
289 output->index = index++; 302 output->scale = 1;
290 output->wl_name = name; 303 output->index = output_index;
291 wl_list_init(&output->workspaces); 304 output->wl_name = name;
292 wl_list_init(&output->hotspots); 305 wl_list_init(&output->workspaces);
293 wl_list_insert(&bar->outputs, &output->link); 306 wl_list_init(&output->hotspots);
307 wl_list_insert(&bar->outputs, &output->link);
308 }
309 ++output_index;
294 } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { 310 } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
295 bar->layer_shell = wl_registry_bind( 311 bar->layer_shell = wl_registry_bind(
296 registry, name, &zwlr_layer_shell_v1_interface, 1); 312 registry, name, &zwlr_layer_shell_v1_interface, 1);
@@ -362,26 +378,24 @@ void bar_setup(struct swaybar *bar,
362 pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); 378 pointer->cursor_surface = wl_compositor_create_surface(bar->compositor);
363 assert(pointer->cursor_surface); 379 assert(pointer->cursor_surface);
364 380
365 // TODO: we might not necessarily be meant to do all of the outputs
366 wl_list_for_each(output, &bar->outputs, link) { 381 wl_list_for_each(output, &bar->outputs, link) {
367 struct config_output *coutput; 382 struct config_output *coutput;
368 wl_list_for_each(coutput, &bar->config->outputs, link) { 383 wl_list_for_each(coutput, &bar->config->outputs, link) {
369 if (coutput->index != output->index) { 384 if (coutput->index == output->index) {
370 continue; 385 output->name = strdup(coutput->name);
386 break;
371 } 387 }
372 output->name = strdup(coutput->name);
373 output->surface = wl_compositor_create_surface(bar->compositor);
374 assert(output->surface);
375 output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
376 bar->layer_shell, output->surface, output->output,
377 ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
378 assert(output->layer_surface);
379 zwlr_layer_surface_v1_add_listener(output->layer_surface,
380 &layer_surface_listener, output);
381 zwlr_layer_surface_v1_set_anchor(output->layer_surface,
382 bar->config->position);
383 break;
384 } 388 }
389 output->surface = wl_compositor_create_surface(bar->compositor);
390 assert(output->surface);
391 output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
392 bar->layer_shell, output->surface, output->output,
393 ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
394 assert(output->layer_surface);
395 zwlr_layer_surface_v1_add_listener(output->layer_surface,
396 &layer_surface_listener, output);
397 zwlr_layer_surface_v1_set_anchor(output->layer_surface,
398 bar->config->position);
385 } 399 }
386 ipc_get_workspaces(bar); 400 ipc_get_workspaces(bar);
387 render_all_frames(bar); 401 render_all_frames(bar);
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index e6231bd2..ed5d9a31 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -331,7 +331,7 @@ bool handle_ipc_readable(struct swaybar *bar) {
331 switch (resp->type) { 331 switch (resp->type) {
332 case IPC_EVENT_WORKSPACE: 332 case IPC_EVENT_WORKSPACE:
333 ipc_get_workspaces(bar); 333 ipc_get_workspaces(bar);
334 return true; 334 break;
335 case IPC_EVENT_MODE: { 335 case IPC_EVENT_MODE: {
336 json_object *result = json_tokener_parse(resp->payload); 336 json_object *result = json_tokener_parse(resp->payload);
337 if (!result) { 337 if (!result) {
@@ -367,5 +367,5 @@ bool handle_ipc_readable(struct swaybar *bar) {
367 return false; 367 return false;
368 } 368 }
369 free_ipc_response(resp); 369 free_ipc_response(resp);
370 return false; 370 return true;
371} 371}