mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +00:00
d9de5b8758
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.
52 lines
1.5 KiB
C
52 lines
1.5 KiB
C
#include <string.h>
|
|
#include "sway/commands.h"
|
|
#include "sway/config.h"
|
|
#include "sway/desktop/idle_inhibit_v1.h"
|
|
#include "sway/tree/container.h"
|
|
#include "sway/tree/view.h"
|
|
|
|
struct cmd_results *cmd_inhibit_idle(int argc, char **argv) {
|
|
struct cmd_results *error = NULL;
|
|
if ((error = checkarg(argc, "inhibit_idle", EXPECTED_EQUAL_TO, 1))) {
|
|
return error;
|
|
}
|
|
|
|
struct sway_container *con = config->handler_context.container;
|
|
if (!con || !con->view) {
|
|
return cmd_results_new(CMD_INVALID,
|
|
"Only views can have idle inhibitors");
|
|
}
|
|
|
|
bool clear = false;
|
|
enum sway_idle_inhibit_mode mode;
|
|
if (strcmp(argv[0], "focus") == 0) {
|
|
mode = INHIBIT_IDLE_FOCUS;
|
|
} else if (strcmp(argv[0], "fullscreen") == 0) {
|
|
mode = INHIBIT_IDLE_FULLSCREEN;
|
|
} else if (strcmp(argv[0], "open") == 0) {
|
|
mode = INHIBIT_IDLE_OPEN;
|
|
} else if (strcmp(argv[0], "none") == 0) {
|
|
clear = true;
|
|
} else if (strcmp(argv[0], "visible") == 0) {
|
|
mode = INHIBIT_IDLE_VISIBLE;
|
|
} else {
|
|
return cmd_results_new(CMD_INVALID,
|
|
"Expected `inhibit_idle focus|fullscreen|open|none|visible`");
|
|
}
|
|
|
|
struct sway_idle_inhibitor_v1 *inhibitor =
|
|
sway_idle_inhibit_v1_user_inhibitor_for_view(con->view);
|
|
if (inhibitor) {
|
|
if (clear) {
|
|
sway_idle_inhibit_v1_user_inhibitor_destroy(inhibitor);
|
|
} else {
|
|
inhibitor->mode = mode;
|
|
sway_idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
|
|
}
|
|
} else if (!clear) {
|
|
sway_idle_inhibit_v1_user_inhibitor_register(con->view, mode);
|
|
}
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
|
}
|