diff options
author | Simon Ser <contact@emersion.fr> | 2023-06-19 21:16:23 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-06-23 12:32:38 +0200 |
commit | b762f455d942e81e076a4a4d475fb9926372da16 (patch) | |
tree | 225c427277bc20279befc7381ad4766fe17a803f /sway/desktop/idle_inhibit_v1.c | |
parent | Use wlr_cursor_unset_image() (diff) | |
download | sway-b762f455d942e81e076a4a4d475fb9926372da16.tar.gz sway-b762f455d942e81e076a4a4d475fb9926372da16.tar.zst sway-b762f455d942e81e076a4a4d475fb9926372da16.zip |
idle-inhibit-v1: simplify with server global
We only have a single running server, no need to keep track of
multiple server instances. Also no need to support multiple
idle inhibit managers.
Diffstat (limited to 'sway/desktop/idle_inhibit_v1.c')
-rw-r--r-- | sway/desktop/idle_inhibit_v1.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c index 3a4d0b87..1fa058e3 100644 --- a/sway/desktop/idle_inhibit_v1.c +++ b/sway/desktop/idle_inhibit_v1.c | |||
@@ -12,7 +12,7 @@ | |||
12 | static void destroy_inhibitor(struct sway_idle_inhibitor_v1 *inhibitor) { | 12 | static void destroy_inhibitor(struct sway_idle_inhibitor_v1 *inhibitor) { |
13 | wl_list_remove(&inhibitor->link); | 13 | wl_list_remove(&inhibitor->link); |
14 | wl_list_remove(&inhibitor->destroy.link); | 14 | wl_list_remove(&inhibitor->destroy.link); |
15 | sway_idle_inhibit_v1_check_active(inhibitor->manager); | 15 | sway_idle_inhibit_v1_check_active(); |
16 | free(inhibitor); | 16 | free(inhibitor); |
17 | } | 17 | } |
18 | 18 | ||
@@ -35,7 +35,6 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { | |||
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | 37 | ||
38 | inhibitor->manager = manager; | ||
39 | inhibitor->mode = INHIBIT_IDLE_APPLICATION; | 38 | inhibitor->mode = INHIBIT_IDLE_APPLICATION; |
40 | inhibitor->wlr_inhibitor = wlr_inhibitor; | 39 | inhibitor->wlr_inhibitor = wlr_inhibitor; |
41 | wl_list_insert(&manager->inhibitors, &inhibitor->link); | 40 | wl_list_insert(&manager->inhibitors, &inhibitor->link); |
@@ -43,33 +42,34 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { | |||
43 | inhibitor->destroy.notify = handle_destroy; | 42 | inhibitor->destroy.notify = handle_destroy; |
44 | wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); | 43 | wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy); |
45 | 44 | ||
46 | sway_idle_inhibit_v1_check_active(manager); | 45 | sway_idle_inhibit_v1_check_active(); |
47 | } | 46 | } |
48 | 47 | ||
49 | void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view, | 48 | void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view, |
50 | enum sway_idle_inhibit_mode mode) { | 49 | enum sway_idle_inhibit_mode mode) { |
50 | struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1; | ||
51 | |||
51 | struct sway_idle_inhibitor_v1 *inhibitor = | 52 | struct sway_idle_inhibitor_v1 *inhibitor = |
52 | calloc(1, sizeof(struct sway_idle_inhibitor_v1)); | 53 | calloc(1, sizeof(struct sway_idle_inhibitor_v1)); |
53 | if (!inhibitor) { | 54 | if (!inhibitor) { |
54 | return; | 55 | return; |
55 | } | 56 | } |
56 | 57 | ||
57 | inhibitor->manager = server.idle_inhibit_manager_v1; | ||
58 | inhibitor->mode = mode; | 58 | inhibitor->mode = mode; |
59 | inhibitor->view = view; | 59 | inhibitor->view = view; |
60 | wl_list_insert(&inhibitor->manager->inhibitors, &inhibitor->link); | 60 | wl_list_insert(&manager->inhibitors, &inhibitor->link); |
61 | 61 | ||
62 | inhibitor->destroy.notify = handle_destroy; | 62 | inhibitor->destroy.notify = handle_destroy; |
63 | wl_signal_add(&view->events.unmap, &inhibitor->destroy); | 63 | wl_signal_add(&view->events.unmap, &inhibitor->destroy); |
64 | 64 | ||
65 | sway_idle_inhibit_v1_check_active(inhibitor->manager); | 65 | sway_idle_inhibit_v1_check_active(); |
66 | } | 66 | } |
67 | 67 | ||
68 | struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view( | 68 | struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view( |
69 | struct sway_view *view) { | 69 | struct sway_view *view) { |
70 | struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1; | ||
70 | struct sway_idle_inhibitor_v1 *inhibitor; | 71 | struct sway_idle_inhibitor_v1 *inhibitor; |
71 | wl_list_for_each(inhibitor, &server.idle_inhibit_manager_v1->inhibitors, | 72 | wl_list_for_each(inhibitor, &manager->inhibitors, link) { |
72 | link) { | ||
73 | if (inhibitor->mode != INHIBIT_IDLE_APPLICATION && | 73 | if (inhibitor->mode != INHIBIT_IDLE_APPLICATION && |
74 | inhibitor->view == view) { | 74 | inhibitor->view == view) { |
75 | return inhibitor; | 75 | return inhibitor; |
@@ -80,9 +80,9 @@ struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view( | |||
80 | 80 | ||
81 | struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_view( | 81 | struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_view( |
82 | struct sway_view *view) { | 82 | struct sway_view *view) { |
83 | struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1; | ||
83 | struct sway_idle_inhibitor_v1 *inhibitor; | 84 | struct sway_idle_inhibitor_v1 *inhibitor; |
84 | wl_list_for_each(inhibitor, &server.idle_inhibit_manager_v1->inhibitors, | 85 | wl_list_for_each(inhibitor, &manager->inhibitors, link) { |
85 | link) { | ||
86 | if (inhibitor->mode == INHIBIT_IDLE_APPLICATION && | 86 | if (inhibitor->mode == INHIBIT_IDLE_APPLICATION && |
87 | view_from_wlr_surface(inhibitor->wlr_inhibitor->surface) == view) { | 87 | view_from_wlr_surface(inhibitor->wlr_inhibitor->surface) == view) { |
88 | return inhibitor; | 88 | return inhibitor; |
@@ -131,8 +131,8 @@ bool sway_idle_inhibit_v1_is_active(struct sway_idle_inhibitor_v1 *inhibitor) { | |||
131 | return false; | 131 | return false; |
132 | } | 132 | } |
133 | 133 | ||
134 | void sway_idle_inhibit_v1_check_active( | 134 | void sway_idle_inhibit_v1_check_active(void) { |
135 | struct sway_idle_inhibit_manager_v1 *manager) { | 135 | struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1; |
136 | struct sway_idle_inhibitor_v1 *inhibitor; | 136 | struct sway_idle_inhibitor_v1 *inhibitor; |
137 | bool inhibited = false; | 137 | bool inhibited = false; |
138 | wl_list_for_each(inhibitor, &manager->inhibitors, link) { | 138 | wl_list_for_each(inhibitor, &manager->inhibitors, link) { |
@@ -140,28 +140,22 @@ void sway_idle_inhibit_v1_check_active( | |||
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | wlr_idle_set_enabled(manager->idle, NULL, !inhibited); | 143 | wlr_idle_set_enabled(server.idle, NULL, !inhibited); |
144 | wlr_idle_notifier_v1_set_inhibited(server.idle_notifier_v1, inhibited); | 144 | wlr_idle_notifier_v1_set_inhibited(server.idle_notifier_v1, inhibited); |
145 | } | 145 | } |
146 | 146 | ||
147 | struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create( | 147 | bool sway_idle_inhibit_manager_v1_init(void) { |
148 | struct wl_display *wl_display, struct wlr_idle *idle) { | 148 | struct sway_idle_inhibit_manager_v1 *manager = &server.idle_inhibit_manager_v1; |
149 | struct sway_idle_inhibit_manager_v1 *manager = | ||
150 | calloc(1, sizeof(struct sway_idle_inhibit_manager_v1)); | ||
151 | if (!manager) { | ||
152 | return NULL; | ||
153 | } | ||
154 | 149 | ||
155 | manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display); | 150 | manager->wlr_manager = wlr_idle_inhibit_v1_create(server.wl_display); |
156 | if (!manager->wlr_manager) { | 151 | if (!manager->wlr_manager) { |
157 | free(manager); | 152 | return false; |
158 | return NULL; | ||
159 | } | 153 | } |
160 | manager->idle = idle; | 154 | |
161 | wl_signal_add(&manager->wlr_manager->events.new_inhibitor, | 155 | wl_signal_add(&manager->wlr_manager->events.new_inhibitor, |
162 | &manager->new_idle_inhibitor_v1); | 156 | &manager->new_idle_inhibitor_v1); |
163 | manager->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; | 157 | manager->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1; |
164 | wl_list_init(&manager->inhibitors); | 158 | wl_list_init(&manager->inhibitors); |
165 | 159 | ||
166 | return manager; | 160 | return true; |
167 | } | 161 | } |