From 2520041da914ce50e44b757c92024f472c5fce19 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Wed, 16 Aug 2023 13:37:44 -0700 Subject: [PATCH 1/3] introspect: Move code for reuse --- js/misc/introspect.js | 59 ++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/js/misc/introspect.js b/js/misc/introspect.js index 3453d1a94..3dcd75b5e 100644 --- a/js/misc/introspect.js +++ b/js/misc/introspect.js @@ -121,6 +121,37 @@ export class IntrospectService { type === Meta.WindowType.UTILITY; } + _getWindowDict(window, app) { + let focusWindow = global.display.get_focus_window(); + let windowId = window.get_id(); + let frameRect = window.get_frame_rect(); + let title = window.get_title(); + let wmClass = window.get_wm_class(); + let sandboxedAppId = window.get_sandboxed_app_id(); + let windowDict = { + 'app-id': GLib.Variant.new('s', app.get_id()), + 'client-type': GLib.Variant.new('u', window.get_client_type()), + 'is-hidden': GLib.Variant.new('b', window.is_hidden()), + 'has-focus': GLib.Variant.new('b', window === focusWindow), + 'width': GLib.Variant.new('u', frameRect.width), + 'height': GLib.Variant.new('u', frameRect.height), + }; + + // These properties may not be available for all windows: + if (title != null) + windowDict['title'] = GLib.Variant.new('s', title); + + if (wmClass != null) + windowDict['wm-class'] = GLib.Variant.new('s', wmClass); + + if (sandboxedAppId != null) { + windowDict['sandboxed-app-id'] = + GLib.Variant.new('s', sandboxedAppId); + } + + return windowDict; + } + async GetRunningApplicationsAsync(params, invocation) { try { await this._senderChecker.checkInvocation(invocation); @@ -133,7 +164,6 @@ export class IntrospectService { } async GetWindowsAsync(params, invocation) { - let focusWindow = global.display.get_focus_window(); let apps = this._appSystem.get_running(); let windowsList = {}; @@ -151,31 +181,8 @@ export class IntrospectService { continue; let windowId = window.get_id(); - let frameRect = window.get_frame_rect(); - let title = window.get_title(); - let wmClass = window.get_wm_class(); - let sandboxedAppId = window.get_sandboxed_app_id(); - - windowsList[windowId] = { - 'app-id': GLib.Variant.new('s', app.get_id()), - 'client-type': GLib.Variant.new('u', window.get_client_type()), - 'is-hidden': GLib.Variant.new('b', window.is_hidden()), - 'has-focus': GLib.Variant.new('b', window === focusWindow), - 'width': GLib.Variant.new('u', frameRect.width), - 'height': GLib.Variant.new('u', frameRect.height), - }; - - // These properties may not be available for all windows: - if (title != null) - windowsList[windowId]['title'] = GLib.Variant.new('s', title); - - if (wmClass != null) - windowsList[windowId]['wm-class'] = GLib.Variant.new('s', wmClass); - - if (sandboxedAppId != null) { - windowsList[windowId]['sandboxed-app-id'] = - GLib.Variant.new('s', sandboxedAppId); - } + let windowDict = this._getWindowVariant(window, app); + windowsList[windowId] = new GLib.Variant('a{sv}', windowDict); } } invocation.return_value(new GLib.Variant('(a{ta{sv}})', [windowsList])); From 4326a2d5683045d027f9f15564445c6daba9515f Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Wed, 16 Aug 2023 14:37:29 -0700 Subject: [PATCH 2/3] introspect: Include 'id' in window variant From the GetWindows method, id is included as the key, but for future uses, lets also include it as a value of the dictionary. --- js/misc/introspect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/misc/introspect.js b/js/misc/introspect.js index 3dcd75b5e..4918d610b 100644 --- a/js/misc/introspect.js +++ b/js/misc/introspect.js @@ -131,6 +131,7 @@ export class IntrospectService { let windowDict = { 'app-id': GLib.Variant.new('s', app.get_id()), 'client-type': GLib.Variant.new('u', window.get_client_type()), + 'id': GLib.Variant.new('t', windowId), 'is-hidden': GLib.Variant.new('b', window.is_hidden()), 'has-focus': GLib.Variant.new('b', window === focusWindow), 'width': GLib.Variant.new('u', frameRect.width), From 7b45ac72ec34f75219d8f5c28d71e0a489a3ac1d Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Wed, 16 Aug 2023 10:24:19 -0700 Subject: [PATCH 3/3] introspect: Enhance WindowsChanged DBus API Splits WindowsChanged into 3 signals: WindowAdded, WindowChanged, WindowRemoved and nclude the window as an argument. This gives us the necessary information to tracked each window changed, rather than requiring continuous calls to GetWindows (returning all windows). The main consumer of the shell-introspect signals is xdg-desktop-portal-gnome, so an API break seems reasonable, rather than introducing a new API. See: https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/merge_requests/93 --- .../org.gnome.Shell.Introspect.xml | 23 +++++++++++++++---- js/misc/introspect.js | 20 +++++++++++++++- src/shell-window-tracker.c | 16 +++++++++---- src/shell-window-tracker.h | 6 +++++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/data/dbus-interfaces/org.gnome.Shell.Introspect.xml b/data/dbus-interfaces/org.gnome.Shell.Introspect.xml index cb19cfec5..875e3facc 100644 --- a/data/dbus-interfaces/org.gnome.Shell.Introspect.xml +++ b/data/dbus-interfaces/org.gnome.Shell.Introspect.xml @@ -19,11 +19,26 @@ - - + + + + + + + + + + +