aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/inhibit_idle.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-03-24 21:21:24 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-03-24 19:26:12 -0600
commitd9de5b87583ccf8b633980ebbdec67227bbe7db4 (patch)
tree4084a568e8b28e2e37142b8a293e00f619d48e17 /sway/commands/inhibit_idle.c
parentFix #3924 (diff)
downloadsway-d9de5b87583ccf8b633980ebbdec67227bbe7db4.tar.gz
sway-d9de5b87583ccf8b633980ebbdec67227bbe7db4.tar.zst
sway-d9de5b87583ccf8b633980ebbdec67227bbe7db4.zip
Implement inhibit_idle command
This implements the following command to set/unset a user idle inhibitor for a view: `inhibit_idle focus|fullscreen|open|none|visible` The modes are as follows: - focus: inhibited when the view is focused by any seat - fullscreen: inhibited when the view is fullscreen (or a descendant of a fullscreen container) and is visible on any output - open: inhibited until the view is closed or the inhibitor is unset or changed - none: unsets any user set idle inhibitors for the view - visible: inhibited when the view is visible on any output This should have no effect on idle inhibitors set by the applications themselves and those should still work as intended. Since this operates on the view in the handler context, it is possible to set it on the currently focused view, on any existing view with criteria, or for any future view with for_window.
Diffstat (limited to 'sway/commands/inhibit_idle.c')
-rw-r--r--sway/commands/inhibit_idle.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/sway/commands/inhibit_idle.c b/sway/commands/inhibit_idle.c
new file mode 100644
index 00000000..aebc2bf9
--- /dev/null
+++ b/sway/commands/inhibit_idle.c
@@ -0,0 +1,51 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/desktop/idle_inhibit_v1.h"
5#include "sway/tree/container.h"
6#include "sway/tree/view.h"
7
8struct cmd_results *cmd_inhibit_idle(int argc, char **argv) {
9 struct cmd_results *error = NULL;
10 if ((error = checkarg(argc, "inhibit_idle", EXPECTED_EQUAL_TO, 1))) {
11 return error;
12 }
13
14 struct sway_container *con = config->handler_context.container;
15 if (!con || !con->view) {
16 return cmd_results_new(CMD_INVALID,
17 "Only views can have idle inhibitors");
18 }
19
20 bool clear = false;
21 enum sway_idle_inhibit_mode mode;
22 if (strcmp(argv[0], "focus") == 0) {
23 mode = INHIBIT_IDLE_FOCUS;
24 } else if (strcmp(argv[0], "fullscreen") == 0) {
25 mode = INHIBIT_IDLE_FULLSCREEN;
26 } else if (strcmp(argv[0], "open") == 0) {
27 mode = INHIBIT_IDLE_OPEN;
28 } else if (strcmp(argv[0], "none") == 0) {
29 clear = true;
30 } else if (strcmp(argv[0], "visible") == 0) {
31 mode = INHIBIT_IDLE_VISIBLE;
32 } else {
33 return cmd_results_new(CMD_INVALID,
34 "Expected `inhibit_idle focus|fullscreen|open|none|visible`");
35 }
36
37 struct sway_idle_inhibitor_v1 *inhibitor =
38 sway_idle_inhibit_v1_user_inhibitor_for_view(con->view);
39 if (inhibitor) {
40 if (clear) {
41 sway_idle_inhibit_v1_user_inhibitor_destroy(inhibitor);
42 } else {
43 inhibitor->mode = mode;
44 sway_idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
45 }
46 } else if (!clear) {
47 sway_idle_inhibit_v1_user_inhibitor_register(con->view, mode);
48 }
49
50 return cmd_results_new(CMD_SUCCESS, NULL);
51}