aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-07-02 09:06:23 +0100
committerLibravatar GitHub <noreply@github.com>2018-07-02 09:06:23 +0100
commitf611a4f9b10ee3e5c8115c3bd89e9fda51ade104 (patch)
tree83939d888351ba8818599a69bece4412fd203b64
parentMerge pull request #2186 from martinetd/static-analysis (diff)
parentidle_inhibit: move server data to its own struct (diff)
downloadsway-f611a4f9b10ee3e5c8115c3bd89e9fda51ade104.tar.gz
sway-f611a4f9b10ee3e5c8115c3bd89e9fda51ade104.tar.zst
sway-f611a4f9b10ee3e5c8115c3bd89e9fda51ade104.zip
Merge pull request #2187 from martinetd/idle-inhibit
Idle inhibit
-rw-r--r--include/sway/desktop/idle_inhibit_v1.h28
-rw-r--r--include/sway/server.h5
-rw-r--r--sway/desktop/idle_inhibit_v1.c79
-rw-r--r--sway/desktop/transaction.c3
-rw-r--r--sway/meson.build1
-rw-r--r--sway/server.c6
6 files changed, 120 insertions, 2 deletions
diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h
new file mode 100644
index 00000000..e5ed8a3d
--- /dev/null
+++ b/include/sway/desktop/idle_inhibit_v1.h
@@ -0,0 +1,28 @@
1#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
2#define _SWAY_DESKTOP_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"
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
15struct sway_idle_inhibitor_v1 {
16 struct sway_idle_inhibit_manager_v1 *manager;
17 struct sway_view *view;
18
19 struct wl_list link;
20 struct wl_listener destroy;
21};
22
23void idle_inhibit_v1_check_active(
24 struct sway_idle_inhibit_manager_v1 *manager);
25
26struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create(
27 struct wl_display *wl_display, struct wlr_idle *idle);
28#endif
diff --git a/include/sway/server.h b/include/sway/server.h
index 1e1aa3cc..a3e32898 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -23,12 +23,14 @@ 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 26
28 struct sway_input_manager *input; 27 struct sway_input_manager *input;
29 28
30 struct wl_listener new_output; 29 struct wl_listener new_output;
31 30
31 struct wlr_idle *idle;
32 struct sway_idle_inhibit_manager_v1 *idle_inhibit_manager_v1;
33
32 struct wlr_layer_shell *layer_shell; 34 struct wlr_layer_shell *layer_shell;
33 struct wl_listener layer_shell_surface; 35 struct wl_listener layer_shell_surface;
34 36
@@ -61,6 +63,7 @@ void server_run(struct sway_server *server);
61 63
62void handle_new_output(struct wl_listener *listener, void *data); 64void handle_new_output(struct wl_listener *listener, void *data);
63 65
66void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data);
64void handle_layer_shell_surface(struct wl_listener *listener, void *data); 67void handle_layer_shell_surface(struct wl_listener *listener, void *data);
65void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); 68void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
66void handle_xdg_shell_surface(struct wl_listener *listener, void *data); 69void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c
new file mode 100644
index 00000000..c02ca26e
--- /dev/null
+++ b/sway/desktop/idle_inhibit_v1.c
@@ -0,0 +1,79 @@
1#include <stdlib.h>
2#include <wlr/types/wlr_idle.h>
3#include "log.h"
4#include "sway/desktop/idle_inhibit_v1.h"
5#include "sway/tree/view.h"
6#include "sway/server.h"
7
8
9static void handle_destroy(struct wl_listener *listener, void *data) {
10 struct sway_idle_inhibitor_v1 *inhibitor =
11 wl_container_of(listener, inhibitor, destroy);
12 wlr_log(L_DEBUG, "Sway idle inhibitor destroyed");
13 wl_list_remove(&inhibitor->link);
14 wl_list_remove(&inhibitor->destroy.link);
15 idle_inhibit_v1_check_active(inhibitor->manager);
16 free(inhibitor);
17}
18
19void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
20 struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
21 struct sway_idle_inhibit_manager_v1 *manager =
22 wl_container_of(listener, manager, new_idle_inhibitor_v1);
23 wlr_log(L_DEBUG, "New sway idle inhibitor");
24
25 struct sway_idle_inhibitor_v1 *inhibitor =
26 calloc(1, sizeof(struct sway_idle_inhibitor_v1));
27 if (!inhibitor) {
28 return;
29 }
30
31 inhibitor->manager = manager;
32 inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface);
33 wl_list_insert(&manager->inhibitors, &inhibitor->link);
34
35
36 inhibitor->destroy.notify = handle_destroy;
37 wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy);
38
39 idle_inhibit_v1_check_active(manager);
40}
41
42void idle_inhibit_v1_check_active(
43 struct sway_idle_inhibit_manager_v1 *manager) {
44 struct sway_idle_inhibitor_v1 *inhibitor;
45 bool inhibited = false;
46 wl_list_for_each(inhibitor, &manager->inhibitors, link) {
47 if (!inhibitor->view) {
48 /* Cannot guess if view is visible so assume it is */
49 inhibited = true;
50 break;
51 }
52 if (view_is_visible(inhibitor->view)) {
53 inhibited = true;
54 break;
55 }
56 }
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;
79}
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index cb524999..7b670aec 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -6,6 +6,7 @@
6#include <wlr/types/wlr_buffer.h> 6#include <wlr/types/wlr_buffer.h>
7#include <wlr/types/wlr_linux_dmabuf.h> 7#include <wlr/types/wlr_linux_dmabuf.h>
8#include "sway/debug.h" 8#include "sway/debug.h"
9#include "sway/desktop/idle_inhibit_v1.h"
9#include "sway/desktop/transaction.h" 10#include "sway/desktop/transaction.h"
10#include "sway/output.h" 11#include "sway/output.h"
11#include "sway/tree/container.h" 12#include "sway/tree/container.h"
@@ -245,6 +246,7 @@ static void transaction_progress_queue() {
245 transaction_destroy(transaction); 246 transaction_destroy(transaction);
246 } 247 }
247 server.transactions->length = 0; 248 server.transactions->length = 0;
249 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
248} 250}
249 251
250static int handle_timeout(void *data) { 252static int handle_timeout(void *data) {
@@ -320,6 +322,7 @@ void transaction_commit(struct sway_transaction *transaction) {
320 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);
321 transaction_apply(transaction); 323 transaction_apply(transaction);
322 transaction_destroy(transaction); 324 transaction_destroy(transaction);
325 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
323 return; 326 return;
324 } 327 }
325 328
diff --git a/sway/meson.build b/sway/meson.build
index 9ff3f05f..a81a3406 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -10,6 +10,7 @@ sway_sources = files(
10 'security.c', 10 'security.c',
11 11
12 'desktop/desktop.c', 12 'desktop/desktop.c',
13 'desktop/idle_inhibit_v1.c',
13 'desktop/layer_shell.c', 14 'desktop/layer_shell.c',
14 'desktop/output.c', 15 'desktop/output.c',
15 'desktop/transaction.c', 16 'desktop/transaction.c',
diff --git a/sway/server.c b/sway/server.c
index bd107617..8106f3c8 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -22,6 +22,7 @@
22// TODO WLR: make Xwayland optional 22// TODO WLR: make Xwayland optional
23#include "list.h" 23#include "list.h"
24#include "sway/config.h" 24#include "sway/config.h"
25#include "sway/desktop/idle_inhibit_v1.h"
25#include "sway/input/input-manager.h" 26#include "sway/input/input-manager.h"
26#include "sway/server.h" 27#include "sway/server.h"
27#include "sway/tree/layout.h" 28#include "sway/tree/layout.h"
@@ -52,7 +53,6 @@ bool server_init(struct sway_server *server) {
52 server->data_device_manager = 53 server->data_device_manager =
53 wlr_data_device_manager_create(server->wl_display); 54 wlr_data_device_manager_create(server->wl_display);
54 55
55 server->idle = wlr_idle_create(server->wl_display);
56 wlr_screenshooter_create(server->wl_display); 56 wlr_screenshooter_create(server->wl_display);
57 wlr_gamma_control_manager_create(server->wl_display); 57 wlr_gamma_control_manager_create(server->wl_display);
58 wlr_primary_selection_device_manager_create(server->wl_display); 58 wlr_primary_selection_device_manager_create(server->wl_display);
@@ -63,6 +63,10 @@ bool server_init(struct sway_server *server) {
63 wlr_xdg_output_manager_create(server->wl_display, 63 wlr_xdg_output_manager_create(server->wl_display,
64 root_container.sway_root->output_layout); 64 root_container.sway_root->output_layout);
65 65
66 server->idle = wlr_idle_create(server->wl_display);
67 server->idle_inhibit_manager_v1 =
68 sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle);
69
66 server->layer_shell = wlr_layer_shell_create(server->wl_display); 70 server->layer_shell = wlr_layer_shell_create(server->wl_display);
67 wl_signal_add(&server->layer_shell->events.new_surface, 71 wl_signal_add(&server->layer_shell->events.new_surface,
68 &server->layer_shell_surface); 72 &server->layer_shell_surface);