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

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