From e4bfb3bc98b28cb083b4138a76d88384a33d6e57 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 27 Jun 2018 18:16:49 +0900 Subject: Add idle inhibit unstable v1 support --- sway/desktop/idle_inhibit_v1.c | 35 +++++++++++++++++++++++++++++++++++ sway/meson.build | 1 + sway/server.c | 6 ++++++ 3 files changed, 42 insertions(+) create mode 100644 sway/desktop/idle_inhibit_v1.c (limited to 'sway') 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); -- cgit v1.2.3 From 072b334abc6f065080bf944767bbd53d7a590e47 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 30 Jun 2018 14:09:32 +0900 Subject: idle_inhibit: stop inhibitor when views become invisible --- include/sway/desktop/idle_inhibit_v1.h | 4 ++++ include/sway/server.h | 1 + sway/desktop/idle_inhibit_v1.c | 22 ++++++++++++++++++++++ sway/desktop/transaction.c | 3 +++ sway/server.c | 1 + 5 files changed, 31 insertions(+) (limited to 'sway') diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h index 94c25a42..1764713c 100644 --- a/include/sway/desktop/idle_inhibit_v1.h +++ b/include/sway/desktop/idle_inhibit_v1.h @@ -6,8 +6,12 @@ struct sway_idle_inhibitor_v1 { struct sway_server *server; + struct sway_view *view; + struct wl_list link; struct wl_listener destroy; }; +void idle_inhibit_v1_check_active(struct sway_server *server); + #endif diff --git a/include/sway/server.h b/include/sway/server.h index 246a9381..693e6b82 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -32,6 +32,7 @@ struct sway_server { struct wlr_idle_inhibit_manager_v1 *idle_inhibit_v1; struct wl_listener new_idle_inhibitor_v1; + struct wl_list idle_inhibitors_v1; struct wlr_layer_shell *layer_shell; struct wl_listener layer_shell_surface; diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c index a06e00d5..a9a8cb24 100644 --- a/sway/desktop/idle_inhibit_v1.c +++ b/sway/desktop/idle_inhibit_v1.c @@ -2,6 +2,7 @@ #include #include "log.h" #include "sway/desktop/idle_inhibit_v1.h" +#include "sway/tree/view.h" #include "sway/server.h" @@ -10,6 +11,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { 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->link); wl_list_remove(&inhibitor->destroy.link); free(inhibitor); } @@ -27,9 +29,29 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { } inhibitor->server = server; + inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface); + wl_list_insert(&server->idle_inhibitors_v1, &inhibitor->link); + inhibitor->destroy.notify = handle_destroy; wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); wlr_idle_set_enabled(server->idle, NULL, false); } + +void idle_inhibit_v1_check_active(struct sway_server *server) { + struct sway_idle_inhibitor_v1 *inhibitor; + bool inhibited = false; + wl_list_for_each(inhibitor, &server->idle_inhibitors_v1, link) { + if (!inhibitor->view) { + /* Cannot guess if view is visible so assume it is */ + inhibited = true; + break; + } + if (view_is_visible(inhibitor->view)) { + inhibited = true; + break; + } + } + wlr_idle_set_enabled(server->idle, NULL, !inhibited); +} diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index d2932c87..7050d70c 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -6,6 +6,7 @@ #include #include #include "sway/debug.h" +#include "sway/desktop/idle_inhibit_v1.h" #include "sway/desktop/transaction.h" #include "sway/output.h" #include "sway/tree/container.h" @@ -245,6 +246,7 @@ static void transaction_progress_queue() { transaction_destroy(transaction); } server.transactions->length = 0; + idle_inhibit_v1_check_active(&server); } static int handle_timeout(void *data) { @@ -320,6 +322,7 @@ void transaction_commit(struct sway_transaction *transaction) { wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction); transaction_apply(transaction); transaction_destroy(transaction); + idle_inhibit_v1_check_active(&server); return; } diff --git a/sway/server.c b/sway/server.c index 3456931c..ee6b7cde 100644 --- a/sway/server.c +++ b/sway/server.c @@ -68,6 +68,7 @@ bool server_init(struct sway_server *server) { wl_signal_add(&server->idle_inhibit->events.new_inhibitor, &server->new_idle_inhibitor_v1); server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; + wl_list_init(&server->idle_inhibitors_v1); server->layer_shell = wlr_layer_shell_create(server->wl_display); wl_signal_add(&server->layer_shell->events.new_surface, -- cgit v1.2.3 From 71224781c48f98f43f5836de663ef6e01604419c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 2 Jul 2018 09:26:57 +0900 Subject: idle_inhibit: move server data to its own struct --- include/sway/desktop/idle_inhibit_v1.h | 17 ++++++++++++--- include/sway/server.h | 7 ++---- sway/desktop/idle_inhibit_v1.c | 40 ++++++++++++++++++++++++++-------- sway/desktop/transaction.c | 4 ++-- sway/server.c | 11 ++++------ 5 files changed, 53 insertions(+), 26 deletions(-) (limited to 'sway') diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h index 1764713c..e5ed8a3d 100644 --- a/include/sway/desktop/idle_inhibit_v1.h +++ b/include/sway/desktop/idle_inhibit_v1.h @@ -1,17 +1,28 @@ - #ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H #define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H #include +#include #include "sway/server.h" +struct sway_idle_inhibit_manager_v1 { + struct wlr_idle_inhibit_manager_v1 *wlr_manager; + struct wl_listener new_idle_inhibitor_v1; + struct wl_list inhibitors; + + struct wlr_idle *idle; +}; + struct sway_idle_inhibitor_v1 { - struct sway_server *server; + struct sway_idle_inhibit_manager_v1 *manager; struct sway_view *view; struct wl_list link; struct wl_listener destroy; }; -void idle_inhibit_v1_check_active(struct sway_server *server); +void idle_inhibit_v1_check_active( + struct sway_idle_inhibit_manager_v1 *manager); +struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create( + struct wl_display *wl_display, struct wlr_idle *idle); #endif diff --git a/include/sway/server.h b/include/sway/server.h index 693e6b82..a3e32898 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -23,16 +23,13 @@ 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 wl_list idle_inhibitors_v1; + struct wlr_idle *idle; + struct sway_idle_inhibit_manager_v1 *idle_inhibit_manager_v1; struct wlr_layer_shell *layer_shell; struct wl_listener layer_shell_surface; diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c index a9a8cb24..c02ca26e 100644 --- a/sway/desktop/idle_inhibit_v1.c +++ b/sway/desktop/idle_inhibit_v1.c @@ -10,16 +10,16 @@ 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->link); wl_list_remove(&inhibitor->destroy.link); + idle_inhibit_v1_check_active(inhibitor->manager); 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); + struct sway_idle_inhibit_manager_v1 *manager = + wl_container_of(listener, manager, new_idle_inhibitor_v1); wlr_log(L_DEBUG, "New sway idle inhibitor"); struct sway_idle_inhibitor_v1 *inhibitor = @@ -28,21 +28,22 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { return; } - inhibitor->server = server; + inhibitor->manager = manager; inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface); - wl_list_insert(&server->idle_inhibitors_v1, &inhibitor->link); + wl_list_insert(&manager->inhibitors, &inhibitor->link); inhibitor->destroy.notify = handle_destroy; wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); - wlr_idle_set_enabled(server->idle, NULL, false); + idle_inhibit_v1_check_active(manager); } -void idle_inhibit_v1_check_active(struct sway_server *server) { +void idle_inhibit_v1_check_active( + struct sway_idle_inhibit_manager_v1 *manager) { struct sway_idle_inhibitor_v1 *inhibitor; bool inhibited = false; - wl_list_for_each(inhibitor, &server->idle_inhibitors_v1, link) { + wl_list_for_each(inhibitor, &manager->inhibitors, link) { if (!inhibitor->view) { /* Cannot guess if view is visible so assume it is */ inhibited = true; @@ -53,5 +54,26 @@ void idle_inhibit_v1_check_active(struct sway_server *server) { break; } } - wlr_idle_set_enabled(server->idle, NULL, !inhibited); + wlr_idle_set_enabled(manager->idle, NULL, !inhibited); +} + +struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create( + struct wl_display *wl_display, struct wlr_idle *idle) { + struct sway_idle_inhibit_manager_v1 *manager = + calloc(1, sizeof(struct sway_idle_inhibit_manager_v1)); + if (!manager) { + return NULL; + } + + manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display); + if (!manager->wlr_manager) { + return NULL; + } + manager->idle = idle; + wl_signal_add(&manager->wlr_manager->events.new_inhibitor, + &manager->new_idle_inhibitor_v1); + manager->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; + wl_list_init(&manager->inhibitors); + + return manager; } diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 7050d70c..e5ceae61 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -246,7 +246,7 @@ static void transaction_progress_queue() { transaction_destroy(transaction); } server.transactions->length = 0; - idle_inhibit_v1_check_active(&server); + idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1); } static int handle_timeout(void *data) { @@ -322,7 +322,7 @@ void transaction_commit(struct sway_transaction *transaction) { wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction); transaction_apply(transaction); transaction_destroy(transaction); - idle_inhibit_v1_check_active(&server); + idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1); return; } diff --git a/sway/server.c b/sway/server.c index ee6b7cde..8106f3c8 100644 --- a/sway/server.c +++ b/sway/server.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ // TODO WLR: make Xwayland optional #include "list.h" #include "sway/config.h" +#include "sway/desktop/idle_inhibit_v1.h" #include "sway/input/input-manager.h" #include "sway/server.h" #include "sway/tree/layout.h" @@ -53,7 +53,6 @@ bool server_init(struct sway_server *server) { server->data_device_manager = wlr_data_device_manager_create(server->wl_display); - server->idle = wlr_idle_create(server->wl_display); wlr_screenshooter_create(server->wl_display); wlr_gamma_control_manager_create(server->wl_display); wlr_primary_selection_device_manager_create(server->wl_display); @@ -64,11 +63,9 @@ 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; - wl_list_init(&server->idle_inhibitors_v1); + server->idle = wlr_idle_create(server->wl_display); + server->idle_inhibit_manager_v1 = + sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle); server->layer_shell = wlr_layer_shell_create(server->wl_display); wl_signal_add(&server->layer_shell->events.new_surface, -- cgit v1.2.3