[gtk+] wayland: Implement gdk_utf8_to_string_target
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] wayland: Implement gdk_utf8_to_string_target
- Date: Thu, 30 Jun 2016 12:11:48 +0000 (UTC)
commit 4b003a75aa4bc7a5210792082380b24c78abc8d5
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jun 27 11:57:21 2016 +0200
wayland: Implement gdk_utf8_to_string_target
The sanitize_utf8() function has been copied from X11 so both
backends behave the same. This allows interaction with older clients
(mainly through Xwayland, and the STRING selection target) that
request non-utf8 text.
https://bugzilla.gnome.org/show_bug.cgi?id=768082
gdk/wayland/gdkselection-wayland.c | 60 +++++++++++++++++++++++++++++++++++-
1 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c
index 69a2145..c21cafd 100644
--- a/gdk/wayland/gdkselection-wayland.c
+++ b/gdk/wayland/gdkselection-wayland.c
@@ -1385,11 +1385,69 @@ _gdk_wayland_display_text_property_to_utf8_list (GdkDisplay *display,
return nitems;
}
+/* This function has been copied straight from the x11 backend */
+static gchar *
+sanitize_utf8 (const gchar *src,
+ gboolean return_latin1)
+{
+ gint len = strlen (src);
+ GString *result = g_string_sized_new (len);
+ const gchar *p = src;
+
+ while (*p)
+ {
+ if (*p == '\r')
+ {
+ p++;
+ if (*p == '\n')
+ p++;
+
+ g_string_append_c (result, '\n');
+ }
+ else
+ {
+ gunichar ch = g_utf8_get_char (p);
+
+ if (!((ch < 0x20 && ch != '\t' && ch != '\n') || (ch >= 0x7f && ch < 0xa0)))
+ {
+ if (return_latin1)
+ {
+ if (ch <= 0xff)
+ g_string_append_c (result, ch);
+ else
+ g_string_append_printf (result,
+ ch < 0x10000 ? "\\u%04x" : "\\U%08x",
+ ch);
+ }
+ else
+ {
+ char buf[7];
+ gint buflen;
+
+ buflen = g_unichar_to_utf8 (ch, buf);
+ g_string_append_len (result, buf, buflen);
+ }
+ }
+
+ p = g_utf8_next_char (p);
+ }
+ }
+
+ return g_string_free (result, FALSE);
+}
+
gchar *
_gdk_wayland_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str)
{
- return NULL;
+ /* This is mainly needed when interfacing with old clients through
+ * Xwayland, the STRING target could be used, and passed as-is
+ * by the compositor.
+ *
+ * There's already some handling of this atom (aka "mimetype" in
+ * this backend) in common code, so we end up in this vfunc.
+ */
+ return sanitize_utf8 (str, TRUE);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]