aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Tamir Zahavi-Brunner <tamir.z3@gmail.com>2020-09-07 01:44:13 +0300
committerLibravatar Simon Ser <contact@emersion.fr>2020-10-30 09:59:54 +0100
commit96578aa91e9856bfb3e2d26fb7a625ff7c9b79e3 (patch)
treeac763cde133816f3bd8218eccbc352416ce88a5f /sway
parentoutput: Revert implementation of evacuate_sticky() (diff)
downloadsway-96578aa91e9856bfb3e2d26fb7a625ff7c9b79e3.tar.gz
sway-96578aa91e9856bfb3e2d26fb7a625ff7c9b79e3.tar.zst
sway-96578aa91e9856bfb3e2d26fb7a625ff7c9b79e3.zip
hide_cursor: Add an option to hide when typing
Add an option for the `hide_cursor` command to hide the cursor when typing, i.e. whenever a key is pressed.
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/seat/hide_cursor.c42
-rw-r--r--sway/config/seat.c5
-rw-r--r--sway/input/cursor.c26
-rw-r--r--sway/input/keyboard.c5
-rw-r--r--sway/sway-input.5.scd15
5 files changed, 78 insertions, 15 deletions
diff --git a/sway/commands/seat/hide_cursor.c b/sway/commands/seat/hide_cursor.c
index 3bfce697..e09b82d9 100644
--- a/sway/commands/seat/hide_cursor.c
+++ b/sway/commands/seat/hide_cursor.c
@@ -3,26 +3,48 @@
3#include "sway/commands.h" 3#include "sway/commands.h"
4#include "sway/config.h" 4#include "sway/config.h"
5#include "sway/input/seat.h" 5#include "sway/input/seat.h"
6#include "sway/input/cursor.h"
7#include "sway/server.h"
6#include "stringop.h" 8#include "stringop.h"
9#include "util.h"
7 10
8struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) { 11struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) {
9 struct cmd_results *error = NULL; 12 struct cmd_results *error = NULL;
10 if ((error = checkarg(argc, "hide_cursor", EXPECTED_EQUAL_TO, 1))) { 13 if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_LEAST, 1))) {
11 return error; 14 return error;
12 } 15 }
13 if (!config->handler_context.seat_config) { 16 if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_MOST, 2))) {
17 return error;
18 }
19 struct seat_config *seat_config = config->handler_context.seat_config;
20 if (!seat_config) {
14 return cmd_results_new(CMD_FAILURE, "No seat defined"); 21 return cmd_results_new(CMD_FAILURE, "No seat defined");
15 } 22 }
16 23
17 char *end; 24 if (argc == 1) {
18 int timeout = strtol(argv[0], &end, 10); 25 char *end;
19 if (*end) { 26 int timeout = strtol(argv[0], &end, 10);
20 return cmd_results_new(CMD_INVALID, "Expected an integer timeout"); 27 if (*end) {
21 } 28 return cmd_results_new(CMD_INVALID, "Expected an integer timeout");
22 if (timeout < 100 && timeout != 0) { 29 }
23 timeout = 100; 30 if (timeout < 100 && timeout != 0) {
31 timeout = 100;
32 }
33 seat_config->hide_cursor_timeout = timeout;
34 } else {
35 if (strcmp(argv[0], "when-typing") != 0) {
36 return cmd_results_new(CMD_INVALID,
37 "Expected 'hide_cursor <timeout>|when-typing [enable|disable]'");
38 }
39 seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ?
40 HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE;
41
42 // Invalidate all the caches for this config
43 struct sway_seat *seat = NULL;
44 wl_list_for_each(seat, &server.input->seats, link) {
45 seat->cursor->hide_when_typing = HIDE_WHEN_TYPING_DEFAULT;
46 }
24 } 47 }
25 config->handler_context.seat_config->hide_cursor_timeout = timeout;
26 48
27 return cmd_results_new(CMD_SUCCESS, NULL); 49 return cmd_results_new(CMD_SUCCESS, NULL);
28} 50}
diff --git a/sway/config/seat.c b/sway/config/seat.c
index e2702de5..84260aa3 100644
--- a/sway/config/seat.c
+++ b/sway/config/seat.c
@@ -29,6 +29,7 @@ struct seat_config *new_seat_config(const char* name) {
29 return NULL; 29 return NULL;
30 } 30 }
31 seat->hide_cursor_timeout = -1; 31 seat->hide_cursor_timeout = -1;
32 seat->hide_cursor_when_typing = HIDE_WHEN_TYPING_DEFAULT;
32 seat->allow_constrain = CONSTRAIN_DEFAULT; 33 seat->allow_constrain = CONSTRAIN_DEFAULT;
33 seat->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT; 34 seat->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT;
34 seat->keyboard_grouping = KEYBOARD_GROUP_DEFAULT; 35 seat->keyboard_grouping = KEYBOARD_GROUP_DEFAULT;
@@ -151,6 +152,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
151 dest->hide_cursor_timeout = source->hide_cursor_timeout; 152 dest->hide_cursor_timeout = source->hide_cursor_timeout;
152 } 153 }
153 154
155 if (source->hide_cursor_when_typing != HIDE_WHEN_TYPING_DEFAULT) {
156 dest->hide_cursor_when_typing = source->hide_cursor_when_typing;
157 }
158
154 if (source->allow_constrain != CONSTRAIN_DEFAULT) { 159 if (source->allow_constrain != CONSTRAIN_DEFAULT) {
155 dest->allow_constrain = source->allow_constrain; 160 dest->allow_constrain = source->allow_constrain;
156 } 161 }
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index e47410a5..b168afc5 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -253,6 +253,32 @@ int cursor_get_timeout(struct sway_cursor *cursor) {
253 return timeout; 253 return timeout;
254} 254}
255 255
256void cursor_notify_key_press(struct sway_cursor *cursor) {
257 if (cursor->hidden) {
258 return;
259 }
260
261 if (cursor->hide_when_typing == HIDE_WHEN_TYPING_DEFAULT) {
262 // No cached value, need to lookup in the seat_config
263 const struct seat_config *seat_config = seat_get_config(cursor->seat);
264 if (!seat_config) {
265 seat_config = seat_get_config_by_name("*");
266 if (!seat_config) {
267 return;
268 }
269 }
270 cursor->hide_when_typing = seat_config->hide_cursor_when_typing;
271 // The default is currently disabled
272 if (cursor->hide_when_typing == HIDE_WHEN_TYPING_DEFAULT) {
273 cursor->hide_when_typing = HIDE_WHEN_TYPING_DISABLE;
274 }
275 }
276
277 if (cursor->hide_when_typing == HIDE_WHEN_TYPING_ENABLE) {
278 cursor_hide(cursor);
279 }
280}
281
256static enum sway_input_idle_source idle_source_from_device( 282static enum sway_input_idle_source idle_source_from_device(
257 struct wlr_input_device *device) { 283 struct wlr_input_device *device) {
258 switch (device->type) { 284 switch (device->type) {
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 541fc90d..ae30e83a 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -13,6 +13,7 @@
13#include "sway/input/input-manager.h" 13#include "sway/input/input-manager.h"
14#include "sway/input/keyboard.h" 14#include "sway/input/keyboard.h"
15#include "sway/input/seat.h" 15#include "sway/input/seat.h"
16#include "sway/input/cursor.h"
16#include "sway/ipc-server.h" 17#include "sway/ipc-server.h"
17#include "log.h" 18#include "log.h"
18 19
@@ -392,6 +393,10 @@ static void handle_key_event(struct sway_keyboard *keyboard,
392 keyboard_shortcuts_inhibitor_get_for_focused_surface(seat); 393 keyboard_shortcuts_inhibitor_get_for_focused_surface(seat);
393 bool shortcuts_inhibited = sway_inhibitor && sway_inhibitor->inhibitor->active; 394 bool shortcuts_inhibited = sway_inhibitor && sway_inhibitor->inhibitor->active;
394 395
396 if (event->state == WLR_KEY_PRESSED) {
397 cursor_notify_key_press(seat->cursor);
398 }
399
395 // Identify new keycode, raw keysym(s), and translated keysym(s) 400 // Identify new keycode, raw keysym(s), and translated keysym(s)
396 struct key_info keyinfo; 401 struct key_info keyinfo;
397 update_keyboard_state(keyboard, event->keycode, event->state, &keyinfo); 402 update_keyboard_state(keyboard, event->keycode, event->state, &keyinfo);
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
index d8180c1c..dbf21d93 100644
--- a/sway/sway-input.5.scd
+++ b/sway/sway-input.5.scd
@@ -229,11 +229,16 @@ correct seat.
229 Set this seat as the fallback seat. A fallback seat will attach any device 229 Set this seat as the fallback seat. A fallback seat will attach any device
230 not explicitly attached to another seat (similar to a "default" seat). 230 not explicitly attached to another seat (similar to a "default" seat).
231 231
232*seat* <name> hide_cursor <timeout> 232*seat* <name> hide_cursor <timeout>|when-typing [enable|disable]
233 Hides the cursor image after the specified _timeout_ (in milliseconds) 233 Hides the cursor image after the specified event occured.
234 has elapsed with no activity on that cursor. A timeout of 0 (default) 234
235 disables hiding the cursor. The minimal timeout is 100 and any value less 235 If _timeout_ is specified, then the cursor will be hidden after _timeout_
236 than that (aside from 0), will be increased to 100. 236 (in milliseconds) has elapsed with no activity on the cursor. A timeout of 0
237 (default) disables hiding the cursor. The minimal timeout is 100 and any
238 value less than that (aside from 0), will be increased to 100.
239
240 If _when-typing_ is enabled, then the cursor will be hidden whenever a key
241 is pressed.
237 242
238*seat* <name> idle_inhibit <sources...> 243*seat* <name> idle_inhibit <sources...>
239 Sets the set of input event sources which can prevent the seat from 244 Sets the set of input event sources which can prevent the seat from