aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Damien Tardy-Panis <damien@tardypad.me>2020-05-05 18:35:03 +0200
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2020-05-29 17:29:41 -0400
commit0cbd26f0dae32db38160a82d557017edab8bb632 (patch)
tree33d51bd6d990ca9606d0306e211e3d0e5f464494
parentseat_cmd_cursor: emit frame events (diff)
downloadsway-0cbd26f0dae32db38160a82d557017edab8bb632.tar.gz
sway-0cbd26f0dae32db38160a82d557017edab8bb632.tar.zst
sway-0cbd26f0dae32db38160a82d557017edab8bb632.zip
Add views idle inhibition status in get_tree output
Fixes #5286
-rw-r--r--include/sway/desktop/idle_inhibit_v1.h6
-rw-r--r--include/sway/tree/view.h2
-rw-r--r--sway/desktop/idle_inhibit_v1.c17
-rw-r--r--sway/ipc-json.c47
-rw-r--r--sway/sway-ipc.7.scd18
-rw-r--r--sway/tree/view.c24
6 files changed, 112 insertions, 2 deletions
diff --git a/include/sway/desktop/idle_inhibit_v1.h b/include/sway/desktop/idle_inhibit_v1.h
index 4d4e59b0..0adafdb9 100644
--- a/include/sway/desktop/idle_inhibit_v1.h
+++ b/include/sway/desktop/idle_inhibit_v1.h
@@ -29,6 +29,9 @@ struct sway_idle_inhibitor_v1 {
29 struct wl_listener destroy; 29 struct wl_listener destroy;
30}; 30};
31 31
32bool sway_idle_inhibit_v1_is_active(
33 struct sway_idle_inhibitor_v1 *inhibitor);
34
32void sway_idle_inhibit_v1_check_active( 35void sway_idle_inhibit_v1_check_active(
33 struct sway_idle_inhibit_manager_v1 *manager); 36 struct sway_idle_inhibit_manager_v1 *manager);
34 37
@@ -38,6 +41,9 @@ void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view,
38struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view( 41struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view(
39 struct sway_view *view); 42 struct sway_view *view);
40 43
44struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_view(
45 struct sway_view *view);
46
41void sway_idle_inhibit_v1_user_inhibitor_destroy( 47void sway_idle_inhibit_v1_user_inhibitor_destroy(
42 struct sway_idle_inhibitor_v1 *inhibitor); 48 struct sway_idle_inhibitor_v1 *inhibitor);
43 49
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 9230f456..ab2dc8e4 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -232,6 +232,8 @@ void view_get_constraints(struct sway_view *view, double *min_width,
232uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, 232uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
233 int height); 233 int height);
234 234
235bool view_inhibit_idle(struct sway_view *view);
236
235/** 237/**
236 * Whether or not the view is the only visible view in its tree. If the view 238 * Whether or not the view is the only visible view in its tree. If the view
237 * is tiling, there may be floating views. If the view is floating, there may 239 * is tiling, there may be floating views. If the view is floating, there may
diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c
index 73e46a8f..a5cfd5b2 100644
--- a/sway/desktop/idle_inhibit_v1.c
+++ b/sway/desktop/idle_inhibit_v1.c
@@ -77,6 +77,19 @@ struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view(
77 return NULL; 77 return NULL;
78} 78}
79 79
80struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_view(
81 struct sway_view *view) {
82 struct sway_idle_inhibitor_v1 *inhibitor;
83 wl_list_for_each(inhibitor, &server.idle_inhibit_manager_v1->inhibitors,
84 link) {
85 if (inhibitor->view == view &&
86 inhibitor->mode == INHIBIT_IDLE_APPLICATION) {
87 return inhibitor;
88 }
89 }
90 return NULL;
91}
92
80void sway_idle_inhibit_v1_user_inhibitor_destroy( 93void sway_idle_inhibit_v1_user_inhibitor_destroy(
81 struct sway_idle_inhibitor_v1 *inhibitor) { 94 struct sway_idle_inhibitor_v1 *inhibitor) {
82 if (!inhibitor) { 95 if (!inhibitor) {
@@ -89,7 +102,7 @@ void sway_idle_inhibit_v1_user_inhibitor_destroy(
89 destroy_inhibitor(inhibitor); 102 destroy_inhibitor(inhibitor);
90} 103}
91 104
92static bool check_active(struct sway_idle_inhibitor_v1 *inhibitor) { 105bool sway_idle_inhibit_v1_is_active(struct sway_idle_inhibitor_v1 *inhibitor) {
93 switch (inhibitor->mode) { 106 switch (inhibitor->mode) {
94 case INHIBIT_IDLE_APPLICATION: 107 case INHIBIT_IDLE_APPLICATION:
95 // If there is no view associated with the inhibitor, assume visible 108 // If there is no view associated with the inhibitor, assume visible
@@ -122,7 +135,7 @@ void sway_idle_inhibit_v1_check_active(
122 struct sway_idle_inhibitor_v1 *inhibitor; 135 struct sway_idle_inhibitor_v1 *inhibitor;
123 bool inhibited = false; 136 bool inhibited = false;
124 wl_list_for_each(inhibitor, &manager->inhibitors, link) { 137 wl_list_for_each(inhibitor, &manager->inhibitors, link) {
125 if ((inhibited = check_active(inhibitor))) { 138 if ((inhibited = sway_idle_inhibit_v1_is_active(inhibitor))) {
126 break; 139 break;
127 } 140 }
128 } 141 }
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index c2e43f6e..066fd8db 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -18,6 +18,7 @@
18#include <wlr/types/wlr_output.h> 18#include <wlr/types/wlr_output.h>
19#include <xkbcommon/xkbcommon.h> 19#include <xkbcommon/xkbcommon.h>
20#include "wlr-layer-shell-unstable-v1-protocol.h" 20#include "wlr-layer-shell-unstable-v1-protocol.h"
21#include "sway/desktop/idle_inhibit_v1.h"
21 22
22static const int i3_output_id = INT32_MAX; 23static const int i3_output_id = INT32_MAX;
23static const int i3_scratch_id = INT32_MAX - 1; 24static const int i3_scratch_id = INT32_MAX - 1;
@@ -139,6 +140,22 @@ static const char *ipc_json_xwindow_type_description(struct sway_view *view) {
139} 140}
140#endif 141#endif
141 142
143static const char *ipc_json_user_idle_inhibitor_description(enum sway_idle_inhibit_mode mode) {
144 switch (mode) {
145 case INHIBIT_IDLE_FOCUS:
146 return "focus";
147 case INHIBIT_IDLE_FULLSCREEN:
148 return "fullscreen";
149 case INHIBIT_IDLE_OPEN:
150 return "open";
151 case INHIBIT_IDLE_VISIBLE:
152 return "visible";
153 case INHIBIT_IDLE_APPLICATION:
154 return NULL;
155 }
156 return NULL;
157}
158
142json_object *ipc_json_get_version(void) { 159json_object *ipc_json_get_version(void) {
143 int major = 0, minor = 0, patch = 0; 160 int major = 0, minor = 0, patch = 0;
144 json_object *version = json_object_new_object(); 161 json_object *version = json_object_new_object();
@@ -492,6 +509,36 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
492 509
493 json_object_object_add(object, "shell", json_object_new_string(view_get_shell(c->view))); 510 json_object_object_add(object, "shell", json_object_new_string(view_get_shell(c->view)));
494 511
512 json_object_object_add(object, "inhibit_idle",
513 json_object_new_boolean(view_inhibit_idle(c->view)));
514
515 json_object *idle_inhibitors = json_object_new_object();
516
517 struct sway_idle_inhibitor_v1 *user_inhibitor =
518 sway_idle_inhibit_v1_user_inhibitor_for_view(c->view);
519
520 if (user_inhibitor) {
521 json_object_object_add(idle_inhibitors, "user",
522 json_object_new_string(
523 ipc_json_user_idle_inhibitor_description(user_inhibitor->mode)));
524 } else {
525 json_object_object_add(idle_inhibitors, "user",
526 json_object_new_string("none"));
527 }
528
529 struct sway_idle_inhibitor_v1 *application_inhibitor =
530 sway_idle_inhibit_v1_application_inhibitor_for_view(c->view);
531
532 if (application_inhibitor) {
533 json_object_object_add(idle_inhibitors, "application",
534 json_object_new_string("enabled"));
535 } else {
536 json_object_object_add(idle_inhibitors, "application",
537 json_object_new_string("none"));
538 }
539
540 json_object_object_add(object, "idle_inhibitors", idle_inhibitors);
541
495#if HAVE_XWAYLAND 542#if HAVE_XWAYLAND
496 if (c->view->type == SWAY_VIEW_XWAYLAND) { 543 if (c->view->type == SWAY_VIEW_XWAYLAND) {
497 json_object_object_add(object, "window", 544 json_object_object_add(object, "window",
diff --git a/sway/sway-ipc.7.scd b/sway/sway-ipc.7.scd
index 5cef0bb4..63e3ceb6 100644
--- a/sway/sway-ipc.7.scd
+++ b/sway/sway-ipc.7.scd
@@ -379,6 +379,14 @@ node and will have the following properties:
379|- shell 379|- shell
380: string 380: string
381: (Only views) The shell of the view, such as _xdg\_shell_ or _xwayland_ 381: (Only views) The shell of the view, such as _xdg\_shell_ or _xwayland_
382|- inhibit_idle
383: boolean
384: (Only views) Whether the view is inhibiting the idle state
385|- idle_inhibitors
386: object
387: (Only views) An object containing the state of the _application_ and _user_ idle inhibitors.
388 _application_ can be _enabled_ or _none_.
389 _user_ can be _focus_, _fullscreen_, _open_, _visible_ or _none_.
382|- window 390|- window
383: integer 391: integer
384: (Only xwayland views) The X11 window ID for the xwayland view 392: (Only xwayland views) The X11 window ID for the xwayland view
@@ -676,6 +684,11 @@ node and will have the following properties:
676 "app_id": null, 684 "app_id": null,
677 "visible": true, 685 "visible": true,
678 "shell": "xwayland", 686 "shell": "xwayland",
687 "inhibit_idle": true,
688 "idle_inhibitors": {
689 "application": "none",
690 "user": "visible",
691 },
679 "window_properties": { 692 "window_properties": {
680 "class": "URxvt", 693 "class": "URxvt",
681 "instance": "urxvt", 694 "instance": "urxvt",
@@ -731,6 +744,11 @@ node and will have the following properties:
731 "app_id": "termite", 744 "app_id": "termite",
732 "visible": true, 745 "visible": true,
733 "shell": "xdg_shell", 746 "shell": "xdg_shell",
747 "inhibit_idle": false,
748 "idle_inhibitors": {
749 "application": "none",
750 "user": "fullscreen",
751 },
734 "nodes": [ 752 "nodes": [
735 ] 753 ]
736 } 754 }
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 2b4b6c09..8e12a229 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -17,6 +17,7 @@
17#include "sway/commands.h" 17#include "sway/commands.h"
18#include "sway/desktop.h" 18#include "sway/desktop.h"
19#include "sway/desktop/transaction.h" 19#include "sway/desktop/transaction.h"
20#include "sway/desktop/idle_inhibit_v1.h"
20#include "sway/input/cursor.h" 21#include "sway/input/cursor.h"
21#include "sway/ipc-server.h" 22#include "sway/ipc-server.h"
22#include "sway/output.h" 23#include "sway/output.h"
@@ -164,6 +165,29 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
164 return 0; 165 return 0;
165} 166}
166 167
168bool view_inhibit_idle(struct sway_view *view) {
169 struct sway_idle_inhibitor_v1 *user_inhibitor =
170 sway_idle_inhibit_v1_user_inhibitor_for_view(view);
171
172 struct sway_idle_inhibitor_v1 *application_inhibitor =
173 sway_idle_inhibit_v1_application_inhibitor_for_view(view);
174
175 if (!user_inhibitor && !application_inhibitor) {
176 return false;
177 }
178
179 if (!user_inhibitor) {
180 return sway_idle_inhibit_v1_is_active(application_inhibitor);
181 }
182
183 if (!application_inhibitor) {
184 return sway_idle_inhibit_v1_is_active(user_inhibitor);
185 }
186
187 return sway_idle_inhibit_v1_is_active(user_inhibitor)
188 || sway_idle_inhibit_v1_is_active(application_inhibitor);
189}
190
167bool view_is_only_visible(struct sway_view *view) { 191bool view_is_only_visible(struct sway_view *view) {
168 bool only_view = true; 192 bool only_view = true;
169 struct sway_container *con = view->container; 193 struct sway_container *con = view->container;