aboutsummaryrefslogtreecommitdiff
path: root/sway/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop')
-rw-r--r--sway/desktop/idle_inhibit_v1.c40
-rw-r--r--sway/desktop/transaction.c4
2 files changed, 33 insertions, 11 deletions
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;
}