Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2018-01-11 15:35:23 +0000
committerAlexander Kurtakov2018-01-11 16:22:44 +0000
commit70bc724bdc4e8386426bb111135ed74b336c4fae (patch)
tree4cd19d8e190833c7a9141131bba373ff7ffe6847
parent347b260b2e3c486cce58494c342e335efb847edd (diff)
downloadeclipse.platform.swt-70bc724bdc4e8386426bb111135ed74b336c4fae.tar.gz
eclipse.platform.swt-70bc724bdc4e8386426bb111135ed74b336c4fae.tar.xz
eclipse.platform.swt-70bc724bdc4e8386426bb111135ed74b336c4fae.zip
Bug 528414 (swtWaylandLauncher) Part 1 SWT GDBus implementation.
General purpose GDBus interface for converting GDBus calls to SWT events. Adding SWT.OpenDocument event handler. To verify: 1) Open child eclipse. 2) Create files: /tmp/hi and /tmp/hithere 3) Run command: gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.FileOpen "['/tmp/hi','/tmp/there']" The two files 'hi' and 'hithere' open in the child eclipse. - If you open two (or more) Eclipse instances, the most recently opened Eclipse will receive gdbus call. - If you close the 2nd eclipse, the previous (first) eclipse receives gdbus calls again. Future improvement: The most-recently *focused* eclipse should receive gdbus call. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=528414 Change-Id: Ib1fbbb09b74de4025611f68813ca53e6c62250b7 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 WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java366
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java31
4 files changed, 409 insertions, 5 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 09c5a4a856..3ee5f4dc0b 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
@@ -108,12 +108,14 @@ public class OS extends C {
// Bug 519124
static {
- String swt_lib_versions = getEnvironmentalVariable ("SWT_LIB_VERSIONS"); // Note, this is read in multiple places.
+ 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.println("SWT_LIB_Gtk:"+gtk_major_version()+"."+gtk_minor_version()+"."+gtk_micro_version());
}
}
+ public static final String SWT_LIB_VERSIONS = "SWT_LIB_VERSIONS";
+
public static String getEnvironmentalVariable (String envVarName) {
String envVarValue = null;
long /*int*/ ptr = C.getenv(ascii(envVarName));
@@ -573,13 +575,18 @@ public class OS extends C {
/**
* DBus Data types as defined by:
* https://dbus.freedesktop.org/doc/dbus-specification.html#idm423
+ * If using these, make sure they're properly handled in all GDBus code. Only some of these are supported by some GDBus classes.
* @category gdbus */
public static final String DBUS_TYPE_BYTE = "y"; // 8 bit, unsigned int.
/** @category gdbus */
public static final String DBUS_TYPE_BOOLEAN = "b";
/** @category gdbus */
+ public static final String DBUS_TYPE_ARRAY = "a";
+ /** @category gdbus */
public static final String DBUS_TYPE_STRING = "s";
/** @category gdbus */
+ public static final String DBUS_TYPE_STRING_ARRAY = "as";
+ /** @category gdbus */
public static final String DBUS_TYPE_DOUBLE = "d";
/** @category gdbus */
public static final String DBUS_TYPE_STRUCT = "r"; // Not used by Dbus, but implemented by GDBus.
@@ -597,6 +604,8 @@ public class OS extends C {
/** @category gdbus */
public static final byte[] G_VARIANT_TYPE_BOOLEAN = ascii(DBUS_TYPE_BOOLEAN);
/** @category gdbus */
+ public static final byte[] G_VARIANT_TYPE_STRING_ARRAY = ascii(DBUS_TYPE_STRING_ARRAY);
+ /** @category gdbus */
public static final byte[] G_VARIANT_TYPE_STRING = ascii(DBUS_TYPE_STRING);
/** @category gdbus */
public static final byte[] G_VARIANT_TYPE_DOUBLE = ascii(DBUS_TYPE_DOUBLE);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java
index 7f3e23dbfe..d8a8912168 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2000, 2018 IBM Corporation and others. All rights reserved.
* The contents of this file are made available under the terms
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -29,7 +29,7 @@ public class WebKitGTK extends C {
* Internal version of "Webkit glue code", used mainly during webkit2 port.
* Used to make it easier to support users on bugzilla. Updated by hand.
*/
- public static final String swtWebkitGlueCodeVersion = " SWT Glue code version: 53.0";
+ public static final String swtWebkitGlueCodeVersion = " SWT Glue code version: 54.0";
public static final String swtWebkitGlueCodeVersionInfo = " info: +BrowserFunction/GDBus, +WebkitExtension Folder versioning, +WebKitExtension OSGI support, +setUrl(..postData..), -setCookie(), -getCookie +mouseDown/Focus";
@@ -55,7 +55,7 @@ public class WebKitGTK extends C {
WEBKIT1 = !WEBKIT2;
}
- String swt_lib_versions = OS.getEnvironmentalVariable ("SWT_LIB_VERSIONS"); // Note, this is read in multiple places.
+ String swt_lib_versions = OS.getEnvironmentalVariable (OS.SWT_LIB_VERSIONS); // Note, this is read in multiple places.
if (swt_lib_versions != null && swt_lib_versions.equals("1")) {
if (WEBKIT1) {
System.out.println("SWT_LIB Webkit1 Webkitgtk:"+ webkit_major_version() +"."+ webkit_minor_version() + "." + webkit_micro_version() + " (webkitgtk < 2.5 is Webkit1)");
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
new file mode 100644
index 0000000000..21bbf2f99c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java
@@ -0,0 +1,366 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.internal;
+
+import java.util.*;
+import java.util.function.*;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.gtk.*;
+
+/**
+ * General purpose DBus interface for SWT to interact with the operating system and vice versa.
+ * (See also WebkitGDBus for the webkit specific gdbus interface).
+ *
+ * This implementation uses GDBus (Gnome DBus) to implement the DBus interface.
+ *
+ * It can be reached via:
+ * gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.YOUR_METHOD YOUR_ARGS
+ * where YOUR_ARGS can be something like "MyString" or "['/tmp/myFile', '/tmp/myFile2']" etc..
+
+ * For hygiene purposes, GVariant/GDBus native types/values should *never* leave this class. Convert on the way in/out.
+ *
+ * Technical notes:
+ * - Concurrent gdbus names can co-exist. (i.e, multiple session names in single proc).
+ * Meaning if you don't like org.eclipse.swt, you can add more session names.
+ * - This implementation is only a small subset of GDBus.
+ * E.g not all types are translated and not functionality implemented. Add them as you need them.
+ *
+ * @category gdbus
+ */
+public class GDBus {
+
+ public static class GDBusMethod {
+ final private String name;
+ final private Function<Object[], Object[]> userFunction;
+ final private String methodArgsXmlSignature;
+
+ /**
+ * Create a method that GDBus will listen to.
+ *
+ * @param name of the method. It will be part of 'org.eclipse.swt.NAME'
+ * @param inputArgs 2D array pair of Strings : (DBUS_TYPE_*, argument_name). Where argument_name is only so that it's seen by command line by user.
+ * @param outputArgs Same as inputArgs, but for returning values.
+ * @param userFunction A Function<Object[],Object[]>, that you would like to run when the user calls the method over gdbus.
+ */
+ public GDBusMethod(String name, String [][] inputArgs, String [][] outputArgs, Function<Object[], Object[]> userFunction) {
+ this.name = name;
+ this.userFunction = userFunction;
+ StringBuilder gdbBusArgsXml = new StringBuilder();
+ for (String [] dataType : inputArgs) {
+ gdbBusArgsXml.append(" <arg type='" + dataType[0] + "' name='" + dataType[1] + "' direction='in'/>\n");
+ }
+ for (String [] dataType : outputArgs) { // I haven't tested output args, but should work if types get converted properly.
+ gdbBusArgsXml.append(" <arg type='" + dataType[0] + "' name='" + dataType[1] + "' direction='out'/>\n");
+ }
+ methodArgsXmlSignature = gdbBusArgsXml.toString();
+ }
+
+ private String getName() {
+ return name;
+ }
+
+ private Function<Object[], Object[]> getUserFunction() {
+ return userFunction;
+ }
+
+ private String getMethodArgsXmlSignature() {
+ return methodArgsXmlSignature;
+ }
+ }
+
+ public static void init (GDBusMethod[] methods) {
+ if (!initialized)
+ initialized = true;
+ else
+ return;
+
+ if (methods == null || methods.length == 0) {
+ System.err.println("SWT Error, no gdbus methods to initialize.");
+ return;
+ }
+
+ gdbusMethods = Arrays.asList(methods);
+
+ int owner_id = OS.g_bus_own_name(OS.G_BUS_TYPE_SESSION,
+ Converter.javaStringToCString(DBUS_SERVICE_NAME),
+ OS.G_BUS_NAME_OWNER_FLAGS_REPLACE | OS.G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, // Allow name to be used by other eclipse instances.
+ onBusAcquired.getAddress(),
+ onNameAcquired.getAddress(), // name_acquired_handler
+ onNameLost.getAddress(), // name_lost_handler
+ 0, // user_data
+ 0); // user_data_free_func
+
+ if (owner_id == 0) {
+ System.err.println("SWT GDBus: Failed to aquire bus name: " + DBUS_SERVICE_NAME);
+ }
+ }
+
+ private static boolean initialized;
+ private static List<GDBusMethod> gdbusMethods;
+
+ private static final String DBUS_SERVICE_NAME = "org.eclipse.swt";
+ private static final String DBUS_OBJECT_NAME = "/org/eclipse/swt";
+ private static final String INTERFACE_NAME = "org.eclipse.swt";
+
+ private static Callback onBusAcquired;
+ private static Callback onNameAcquired;
+ private static Callback onNameLost;
+ private static Callback handleMethod;
+
+ static {
+ onBusAcquired = new Callback (GDBus.class, "onBusAcquired", 3); //$NON-NLS-1$
+ if (onBusAcquired.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ onNameAcquired = new Callback (GDBus.class, "onNameAcquired", 3); //$NON-NLS-1$
+ if (onNameAcquired.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ onNameLost = new Callback (GDBus.class, "onNameLost", 3); //$NON-NLS-1$
+ if (onNameLost.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ handleMethod = new Callback (GDBus.class, "handleMethod", 8); //$NON-NLS-1$
+ if (handleMethod.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ String swt_lib_versions = OS.getEnvironmentalVariable (OS.SWT_LIB_VERSIONS); // Note, this is read in multiple places. //leotask move string to a constant in OS.java
+ if (swt_lib_versions != null && swt_lib_versions.equals("1")) {
+ System.out.println("SWT_LIB GDbus implementation v1.");
+ }
+ }
+
+ static void teardown_gdbus() {
+ // Currently GDBus is persistent.
+ // If ever needed, gdbus can be disposed via:
+ // g_bus_unown_name (owner_id); // owner_id would need to be made global
+ // g_dbus_node_info_unref (gdBusNodeInfo); // introspection_data Would need to be made global
+ }
+
+ /**
+ * @return void. (No return value actually returned to OS. Just SWT mechanism dicates 'long' is returned.
+ */
+ @SuppressWarnings("unused") // Callback only called directly by JNI.
+ private static long /*int*/ onBusAcquired (long /*int*/ gDBusConnection, long /*int*/ const_gchar_name, long /*int*/ user_data) {
+ long /*int*/ gdBusNodeInfo;
+
+ { // Generate and parse DBus XML interface.
+ StringBuilder dbus_introspection_xml = new StringBuilder();
+ dbus_introspection_xml.append("<node><interface name='" + INTERFACE_NAME + "'>\n");
+ for (GDBusMethod method : gdbusMethods) {
+
+ dbus_introspection_xml.append(" <method name='" + method.name + "'>\n");
+ dbus_introspection_xml.append(" " + method.getMethodArgsXmlSignature() + "\n");
+ dbus_introspection_xml.append(" </method>\n");
+ }
+ dbus_introspection_xml.append("</interface></node>");
+
+ long /*int*/ [] error = new long /*int*/ [1];
+ gdBusNodeInfo = OS.g_dbus_node_info_new_for_xml(Converter.javaStringToCString(dbus_introspection_xml.toString()), error);
+ if (gdBusNodeInfo == 0 || error[0] != 0) {
+ System.err.println("SWT GDBus: Failed to get introspection data");
+ }
+ assert gdBusNodeInfo != 0 : "SWT GDBus: introspection data should not be 0";
+ }
+
+ { // Register object
+ long /*int*/ [] error = new long /*int*/ [1];
+ long /*int*/ interface_info = OS.g_dbus_node_info_lookup_interface(gdBusNodeInfo, Converter.javaStringToCString(INTERFACE_NAME));
+ long /*int*/ vtable [] = { handleMethod.getAddress(), 0, 0 };
+ OS.g_dbus_connection_register_object(
+ gDBusConnection,
+ Converter.javaStringToCString(DBUS_OBJECT_NAME),
+ interface_info,
+ vtable,
+ 0, // user_data
+ 0, // user_data_free_func
+ error);
+ if (error[0] != 0) {
+ System.err.println("SWT GDBus: Failed to register object: " + DBUS_OBJECT_NAME);
+ return 0;
+ }
+ }
+
+ // Developer note:
+ // To verify that a gdbus interface is regisetered on the gdbus, you can use the 'gdbus' utility.
+ // e.g:
+ // gdbus introspect --session --dest org.eclipse <Press TAB KEY> // it should expand to something like: (uniqueID might be appended at the end).
+ // gdbus introspect --session --dest org.eclipse.swt // you can then get object info like:
+ // gdbus introspect --session --dest org.eclipse.swt --object-path /org/eclipse/swt ... etc
+
+ return 0; // Actual callback is void.
+ }
+
+
+ @SuppressWarnings("unused") // Callback Only called directly by JNI.
+ private static long /*int*/ onNameAcquired (long /*int*/ connection, long /*int*/ name, long /*int*/ user_data) {
+ // Currently not used, but can be used if acquring the gdbus name should trigger something to load.
+ return 0;
+ }
+
+ @SuppressWarnings("unused") // Callback Only called directly by JNI.
+ private static long /*int*/ onNameLost (long /*int*/ connection, long /*int*/ name, long /*int*/ user_data) {
+ System.err.println("SWT GDBus.java: Lost GDBus name. Maybe stolen?");
+ return 0;
+ }
+
+
+ /**
+ * This is called when a client calls one of the GDBus methods.
+ *
+ * Developer note:
+ * This method can be reached directly from GDBus cmd utility:
+ * gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.<your method>
+ * Tip: Use tab-completion.
+ *
+ * @param connection GDBusConnection
+ * @param sender const gchar
+ * @param object_path const gchar
+ * @param interface_name const gchar
+ * @param method_name const gchar
+ * @param gvar_parameters GVariant
+ * @param invocation GDBusMethodInvocation
+ * @param user_data gpointer
+ * @return
+ */
+ @SuppressWarnings("unused") // Callback only called directly by JNI.
+ private static long /*int*/ handleMethod (
+ long /*int*/ connection, long /*int*/ sender,
+ long /*int*/ object_path, long /*int*/ interface_name,
+ long /*int*/ method_name, long /*int*/ gvar_parameters,
+ long /*int*/ invocation, long /*int*/ user_data) {
+
+ long /*int*/ resultGVariant = 0;
+ try {
+ String java_method_name = Converter.cCharPtrToJavaString(method_name, false);
+
+ for (GDBusMethod gdbusMethod : gdbusMethods) {
+ if (gdbusMethod.getName().equals(java_method_name)) {
+ Object [] args = convertGVariantToJava(gvar_parameters);
+ Object [] returnVal = gdbusMethod.getUserFunction().apply(args); // Return value currently not used. Can be added/implemented if required.
+ resultGVariant = convertJavaToGVariant(returnVal);
+ break;
+ }
+ }
+ } catch (Exception e) {
+ System.err.println("SWT GDBUS ERROR: Error in handling method.");
+ } finally {
+ // - GDBus method should always return to prevent caller from hanging.
+ // - Note, result must be a tuple. (or null..).
+
+ OS.g_dbus_method_invocation_return_value(invocation, resultGVariant);
+ }
+ return 0; // void return value.
+ }
+
+ /**
+ * Converts the given GVariant(s) to Java Object(s).
+ * If GVariant is not an array, this returns an Object[] array with one element.
+ *
+ * Only subset of types is currently supported, add type(s) as/when you need them.
+ * For inspiration, see WebkitGDBus.java:convert..()
+ *
+ * @param gVariant a pointer to the native GVariant
+ */
+ private static Object[] convertGVariantToJava(long /*int*/ gVariant) {
+ Object retVal = convertGVariantToJavaHelper(gVariant);
+ if (retVal instanceof Object[]) {
+ return (Object[]) retVal;
+ } else {
+ System.err.println("SWT GDBus Error converting arguments : Expecting object array, received Object.");
+ return null;
+ }
+ }
+
+ private static Object convertGVariantToJavaHelper(long /*int*/ gVariant){
+ // - Developer note:
+ // When instantiating GDBus dynamically (as we do),
+ // GDBus's 'Parameters' is _always_ a tuple of stuff.
+ // E.g If you pass it only a single argument, then you will have a tuple with one object (s).
+ // As such, '1) convert specific types' is only reached, at the earliest
+ // on the 2nd invocation of this recursive function.
+ // - Note, tuples '()' are not the same as arrays 'a'. They're treated in different ways.
+
+ // 1) Convert specific types. (non-array).
+ if (OS.g_variant_is_of_type(gVariant, OS.G_VARIANT_TYPE_STRING)){
+ return Converter.cCharPtrToJavaString(OS.g_variant_get_string(gVariant, null), false);
+ }
+
+ // <add your primitive types>
+
+ //2) Handle struct of defined types. (Sort of like arrays, but note, tuples!=array).
+ if (OS.g_variant_is_of_type(gVariant, OS.G_VARIANT_TYPE_TUPLE)) {
+ int length = (int)OS.g_variant_n_children (gVariant);
+ Object[] result = new Object[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = convertGVariantToJavaHelper (OS.g_variant_get_child_value(gVariant, i));
+ }
+ return result;
+ }
+
+ // 2 b) Handle an array of Strings. Same as above, except type is String.
+ if (OS.g_variant_is_of_type(gVariant, OS.G_VARIANT_TYPE_STRING_ARRAY)) {
+ int length = (int)OS.g_variant_n_children (gVariant);
+ String[] result = new String[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = (String) convertGVariantToJavaHelper (OS.g_variant_get_child_value(gVariant, i));
+ }
+ return result;
+ }
+
+ String typeString = Converter.cCharPtrToJavaString(OS.g_variant_get_type_string(gVariant), false);
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT, new Throwable("SWT GDBus: Unhandled variant type " + typeString ));
+ return null;
+ }
+
+ /**
+ * Converts the given Java Object to a GVariant * representation.
+ * (Only subset of types is currently supported).
+ *
+ * We assume that input Object may contain invalid types.
+ *
+ * @return pointer GVariant *
+ */
+ private static long /*int*/ convertJavaToGVariant(Object javaObject) throws SWTException {
+ if (javaObject == null) {
+ return 0;
+ }
+
+ if (javaObject instanceof String) {
+ return OS.g_variant_new_string (Converter.javaStringToCString((String) javaObject));
+ }
+
+ // Add your types here.
+
+ // Dangers:
+ // Null values and empty arrays can cause problems.
+ // - DBus doesn't have notion of 'null'.
+ // - DBus doesn't support empty arrays.
+ // If needed, see workaround implemented in WebkitGDBus.java
+
+ if (javaObject instanceof Object[]) {
+ Object[] arrayValue = (Object[]) javaObject;
+ int length = arrayValue.length;
+
+ long /*int*/ variants[] = new long /*int*/[length];
+ for (int i = 0; i < length; i++) {
+ variants[i] = convertJavaToGVariant(arrayValue[i]);
+ }
+ return OS.g_variant_new_tuple(variants, length);
+ }
+
+ System.err.println("SWT GDbus: Invalid object being returned to caller: " + javaObject.toString());
+ throw new SWTException(SWT.ERROR_INVALID_ARGUMENT, "Given object is not valid: " + javaObject.toString());
+ }
+
+
+} \ No newline at end of file
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 dd79d22315..4a1c936285 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,6 +20,7 @@ import java.util.regex.Pattern;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.GDBus.*;
import org.eclipse.swt.internal.cairo.*;
import org.eclipse.swt.internal.gtk.*;
@@ -1103,6 +1104,31 @@ 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);
+
+
+ { // GDBus
+
+ // Handle files passed to Eclipse via GDBus. (e.g from Equinox launcher).
+ // For example, this 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"
+ GDBusMethod fileOpenMethod = new GDBusMethod(
+ "FileOpen",
+ new String [][] {{OS.DBUS_TYPE_STRING_ARRAY,"FileNameArray"}},
+ new String [0][0],
+ (args) -> {
+ String[] fileNames = (String[]) args[0]; // Arg 1 is an arraay of strings.
+ for (int i = 0; i < fileNames.length; i++) {
+ Event event = new Event ();
+ event.text = fileNames[i];
+ sendEvent (SWT.OpenDocument, event);
+ }
+ return null;
+ });
+ GDBusMethod[] methods = {fileOpenMethod};
+ GDBus.init(methods);
+ }
}
/**
@@ -5686,6 +5712,9 @@ long /*int*/ signalProc (long /*int*/ gobject, long /*int*/ arg1, long /*int*/ u
settingsChanged = true;
break;
case PROPERTY_NOTIFY:
+
+ // Bug 528414 This whole mechanism is to be removed.
+ // Files passed by changing a window property. Uses X, which doesn't work on wayland.
GdkEventProperty gdkEvent = new GdkEventProperty ();
OS.memmove (gdkEvent, arg1);
if (gdkEvent.type == OS.GDK_PROPERTY_NOTIFY) {

Back to the top