idle_inhibit: stop inhibitor when views become invisible

This commit is contained in:
Dominique Martinet 2018-06-30 14:09:32 +09:00
parent e4bfb3bc98
commit 072b334abc
5 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -2,6 +2,7 @@
#include <wlr/types/wlr_idle.h>
#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);
}

View File

@ -6,6 +6,7 @@
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_linux_dmabuf.h>
#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;
}

View File

@ -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,