Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2018-01-26 14:33:23 -0500
committerLeo Ufimtsev2018-01-26 15:38:45 -0500
commite1810e11b59acc83c8b0dc376540d361c667fc82 (patch)
tree511bd2a5dcef6d5ce52aaac116f025b0343a10b2
parent3f989c6347191e1555c2f903ec7acdf1a9218d90 (diff)
downloadeclipse.platform.swt-e1810e11b59acc83c8b0dc376540d361c667fc82.tar.gz
eclipse.platform.swt-e1810e11b59acc83c8b0dc376540d361c667fc82.tar.xz
eclipse.platform.swt-e1810e11b59acc83c8b0dc376540d361c667fc82.zip
Bug 530397 – [Gtk] Make gdbus initialization dynamic
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=530397 Change-Id: Ia99129ce35b8e190402abea3a2eb75d668e8c825 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java90
-rw-r--r--tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java11
4 files changed, 56 insertions, 58 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 959aa999a8..8930c19657 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -106,20 +106,13 @@ public class OS extends C {
}
}
- public static final String GDBUS_SYSTEM_PROPERTY = "swt.dbus.init";
-
// Bug 519124
static {
String swt_lib_versions = getEnvironmentalVariable (OS.SWT_LIB_VERSIONS); // Note, this is read in multiple places.
if (swt_lib_versions != null && swt_lib_versions.equals("1")) {
System.out.print("SWT_LIB_Gtk:"+gtk_major_version()+"."+gtk_minor_version()+"."+gtk_micro_version());
- if (System.getProperty(GDBUS_SYSTEM_PROPERTY) != null) {
- System.out.print(" (DBus enabled)");
- System.out.print(" (OpenUrl/OpenDocument supported)");
- } else {
- System.out.print(" (DBus dissabled)");
- }
- System.out.print("\n");
+ System.out.print(" (Dynamic gdbus)");
+ System.out.println("");
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java
index e1bd5bd8c0..783a5fab48 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java
@@ -44,7 +44,7 @@ import org.eclipse.swt.internal.gtk.*;
*/
public class GDBus {
- final static String SWT_GDBUS_VERSION_INFO = "SWT_LIB GDbus firing up. Implementation v1.4";
+ final static String SWT_GDBUS_VERSION_INFO = "SWT_LIB GDbus firing up. Implementation v1.5";
public static class GDBusMethod {
final private String name;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 7e8ac7db00..c2e67213aa 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -695,9 +695,55 @@ public void addListener (int eventType, Listener listener) {
checkDevice ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) eventTable = new EventTable ();
+ if (eventType == SWT.OpenDocument || eventType == SWT.OpenUrl) {
+ gdbus_init_methods();
+ }
eventTable.hook (eventType, listener);
}
+/**
+ * Handle gdbus on 'org.eclipse.swt' DBus session.
+ * E.g equinox launcher passes files/urls to SWT via gdbus. "./eclipse myFile" or "./eclipse http://www.google.com"
+ *
+ * Only one SWT instance can hold the unique and well-known name at one time, so we have to be mindful
+ * of the case where an SWT app could steal the well-known name and make the equinox launcher confused.
+ *
+ * For equinox launcher, See eclipseGtk.c:gtkPlatformJavaSystemProperties
+ */
+private void gdbus_init_methods() {
+ GDBusMethod[] methods = {
+ new GDBusMethod(
+ // FileOpen call can be reached via:
+ // gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.FileOpen "['/tmp/hi','http://www.eclipse.org']"
+ // See Bug525305_Browser_OpenUrl.java test snippet for testing/verification.
+ // In a child eclipse, this will open the files in a new editor.
+ // This is reached by equinox launcher from eclipseGtk.c. Look for "g_dbus_proxy_call_sync"
+ "FileOpen",
+ new String [][] {{OS.DBUS_TYPE_STRING_ARRAY,"A String array containing file paths or URLs for OpenDocument/OpenUrl signal"}},
+ new String [0][0],
+ (args) -> {
+ String[] fileNames = (String[]) args[0];
+ for (int i = 0; i < fileNames.length; i++) {
+ Event event = new Event ();
+ event.text = fileNames[i];
+ try {
+ if (new URI (fileNames[i]).getScheme() != null) { // For specs, see: https://docs.oracle.com/javase/8/docs/api/java/net/URI.html
+ // E.g: eclipse http://www.google.com
+ sendEvent (SWT.OpenUrl, event);
+ } else {
+ throw new URISyntaxException(fileNames[i], "Not a valid Url. Probably file.");
+ }
+ } catch (URISyntaxException e) {
+ // E.g eclipse /tmp/myfile (absolute) or eclipse myfile (relative)
+ sendEvent (SWT.OpenDocument, event);
+ }
+ }
+ return null;
+ })
+ };
+ GDBus.init(methods);
+}
+
long /*int*/ allChildrenProc (long /*int*/ widget, long /*int*/ recurse) {
allChildren = OS.g_list_append (allChildren, widget);
if (recurse != 0 && OS.GTK_IS_CONTAINER (widget)) {
@@ -1105,50 +1151,6 @@ void createDisplay (DeviceData data) {
keysChangedProc = keysChangedCallback.getAddress ();
if (keysChangedProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
OS.g_signal_connect (OS.gdk_keymap_get_default (), OS.keys_changed, keysChangedProc, 0);
-
-
- // Handle gdbus on 'org.eclipse.swt' DBus session.
- // E.g equinox launcher passes files/urls to SWT via gdbus. "./eclipse myFile" or "./eclipse http://www.google.com"
- //
- // Only one SWT instance can hold the unique and well-known name at one time, so we have to be mindful
- // of the case where an SWT app could steal the well-known name and make the equinox launcher confused.
- // We only initiate GDBus if system property is set.
- //
- // To force enable this, in a run-configuration, under arguments, append to the "VM arguments" : -Dswt.dbus.init
- // For equinox launcher, See eclipseGtk.c:gtkPlatformJavaSystemProperties
- if (System.getProperty(OS.GDBUS_SYSTEM_PROPERTY) != null) {
- GDBusMethod[] methods = {
- new GDBusMethod(
- // FileOpen call can be reached via:
- // gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.FileOpen "['/tmp/hi','/tmp/there']"
- // In a child eclipse, this will open the files in a new editor.
- // This is reached by equinox launcher from eclipseGtk.c. Look for "g_dbus_proxy_call_sync"
- "FileOpen",
- new String [][] {{OS.DBUS_TYPE_STRING_ARRAY,"A String array containing file paths or URLs for OpenDocument/OpenUrl signal"}},
- new String [0][0],
- (args) -> {
- String[] fileNames = (String[]) args[0];
- for (int i = 0; i < fileNames.length; i++) {
- Event event = new Event ();
- event.text = fileNames[i];
- try {
- if (new URI (fileNames[i]).getScheme() != null) { // For specs, see: https://docs.oracle.com/javase/8/docs/api/java/net/URI.html
- // E.g: eclipse http://www.google.com
- sendEvent (SWT.OpenUrl, event);
- } else {
- throw new URISyntaxException(fileNames[i], "Not a valid Url. Probably file.");
- }
- } catch (URISyntaxException e) {
- // E.g eclipse /tmp/myfile (absolute) or eclipse myfile (relative)
- sendEvent (SWT.OpenDocument, event);
-
- }
- }
- return null;
- })
- };
- GDBus.init(methods);
- }
}
/**
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java
index 261582c0f7..e1e8f52d6c 100644
--- a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java
+++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug525305_Browser_OpenUrl.java
@@ -8,10 +8,13 @@ import org.eclipse.swt.widgets.Shell;
/*
* Title: Handle files or URLs from eclipse launcher or gdbus.
- * How to run:
- - Open snippet with Launch Configuration VM Argument: -Dswt.dbus.init
- - Run launcher with file or url
- eclipse /myFile htpp://www.google.com
+ * How to run:
+ * - Launch snippet.
+ * - In terminal, run like:
+ * gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.FileOpen "['/tmp/hi','http://www.eclipse.org']"
+ * - Expect output:
+ * "OpenUrl with .. "
+ * "OpenDocument with .. "
* Bug description:
* Expected results: Browser opens URLs, filenames printed.
* GTK Version(s): 3.22/2.24

Back to the top