diff options
Diffstat (limited to 'sway/desktop/idle_inhibit_v1.c')
-rw-r--r-- | sway/desktop/idle_inhibit_v1.c | 40 |
1 files changed, 31 insertions, 9 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) { | |||
10 | struct sway_idle_inhibitor_v1 *inhibitor = | 10 | struct sway_idle_inhibitor_v1 *inhibitor = |
11 | wl_container_of(listener, inhibitor, destroy); | 11 | wl_container_of(listener, inhibitor, destroy); |
12 | wlr_log(L_DEBUG, "Sway idle inhibitor destroyed"); | 12 | wlr_log(L_DEBUG, "Sway idle inhibitor destroyed"); |
13 | wlr_idle_set_enabled(inhibitor->server->idle, NULL, true); | ||
14 | wl_list_remove(&inhibitor->link); | 13 | wl_list_remove(&inhibitor->link); |
15 | wl_list_remove(&inhibitor->destroy.link); | 14 | wl_list_remove(&inhibitor->destroy.link); |
15 | idle_inhibit_v1_check_active(inhibitor->manager); | ||
16 | free(inhibitor); | 16 | free(inhibitor); |
17 | } | 17 | } |
18 | 18 | ||
19 | void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { | 19 | void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { |
20 | struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data; | 20 | struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data; |
21 | struct sway_server *server = | 21 | struct sway_idle_inhibit_manager_v1 *manager = |
22 | wl_container_of(listener, server, new_idle_inhibitor_v1); | 22 | wl_container_of(listener, manager, new_idle_inhibitor_v1); |
23 | wlr_log(L_DEBUG, "New sway idle inhibitor"); | 23 | wlr_log(L_DEBUG, "New sway idle inhibitor"); |
24 | 24 | ||
25 | struct sway_idle_inhibitor_v1 *inhibitor = | 25 | struct sway_idle_inhibitor_v1 *inhibitor = |
@@ -28,21 +28,22 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { | |||
28 | return; | 28 | return; |
29 | } | 29 | } |
30 | 30 | ||
31 | inhibitor->server = server; | 31 | inhibitor->manager = manager; |
32 | inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface); | 32 | inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface); |
33 | wl_list_insert(&server->idle_inhibitors_v1, &inhibitor->link); | 33 | wl_list_insert(&manager->inhibitors, &inhibitor->link); |
34 | 34 | ||
35 | 35 | ||
36 | inhibitor->destroy.notify = handle_destroy; | 36 | inhibitor->destroy.notify = handle_destroy; |
37 | wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); | 37 | wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); |
38 | 38 | ||
39 | wlr_idle_set_enabled(server->idle, NULL, false); | 39 | idle_inhibit_v1_check_active(manager); |
40 | } | 40 | } |
41 | 41 | ||
42 | void idle_inhibit_v1_check_active(struct sway_server *server) { | 42 | void idle_inhibit_v1_check_active( |
43 | struct sway_idle_inhibit_manager_v1 *manager) { | ||
43 | struct sway_idle_inhibitor_v1 *inhibitor; | 44 | struct sway_idle_inhibitor_v1 *inhibitor; |
44 | bool inhibited = false; | 45 | bool inhibited = false; |
45 | wl_list_for_each(inhibitor, &server->idle_inhibitors_v1, link) { | 46 | wl_list_for_each(inhibitor, &manager->inhibitors, link) { |
46 | if (!inhibitor->view) { | 47 | if (!inhibitor->view) { |
47 | /* Cannot guess if view is visible so assume it is */ | 48 | /* Cannot guess if view is visible so assume it is */ |
48 | inhibited = true; | 49 | inhibited = true; |
@@ -53,5 +54,26 @@ void idle_inhibit_v1_check_active(struct sway_server *server) { | |||
53 | break; | 54 | break; |
54 | } | 55 | } |
55 | } | 56 | } |
56 | wlr_idle_set_enabled(server->idle, NULL, !inhibited); | 57 | wlr_idle_set_enabled(manager->idle, NULL, !inhibited); |
58 | } | ||
59 | |||
60 | struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create( | ||
61 | struct wl_display *wl_display, struct wlr_idle *idle) { | ||
62 | struct sway_idle_inhibit_manager_v1 *manager = | ||
63 | calloc(1, sizeof(struct sway_idle_inhibit_manager_v1)); | ||
64 | if (!manager) { | ||
65 | return NULL; | ||
66 | } | ||
67 | |||
68 | manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display); | ||
69 | if (!manager->wlr_manager) { | ||
70 | return NULL; | ||
71 | } | ||
72 | manager->idle = idle; | ||
73 | wl_signal_add(&manager->wlr_manager->events.new_inhibitor, | ||
74 | &manager->new_idle_inhibitor_v1); | ||
75 | manager->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; | ||
76 | wl_list_init(&manager->inhibitors); | ||
77 | |||
78 | return manager; | ||
57 | } | 79 | } |