gdk: Remove gdk_utf8_to_string_target()

Only keep the X11 version around in the backend.
This commit is contained in:
Benjamin Otte 2020-02-22 18:33:20 +01:00
parent a62d78bf70
commit 6442ec2f8d
21 changed files with 62 additions and 195 deletions

View File

@ -352,7 +352,6 @@ gdk_content_formats_builder_get_type
<FILE>properties</FILE>
GdkAtom
gdk_text_property_to_utf8_list_for_display
gdk_utf8_to_string_target
</SECTION>
<SECTION>

View File

@ -429,7 +429,6 @@ gdk_broadway_display_class_init (GdkBroadwayDisplayClass * class)
display_class->create_surface = _gdk_broadway_display_create_surface;
display_class->get_keymap = _gdk_broadway_display_get_keymap;
display_class->text_property_to_utf8_list = _gdk_broadway_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_broadway_display_utf8_to_string_target;
display_class->get_n_monitors = gdk_broadway_display_get_n_monitors;
display_class->get_monitor = gdk_broadway_display_get_monitor;

View File

@ -119,8 +119,6 @@ gint _gdk_broadway_display_text_property_to_utf8_list (GdkDisplay *display,
const guchar *text,
gint length,
gchar ***list);
gchar *_gdk_broadway_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str);
GdkKeymap* _gdk_broadway_display_get_keymap (GdkDisplay *display);
void _gdk_broadway_display_consume_all_input (GdkDisplay *display);
BroadwayInputMsg * _gdk_broadway_display_block_for_input (GdkDisplay *display,

View File

@ -135,9 +135,3 @@ _gdk_broadway_display_text_property_to_utf8_list (GdkDisplay *display,
return 0;
}
gchar *
_gdk_broadway_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str)
{
return g_strdup (str);
}

View File

@ -156,8 +156,6 @@ struct _GdkDisplayClass
const guchar *text,
gint length,
gchar ***list);
gchar * (*utf8_to_string_target) (GdkDisplay *display,
const gchar *text);
gboolean (*make_gl_context_current) (GdkDisplay *display,
GdkGLContext *context);

View File

@ -43,9 +43,6 @@ gint gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
gint length,
gchar ***list);
GDK_AVAILABLE_IN_ALL
gchar *gdk_utf8_to_string_target (const gchar *str);
G_END_DECLS
#endif /* __GDK_PROPERTY_H__ */

View File

@ -61,25 +61,3 @@ gdk_text_property_to_utf8_list_for_display (GdkDisplay *display,
->text_property_to_utf8_list (display, encoding, format, text, length, list);
}
/**
* gdk_utf8_to_string_target:
* @str: a UTF-8 string
*
* Converts a UTF-8 string into the best possible representation
* as a STRING. The representation of characters not in STRING
* is not specified; it may be as pseudo-escape sequences
* \x{ABCD}, or it may be in some other form of approximation.
*
* Returns: (nullable): the newly-allocated string, or %NULL if the
* conversion failed. (It should not fail for any properly
* formed UTF-8 string unless system limits like memory or
* file descriptors are exceeded.)
**/
gchar *
gdk_utf8_to_string_target (const gchar *str)
{
GdkDisplay *display = gdk_display_get_default ();
return GDK_DISPLAY_GET_CLASS (display)->utf8_to_string_target (display, str);
}

View File

@ -231,7 +231,6 @@ gdk_quartz_display_class_init (GdkQuartzDisplayClass *class)
display_class->create_surface_impl = _gdk_quartz_display_create_surface_impl;
display_class->get_keymap = _gdk_quartz_display_get_keymap;
display_class->text_property_to_utf8_list = _gdk_quartz_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_quartz_display_utf8_to_string_target;
display_class->get_n_monitors = gdk_quartz_display_get_n_monitors;
display_class->get_monitor = gdk_quartz_display_get_monitor;
display_class->get_setting = gdk_quartz_display_get_setting;

View File

@ -76,8 +76,6 @@ gint _gdk_quartz_display_text_property_to_utf8_list (GdkDisplay *disp
const guchar *text,
gint length,
gchar ***list);
gchar * _gdk_quartz_display_utf8_to_string_target (GdkDisplay *displayt,
const gchar *str);
G_END_DECLS

View File

