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 | |
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.
-rw-r--r-- | include/sway/desktop/idle_inhibit_v1.h | 11 | ||||
-rw-r--r-- | include/sway/server.h | 3 | ||||
-rw-r--r-- | sway/commands/inhibit_idle.c | 2 | ||||
-rw-r--r-- | sway/desktop/idle_inhibit_v1.c | 44 | ||||
-rw-r--r-- | sway/desktop/transaction.c | 2 | ||||
-rw-r--r-- | sway/server.c | 3 |
6 files changed, 27 insertions, 38 deletions
diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h index 58d54c68..6dda1af9 100644 --- a/include/sway/desktop/idle_inhibit_v1.h +++ b/include/sway/desktop/idle_inhibit_v1.h | |||
@@ -2,7 +2,6 @@ | |||
2 | #define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H | 2 | #define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H |
3 | #include <wlr/types/wlr_idle_inhibit_v1.h> | 3 | #include <wlr/types/wlr_idle_inhibit_v1.h> |
4 | #include <wlr/types/wlr_idle.h> | 4 | #include <wlr/types/wlr_idle.h> |
5 | #include "sway/server.h" | ||
6 | 5 | ||
7 | enum sway_idle_inhibit_mode { | 6 | enum sway_idle_inhibit_mode { |
8 | INHIBIT_IDLE_APPLICATION, // Application set inhibitor (when visible) | 7 | INHIBIT_IDLE_APPLICATION, // Application set inhibitor (when visible) |
@@ -16,12 +15,9 @@ struct sway_idle_inhibit_manager_v1 { | |||
16 | struct wlr_idle_inhibit_manager_v1 *wlr_manager; | 15 | struct wlr_idle_inhibit_manager_v1 *wlr_manager; |
17 | struct wl_listener new_idle_inhibitor_v1; | 16 | struct wl_listener new_idle_inhibitor_v1; |
18 | struct wl_list inhibitors; | 17 | struct wl_list inhibitors; |
19 | |||
20 | struct wlr_idle *idle; | ||
21 | }; | 18 | }; |
22 | 19 | ||
23 | struct sway_idle_inhibitor_v1 { | 20 | struct sway_idle_inhibitor_v1 { |
24 | struct sway_idle_inhibit_manager_v1 *manager; | ||
25 | struct wlr_idle_inhibitor_v1 *wlr_inhibitor; | 21 | struct wlr_idle_inhibitor_v1 *wlr_inhibitor; |
26 | struct sway_view *view; | 22 | struct sway_view *view; |
27 | enum sway_idle_inhibit_mode mode; | 23 | enum sway_idle_inhibit_mode mode; |
@@ -33,8 +29,7 @@ struct sway_idle_inhibitor_v1 { | |||
33 | bool sway_idle_inhibit_v1_is_active( | 29 | bool sway_idle_inhibit_v1_is_active( |
34 | struct sway_idle_inhibitor_v1 *inhibitor); | 30 | struct sway_idle_inhibitor_v1 *inhibitor); |
35 | 31 | ||
36 | void sway_idle_inhibit_v1_check_active( | 32 | void sway_idle_inhibit_v1_check_active(void); |
37 | struct sway_idle_inhibit_manager_v1 *manager); | ||
38 | 33 | ||
39 | void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view, | 34 | void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view, |
40 | enum sway_idle_inhibit_mode mode); | 35 | enum sway_idle_inhibit_mode mode); |
@@ -48,6 +43,6 @@ struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_vi | |||
48 | void sway_idle_inhibit_v1_user_inhibitor_destroy( | 43 | void sway_idle_inhibit_v1_user_inhibitor_destroy( |
49 | struct sway_idle_inhibitor_v1 *inhibitor); | 44 | struct sway_idle_inhibitor_v1 *inhibitor); |
50 | 45 | ||
51 | struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create( | 46 | bool sway_idle_inhibit_manager_v1_init(void); |
52 | struct wl_display *wl_display, struct wlr_idle *idle); | 47 | |
53 | #endif | 48 | #endif |
diff --git a/include/sway/server.h b/include/sway/server.h index aaa8781b..0e4ec2be 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <wlr/types/wlr_xdg_shell.h> | 21 | #include <wlr/types/wlr_xdg_shell.h> |
22 | #include "config.h" | 22 | #include "config.h" |
23 | #include "list.h" | 23 | #include "list.h" |
24 | #include "sway/desktop/idle_inhibit_v1.h" | ||
24 | #if HAVE_XWAYLAND | 25 | #if HAVE_XWAYLAND |
25 | #include "sway/xwayland.h" | 26 | #include "sway/xwayland.h" |
26 | #endif | 27 | #endif |
@@ -53,7 +54,7 @@ struct sway_server { | |||
53 | 54 | ||
54 | struct wlr_idle *idle; | 55 | struct wlr_idle *idle; |
55 | struct wlr_idle_notifier_v1 *idle_notifier_v1; | 56 | struct wlr_idle_notifier_v1 *idle_notifier_v1; |
56 | struct sway_idle_inhibit_manager_v1 *idle_inhibit_manager_v1; | 57 | struct sway_idle_inhibit_manager_v1 idle_inhibit_manager_v1; |
57 | 58 | ||
58 | struct wlr_layer_shell_v1 *layer_shell; | 59 | struct wlr_layer_shell_v1 *layer_shell; |
59 | struct wl_listener layer_shell_surface; | 60 | struct wl_listener layer_shell_surface; |
diff --git a/sway/commands/inhibit_idle.c b/sway/commands/inhibit_idle.c index aebc2bf9..6125736a 100644 --- a/sway/commands/inhibit_idle.c +++ b/sway/commands/inhibit_idle.c | |||
@@ -41,7 +41,7 @@ struct cmd_results *cmd_inhibit_idle(int argc, char **argv) { | |||
41 | sway_idle_inhibit_v1_user_inhibitor_destroy(inhibitor); | 41 | sway_idle_inhibit_v1_user_inhibitor_destroy(inhibitor); |
42 | } else { | 42 | } else { |
43 | inhibitor->mode = mode; | 43 | inhibitor->mode = mode; |
44 | sway_idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1); | 44 | sway_idle_inhibit_v1_check_active(); |
45 | } | 45 | } |
46 | } else if (!clear) { | 46 | } else if (!clear) { |
47 | sway_idle_inhibit_v1_user_inhibitor_register(con->view, mode); | 47 | sway_idle_inhibit_v1_user_inhibitor_register(con->view, mode); |
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 | } |
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index f5a3a053..6947e138 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c | |||
@@ -344,7 +344,7 @@ static void transaction_progress(void) { | |||
344 | server.queued_transaction = NULL; | 344 | server.queued_transaction = NULL; |
345 | 345 | ||
346 | if (!server.pending_transaction) { | 346 | if (!server.pending_transaction) { |
347 | sway_idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1); | 347 | sway_idle_inhibit_v1_check_active(); |
348 | return; | 348 | return; |
349 | } | 349 | } |
350 | 350 | ||
diff --git a/sway/server.c b/sway/server.c index 9797cf60..cc4719d7 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -130,8 +130,7 @@ bool server_init(struct sway_server *server) { | |||
130 | 130 | ||
131 | server->idle = wlr_idle_create(server->wl_display); | 131 | server->idle = wlr_idle_create(server->wl_display); |
132 | server->idle_notifier_v1 = wlr_idle_notifier_v1_create(server->wl_display); | 132 | server->idle_notifier_v1 = wlr_idle_notifier_v1_create(server->wl_display); |
133 | server->idle_inhibit_manager_v1 = | 133 | sway_idle_inhibit_manager_v1_init(); |
134 | sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle); | ||
135 | 134 | ||
136 | server->layer_shell = wlr_layer_shell_v1_create(server->wl_display, | 135 | server->layer_shell = wlr_layer_shell_v1_create(server->wl_display, |
137 | SWAY_LAYER_SHELL_VERSION); | 136 | SWAY_LAYER_SHELL_VERSION); |