summaryrefslogtreecommitdiffstats
path: root/sway/commands/seat/idle.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/seat/idle.c')
-rw-r--r--sway/commands/seat/idle.c73
1 files changed, 73 insertions, 0 deletions
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 @@
1#define _POSIX_C_SOURCE 200809L
2#include <limits.h>
3#include <string.h>
4#include <strings.h>
5#include <stdint.h>
6#include "sway/commands.h"
7#include "sway/config.h"
8#include "sway/input/seat.h"
9
10static const struct {
11 const char *name;
12 uint32_t value;
13} idle_source_strings[] = {
14 { "keyboard", IDLE_SOURCE_KEYBOARD },
15 { "pointer", IDLE_SOURCE_POINTER },
16 { "touch", IDLE_SOURCE_TOUCH },
17 { "tablet_pad", IDLE_SOURCE_TABLET_PAD },
18 { "tablet_tool", IDLE_SOURCE_TABLET_TOOL },
19 { "switch", IDLE_SOURCE_SWITCH },
20};
21
22static uint32_t parse_sources(int argc, char **argv) {
23 uint32_t sources = 0;
24 for (int i = 0; i < argc; ++i) {
25 uint32_t value = 0;
26 for (size_t j = 0; j < sizeof(idle_source_strings)
27 / sizeof(idle_source_strings[0]); ++j) {
28 if (strcasecmp(idle_source_strings[j].name, argv[i]) == 0) {
29 value = idle_source_strings[j].value;
30 break;
31 }
32 }
33 if (value == 0) {
34 return UINT32_MAX;
35 }
36 sources |= value;
37 }
38 return sources;
39}
40
41struct cmd_results *seat_cmd_idle_inhibit(int argc, char **argv) {
42 struct cmd_results *error = NULL;
43 if ((error = checkarg(argc, "idle_inhibit", EXPECTED_AT_LEAST, 1))) {
44 return error;
45 }
46 if (!config->handler_context.seat_config) {
47 return cmd_results_new(CMD_FAILURE, "No seat defined");
48 }
49
50 uint32_t sources = parse_sources(argc, argv);
51 if (sources == UINT32_MAX) {
52 return cmd_results_new(CMD_FAILURE, "Invalid idle source");
53 }
54 config->handler_context.seat_config->idle_inhibit_sources = sources;
55 return cmd_results_new(CMD_SUCCESS, NULL);
56}
57
58struct cmd_results *seat_cmd_idle_wake(int argc, char **argv) {
59 struct cmd_results *error = NULL;
60 if ((error = checkarg(argc, "idle_wake", EXPECTED_AT_LEAST, 1))) {
61 return error;
62 }
63 if (!config->handler_context.seat_config) {
64 return cmd_results_new(CMD_FAILURE, "No seat defined");
65 }
66
67 uint32_t sources = parse_sources(argc, argv);
68 if (sources == UINT32_MAX) {
69 return cmd_results_new(CMD_FAILURE, "Invalid idle source");
70 }
71 config->handler_context.seat_config->idle_wake_sources = sources;
72 return cmd_results_new(CMD_SUCCESS, NULL);
73}