2019-01-31 14:07:06 +00:00
|
|
|
/* exported IntrospectService */
|
2023-06-08 04:52:46 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2018-09-05 09:15:30 +00:00
|
|
|
|
2021-06-21 19:32:50 +00:00
|
|
|
const APP_ALLOWLIST = [
|
|
|
|
'org.freedesktop.impl.portal.desktop.gtk',
|
|
|
|
'org.freedesktop.impl.portal.desktop.gnome',
|
|
|
|
];
|
2018-09-05 09:15:30 +00:00
|
|
|
|
2020-07-22 16:38:22 +00:00
|
|
|
const INTROSPECT_DBUS_API_VERSION = 3;
|
2019-10-01 10:07:03 +00:00
|
|
|
|
2018-09-05 09:15:30 +00:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
2021-06-16 17:09:42 +00:00
|
|
|
const { DBusSenderChecker } = imports.misc.util;
|
2018-09-05 09:15:30 +00:00
|
|
|
|
|
|
|
const IntrospectDBusIface = loadInterfaceXML('org.gnome.Shell.Introspect');
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var IntrospectService = class {
|
|
|
|
constructor() {
|
2018-09-05 09:15:30 +00:00
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(IntrospectDBusIface,
|
|
|
|
this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell/Introspect');
|
|
|
|
Gio.DBus.session.own_name('org.gnome.Shell.Introspect',
|
|
|
|
Gio.BusNameOwnerFlags.REPLACE,
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
this._runningApplications = {};
|
|
|
|
this._runningApplicationsDirty = true;
|
|
|
|
this._activeApplication = null;
|
|
|
|
this._activeApplicationDirty = true;
|
2019-10-01 10:07:03 +00:00
|
|
|
this._animationsEnabled = true;
|
2018-09-05 09:15:30 +00:00
|
|
|
|
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
|
|
|
this._appSystem.connect('app-state-changed',
|
|
|
|
() => {
|
|
|
|
this._runningApplicationsDirty = true;
|
|
|
|
this._syncRunningApplications();
|
|
|
|
});
|
|
|
|
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
tracker.connect('notify::focus-app',
|
|
|
|
() => {
|
|
|
|
this._activeApplicationDirty = true;
|
|
|
|
this._syncRunningApplications();
|
|
|
|
});
|
|
|
|
|
2022-03-06 18:32:48 +00:00
|
|
|
tracker.connect('tracked-windows-changed',
|
|
|
|
() => this._dbusImpl.emit_signal('WindowsChanged', null));
|
|
|
|
|
2018-09-05 09:15:30 +00:00
|
|
|
this._syncRunningApplications();
|
2019-11-25 18:44:10 +00:00
|
|
|
|
2021-06-16 17:09:42 +00:00
|
|
|
this._senderChecker = new DBusSenderChecker(APP_ALLOWLIST);
|
2019-10-01 10:07:03 +00:00
|
|
|
|
|
|
|
this._settings = St.Settings.get();
|
|
|
|
this._settings.connect('notify::enable-animations',
|
|
|
|
this._syncAnimationsEnabled.bind(this));
|
|
|
|
this._syncAnimationsEnabled();
|
2020-07-22 16:38:22 +00:00
|
|
|
|
2022-09-07 18:24:44 +00:00
|
|
|
const monitorManager = global.backend.get_monitor_manager();
|
2020-07-22 16:38:22 +00:00
|
|
|
monitorManager.connect('monitors-changed',
|
|
|
|
this._syncScreenSize.bind(this));
|
|
|
|
this._syncScreenSize();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-09-05 09:15:30 +00:00
|
|
|
|
|
|
|
_isStandaloneApp(app) {
|
|
|
|
return app.get_windows().some(w => w.transient_for == null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-09-05 09:15:30 +00:00
|
|
|
|
2019-05-15 22:57:27 +00:00
|
|
|
_getSandboxedAppId(app) {
|
|
|
|
let ids = app.get_windows().map(w => w.get_sandboxed_app_id());
|
|
|
|
return ids.find(id => id != null);
|
|
|
|
}
|
|
|
|
|
2018-09-05 09:15:30 +00:00
|
|
|
_syncRunningApplications() {
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
let apps = this._appSystem.get_running();
|
|
|
|
let seatName = "seat0";
|
|
|
|
let newRunningApplications = {};
|
|
|
|
|
|
|
|
let newActiveApplication = null;
|
|
|
|
let focusedApp = tracker.focus_app;
|
|
|
|
|
|
|
|
for (let app of apps) {
|
|
|
|
let appInfo = {};
|
2019-08-19 19:38:51 +00:00
|
|
|
let isAppActive = focusedApp == app;
|
2018-09-05 09:15:30 +00:00
|
|
|
|
|
|
|
if (!this._isStandaloneApp(app))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (isAppActive) {
|
|
|
|
appInfo['active-on-seats'] = new GLib.Variant('as', [seatName]);
|
|
|
|
newActiveApplication = app.get_id();
|
|
|
|
}
|
|
|
|
|
2019-05-15 22:57:27 +00:00
|
|
|
let sandboxedAppId = this._getSandboxedAppId(app);
|
|
|
|
if (sandboxedAppId)
|
|
|
|
appInfo['sandboxed-app-id'] = new GLib.Variant('s', sandboxedAppId);
|
|
|
|
|
2018-09-05 09:15:30 +00:00
|
|
|
newRunningApplications[app.get_id()] = appInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._runningApplicationsDirty ||
|
|
|
|
(this._activeApplicationDirty &&
|
|
|
|
this._activeApplication != newActiveApplication)) {
|
|
|
|
this._runningApplications = newRunningApplications;
|
|
|
|
this._activeApplication = newActiveApplication;
|
|
|
|
|
|
|
|
this._dbusImpl.emit_signal('RunningApplicationsChanged', null);
|
|
|
|
}
|
|
|
|
this._runningApplicationsDirty = false;
|
|
|
|
this._activeApplicationDirty = false;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-09-05 09:15:30 +00:00
|
|
|
|
2018-12-12 15:02:29 +00:00
|
|
|
_isEligibleWindow(window) {
|
|
|
|
if (window.is_override_redirect())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let type = window.get_window_type();
|
2019-08-19 19:38:51 +00:00
|
|
|
return type == Meta.WindowType.NORMAL ||
|
2018-12-12 15:02:29 +00:00
|
|
|
type == Meta.WindowType.DIALOG ||
|
|
|
|
type == Meta.WindowType.MODAL_DIALOG ||
|
2019-08-19 19:38:51 +00:00
|
|
|
type == Meta.WindowType.UTILITY;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-12-12 15:02:29 +00:00
|
|
|
|
2021-11-23 01:48:04 +00:00
|
|
|
async GetRunningApplicationsAsync(params, invocation) {
|
2021-09-02 14:23:38 +00:00
|
|
|
try {
|
2021-11-23 01:48:04 +00:00
|
|
|
await this._senderChecker.checkInvocation(invocation);
|
2021-09-02 14:23:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
invocation.return_gerror(e);
|
2018-09-05 09:15:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
invocation.return_value(new GLib.Variant('(a{sa{sv}})', [this._runningApplications]));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-12-12 15:02:29 +00:00
|
|
|
|
2021-11-23 01:48:04 +00:00
|
|
|
async GetWindowsAsync(params, invocation) {
|
2018-12-12 15:02:29 +00:00
|
|
|
let focusWindow = global.display.get_focus_window();
|
|
|
|
let apps = this._appSystem.get_running();
|
|
|
|
let windowsList = {};
|
|
|
|
|
2021-09-02 14:23:38 +00:00
|
|
|
try {
|
2021-11-23 01:48:04 +00:00
|
|
|
await this._senderChecker.checkInvocation(invocation);
|
2021-09-02 14:23:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
invocation.return_gerror(e);
|
2018-12-12 15:02:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let app of apps) {
|
|
|
|
let windows = app.get_windows();
|
|
|
|
for (let window of windows) {
|
|
|
|
if (!this._isEligibleWindow(window))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let windowId = window.get_id();
|
|
|
|
let frameRect = window.get_frame_rect();
|
|
|
|
let title = window.get_title();
|
|
|
|
let wmClass = window.get_wm_class();
|
2019-05-15 22:57:27 +00:00
|
|
|
let sandboxedAppId = window.get_sandboxed_app_id();
|
2018-12-12 15:02:29 +00:00
|
|
|
|
|
|
|
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()),
|
2019-08-19 19:38:51 +00:00
|
|
|
'has-focus': GLib.Variant.new('b', window == focusWindow),
|
2018-12-12 15:02:29 +00:00
|
|
|
'width': GLib.Variant.new('u', frameRect.width),
|
2019-08-20 21:43:54 +00:00
|
|
|
'height': GLib.Variant.new('u', frameRect.height),
|
2018-12-12 15:02:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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);
|
2019-05-15 22:57:27 +00:00
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (sandboxedAppId != null) {
|
2019-05-15 22:57:27 +00:00
|
|
|
windowsList[windowId]['sandboxed-app-id'] =
|
|
|
|
GLib.Variant.new('s', sandboxedAppId);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2018-12-12 15:02:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
invocation.return_value(new GLib.Variant('(a{ta{sv}})', [windowsList]));
|
2018-09-05 09:15:30 +00:00
|
|
|
}
|
2019-10-01 10:07:03 +00:00
|
|
|
|
|
|
|
_syncAnimationsEnabled() {
|
|
|
|
let wasAnimationsEnabled = this._animationsEnabled;
|
|
|
|
this._animationsEnabled = this._settings.enable_animations;
|
|
|
|
if (wasAnimationsEnabled !== this._animationsEnabled) {
|
|
|
|
let variant = new GLib.Variant('b', this._animationsEnabled);
|
|
|
|
this._dbusImpl.emit_property_changed('AnimationsEnabled', variant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 16:38:22 +00:00
|
|
|
_syncScreenSize() {
|
|
|
|
const oldScreenWidth = this._screenWidth;
|
|
|
|
const oldScreenHeight = this._screenHeight;
|
|
|
|
this._screenWidth = global.screen_width;
|
|
|
|
this._screenHeight = global.screen_height;
|
|
|
|
|
|
|
|
if (oldScreenWidth !== this._screenWidth ||
|
|
|
|
oldScreenHeight !== this._screenHeight) {
|
|
|
|
const variant = new GLib.Variant('(ii)',
|
|
|
|
[this._screenWidth, this._screenHeight]);
|
|
|
|
this._dbusImpl.emit_property_changed('ScreenSize', variant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 10:07:03 +00:00
|
|
|
get AnimationsEnabled() {
|
|
|
|
return this._animationsEnabled;
|
|
|
|
}
|
|
|
|
|
2020-07-22 16:38:22 +00:00
|
|
|
get ScreenSize() {
|
|
|
|
return [this._screenWidth, this._screenHeight];
|
|
|
|
}
|
|
|
|
|
2019-10-01 10:07:03 +00:00
|
|
|
get version() {
|
|
|
|
return INTROSPECT_DBUS_API_VERSION;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|