diff options
author | 2018-06-30 14:09:32 +0900 | |
---|---|---|
committer | 2018-07-02 09:29:16 +0900 | |
commit | 072b334abc6f065080bf944767bbd53d7a590e47 (patch) | |
tree | 113617af8597e174182e4c11736cbb912d151c03 /sway | |
parent | Add idle inhibit unstable v1 support (diff) | |
download | sway-072b334abc6f065080bf944767bbd53d7a590e47.tar.gz sway-072b334abc6f065080bf944767bbd53d7a590e47.tar.zst sway-072b334abc6f065080bf944767bbd53d7a590e47.zip |
idle_inhibit: stop inhibitor when views become invisible
Diffstat (limited to 'sway')
-rw-r--r-- | sway/desktop/idle_inhibit_v1.c | 22 | ||||
-rw-r--r-- | sway/desktop/transaction.c | 3 | ||||
-rw-r--r-- | sway/server.c | 1 |
3 files changed, 26 insertions, 0 deletions
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 @@ | |||
2 | #include <wlr/types/wlr_idle.h> | 2 | #include <wlr/types/wlr_idle.h> |
3 | #include "log.h" | 3 | #include "log.h" |
4 | #include "sway/desktop/idle_inhibit_v1.h" | 4 | #include "sway/desktop/idle_inhibit_v1.h" |
5 | #include "sway/tree/view.h" | ||
5 | #include "sway/server.h" | 6 | #include "sway/server.h" |
6 | 7 | ||
7 | 8 | ||
@@ -10,6 +11,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { | |||
10 | wl_container_of(listener, inhibitor, destroy); | 11 | wl_container_of(listener, inhibitor, destroy); |
11 | wlr_log(L_DEBUG, "Sway idle inhibitor destroyed"); | 12 | wlr_log(L_DEBUG, "Sway idle inhibitor destroyed"); |
12 | wlr_idle_set_enabled(inhibitor->server->idle, NULL, true); | 13 | wlr_idle_set_enabled(inhibitor->server->idle, NULL, true); |
14 | wl_list_remove(&inhibitor->link); | ||
13 | wl_list_remove(&inhibitor->destroy.link); | 15 | wl_list_remove(&inhibitor->destroy.link); |
14 | free(inhibitor); | 16 | free(inhibitor); |
15 | } | 17 | } |
@@ -27,9 +29,29 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { | |||
27 | } | 29 | } |
28 | 30 | ||
29 | inhibitor->server = server; | 31 | inhibitor->server = server; |
32 | inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface); | ||
33 | wl_list_insert(&server->idle_inhibitors_v1, &inhibitor->link); | ||
34 | |||
30 | 35 | ||
31 | inhibitor->destroy.notify = handle_destroy; | 36 | inhibitor->destroy.notify = handle_destroy; |
32 | wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); | 37 | wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); |
33 | 38 | ||
34 | wlr_idle_set_enabled(server->idle, NULL, false); | 39 | wlr_idle_set_enabled(server->idle, NULL, false); |
35 | } | 40 | } |
41 | |||
42 | void idle_inhibit_v1_check_active(struct sway_server *server) { | ||
43 | struct sway_idle_inhibitor_v1 *inhibitor; | ||
44 | bool inhibited = false; | ||
45 | wl_list_for_each(inhibitor, &server->idle_inhibitors_v1, link) { | ||
46 | if (!inhibitor->view) { | ||
47 | /* Cannot guess if view is visible so assume it is */ | ||
48 | inhibited = true; | ||
49 | break; | ||
50 | } | ||
51 | if (view_is_visible(inhibitor->view)) { | ||
52 | inhibited = true; | ||
53 | break; | ||
54 | } | ||
55 | } | ||
56 | wlr_idle_set_enabled(server->idle, NULL, !inhibited); | ||
57 | } | ||
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 @@ | |||
6 | #include <wlr/types/wlr_buffer.h> | 6 | #include <wlr/types/wlr_buffer.h> |
7 | #include <wlr/types/wlr_linux_dmabuf.h> | 7 | #include <wlr/types/wlr_linux_dmabuf.h> |
8 | #include "sway/debug.h" | 8 | #include "sway/debug.h" |
9 | #include "sway/desktop/idle_inhibit_v1.h" | ||
9 | #include "sway/desktop/transaction.h" | 10 | #include "sway/desktop/transaction.h" |
10 | #include "sway/output.h" | 11 | #include "sway/output.h" |
11 | #include "sway/tree/container.h" | 12 | #include "sway/tree/container.h" |
@@ -245,6 +246,7 @@ static void transaction_progress_queue() { | |||
245 | transaction_destroy(transaction); | 246 | transaction_destroy(transaction); |
246 | } | 247 | } |
247 | server.transactions->length = 0; | 248 | server.transactions->length = 0; |
249 | idle_inhibit_v1_check_active(&server); | ||
248 | } | 250 | } |
249 | 251 | ||
250 | static int handle_timeout(void *data) { | 252 | static int handle_timeout(void *data) { |
@@ -320,6 +322,7 @@ void transaction_commit(struct sway_transaction *transaction) { | |||
320 | wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction); | 322 | wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction); |
321 | transaction_apply(transaction); | 323 | transaction_apply(transaction); |
322 | transaction_destroy(transaction); | 324 | transaction_destroy(transaction); |
325 | idle_inhibit_v1_check_active(&server); | ||
323 | return; | 326 | return; |
324 | } | 327 | } |
325 | 328 | ||
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) { | |||
68 | wl_signal_add(&server->idle_inhibit->events.new_inhibitor, | 68 | wl_signal_add(&server->idle_inhibit->events.new_inhibitor, |
69 | &server->new_idle_inhibitor_v1); | 69 | &server->new_idle_inhibitor_v1); |
70 | server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; | 70 | server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; |
71 | wl_list_init(&server->idle_inhibitors_v1); | ||
71 | 72 | ||
72 | server->layer_shell = wlr_layer_shell_create(server->wl_display); | 73 | server->layer_shell = wlr_layer_shell_create(server->wl_display); |
73 | wl_signal_add(&server->layer_shell->events.new_surface, | 74 | wl_signal_add(&server->layer_shell->events.new_surface, |