[xutil] Rewrite gettextprop() proto

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-28 22:56:16 +02:00
parent 7468bb6794
commit de3fbffcf1
5 changed files with 30 additions and 36 deletions

View File

@ -107,7 +107,8 @@ scan()
/* Get the tree of the children Windows of the current root /* Get the tree of the children Windows of the current root
* Window */ * Window */
wins = xcb_query_tree_children(tree_r); if(!(wins = xcb_query_tree_children(tree_r)))
eprint("E: cannot get tree children\n");
tree_c_len = xcb_query_tree_children_length(tree_r); tree_c_len = xcb_query_tree_children_length(tree_r);
attr_wins = p_new(xcb_get_window_attributes_cookie_t, tree_c_len); attr_wins = p_new(xcb_get_window_attributes_cookie_t, tree_c_len);

View File

@ -54,17 +54,15 @@ client_loadprops(client_t * c, int screen)
{ {
int i, ntags = 0; int i, ntags = 0;
tag_t *tag; tag_t *tag;
char *prop; char *prop = NULL;
bool result = false; bool result = false;
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
ntags++; ntags++;
prop = p_new(char, ntags + 3);
if(xutil_gettextprop(globalconf.connection, c->win, if(xutil_gettextprop(globalconf.connection, c->win,
xutil_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"), xutil_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"),
prop, ntags + 3)) &prop))
{ {
for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next) for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
if(prop[i] == '1') if(prop[i] == '1')
@ -189,17 +187,18 @@ client_get_byname(client_t *list, char *name)
void void
client_updatetitle(client_t *c) client_updatetitle(client_t *c)
{ {
char buf[512]; char *name;
if(!xutil_gettextprop(globalconf.connection, c->win, if(!xutil_gettextprop(globalconf.connection, c->win,
xutil_intern_atom(globalconf.connection, "_NET_WM_NAME"), xutil_intern_atom(globalconf.connection, "_NET_WM_NAME"),
buf, ssizeof(buf))) &name))
xutil_gettextprop(globalconf.connection, c->win, if(!xutil_gettextprop(globalconf.connection, c->win,
xutil_intern_atom(globalconf.connection, "WM_NAME"), xutil_intern_atom(globalconf.connection, "WM_NAME"),
buf, ssizeof(buf)); &name))
if(c->name) return;
p_delete(&c->name); p_delete(&c->name);
c->name = a_strndup(buf, ssizeof(buf)); c->name = name;
titlebar_draw(c); titlebar_draw(c);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }

View File

@ -35,12 +35,11 @@
* \param w window * \param w window
* \param atom the atom * \param atom the atom
* \param text buffer to fill * \param text buffer to fill
* \param textlen buffer lenght
* \return true on sucess, falsse on failure * \return true on sucess, falsse on failure
*/ */
bool bool
xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
char *text, ssize_t textlen) char **text)
{ {
xcb_get_property_cookie_t prop_c; xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r; xcb_get_property_reply_t *prop_r;
@ -51,7 +50,7 @@ xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
XCB_GET_PROPERTY_TYPE_ANY, XCB_GET_PROPERTY_TYPE_ANY,
0L, 1000000L); 0L, 1000000L);
if(!text || !textlen) if(!text)
return false; return false;
prop_r = xcb_get_property_reply(conn, prop_c, NULL); prop_r = xcb_get_property_reply(conn, prop_c, NULL);
@ -71,17 +70,10 @@ xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
if(prop_r->type == STRING || if(prop_r->type == STRING ||
prop_r->type == xutil_intern_atom(conn, "UTF8_STRING")) prop_r->type == xutil_intern_atom(conn, "UTF8_STRING"))
{ {
if((ssize_t) prop_r->value_len < textlen - 1) *text = p_new(char, prop_r->value_len + 1);
{
/* use memcpy() because prop_val may not be \0 terminated */ /* use memcpy() because prop_val may not be \0 terminated */
memcpy(text, prop_val, prop_r->value_len); memcpy(*text, prop_val, prop_r->value_len);
text[prop_r->value_len] = '\0'; (*text)[prop_r->value_len] = '\0';
}
else
{
memcpy(text, prop_val, textlen - 2);
text[textlen - 1] = '\0';
}
} }
p_delete(&prop_r); p_delete(&prop_r);
@ -111,14 +103,14 @@ xutil_getlockmask(xcb_connection_t *conn, xcb_key_symbols_t *keysyms,
kc = modmap[i * modmap_r->keycodes_per_modifier + j]; kc = modmap[i * modmap_r->keycodes_per_modifier + j];
mask = (1 << i); mask = (1 << i);
if(numlockmask != NULL && if(numlockmask != NULL
kc == xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock)) && kc == xcb_key_symbols_get_keycode(keysyms, XK_Num_Lock))
*numlockmask = mask; *numlockmask = mask;
else if(shiftlockmask != NULL && else if(shiftlockmask != NULL
kc == xcb_key_symbols_get_keycode(keysyms, XK_Shift_Lock)) && kc == xcb_key_symbols_get_keycode(keysyms, XK_Shift_Lock))
*shiftlockmask = mask; *shiftlockmask = mask;
else if(capslockmask != NULL && else if(capslockmask != NULL
kc == xcb_key_symbols_get_keycode(keysyms, XK_Caps_Lock)) && kc == xcb_key_symbols_get_keycode(keysyms, XK_Caps_Lock))
*capslockmask = mask; *capslockmask = mask;
} }

View File

@ -31,7 +31,7 @@
/* XCB doesn't provide keysyms definition */ /* XCB doesn't provide keysyms definition */
#include <X11/keysym.h> #include <X11/keysym.h>
bool xutil_gettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char *, ssize_t); bool xutil_gettextprop(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **);
void xutil_getlockmask(xcb_connection_t *, xcb_key_symbols_t *, void xutil_getlockmask(xcb_connection_t *, xcb_key_symbols_t *,
unsigned int *, unsigned int *, unsigned int *); unsigned int *, unsigned int *, unsigned int *);

View File

@ -56,7 +56,7 @@ rule_t *
rule_matching_client(client_t *c) rule_matching_client(client_t *c)
{ {
rule_t *r; rule_t *r;
char *prop = NULL, buf[512]; char *prop = NULL, *buf = NULL;
regmatch_t tmp; regmatch_t tmp;
ssize_t len; ssize_t len;
class_hint_t *ch = NULL; class_hint_t *ch = NULL;
@ -87,9 +87,11 @@ rule_matching_client(client_t *c)
&& r->xpropval_r && r->xpropval_r
&& xutil_gettextprop(globalconf.connection, c->win, && xutil_gettextprop(globalconf.connection, c->win,
xutil_intern_atom(globalconf.connection, r->xprop), xutil_intern_atom(globalconf.connection, r->xprop),
buf, ssizeof(buf))) &buf))
ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0); ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
p_delete(&buf);
if(ret) if(ret)
{ {
p_delete(&prop); p_delete(&prop);