aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-07-02 09:26:57 +0900
committerLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-07-02 09:29:16 +0900
commit71224781c48f98f43f5836de663ef6e01604419c (patch)
tree7c2336020076f123184d1c18bbcb7db3e95be526 /sway
parentidle_inhibit: stop inhibitor when views become invisible (diff)
downloadsway-71224781c48f98f43f5836de663ef6e01604419c.tar.gz
sway-71224781c48f98f43f5836de663ef6e01604419c.tar.zst
sway-71224781c48f98f43f5836de663ef6e01604419c.zip
idle_inhibit: move server data to its own struct
Diffstat (limited to 'sway')
-rw-r--r--sway/desktop/idle_inhibit_v1.c40
-rw-r--r--sway/desktop/transaction.c4
-rw-r--r--sway/server.c11
3 files changed, 37 insertions, 18 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
19void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) { 19void 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
42void idle_inhibit_v1_check_active(struct sway_server *server) { 42void 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
60struct 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}
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() {
246 transaction_destroy(transaction); 246 transaction_destroy(transaction);
247 } 247 }
248 server.transactions->length = 0; 248 server.transactions->length = 0;
249 idle_inhibit_v1_check_active(&server); 249 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
250} 250}
251 251
252static int handle_timeout(void *data) { 252static int handle_timeout(void *data) {
@@ -322,7 +322,7 @@ void transaction_commit(struct sway_transaction *transaction) {
322 wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction); 322 wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction);
323 transaction_apply(transaction); 323 transaction_apply(transaction);
324 transaction_destroy(transaction); 324 transaction_destroy(transaction);
325 idle_inhibit_v1_check_active(&server); 325 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
326 return; 326 return;
327 } 327 }
328 328
diff --git a/sway/server.c b/sway/server.c
index ee6b7cde..8106f3c8 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -10,7 +10,6 @@
10#include <wlr/types/wlr_export_dmabuf_v1.h> 10#include <wlr/types/wlr_export_dmabuf_v1.h>
11#include <wlr/types/wlr_gamma_control.h> 11#include <wlr/types/wlr_gamma_control.h>
12#include <wlr/types/wlr_idle.h> 12#include <wlr/types/wlr_idle.h>
13#include <wlr/types/wlr_idle_inhibit_v1.h>
14#include <wlr/types/wlr_layer_shell.h> 13#include <wlr/types/wlr_layer_shell.h>
15#include <wlr/types/wlr_linux_dmabuf.h> 14#include <wlr/types/wlr_linux_dmabuf.h>
16#include <wlr/types/wlr_primary_selection.h> 15#include <wlr/types/wlr_primary_selection.h>
@@ -23,6 +22,7 @@
23// TODO WLR: make Xwayland optional 22// TODO WLR: make Xwayland optional
24#include "list.h" 23#include "list.h"
25#include "sway/config.h" 24#include "sway/config.h"
25#include "sway/desktop/idle_inhibit_v1.h"
26#include "sway/input/input-manager.h" 26#include "sway/input/input-manager.h"
27#include "sway/server.h" 27#include "sway/server.h"
28#include "sway/tree/layout.h" 28#include "sway/tree/layout.h"
@@ -53,7 +53,6 @@ bool server_init(struct sway_server *server) {
53 server->data_device_manager = 53 server->data_device_manager =
54 wlr_data_device_manager_create(server->wl_display); 54 wlr_data_device_manager_create(server->wl_display);
55 55
56 server->idle = wlr_idle_create(server->wl_display);
57 wlr_screenshooter_create(server->wl_display); 56 wlr_screenshooter_create(server->wl_display);
58 wlr_gamma_control_manager_create(server->wl_display); 57 wlr_gamma_control_manager_create(server->wl_display);
59 wlr_primary_selection_device_manager_create(server->wl_display); 58 wlr_primary_selection_device_manager_create(server->wl_display);
@@ -64,11 +63,9 @@ bool server_init(struct sway_server *server) {
64 wlr_xdg_output_manager_create(server->wl_display, 63 wlr_xdg_output_manager_create(server->wl_display,
65 root_container.sway_root->output_layout); 64 root_container.sway_root->output_layout);
66 65
67 server->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display); 66 server->idle = wlr_idle_create(server->wl_display);
68 wl_signal_add(&server->idle_inhibit->events.new_inhibitor, 67 server->idle_inhibit_manager_v1 =
69 &server->new_idle_inhibitor_v1); 68 sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle);
70 server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1;
71 wl_list_init(&server->idle_inhibitors_v1);
72 69
73 server->layer_shell = wlr_layer_shell_create(server->wl_display); 70 server->layer_shell = wlr_layer_shell_create(server->wl_display);
74 wl_signal_add(&server->layer_shell->events.new_surface, 71 wl_signal_add(&server->layer_shell->events.new_surface,