aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/desktop/idle_inhibit_v1.h17
-rw-r--r--include/sway/server.h7
-rw-r--r--sway/desktop/idle_inhibit_v1.c40
-rw-r--r--sway/desktop/transaction.c4
-rw-r--r--sway/server.c11
5 files changed, 53 insertions, 26 deletions
diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h
index 1764713c..e5ed8a3d 100644
--- a/include/sway/desktop/idle_inhibit_v1.h
+++ b/include/sway/desktop/idle_inhibit_v1.h
@@ -1,17 +1,28 @@
1
2#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H 1#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
3#define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H 2#define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
4#include <wlr/types/wlr_idle_inhibit_v1.h> 3#include <wlr/types/wlr_idle_inhibit_v1.h>
4#include <wlr/types/wlr_idle.h>
5#include "sway/server.h" 5#include "sway/server.h"
6 6
7struct sway_idle_inhibit_manager_v1 {
8 struct wlr_idle_inhibit_manager_v1 *wlr_manager;
9 struct wl_listener new_idle_inhibitor_v1;
10 struct wl_list inhibitors;
11
12 struct wlr_idle *idle;
13};
14
7struct sway_idle_inhibitor_v1 { 15struct sway_idle_inhibitor_v1 {
8 struct sway_server *server; 16 struct sway_idle_inhibit_manager_v1 *manager;
9 struct sway_view *view; 17 struct sway_view *view;
10 18
11 struct wl_list link; 19 struct wl_list link;
12 struct wl_listener destroy; 20 struct wl_listener destroy;
13}; 21};
14 22
15void idle_inhibit_v1_check_active(struct sway_server *server); 23void idle_inhibit_v1_check_active(
24 struct sway_idle_inhibit_manager_v1 *manager);
16 25
26struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create(
27 struct wl_display *wl_display, struct wlr_idle *idle);
17#endif 28#endif
diff --git a/include/sway/server.h b/include/sway/server.h
index 693e6b82..a3e32898 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -23,16 +23,13 @@ struct sway_server {
23 23
24 struct wlr_compositor *compositor; 24 struct wlr_compositor *compositor;
25 struct wlr_data_device_manager *data_device_manager; 25 struct wlr_data_device_manager *data_device_manager;
26 struct wlr_idle *idle;
27 struct wlr_idle_inhibit_manager_v1 *idle_inhibit;
28 26
29 struct sway_input_manager *input; 27 struct sway_input_manager *input;
30 28
31 struct wl_listener new_output; 29 struct wl_listener new_output;
32 30
33 struct wlr_idle_inhibit_manager_v1 *idle_inhibit_v1; 31 struct wlr_idle *idle;
34 struct wl_listener new_idle_inhibitor_v1; 32 struct sway_idle_inhibit_manager_v1 *idle_inhibit_manager_v1;
35 struct wl_list idle_inhibitors_v1;
36 33
37 struct wlr_layer_shell *layer_shell; 34 struct wlr_layer_shell *layer_shell;
38 struct wl_listener layer_shell_surface; 35 struct wl_listener layer_shell_surface;
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,