[sushi: 1/2] Add NautilusPreviewer2 DBus interface
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi: 1/2] Add NautilusPreviewer2 DBus interface
- Date: Tue, 27 Aug 2019 09:36:52 +0000 (UTC)
commit 9c902eb99c385aa16fdefa3ec059ea45aebf93d5
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Jul 2 20:18:10 2019 -0700
Add NautilusPreviewer2 DBus interface
This is necessary in order to set our window as transient on the
Nautilus one on Wayland.
We keep support for the v1 interface around as well, in case people may
run a new Sushi with an old Nautilus.
https://gitlab.gnome.org/GNOME/sushi/issues/1
src/org.gnome.NautilusPreviewer.data.gresource.xml | 1 +
src/org.gnome.NautilusPreviewer2.xml | 11 ++++
src/ui/application.js | 71 +++++++++++++++++-----
src/ui/mainWindow.js | 3 +-
4 files changed, 70 insertions(+), 16 deletions(-)
---
diff --git a/src/org.gnome.NautilusPreviewer.data.gresource.xml
b/src/org.gnome.NautilusPreviewer.data.gresource.xml
index e4ef400..134eec3 100644
--- a/src/org.gnome.NautilusPreviewer.data.gresource.xml
+++ b/src/org.gnome.NautilusPreviewer.data.gresource.xml
@@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/NautilusPreviewer">
<file>org.gnome.NautilusPreviewer.xml</file>
+ <file>org.gnome.NautilusPreviewer2.xml</file>
</gresource>
</gresources>
diff --git a/src/org.gnome.NautilusPreviewer2.xml b/src/org.gnome.NautilusPreviewer2.xml
new file mode 100644
index 0000000..41d79de
--- /dev/null
+++ b/src/org.gnome.NautilusPreviewer2.xml
@@ -0,0 +1,11 @@
+<node>
+ <interface name="org.gnome.NautilusPreviewer2">
+ <method name="ShowFile">
+ <arg type="s" direction="in" name="uri" />
+ <arg type="s" direction="in" name="windowHandle" />
+ <arg type="b" direction="in" name="closeIfAlreadyShown" />
+ </method>
+ <method name="Close">
+ </method>
+ </interface>
+</node>
diff --git a/src/ui/application.js b/src/ui/application.js
index a867384..90ce116 100644
--- a/src/ui/application.js
+++ b/src/ui/application.js
@@ -29,31 +29,74 @@ const ByteArray = imports.byteArray;
const MainWindow = imports.ui.mainWindow;
-var Application = GObject.registerClass(class Application extends Gtk.Application {
- vfunc_startup() {
- super.vfunc_startup();
-
- this._defineStyleAndThemes();
- }
+var NautilusPreviewerSkeleton = class {
+ constructor(application, resource) {
+ this.application = application;
- vfunc_dbus_register(connection, path) {
- let bytes = Gio.resources_lookup_data(
- '/org/gnome/NautilusPreviewer/org.gnome.NautilusPreviewer.xml', 0);
+ let bytes = Gio.resources_lookup_data(resource, 0);
this._skeleton = Gio.DBusExportedObject.wrapJSObject(
ByteArray.toString(bytes.toArray()), this);
+ }
+ export(connection, path) {
try {
this._skeleton.export(connection, path);
} catch (e) {
logError(e, 'Failed to export NautilusPreviewer DBus interface');
}
+ }
+
+ unexport(connection) {
+ if (this._skeleton && this._skeleton.has_connection(connection))
+ this._skeleton.unexport_from_connection(connection);
+ }
+
+ Close() {
+ this.application.close();
+ }
+}
+
+var NautilusPreviewer1Skeleton = class extends NautilusPreviewerSkeleton {
+ constructor(application) {
+ super(application, '/org/gnome/NautilusPreviewer/org.gnome.NautilusPreviewer.xml');
+ }
+
+ ShowFile(uri, xid, closeIfAlreadyShown) {
+ let handle = 'x11:%d'.format(xid);
+ this.application.showFile(uri, handle, closeIfAlreadyShown);
+ }
+}
+
+var NautilusPreviewer2Skeleton = class extends NautilusPreviewerSkeleton {
+ constructor(application) {
+ super(application, '/org/gnome/NautilusPreviewer/org.gnome.NautilusPreviewer2.xml');
+ }
+
+ ShowFile(uri, windowHandle, closeIfAlreadyShown) {
+ this.application.showFile(uri, windowHandle, closeIfAlreadyShown);
+ }
+}
+
+var Application = GObject.registerClass(class Application extends Gtk.Application {
+ vfunc_startup() {
+ super.vfunc_startup();
+
+ this._defineStyleAndThemes();
+ }
+
+ vfunc_dbus_register(connection, path) {
+ this._skeleton = new NautilusPreviewer1Skeleton(this);
+ this._skeleton2 = new NautilusPreviewer2Skeleton(this);
+
+ this._skeleton.export(connection, path);
+ this._skeleton2.export(connection, path);
return super.vfunc_dbus_register(connection, path);
}
vfunc_dbus_unregister(connection, path) {
- if (this._skeleton && this._skeleton.has_connection(connection))
- this._skeleton.unexport_from_connection(connection);
+ this._skeleton.unexport(connection);
+ this._skeleton2.unexport(connection);
return super.vfunc_dbus_unregister(connection, path);
}
@@ -76,12 +119,12 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
settings.gtk_application_prefer_dark_theme = true;
}
- Close() {
+ close() {
if (this._mainWindow)
this._mainWindow.destroy();
}
- ShowFile(uri, xid, closeIfAlreadyShown) {
+ showFile(uri, windowHandle, closeIfAlreadyShown) {
this._ensureMainWindow();
let file = Gio.file_new_for_uri(uri);
@@ -90,7 +133,7 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
this._mainWindow.file.equal(file)) {
this._mainWindow.destroy();
} else {
- this._mainWindow.setParent(xid);
+ this._mainWindow.setParent(windowHandle);
this._mainWindow.setFile(file);
}
}
diff --git a/src/ui/mainWindow.js b/src/ui/mainWindow.js
index e18632f..530bb5e 100644
--- a/src/ui/mainWindow.js
+++ b/src/ui/mainWindow.js
@@ -358,8 +358,7 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.ApplicationW
/**************************************************************************
************************ public methods **********************************
**************************************************************************/
- setParent(xid) {
- let handle = 'x11:%d'.format(xid);
+ setParent(handle) {
Sushi.window_set_child_of_external(this, handle);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]