diff options
Diffstat (limited to 'sway/commands/seat/cursor.c')
-rw-r--r-- | sway/commands/seat/cursor.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 8d9e426a..4f805b22 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c | |||
@@ -10,7 +10,7 @@ | |||
10 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, | 10 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, |
11 | char *action, char *button_str); | 11 | char *action, char *button_str); |
12 | 12 | ||
13 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " | 13 | static const char expected_syntax[] = "Expected 'cursor <move> <x> <y>' or " |
14 | "'cursor <set> <x> <y>' or " | 14 | "'cursor <set> <x> <y>' or " |
15 | "'curor <press|release> <button[1-9]|event-name-or-code>'"; | 15 | "'curor <press|release> <button[1-9]|event-name-or-code>'"; |
16 | 16 | ||
@@ -18,7 +18,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor, | |||
18 | int argc, char **argv) { | 18 | int argc, char **argv) { |
19 | if (strcasecmp(argv[0], "move") == 0) { | 19 | if (strcasecmp(argv[0], "move") == 0) { |
20 | if (argc < 3) { | 20 | if (argc < 3) { |
21 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 21 | return cmd_results_new(CMD_INVALID, expected_syntax); |
22 | } | 22 | } |
23 | int delta_x = strtol(argv[1], NULL, 10); | 23 | int delta_x = strtol(argv[1], NULL, 10); |
24 | int delta_y = strtol(argv[2], NULL, 10); | 24 | int delta_y = strtol(argv[2], NULL, 10); |
@@ -26,7 +26,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor, | |||
26 | cursor_rebase(cursor); | 26 | cursor_rebase(cursor); |
27 | } else if (strcasecmp(argv[0], "set") == 0) { | 27 | } else if (strcasecmp(argv[0], "set") == 0) { |
28 | if (argc < 3) { | 28 | if (argc < 3) { |
29 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 29 | return cmd_results_new(CMD_INVALID, expected_syntax); |
30 | } | 30 | } |
31 | // map absolute coords (0..1,0..1) to root container coords | 31 | // map absolute coords (0..1,0..1) to root container coords |
32 | float x = strtof(argv[1], NULL) / root->width; | 32 | float x = strtof(argv[1], NULL) / root->width; |
@@ -35,7 +35,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor, | |||
35 | cursor_rebase(cursor); | 35 | cursor_rebase(cursor); |
36 | } else { | 36 | } else { |
37 | if (argc < 2) { | 37 | if (argc < 2) { |
38 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 38 | return cmd_results_new(CMD_INVALID, expected_syntax); |
39 | } | 39 | } |
40 | struct cmd_results *error = NULL; | 40 | struct cmd_results *error = NULL; |
41 | if ((error = press_or_release(cursor, argv[0], argv[1]))) { | 41 | if ((error = press_or_release(cursor, argv[0], argv[1]))) { |
@@ -43,7 +43,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor, | |||
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 46 | return cmd_results_new(CMD_SUCCESS, NULL); |
47 | } | 47 | } |
48 | 48 | ||
49 | struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | 49 | struct cmd_results *seat_cmd_cursor(int argc, char **argv) { |
@@ -53,18 +53,17 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
53 | } | 53 | } |
54 | struct seat_config *sc = config->handler_context.seat_config; | 54 | struct seat_config *sc = config->handler_context.seat_config; |
55 | if (!sc) { | 55 | if (!sc) { |
56 | return cmd_results_new(CMD_FAILURE, "cursor", "No seat defined"); | 56 | return cmd_results_new(CMD_FAILURE, "No seat defined"); |
57 | } | 57 | } |
58 | 58 | ||
59 | if (config->reading || !config->active) { | 59 | if (config->reading || !config->active) { |
60 | return cmd_results_new(CMD_DEFER, NULL, NULL); | 60 | return cmd_results_new(CMD_DEFER, NULL); |
61 | } | 61 | } |
62 | 62 | ||
63 | if (strcmp(sc->name, "*") != 0) { | 63 | if (strcmp(sc->name, "*") != 0) { |
64 | struct sway_seat *seat = input_manager_get_seat(sc->name); | 64 | struct sway_seat *seat = input_manager_get_seat(sc->name); |
65 | if (!seat) { | 65 | if (!seat) { |
66 | return cmd_results_new(CMD_FAILURE, "cursor", | 66 | return cmd_results_new(CMD_FAILURE, "Failed to get seat"); |
67 | "Failed to get seat"); | ||
68 | } | 67 | } |
69 | error = handle_command(seat->cursor, argc, argv); | 68 | error = handle_command(seat->cursor, argc, argv); |
70 | } else { | 69 | } else { |
@@ -77,7 +76,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
77 | } | 76 | } |
78 | } | 77 | } |
79 | 78 | ||
80 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | 79 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL); |
81 | } | 80 | } |
82 | 81 | ||
83 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, | 82 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, |
@@ -89,14 +88,14 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, | |||
89 | } else if (strcasecmp(action, "release") == 0) { | 88 | } else if (strcasecmp(action, "release") == 0) { |
90 | state = WLR_BUTTON_RELEASED; | 89 | state = WLR_BUTTON_RELEASED; |
91 | } else { | 90 | } else { |
92 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 91 | return cmd_results_new(CMD_INVALID, expected_syntax); |
93 | } | 92 | } |
94 | 93 | ||
95 | char *message = NULL; | 94 | char *message = NULL; |
96 | button = get_mouse_button(button_str, &message); | 95 | button = get_mouse_button(button_str, &message); |
97 | if (message) { | 96 | if (message) { |
98 | struct cmd_results *error = | 97 | struct cmd_results *error = |
99 | cmd_results_new(CMD_INVALID, "cursor", message); | 98 | cmd_results_new(CMD_INVALID, message); |
100 | free(message); | 99 | free(message); |
101 | return error; | 100 | return error; |
102 | } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN | 101 | } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN |
@@ -117,11 +116,10 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, | |||
117 | .delta_discrete = delta | 116 | .delta_discrete = delta |
118 | }; | 117 | }; |
119 | dispatch_cursor_axis(cursor, &event); | 118 | dispatch_cursor_axis(cursor, &event); |
120 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 119 | return cmd_results_new(CMD_SUCCESS, NULL); |
121 | } else if (!button) { | 120 | } else if (!button) { |
122 | return cmd_results_new(CMD_INVALID, "curor", | 121 | return cmd_results_new(CMD_INVALID, "Unknown button %s", button_str); |
123 | "Unknown button %s", button_str); | ||
124 | } | 122 | } |
125 | dispatch_cursor_button(cursor, NULL, 0, button, state); | 123 | dispatch_cursor_button(cursor, NULL, 0, button, state); |
126 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 124 | return cmd_results_new(CMD_SUCCESS, NULL); |
127 | } | 125 | } |