[common/xutil.c] Rewrite xgettextprop properly for UTF8_STRING
This commit is contained in:
parent
b0b0dcf525
commit
d99586f68b
|
@ -33,32 +33,39 @@ bool
|
||||||
xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
|
xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
|
||||||
char *text, ssize_t textlen)
|
char *text, ssize_t textlen)
|
||||||
{
|
{
|
||||||
xcb_get_property_reply_t *name = NULL;
|
xcb_get_property_reply_t *prop_r = NULL;
|
||||||
char *prop_val = NULL;
|
void *prop_val;
|
||||||
|
|
||||||
if(!text || !textlen)
|
if(!text || !textlen)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
text[0] = '\0';
|
text[0] = '\0';
|
||||||
name = xcb_get_property_reply(conn,
|
prop_r = xcb_get_property_reply(conn,
|
||||||
xcb_get_property_unchecked(conn, false,
|
xcb_get_property_unchecked(conn, false,
|
||||||
w, atom,
|
w, atom,
|
||||||
XCB_GET_PROPERTY_TYPE_ANY,
|
XCB_GET_PROPERTY_TYPE_ANY,
|
||||||
0L, 1000000L),
|
0L, 1000000L),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
|
||||||
|
if(!prop_r || !prop_r->value_len || prop_r->format != 8)
|
||||||
|
{
|
||||||
|
if(prop_r)
|
||||||
|
p_delete(&prop_r);
|
||||||
|
|
||||||
if(!name->value_len)
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
prop_val = (char *) xcb_get_property_value(name);
|
prop_val = xcb_get_property_value(prop_r);
|
||||||
|
|
||||||
/* TODO: XCB doesn't provide a XmbTextPropertyToTextList(), check
|
/* Check whether the returned property value is just an ascii
|
||||||
* whether this code is correct (locales) */
|
* string or utf8 string. At the moment it doesn't handle
|
||||||
if(name->type == STRING || name->format == 8)
|
* COMPOUND_TEXT and multibyte but it's not needed... */
|
||||||
a_strncpy(text, name->value_len + 1, prop_val, textlen - 1);
|
if(prop_r->type == STRING ||
|
||||||
|
prop_r->type == xutil_intern_atom(conn, "UTF8_STRING"))
|
||||||
|
a_strncpy(text, prop_r->value_len + 1, prop_val, textlen - 1);
|
||||||
|
|
||||||
text[textlen - 1] = '\0';
|
p_delete(&prop_r);
|
||||||
p_delete(&name);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue