diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-12-11 11:00:39 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-12-12 10:37:30 -0500 |
commit | 2f3c6cccf5d6b2d6ffd3cee62e7b624dc80dc6e6 (patch) | |
tree | 69d3367cf7dbd7f756d45d89cd37e6016503a88d /sway/commands | |
parent | f645f8efd688104cdeac01cd940b32a8ff978571 (diff) |
Add seat <seat> idle_{inhibit,wake} <sources...>
This adds seat configuration options which can be used to configure what
events affect the idle behavior of sway.
An example use-case is mobile devices: you would remove touch from the
list of idle_wake events. This allows the phone to stay on while you're
actively using it, but doesn't wake from idle on touch events while it's
sleeping in your pocket.
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/seat.c | 2 | ||||
-rw-r--r-- | sway/commands/seat/idle.c | 73 |
2 files changed, 75 insertions, 0 deletions
diff --git a/sway/commands/seat.c b/sway/commands/seat.c index a2a3fbc4..eba28cac 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -18,6 +18,8 @@ static struct cmd_handler seat_handlers[] = { { "attach", seat_cmd_attach }, { "fallback", seat_cmd_fallback }, { "hide_cursor", seat_cmd_hide_cursor }, + { "idle_inhibit", seat_cmd_idle_inhibit }, + { "idle_wake", seat_cmd_idle_wake }, { "keyboard_grouping", seat_cmd_keyboard_grouping }, { "pointer_constraint", seat_cmd_pointer_constraint }, { "xcursor_theme", seat_cmd_xcursor_theme }, diff --git a/sway/commands/seat/idle.c b/sway/commands/seat/idle.c new file mode 100644 index 00000000..82428f2c --- /dev/null +++ b/sway/commands/seat/idle.c @@ -0,0 +1,73 @@ +#define _POSIX_C_SOURCE 200809L +#include <limits.h> +#include <string.h> +#include <strings.h> +#include <stdint.h> +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/input/seat.h" + +static const struct { + const char *name; + uint32_t value; +} idle_source_strings[] = { + { "keyboard", IDLE_SOURCE_KEYBOARD }, + { "pointer", IDLE_SOURCE_POINTER }, + { "touch", IDLE_SOURCE_TOUCH }, + { "tablet_pad", IDLE_SOURCE_TABLET_PAD }, + { "tablet_tool", IDLE_SOURCE_TABLET_TOOL }, + { "switch", IDLE_SOURCE_SWITCH }, +}; + +static uint32_t parse_sources(int argc, char **argv) { + uint32_t sources = 0; + for (int i = 0; i < argc; ++i) { + uint32_t value = 0; + for (size_t j = 0; j < sizeof(idle_source_strings) + / sizeof(idle_source_strings[0]); ++j) { + if (strcasecmp(idle_source_strings[j].name, argv[i]) == 0) { + value = idle_source_strings[j].value; + break; + } + } + if (value == 0) { + return UINT32_MAX; + } + sources |= value; + } + return sources; +} + +struct cmd_results *seat_cmd_idle_inhibit(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "idle_inhibit", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!config->handler_context.seat_config) { + return cmd_results_new(CMD_FAILURE, "No seat defined"); + } + + uint32_t sources = parse_sources(argc, argv); + if (sources == UINT32_MAX) { + return cmd_results_new(CMD_FAILURE, "Invalid idle source"); + } + config->handler_context.seat_config->idle_inhibit_sources = sources; + return cmd_results_new(CMD_SUCCESS, NULL); +} + +struct cmd_results *seat_cmd_idle_wake(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "idle_wake", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!config->handler_context.seat_config) { + return cmd_results_new(CMD_FAILURE, "No seat defined"); + } + + uint32_t sources = parse_sources(argc, argv); + if (sources == UINT32_MAX) { + return cmd_results_new(CMD_FAILURE, "Invalid idle source"); + } + config->handler_context.seat_config->idle_wake_sources = sources; + return cmd_results_new(CMD_SUCCESS, NULL); +} |