diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-04-10 12:05:34 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-04-10 12:05:34 +0200 |
commit | e54e012500ecf2ebd35bbfef669f3971fb199bad (patch) | |
tree | b6dea9aecbe38249641042f9f1906533d7918018 /source/x11-helper.c | |
parent | c3b236db28538d5f53dd085c3d52092f3d3e7fcf (diff) |
Issue: #381: Try to handle X11 input and UTF-8 better.
In window_get_text_prop do conversion when input is of type STRING. (latin1) to utf8.
Dmenu: don't skip invalid lines, but try to display as much as possible.
Window mode: Double check all input from X.
Diffstat (limited to 'source/x11-helper.c')
-rw-r--r-- | source/x11-helper.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/source/x11-helper.c b/source/x11-helper.c index 9a98d507..f56122ab 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -39,6 +39,7 @@ #include "xcb-internal.h" #include "xcb.h" #include "settings.h" +#include "helper.h" #include <rofi.h> #define OVERLAP( a, b, c, \ @@ -90,9 +91,17 @@ char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom ) xcb_get_property_reply_t *r = xcb_get_property_reply ( xcb->connection, c, NULL ); if ( r ) { if ( xcb_get_property_value_length ( r ) > 0 ) { - char *str = g_malloc ( xcb_get_property_value_length ( r ) + 1 ); - memcpy ( str, xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) ); - str[xcb_get_property_value_length ( r )] = '\0'; + char *str = NULL; + if ( r->type == netatoms[UTF8_STRING] ) { + str = g_strndup ( xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) ); + } + else if ( r->type == netatoms[STRING] ) { + str = rofi_latin_to_utf8_strdup ( xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) ); + } + else { + str = g_strdup ( "Invalid encoding." ); + } + free ( r ); return str; } |