diff options
author | Damien Tardy-Panis <damien@tardypad.me> | 2020-05-05 18:35:03 +0200 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2020-05-29 17:29:41 -0400 |
commit | 0cbd26f0dae32db38160a82d557017edab8bb632 (patch) | |
tree | 33d51bd6d990ca9606d0306e211e3d0e5f464494 /sway | |
parent | seat_cmd_cursor: emit frame events (diff) | |
download | sway-0cbd26f0dae32db38160a82d557017edab8bb632.tar.gz sway-0cbd26f0dae32db38160a82d557017edab8bb632.tar.zst sway-0cbd26f0dae32db38160a82d557017edab8bb632.zip |
Add views idle inhibition status in get_tree output
Fixes #5286
Diffstat (limited to 'sway')
-rw-r--r-- | sway/desktop/idle_inhibit_v1.c | 17 | ||||
-rw-r--r-- | sway/ipc-json.c | 47 | ||||
-rw-r--r-- | sway/sway-ipc.7.scd | 18 | ||||
-rw-r--r-- | sway/tree/view.c | 24 |
4 files changed, 104 insertions, 2 deletions
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 | ||
80 | struct 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 | |||
80 | void sway_idle_inhibit_v1_user_inhibitor_destroy( | 93 | void 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 | ||
92 | static bool check_active(struct sway_idle_inhibitor_v1 *inhibitor) { | 105 | bool 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 | ||
22 | static const int i3_output_id = INT32_MAX; | 23 | static const int i3_output_id = INT32_MAX; |
23 | static const int i3_scratch_id = INT32_MAX - 1; | 24 | static 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 | ||
143 | static 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 | |||
142 | json_object *ipc_json_get_version(void) { | 159 | json_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 | ||
168 | bool 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 | |||
167 | bool view_is_only_visible(struct sway_view *view) { | 191 | bool 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; |