@ -23,14 +23,6 @@
#include "gdkproperty.h"
#include "gdkquartz.h"
gchar *
_gdk_quartz_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str)
{
/* FIXME: Implement */
return NULL;
}
static gint
make_list (const gchar *text,
gint length,

View File

@ -1031,7 +1031,6 @@ gdk_wayland_display_class_init (GdkWaylandDisplayClass *class)
display_class->create_surface = _gdk_wayland_display_create_surface;
display_class->get_keymap = _gdk_wayland_display_get_keymap;
display_class->text_property_to_utf8_list = _gdk_wayland_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_wayland_display_utf8_to_string_target;
display_class->make_gl_context_current = gdk_wayland_display_make_gl_context_current;

View File

@ -133,8 +133,6 @@ gint _gdk_wayland_display_text_property_to_utf8_list (GdkDisplay *disp
const guchar *text,
gint length,
gchar ***list);
gchar * _gdk_wayland_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str);
void _gdk_wayland_display_create_seat (GdkWaylandDisplay *display,
guint32 id,

View File

@ -73,68 +73,3 @@ _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)
{
/* 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);
}

View File

@ -2782,13 +2782,6 @@ _gdk_win32_display_text_property_to_utf8_list (GdkDisplay *display,
}
}
gchar *
_gdk_win32_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str)
{
return g_strdup (str);
}
gint
_gdk_win32_add_contentformat_to_pairs (const gchar *contentformat,
GArray *array)

View File

@ -1119,7 +1119,6 @@ gdk_win32_display_class_init (GdkWin32DisplayClass *klass)
display_class->get_keymap = _gdk_win32_display_get_keymap;
display_class->text_property_to_utf8_list = _gdk_win32_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_win32_display_utf8_to_string_target;
display_class->make_gl_context_current = _gdk_win32_display_make_gl_context_current;
display_class->get_n_monitors = gdk_win32_display_get_n_monitors;

View File

@ -401,7 +401,6 @@ gint _gdk_win32_display_text_property_to_utf8_list (GdkDisplay *display,
const guchar *text,
gint length,
gchar ***list);
gchar *_gdk_win32_display_utf8_to_string_target (GdkDisplay *display, const gchar *str);
gboolean _gdk_win32_keymap_has_altgr (GdkWin32Keymap *keymap);
guint8 _gdk_win32_keymap_get_active_group (GdkWin32Keymap *keymap);

View File

@ -3053,7 +3053,6 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class)
display_class->create_surface = _gdk_x11_display_create_surface;
display_class->get_keymap = gdk_x11_display_get_keymap;
display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;
display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current;

View File

@ -125,8 +125,8 @@ gint _gdk_x11_display_text_property_to_utf8_list (GdkDisplay *display
const guchar *text,
gint length,
gchar ***list);
gchar * _gdk_x11_display_utf8_to_string_target (GdkDisplay *displayt,
const gchar *str);
char * gdk_x11_utf8_to_string_target (const char *utf8_str,
gboolean return_latin1);
void _gdk_x11_device_check_extension_events (GdkDevice *device);

View File

@ -325,70 +325,6 @@ gdk_x11_display_string_to_compound_text (GdkDisplay *display,
return res;
}
/* The specifications for COMPOUND_TEXT and STRING specify that C0 and
* C1 are not allowed except for \n and \t, however the X conversions
* routines for COMPOUND_TEXT only enforce this in one direction,
* causing cut-and-paste of \r and \r\n separated text to fail.
* This routine strips out all non-allowed C0 and C1 characters
* from the input string and also canonicalizes \r, and \r\n to \n
*/
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_x11_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str)
{
return sanitize_utf8 (str, TRUE);
}
/**
* gdk_x11_display_utf8_to_compound_text:
* @display: (type GdkX11Display): a #GdkDisplay
@ -423,7 +359,7 @@ gdk_x11_display_utf8_to_compound_text (GdkDisplay *display,
need_conversion = !g_get_charset (&charset);
tmp_str = sanitize_utf8 (str, FALSE);
tmp_str = gdk_x11_utf8_to_string_target (str, FALSE);
if (need_conversion)
{

View File

@ -2235,7 +2235,7 @@ set_text_property (GdkDisplay *display,
if (utf8_is_latin1 (utf8_str))
{
prop_type = XA_STRING;
prop_text = _gdk_x11_display_utf8_to_string_target (display, utf8_str);
prop_text = gdk_x11_utf8_to_string_target (utf8_str, TRUE);
prop_length = prop_text ? strlen (prop_text) : 0;
prop_format = 8;
is_compound_text = FALSE;

View File

@ -121,6 +121,63 @@ gdk_x11_text_list_converter_decode (GdkX11TextListConverter *conv,
}
}
/* The specifications for COMPOUND_TEXT and STRING specify that C0 and
* C1 are not allowed except for \n and \t, however the X conversions
* routines for COMPOUND_TEXT only enforce this in one direction,
* causing cut-and-paste of \r and \r\n separated text to fail.
* This routine strips out all non-allowed C0 and C1 characters
* from the input string and also canonicalizes \r, and \r\n to \n
*/
char *
gdk_x11_utf8_to_string_target (const char *utf8_str,
gboolean return_latin1)
{
gint len = strlen (utf8_str);
GString *result = g_string_sized_new (len);
const gchar *p = utf8_str;
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);
}
static GConverterResult
gdk_x11_text_list_converter_encode (GdkX11TextListConverter *conv,
const void *inbuf,
@ -146,7 +203,7 @@ gdk_x11_text_list_converter_encode (GdkX11TextListConverter *conv,
gchar *tmp, *latin1;
tmp = g_strndup (inbuf, inbuf_size);
latin1 = gdk_utf8_to_string_target (tmp);
latin1 = gdk_x11_utf8_to_string_target (tmp, TRUE);
g_free (tmp);
if (latin1)
{