From 0a1c0bdf3a49433f827ca7c7c94da3212dd1165f Mon Sep 17 00:00:00 2001 From: Leonhard Date: Fri, 5 Apr 2024 00:11:20 +0200 Subject: [PATCH] Move desktopintegration into own file --- src/Background/Portal.vala | 32 ++++++-------------------------- src/DesktopIntegration.vala | 36 ++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + 3 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 src/DesktopIntegration.vala diff --git a/src/Background/Portal.vala b/src/Background/Portal.vala index 58a1f55d..0e269bad 100644 --- a/src/Background/Portal.vala +++ b/src/Background/Portal.vala @@ -3,21 +3,6 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -[DBus (name = "org.pantheon.gala.DesktopIntegration")] -private interface Gala.DesktopIntegration : Object { - public signal void running_applications_changed (); - - public const string NAME = "org.pantheon.gala"; - public const string PATH = "/org/pantheon/gala/DesktopInterface"; - - public struct RunningApplications { - string app_id; - HashTable details; - } - - public abstract async RunningApplications[] get_running_applications () throws DBusError, IOError; -} - [DBus (name = "org.freedesktop.impl.portal.Background")] public class Background.Portal : Object { public signal void running_applications_changed (); @@ -28,18 +13,13 @@ public class Background.Portal : Object { public Portal (DBusConnection connection) { this.connection = connection; - connection.get_proxy.begin ( - Gala.DesktopIntegration.NAME, - Gala.DesktopIntegration.PATH, - NONE, null, (obj, res) => { - try { - desktop_integration = connection.get_proxy.end (res); - desktop_integration.running_applications_changed.connect (() => running_applications_changed ()); - } catch { - warning ("Cannot connect to compositor, portal working with reduced functionality."); - } + Gala.DesktopIntegration.get_instance.begin ((obj, res) => { + desktop_integration = Gala.DesktopIntegration.get_instance.end (res); + + if (desktop_integration != null) { + desktop_integration.running_applications_changed.connect (() => running_applications_changed ()); } - ); + }); } [CCode (type_signature = "u")] diff --git a/src/DesktopIntegration.vala b/src/DesktopIntegration.vala new file mode 100644 index 00000000..a999fe82 --- /dev/null +++ b/src/DesktopIntegration.vala @@ -0,0 +1,36 @@ +[DBus (name = "org.pantheon.gala.DesktopIntegration")] +public interface Gala.DesktopIntegration : Object { + public struct RunningApplications { + string app_id; + HashTable details; + } + + public struct Window { + uint64 uid; + HashTable details; + } + + private const string NAME = "org.pantheon.gala"; + private const string PATH = "/org/pantheon/gala/DesktopInterface"; + + public signal void running_applications_changed (); + + public abstract async RunningApplications[] get_running_applications () throws DBusError, IOError; + public abstract async Window[] get_windows () throws DBusError, IOError; + + private static Gala.DesktopIntegration? instance; + + public static async Gala.DesktopIntegration? get_instance () { + if (instance != null) { + return instance; + } + + try { + instance = yield Bus.get_proxy (SESSION, NAME, PATH); + } catch (Error e) { + warning ("Cannot connect to compositor, portal working with reduced functionality."); + } + + return instance; + } +} \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 90d99bc0..a7503717 100644 --- a/src/meson.build +++ b/src/meson.build @@ -17,6 +17,7 @@ executable( 'ScreenCast/Session.vala', 'Wallpaper/Portal.vala', configure_file(input: 'Config.vala.in', output: '@BASENAME@', configuration: conf_data), + 'DesktopIntegration.vala', 'ExternalWindow.vala', 'XdgDesktopPortalPantheon.vala', dependencies: [