mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-29 06:51:10 +00:00
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
This commit is contained in:
parent
51444b7909
commit
4b003a75aa
@ -1385,11 +1385,69 @@ _gdk_wayland_display_text_property_to_utf8_list (GdkDisplay *display,
|
|||||||
return nitems;
|
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 *
|
gchar *
|
||||||
_gdk_wayland_display_utf8_to_string_target (GdkDisplay *display,
|
_gdk_wayland_display_utf8_to_string_target (GdkDisplay *display,
|
||||||
const gchar *str)
|
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
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user