summaryrefslogtreecommitdiff
path: root/sway/desktop/idle_inhibit_v1.c
diff options
context:
space:
mode:
authorReza Jelveh <[email protected]>2024-04-15 13:39:41 +0800
committerGitHub <[email protected]>2024-04-15 01:39:41 -0400
commitfb86ed6b0588dfdebfb66ce875bc63cfa0a897f6 (patch)
tree29857a1769107adc58696f08d379f608aa4e29a2 /sway/desktop/idle_inhibit_v1.c
parenta5e79676c4bd22fc5902182acf0667907202a465 (diff)
feat: 1.9 merge (#277)
Co-authored-by: William McKinnon <[email protected]> Co-authored-by: Erik Reider <[email protected]>
Diffstat (limited to 'sway/desktop/idle_inhibit_v1.c')
-rw-r--r--sway/desktop/idle_inhibit_v1.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c
index 3a4d0b87..f3af7aa1 100644
--- a/sway/desktop/idle_inhibit_v1.c
+++ b/sway/desktop/idle_inhibit_v1.c
@@ -1,5 +1,4 @@
#include <stdlib.h>
-#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include "log.h"
#include "sway/desktop/idle_inhibit_v1.h"
@@ -12,7 +11,7 @@
static void destroy_inhibitor(struct sway_idle_inhibitor_v1 *inhibitor) {
wl_list_remove(&inhibitor->link);
wl_list_remove(&inhibitor->destroy.link);
- sway_idle_inhibit_v1_check_active(inhibitor->manager);
+ sway_idle_inhibit_v1_check_active();
free(inhibitor);
}
@@ -35,7 +34,6 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
return;
}
- inhibitor->manager = manager;
inhibitor->mode = INHIBIT_IDLE_APPLICATION;
inhibitor->wlr_inhibitor = wlr_inhibitor;
wl_list_insert(&manager->inhibitors, &inhibitor->link);
@@ -43,33 +41,34 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
inhibitor->destroy.notify = handle_destroy;
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy);
- sway_idle_inhibit_v1_check_active(manager);
+ sway_idle_inhibit_v1_check_active();
}
void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view,
enum sway_idle_inhibit_mode mode) {
+ struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1;
+
struct sway_idle_inhibitor_v1 *inhibitor =
calloc(1, sizeof(struct sway_idle_inhibitor_v1));
if (!inhibitor) {
return;
}
- inhibitor->manager = server.idle_inhibit_manager_v1;
inhibitor->mode = mode;
inhibitor->view = view;
- wl_list_insert(&inhibitor->manager->inhibitors, &inhibitor->link);
+ wl_list_insert(&manager->inhibitors, &inhibitor->link);
inhibitor->destroy.notify = handle_destroy;
wl_signal_add(&view->events.unmap, &inhibitor->destroy);
- sway_idle_inhibit_v1_check_active(inhibitor->manager);
+ sway_idle_inhibit_v1_check_active();
}
struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view(
struct sway_view *view) {
+ struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1;
struct sway_idle_inhibitor_v1 *inhibitor;
- wl_list_for_each(inhibitor, &server.idle_inhibit_manager_v1->inhibitors,
- link) {
+ wl_list_for_each(inhibitor, &manager->inhibitors, link) {
if (inhibitor->mode != INHIBIT_IDLE_APPLICATION &&
inhibitor->view == view) {
return inhibitor;
@@ -80,9 +79,9 @@ struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view(
struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_view(
struct sway_view *view) {
+ struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1;
struct sway_idle_inhibitor_v1 *inhibitor;
- wl_list_for_each(inhibitor, &server.idle_inhibit_manager_v1->inhibitors,
- link) {
+ wl_list_for_each(inhibitor, &manager->inhibitors, link) {
if (inhibitor->mode == INHIBIT_IDLE_APPLICATION &&
view_from_wlr_surface(inhibitor->wlr_inhibitor->surface) == view) {
return inhibitor;
@@ -131,8 +130,8 @@ bool sway_idle_inhibit_v1_is_active(struct sway_idle_inhibitor_v1 *inhibitor) {
return false;
}
-void sway_idle_inhibit_v1_check_active(
- struct sway_idle_inhibit_manager_v1 *manager) {
+void sway_idle_inhibit_v1_check_active(void) {
+ struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1;
struct sway_idle_inhibitor_v1 *inhibitor;
bool inhibited = false;
wl_list_for_each(inhibitor, &manager->inhibitors, link) {
@@ -140,28 +139,21 @@ void sway_idle_inhibit_v1_check_active(
break;
}
}
- wlr_idle_set_enabled(manager->idle, NULL, !inhibited);
wlr_idle_notifier_v1_set_inhibited(server.idle_notifier_v1, 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;
- }
+bool sway_idle_inhibit_manager_v1_init(void) {
+ struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1;
- manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display);
+ manager->wlr_manager = wlr_idle_inhibit_v1_create(server.wl_display);
if (!manager->wlr_manager) {
- free(manager);
- return NULL;
+ return false;
}
- 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;
+ return true;
}