diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h new file mode 100644 index 00000000..94c25a42 --- /dev/null +++ b/include/sway/desktop/idle_inhibit_v1.h @@ -0,0 +1,13 @@ + +#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H +#define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H +#include +#include "sway/server.h" + +struct sway_idle_inhibitor_v1 { + struct sway_server *server; + + struct wl_listener destroy; +}; + +#endif diff --git a/include/sway/server.h b/include/sway/server.h index 1e1aa3cc..246a9381 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -24,11 +24,15 @@ struct sway_server { struct wlr_compositor *compositor; struct wlr_data_device_manager *data_device_manager; struct wlr_idle *idle; + struct wlr_idle_inhibit_manager_v1 *idle_inhibit; struct sway_input_manager *input; struct wl_listener new_output; + struct wlr_idle_inhibit_manager_v1 *idle_inhibit_v1; + struct wl_listener new_idle_inhibitor_v1; + struct wlr_layer_shell *layer_shell; struct wl_listener layer_shell_surface; @@ -61,6 +65,7 @@ void server_run(struct sway_server *server); void handle_new_output(struct wl_listener *listener, void *data); +void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data); void handle_layer_shell_surface(struct wl_listener *listener, void *data); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_xdg_shell_surface(struct wl_listener *listener, void *data); diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c new file mode 100644 index 00000000..a06e00d5 --- /dev/null +++ b/sway/desktop/idle_inhibit_v1.c @@ -0,0 +1,35 @@ +#include +#include +#include "log.h" +#include "sway/desktop/idle_inhibit_v1.h" +#include "sway/server.h" + + +static void handle_destroy(struct wl_listener *listener, void *data) { + struct sway_idle_inhibitor_v1 *inhibitor = + wl_container_of(listener, inhibitor, destroy); + wlr_log(L_DEBUG, "Sway idle inhibitor destroyed"); + wlr_idle_set_enabled(inhibitor->server->idle, NULL, true); + wl_list_remove(&inhibitor->destroy.link); + free(inhibitor); +} + +void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { + struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data; + struct sway_server *server = + wl_container_of(listener, server, new_idle_inhibitor_v1); + wlr_log(L_DEBUG, "New sway idle inhibitor"); + + struct sway_idle_inhibitor_v1 *inhibitor = + calloc(1, sizeof(struct sway_idle_inhibitor_v1)); + if (!inhibitor) { + return; + } + + inhibitor->server = server; + + inhibitor->destroy.notify = handle_destroy; + wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); + + wlr_idle_set_enabled(server->idle, NULL, false); +} diff --git a/sway/meson.build b/sway/meson.build index 9ff3f05f..a81a3406 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -10,6 +10,7 @@ sway_sources = files( 'security.c', 'desktop/desktop.c', + 'desktop/idle_inhibit_v1.c', 'desktop/layer_shell.c', 'desktop/output.c', 'desktop/transaction.c', diff --git a/sway/server.c b/sway/server.c index bd107617..3456931c 100644 --- a/sway/server.c +++ b/sway/server.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,11 @@ bool server_init(struct sway_server *server) { wlr_xdg_output_manager_create(server->wl_display, root_container.sway_root->output_layout); + server->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display); + wl_signal_add(&server->idle_inhibit->events.new_inhibitor, + &server->new_idle_inhibitor_v1); + server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; + server->layer_shell = wlr_layer_shell_create(server->wl_display); wl_signal_add(&server->layer_shell->events.new_surface, &server->layer_shell_surface);