Blame SOURCES/imsettings-dont-set-envvar-on-unsupported-desktop.patch

956a34
diff -pruN imsettings-1.6.3.orig/data/imsettings-functions.in imsettings-1.6.3/data/imsettings-functions.in
956a34
--- imsettings-1.6.3.orig/data/imsettings-functions.in	2019-02-22 08:34:48.223926116 +0000
956a34
+++ imsettings-1.6.3/data/imsettings-functions.in	2019-02-22 08:52:07.854839883 +0000
956a34
@@ -169,6 +169,11 @@ function is_xim_supported() {
956a34
     return 1
956a34
 }
956a34
 
956a34
+function is_desktop_supported() {
956a34
+    @libexecdir[@]/imsettings-target-checker.sh >/dev/null
956a34
+    [ $? -eq 0 ]
956a34
+}
956a34
+
956a34
 function setup_gtk_immodule() {
956a34
     if is_imsettings_enabled && is_gtk_supported; then
956a34
 	# Ensure GTK_IM_MODULE is empty. otherwise GTK+ doesn't pick up immodule through XSETTINGS
956a34
diff -pruN imsettings-1.6.3.orig/data/xinput.sh.in.in imsettings-1.6.3/data/xinput.sh.in.in
956a34
--- imsettings-1.6.3.orig/data/xinput.sh.in.in	2019-02-22 08:34:48.236926116 +0000
956a34
+++ imsettings-1.6.3/data/xinput.sh.in.in	2019-02-22 08:49:06.690865058 +0000
956a34
@@ -39,6 +39,11 @@ tmplang=${LC_CTYPE:-${LANG:-"en_US.UTF-8
956a34
 unset AUXILIARY_PROGRAM AUXILIARY_ARGS GTK_IM_MODULE ICON IMSETTINGS_IGNORE_ME LONG_DESC NOT_RUN PREFERENCE_PROGRAM PREFERENCE_ARGS QT_IM_MODULE SHORT_DESC XIM XIM_PROGRAM XIM_ARGS XMODIFIERS
956a34
 
956a34
 [ -z "${IMSETTINGS_DISABLE_USER_XINPUTRC-}" ] && IMSETTINGS_DISABLE_USER_XINPUTRC=no
956a34
+[ -z "${IMSETTINGS_DISABLE_SYS_XINPUTRC-}" ] && IMSETTINGS_DISABLE_SYS_XINPUTRC=no
956a34
+
956a34
+if ! is_desktop_supported; then
956a34
+    IMSETTINGS_DISABLE_SYS_XINPUTRC=yes
956a34
+fi
956a34
 
956a34
 # migrate old configuration file
956a34
 [ ! -d $CONFIGDIR ] && mkdir -p $CONFIGDIR || :
956a34
@@ -51,7 +56,7 @@ if [ -r "$USER_XINPUTRC" -a "x$IMSETTING
956a34
     if [ ! -h "$USER_XINPUTRC" ]; then
956a34
 	SHORT_DESC="User Specific"
956a34
     fi
956a34
-elif [ -r "$SYS_XINPUTRC" ]; then
956a34
+elif [ -r "$SYS_XINPUTRC" -a "x$IMSETTINGS_DISABLE_SYS_XINPUTRC" = "xno" ]; then
956a34
     # FIXME: This hardcoded list has to be gone in the future.
956a34
     # Locales that normally use input-method for native input
956a34
     _im_language_list="as bn gu hi ja kn ko mai ml mr ne or pa si ta te th ur vi zh"
956a34
@@ -87,7 +92,7 @@ fi
956a34
 [ -z "${IMSETTINGS_INTEGRATE_DESKTOP-}" ] && IMSETTINGS_INTEGRATE_DESKTOP=yes
956a34
 export IMSETTINGS_INTEGRATE_DESKTOP
956a34
 
956a34
-[ -z "$XIM" ] && XIM=none
956a34
+[ -z "$XIM" -a "x$IMSETTINGS_DISABLE_SYS_XINPUTRC" = "xno" ] && XIM=none
956a34
 
956a34
 # start IM via imsettings
956a34
 IMSETTINGS_MODULE=${SHORT_DESC:-${XIM}}
956a34
diff -pruN imsettings-1.6.3.orig/data/xinputinfo.sh.in imsettings-1.6.3/data/xinputinfo.sh.in
956a34
--- imsettings-1.6.3.orig/data/xinputinfo.sh.in	2019-02-22 08:34:48.236926116 +0000
956a34
+++ imsettings-1.6.3/data/xinputinfo.sh.in	2019-02-22 08:53:17.758832692 +0000
956a34
@@ -57,11 +57,12 @@ if [ $# -gt 0 ]; then
956a34
     IMSETTINGS_FILENAME=$1
956a34
 else
956a34
     [ -z "${IMSETTINGS_DISABLE_USER_XINPUTRC-}" ] && IMSETTINGS_DISABLE_USER_XINPUTRC=no
956a34
+    [ -z "${IMSETTINGS_DISABLE_SYS_XINPUTRC-}" ] && IMSETTINGS_DISABLE_SYS_XINPUTRC=no
956a34
 
956a34
     if [ -r "$USER_XINPUTRC" -a "x$IMSETTINGS_DISABLE_USER_XINPUTRC" = "xno" ]; then
956a34
 	source "$USER_XINPUTRC"
956a34
 	IMSETTINGS_FILENAME=$USER_XINPUTRC
956a34
-    elif [ -r "$SYS_XINPUTRC" ]; then
956a34
+    elif [ -r "$SYS_XINPUTRC" -a "x$IMSETTINGS_DISABLE_SYS_XINPUTRC" = "xno" ]; then
956a34
 	source "$SYS_XINPUTRC"
956a34
 	IMSETTINGS_FILENAME=$SYS_XINPUTRC
956a34
     fi
956a34
diff -pruN imsettings-1.6.3.orig/imsettings/imsettings-client.c imsettings-1.6.3/imsettings/imsettings-client.c
956a34
--- imsettings-1.6.3.orig/imsettings/imsettings-client.c	2013-01-18 03:25:38.000000000 +0000
956a34
+++ imsettings-1.6.3/imsettings/imsettings-client.c	2019-02-22 11:20:19.756465170 +0000
956a34
@@ -1372,3 +1372,106 @@ imsettings_client_ping(IMSettingsClient
956a34
 
956a34
 	return FALSE;
956a34
 }
956a34
+
956a34
+/**
956a34
+ * imsettings_client_is_supported_desktop:
956a34
+ * @client: a #IMSettingsClient.
956a34
+ * @cancellable: (allow-none): a #GCancellable or %NULL.
956a34
+ * @error: (allow-none): a #GError to store an error if any, or %NULL.
956a34
+ *
956a34
+ * Check if current desktop is supported by IMSettings or not.
956a34
+ *
956a34
+ * You could access through DBus API instead:
956a34
+ *
956a34
+ * |[
956a34
+ *   <interface name='com.redhat.imsettings'>
956a34
+ *     <method name='IsSupportedDesktop'>
956a34
+ *       <arg type='s' name='desktop' direction='in' />
956a34
+ *       <arg type='b' name='ret' direction'out' />
956a34
+ *     </method>
956a34
+ *   </interface>
956a34
+ * ]|
956a34
+ *
956a34
+ * Returns: if supported, returns %TRUE otherwise %FALSE.
956a34
+ */
956a34
+gboolean
956a34
+imsettings_client_is_supported_desktop(IMSettingsClient  *client,
956a34
+				       GCancellable      *cancellable,
956a34
+				       GError           **error)
956a34
+{
956a34
+	const gchar *desktop;
956a34
+	GDBusProxy *proxy;
956a34
+	GVariant *value;
956a34
+	gboolean retval = FALSE;
956a34
+
956a34
+	g_return_val_if_fail (IMSETTINGS_IS_CLIENT (client), FALSE);
956a34
+
956a34
+	desktop = NULL;
956a34
+	proxy = imsettings_client_get_proxy(client);
956a34
+	value = g_dbus_proxy_call_sync(proxy,
956a34
+				       "IsSupportedDesktop",
956a34
+				       g_variant_new("(s)",
956a34
+						     desktop ? desktop : ""),
956a34
+				       G_DBUS_CALL_FLAGS_NONE,
956a34
+				       -1,
956a34
+				       cancellable,
956a34
+				       error);
956a34
+	if (value) {
956a34
+		g_variant_get(value, "(b)", &retval);
956a34
+		g_variant_unref(value);
956a34
+	}
956a34
+
956a34
+	return retval;
956a34
+}
956a34
+
956a34
+/**
956a34
+ * imsettings_client_is_supported_desktop_start:
956a34
+ * @client: a #IMSettingsClient.
956a34
+ * @cancellable: (allow-none): a #GCancellable or %NULL.
956a34
+ * @callback: (scope async): a #GAsyncReadyCallback.
956a34
+ * @user_data: (closure): a pointer of the user data to give it to @callback.
956a34
+ *
956a34
+ * Request asking if current desktop is supported or not asynchronously
956a34
+ */
956a34
+void
956a34
+imsettings_client_is_supported_desktop_start(IMSettingsClient    *client,
956a34
+					     GCancellable        *cancellable,
956a34
+					     GAsyncReadyCallback  callback,
956a34
+					     gpointer             user_data)
956a34
+{
956a34
+	GDBusProxy *proxy;
956a34
+	const gchar *desktop;
956a34
+
956a34
+	g_return_if_fail (IMSETTINGS_IS_CLIENT (client));
956a34
+
956a34
+	desktop = NULL;
956a34
+	proxy = imsettings_client_get_proxy(client);
956a34
+	g_dbus_proxy_call(proxy,
956a34
+			  "IsSupportedDesktop",
956a34
+			  g_variant_new("(s)", desktop ? desktop : ""),
956a34
+			  G_DBUS_CALL_FLAGS_NONE,
956a34
+			  -1,
956a34
+			  cancellable,
956a34
+			  callback,
956a34
+			  user_data);
956a34
+}
956a34
+
956a34
+/**
956a34
+ * imsettings_client_is_supported_desktop_finish:
956a34
+ * @client: a #IMSettingsClient.
956a34
+ * @result: a #GAsyncResult pushed through #GAsyncReadyCallback.
956a34
+ * @error: (allow-none): a #GError to store an error if any, or %NULL.
956a34
+ *
956a34
+ * Obtains the result of the request from
956a34
+ * imsettings_client_is_supported_desktop_start().
956a34
+ *
956a34
+ * Returns: if the operation is successfully done, returns %TRUE
956a34
+ *          otherwise %FALSE
956a34
+ */
956a34
+gboolean
956a34
+imsettings_client_is_supported_desktop_finish(IMSettingsClient  *client,
956a34
+					      GAsyncResult      *result,
956a34
+					      GError           **error)
956a34
+{
956a34
+	return imsettings_client_async_result_boolean(client, result, error);
956a34
+}
956a34
diff -pruN imsettings-1.6.3.orig/imsettings/imsettings-client.h imsettings-1.6.3/imsettings/imsettings-client.h
956a34
--- imsettings-1.6.3.orig/imsettings/imsettings-client.h	2012-12-13 08:36:42.000000000 +0000
956a34
+++ imsettings-1.6.3/imsettings/imsettings-client.h	2019-02-22 11:16:30.576563361 +0000
956a34
@@ -117,6 +117,9 @@ gboolean        imsettings_client_im_is_
956a34
                                                        const gchar       *module,
956a34
                                                        GCancellable      *cancellable,
956a34
                                                        GError           **error);
956a34
+gboolean        imsettings_client_is_supported_desktop(IMSettingsClient  *client,
956a34
+						       GCancellable      *cancellable,
956a34
+						       GError           **error);
956a34
 gboolean        imsettings_client_switch_im           (IMSettingsClient  *client,
956a34
                                                        const gchar       *module,
956a34
                                                        gboolean           update_xinputrc,
956a34
@@ -161,6 +164,13 @@ void      imsettings_client_get_system_i
956a34
 gchar    *imsettings_client_get_system_im_finish    (IMSettingsClient     *client,
956a34
 						     GAsyncResult         *result,
956a34
 						     GError              **error);
956a34
+void      imsettings_client_is_supported_desktop_start(IMSettingsClient    *client,
956a34
+						       GCancellable        *cancellable,
956a34
+						       GAsyncReadyCallback  callback,
956a34
+						       gpointer             user_data);
956a34
+gboolean  imsettings_client_is_supported_desktop_finish(IMSettingsClient  *client,
956a34
+							GAsyncResult      *result,
956a34
+							GError           **error);
956a34
 void      imsettings_client_switch_im_start         (IMSettingsClient     *client,
956a34
 						     const gchar          *module,
956a34
 						     gboolean              update_xinputrc,
956a34
diff -pruN imsettings-1.6.3.orig/imsettings/imsettings-utils.c imsettings-1.6.3/imsettings/imsettings-utils.c
956a34
--- imsettings-1.6.3.orig/imsettings/imsettings-utils.c	2012-12-13 08:36:42.000000000 +0000
956a34
+++ imsettings-1.6.3/imsettings/imsettings-utils.c	2019-02-22 11:17:26.029541189 +0000
956a34
@@ -85,6 +85,10 @@ static const gchar introspection_xml[] =
956a34
 	"    <method name='DumpModuleSettings'>"
956a34
 	"      <arg type='a{ss}' name='ret' direction='out' />"
956a34
 	"    </method>"
956a34
+	"    <method name='IsSupportedDesktop'>"
956a34
+	"      <arg type='s' name='desktop' direction='in' />"
956a34
+	"      <arg type='b' name='ret' direction='out' />"
956a34
+	"    </method>"
956a34
 	"    "
956a34
 	"    <method name='SwitchIM'>"
956a34
 	"      <arg type='s' name='lang' direction='in' />"
956a34
diff -pruN imsettings-1.6.3.orig/imsettings/imsettings.h imsettings-1.6.3/imsettings/imsettings.h
956a34
--- imsettings-1.6.3.orig/imsettings/imsettings.h	2012-12-13 08:36:42.000000000 +0000
956a34
+++ imsettings-1.6.3/imsettings/imsettings.h	2019-02-22 11:17:45.845532854 +0000
956a34
@@ -78,7 +78,7 @@ G_BEGIN_DECLS
956a34
  *
956a34
  * A DBus API version in imsettings.
956a34
  */
956a34
-#define IMSETTINGS_SETTINGS_API_VERSION	5
956a34
+#define IMSETTINGS_SETTINGS_API_VERSION	6
956a34
 
956a34
 /**
956a34
  * IMSETTINGS_GLOBAL_XINPUT_CONF:
956a34
diff -pruN imsettings-1.6.3.orig/imsettings-daemon/imsettings-server.c imsettings-1.6.3/imsettings-daemon/imsettings-server.c
956a34
--- imsettings-1.6.3.orig/imsettings-daemon/imsettings-server.c	2019-02-22 08:34:48.233926116 +0000
956a34
+++ imsettings-1.6.3/imsettings-daemon/imsettings-server.c	2019-02-22 11:12:54.983660142 +0000
956a34
@@ -685,6 +685,67 @@ imsettings_server_cb_get_info_variant(IM
956a34
 	return value;
956a34
 }
956a34
 
956a34
+static gchar *
956a34
+_escape_desktop_name(const gchar *name)
956a34
+{
956a34
+	if (name) {
956a34
+		size_t l, len = strlen(name);
956a34
+		GString *ss = g_string_new(NULL);
956a34
+
956a34
+		for (l = 0; l < len; l++) {
956a34
+			if ((name[l] >= 'A' && name[l] <= 'Z') ||
956a34
+			    (name[l] >= 'a' && name[l] <= 'z') ||
956a34
+			    (name[l] >= '0' && name[l] <= '9') ||
956a34
+			    name[l] == '-' || name[l] == '+' || name[l] == '_' || name[l] == '.' || name[l] == ',')
956a34
+				g_string_append_c(ss, name[l]);
956a34
+			else
956a34
+				g_string_append_c(ss, '_');
956a34
+		}
956a34
+		return g_string_free(ss, FALSE);
956a34
+	}
956a34
+
956a34
+	return NULL;
956a34
+}
956a34
+
956a34
+static gboolean
956a34
+imsettings_server_cb_is_supported_desktop(IMSettingsServer  *server,
956a34
+					  const gchar       *desktop)
956a34
+{
956a34
+	const gchar *pp;
956a34
+	gchar *helper_path, *script, *quoted_desktop = NULL;
956a34
+	gchar *cmd;
956a34
+	gint ret;
956a34
+	gboolean match = FALSE;
956a34
+	GError *err = NULL;
956a34
+
956a34
+	quoted_desktop = _escape_desktop_name(desktop);
956a34
+	pp = g_getenv("IMSETTINGS_HELPER_PATH");
956a34
+	if (pp)
956a34
+		helper_path = g_strdup(pp);
956a34
+	else
956a34
+		helper_path = g_strdup(IMSETTINGS_HELPER_PATH);
956a34
+	script = g_build_filename(helper_path, "imsettings-target-checker.sh", NULL);
956a34
+	if (desktop)
956a34
+		cmd = g_strdup_printf("sh -c 'export XDG_CURRENT_DESKTOP=%s; sh %s'", quoted_desktop ? quoted_desktop : "", script);
956a34
+	else
956a34
+		cmd = g_strdup_printf("sh -c %s", script);
956a34
+	g_free(script);
956a34
+	g_free(helper_path);
956a34
+
956a34
+	if (g_spawn_command_line_sync(cmd, NULL, NULL, &ret, &err))
956a34
+		match = TRUE;
956a34
+	if (!g_spawn_check_exit_status(ret, &err))
956a34
+		match = FALSE;
956a34
+	if (err) {
956a34
+		g_warning("%s", err->message);
956a34
+		g_error_free(err);
956a34
+	}
956a34
+	g_free(cmd);
956a34
+	g_free(quoted_desktop);
956a34
+
956a34
+	return !match;
956a34
+}
956a34
+
956a34
 static gboolean
956a34
 imsettings_server_cb_switch_im(IMSettingsServer  *server,
956a34
 			       const gchar       *lang,
956a34
@@ -699,11 +760,6 @@ imsettings_server_cb_switch_im(IMSetting
956a34
 	const gchar *homedir, *xinputfile;
956a34
 	struct stat st;
956a34
 	gint save_errno;
956a34
-	const gchar *pp;
956a34
-	gchar *helper_path, *script;
956a34
-	gboolean match = FALSE;
956a34
-	gchar *cmd;
956a34
-	gint ret;
956a34
 
956a34
 	g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO,
956a34
 	      "Attempting to switch IM to %s [lang=%s, update=%s]",
956a34
@@ -737,24 +793,7 @@ imsettings_server_cb_switch_im(IMSetting
956a34
 		return FALSE;
956a34
 	}
956a34
 
956a34
-	pp = g_getenv("IMSETTINGS_HELPER_PATH");
956a34
-	if (pp)
956a34
-		helper_path = g_strdup(pp);
956a34
-	else
956a34
-		helper_path = g_strdup(IMSETTINGS_HELPER_PATH);
956a34
-	script = g_build_filename(helper_path, "imsettings-target-checker.sh", NULL);
956a34
-	cmd = g_strdup_printf("sh %s", script);
956a34
-	g_free(script);
956a34
-	g_free(helper_path);
956a34
-
956a34
-	if (g_spawn_command_line_sync(cmd, NULL, NULL, &ret, error))
956a34
-		match = TRUE;
956a34
-	if (!g_spawn_check_exit_status(ret, error))
956a34
-		match = FALSE;
956a34
-	g_free(cmd);
956a34
-	if (*error) {
956a34
-		g_clear_error(error);
956a34
-	} else if (match) {
956a34
+	if (!imsettings_server_cb_is_supported_desktop(server, NULL)) {
956a34
 		g_set_error(error, IMSETTINGS_GERROR, IMSETTINGS_GERROR_NOT_TARGETED_DESKTOP,
956a34
 			    _("Current desktop isn't targeted by IMSettings."));
956a34
 		g_warning("%s", (*error)->message);
956a34
@@ -1208,6 +1247,14 @@ imsettings_server_bus_method_call(GDBusC
956a34
 				    IMSETTINGS_GERROR_CONFIGURATION_ERROR,
956a34
 				    "No modules loaded");
956a34
 		}
956a34
+	} else if (g_strcmp0(method_name, "IsSupportedDesktop") == 0) {
956a34
+		const gchar *desktop;
956a34
+		gboolean ret;
956a34
+
956a34
+		g_variant_get(parameters, "(&s)",
956a34
+			      &desktop);
956a34
+		ret = imsettings_server_cb_is_supported_desktop(server, desktop);
956a34
+		value = g_variant_new_boolean(ret);
956a34
 	}
956a34
   finalize:
956a34
 	/* GVariant uses a floating reference count system.
956a34
diff -pruN imsettings-1.6.3.orig/utils/imsettings-switch.c imsettings-1.6.3/utils/imsettings-switch.c
956a34
--- imsettings-1.6.3.orig/utils/imsettings-switch.c	2013-05-27 03:39:15.000000000 +0000
956a34
+++ imsettings-1.6.3/utils/imsettings-switch.c	2019-02-22 11:18:25.882515247 +0000
956a34
@@ -102,6 +102,11 @@ main(int    argc,
956a34
 		retval = 1;
956a34
 		goto end;
956a34
 	}
956a34
+	if (!imsettings_client_is_supported_desktop(client, NULL, &error)) {
956a34
+		g_printerr(_("Current desktop isn't supported by IMSettings. Please follow instructions on your desktop to enable Input Method.\n"));
956a34
+		retval = 1;
956a34
+		goto end;
956a34
+	}
956a34
 	v = imsettings_client_get_module_settings(client, NULL, &error);
956a34
 	if (error)
956a34
 		goto error;