aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-12-27 12:06:35 -0500
committerBrian Ashworth <bosrsf04@gmail.com>2018-12-29 22:02:19 -0500
commit6ec2983d9636250c69f95e4edeb03519e873e833 (patch)
tree40dffb6a9fdfda11e51de4580f090561ab8a7d92
parent3e8f548d1d0acb3aba384842615e6528b3027283 (diff)
seat_cmd_cursor: work on seat name provided
Instead of simulating events on the current seat, this makes it so seat_cmd_cursor respects the seat name provided by `seat <name> cursor <args>`. It also adds support for simulating events on all seats when the wildcard is given. This also defers the command when reading the config, which allows the user to set the initial position of the cursor when the command is included in the config file.
-rw-r--r--sway/commands/seat/cursor.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c
index 495c2338..b4728543 100644
--- a/sway/commands/seat/cursor.c
+++ b/sway/commands/seat/cursor.c
@@ -17,18 +17,8 @@ static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or "
"'cursor <set> <x> <y>' or "
"'curor <press|release> <left|right|1|2|3...>'";
-struct cmd_results *seat_cmd_cursor(int argc, char **argv) {
- struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "cursor", EXPECTED_AT_LEAST, 2))) {
- return error;
- }
- struct sway_seat *seat = config->handler_context.seat;
- if (!seat) {
- return cmd_results_new(CMD_FAILURE, "cursor", "No seat defined");
- }
-
- struct sway_cursor *cursor = seat->cursor;
-
+static struct cmd_results *handle_command(struct sway_cursor *cursor,
+ int argc, char **argv) {
if (strcasecmp(argv[0], "move") == 0) {
if (argc < 3) {
return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
@@ -50,6 +40,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) {
if (argc < 2) {
return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
}
+ struct cmd_results *error = NULL;
if ((error = press_or_release(cursor, argv[0], argv[1]))) {
return error;
}
@@ -58,6 +49,40 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+struct cmd_results *seat_cmd_cursor(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "cursor", EXPECTED_AT_LEAST, 2))) {
+ return error;
+ }
+ struct seat_config *sc = config->handler_context.seat_config;
+ if (!sc) {
+ return cmd_results_new(CMD_FAILURE, "cursor", "No seat defined");
+ }
+
+ if (config->reading || !config->active) {
+ return cmd_results_new(CMD_DEFER, NULL, NULL);
+ }
+
+ if (strcmp(sc->name, "*") != 0) {
+ struct sway_seat *seat = input_manager_get_seat(sc->name);
+ if (!seat) {
+ return cmd_results_new(CMD_FAILURE, "cursor",
+ "Failed to get seat");
+ }
+ error = handle_command(seat->cursor, argc, argv);
+ } else {
+ struct sway_seat *seat = NULL;
+ wl_list_for_each(seat, &server.input->seats, link) {
+ error = handle_command(seat->cursor, argc, argv);
+ if ((error && error->status != CMD_SUCCESS)) {
+ break;
+ }
+ }
+ }
+
+ return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
static struct cmd_results *press_or_release(struct sway_cursor *cursor,
char *action, char *button_str) {
enum wlr_button_state state;