Skip to content

Commit

Permalink
Move desktopintegration into own file
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Apr 4, 2024
1 parent f0930e6 commit 0a1c0bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/Background/Portal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,Variant> 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 ();
Expand All @@ -28,18 +13,13 @@ public class Background.Portal : Object {
public Portal (DBusConnection connection) {
this.connection = connection;

connection.get_proxy.begin<Gala.DesktopIntegration> (
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")]
Expand Down
36 changes: 36 additions & 0 deletions src/DesktopIntegration.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[DBus (name = "org.pantheon.gala.DesktopIntegration")]
public interface Gala.DesktopIntegration : Object {
public struct RunningApplications {
string app_id;
HashTable<string, Variant> details;
}

public struct Window {
uint64 uid;
HashTable<string, Variant> 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;
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 0a1c0bd

Please sign in to comment.