2018-12-18 07:37:15 +11:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <string.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/input/seat.h"
|
2020-09-07 08:44:13 +10:00
|
|
|
#include "sway/input/cursor.h"
|
|
|
|
#include "sway/server.h"
|
2018-12-18 07:37:15 +11:00
|
|
|
#include "stringop.h"
|
2020-09-07 08:44:13 +10:00
|
|
|
#include "util.h"
|
2018-12-18 07:37:15 +11:00
|
|
|
|
2018-12-27 16:32:15 +11:00
|
|
|
struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) {
|
2018-12-18 07:37:15 +11:00
|
|
|
struct cmd_results *error = NULL;
|
2020-09-07 08:44:13 +10:00
|
|
|
if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_LEAST, 1))) {
|
2018-12-18 07:37:15 +11:00
|
|
|
return error;
|
|
|
|
}
|
2020-09-07 08:44:13 +10:00
|
|
|
if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_MOST, 2))) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
struct seat_config *seat_config = config->handler_context.seat_config;
|
|
|
|
if (!seat_config) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_FAILURE, "No seat defined");
|
2018-12-27 16:32:15 +11:00
|
|
|
}
|
2018-12-18 07:37:15 +11:00
|
|
|
|
2020-09-07 08:44:13 +10:00
|
|
|
if (argc == 1) {
|
|
|
|
char *end;
|
|
|
|
int timeout = strtol(argv[0], &end, 10);
|
|
|
|
if (*end) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "Expected an integer timeout");
|
|
|
|
}
|
|
|
|
if (timeout < 100 && timeout != 0) {
|
|
|
|
timeout = 100;
|
|
|
|
}
|
|
|
|
seat_config->hide_cursor_timeout = timeout;
|
|
|
|
} else {
|
|
|
|
if (strcmp(argv[0], "when-typing") != 0) {
|
|
|
|
return cmd_results_new(CMD_INVALID,
|
|
|
|
"Expected 'hide_cursor <timeout>|when-typing [enable|disable]'");
|
|
|
|
}
|
|
|
|
seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ?
|
|
|
|
HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE;
|
|
|
|
|
|
|
|
// Invalidate all the caches for this config
|
|
|
|
struct sway_seat *seat = NULL;
|
|
|
|
wl_list_for_each(seat, &server.input->seats, link) {
|
|
|
|
seat->cursor->hide_when_typing = HIDE_WHEN_TYPING_DEFAULT;
|
|
|
|
}
|
2018-12-18 07:37:15 +11:00
|
|
|
}
|
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-12-18 07:37:15 +11:00
|
|
|
}
|