From 6ec2983d9636250c69f95e4edeb03519e873e833 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 27 Dec 2018 12:06:35 -0500 Subject: [PATCH] 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 cursor `. 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. --- sway/commands/seat/cursor.c | 49 ++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 495c23382..b47285435 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -17,18 +17,8 @@ static const char *expected_syntax = "Expected 'cursor ' or " "'cursor ' or " "'curor '"; -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;