[xutil] Rework some stuff and rename xgettextprop()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-09 13:46:42 +02:00
parent 328a04fb17
commit 82f305b1b1
4 changed files with 50 additions and 41 deletions

View File

@ -62,9 +62,9 @@ client_loadprops(Client * c, int screen)
prop = p_new(char, ntags + 3); prop = p_new(char, ntags + 3);
if(xgettextprop(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, ntags + 3))
{ {
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')
@ -143,13 +143,13 @@ client_get_byname(Client *list, char *name)
void void
client_updatetitle(Client *c) client_updatetitle(Client *c)
{ {
if(!xgettextprop(globalconf.connection, c->win, if(!xutil_gettextprop(globalconf.connection, c->win,
xutil_intern_atom(globalconf.connection, "_NET_WM_NAME"), c->name, sizeof(c->name))) xutil_intern_atom(globalconf.connection, "_NET_WM_NAME"),
xgettextprop(globalconf.connection, c->win, c->name, sizeof(c->name)))
xutil_intern_atom(globalconf.connection, "WM_NAME"), c->name, sizeof(c->name)); xutil_gettextprop(globalconf.connection, c->win,
xutil_intern_atom(globalconf.connection, "WM_NAME"),
c->name, sizeof(c->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

@ -24,14 +24,21 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xcb_atom.h> #include <xcb/xcb_atom.h>
#include <xcb/xinerama.h>
#include "common/util.h" #include "common/util.h"
#include "common/xutil.h" #include "common/xutil.h"
/** Get the string value of an atom.
* \param conn X connection
* \param w window
* \param atom the atom
* \param text buffer to fill
* \param textlen buffer lenght
* \return true on sucess, falsse on failure
*/
bool bool
xgettextprop(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, ssize_t textlen)
{ {
xcb_get_property_reply_t *prop_r = NULL; xcb_get_property_reply_t *prop_r = NULL;
void *prop_val; void *prop_val;
@ -39,7 +46,6 @@ xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
if(!text || !textlen) if(!text || !textlen)
return false; return false;
text[0] = '\0';
prop_r = 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,
@ -52,7 +58,6 @@ xgettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
{ {
if(prop_r) if(prop_r)
p_delete(&prop_r); p_delete(&prop_r);
return false; return false;
} }
@ -109,7 +114,6 @@ xutil_getlockmask(xcb_connection_t *conn, xcb_key_symbols_t *keysyms,
/** Equivalent to 'XGetTransientForHint' which is actually a /** Equivalent to 'XGetTransientForHint' which is actually a
* 'XGetWindowProperty' which gets the WM_TRANSIENT_FOR property of * 'XGetWindowProperty' which gets the WM_TRANSIENT_FOR property of
* the specified window * the specified window
*
* \param c X connection * \param c X connection
* \param win get the property from this window * \param win get the property from this window
* \param prop_win returns the WM_TRANSIENT_FOR property of win * \param prop_win returns the WM_TRANSIENT_FOR property of win
@ -117,7 +121,7 @@ xutil_getlockmask(xcb_connection_t *conn, xcb_key_symbols_t *keysyms,
*/ */
bool bool
xutil_get_transient_for_hint(xcb_connection_t *c, xcb_window_t win, xutil_get_transient_for_hint(xcb_connection_t *c, xcb_window_t win,
xcb_window_t *prop_win) xcb_window_t *prop_win)
{ {
xcb_get_property_reply_t *t_hint_r; xcb_get_property_reply_t *t_hint_r;
@ -145,21 +149,27 @@ xutil_get_transient_for_hint(xcb_connection_t *c, xcb_window_t win,
return true; return true;
} }
/** Get an internal atom.
* \param c X connection
* \param property atom name
* \return an brand new xcb_atom_t
*/
xcb_atom_t xcb_atom_t
xutil_intern_atom(xcb_connection_t *c, const char *property) xutil_intern_atom(xcb_connection_t *c, const char *property)
{ {
xcb_atom_t atom; xcb_atom_t atom = 0;
xcb_intern_atom_reply_t *r_atom; xcb_intern_atom_reply_t *r_atom;
r_atom = xcb_intern_atom_reply(c, if((r_atom = xcb_intern_atom_reply(c,
xcb_intern_atom_unchecked(c, false, strlen(property), property), xcb_intern_atom_unchecked(c,
NULL); false,
a_strlen(property),
if(!r_atom) property),
return 0; NULL)))
{
atom = r_atom->atom; atom = r_atom->atom;
p_delete(&r_atom); p_delete(&r_atom);
}
return atom; return atom;
} }
@ -167,18 +177,17 @@ xutil_intern_atom(xcb_connection_t *c, const char *property)
class_hint_t * class_hint_t *
xutil_get_class_hint(xcb_connection_t *conn, xcb_window_t win) xutil_get_class_hint(xcb_connection_t *conn, xcb_window_t win)
{ {
xcb_get_property_reply_t *class_hint_r = NULL; xcb_get_property_reply_t *class_hint_r;
xcb_get_property_cookie_t class_hint_c;
char *data; char *data;
int len_name, len_class; int len_name, len_class;
class_hint_t *ch;
class_hint_t *ch = p_new(class_hint_t, 1); class_hint_c = xcb_get_property_unchecked(conn, false, win, WM_CLASS,
STRING, 0L, 2048L);
ch = p_new(class_hint_t, 1);
class_hint_r = xcb_get_property_reply(conn, class_hint_r = xcb_get_property_reply(conn, class_hint_c, NULL);
xcb_get_property_unchecked(conn,
false, win, WM_CLASS,
STRING, 0L, 2048L),
NULL);
if(!class_hint_r || class_hint_r->type != STRING || if(!class_hint_r || class_hint_r->type != STRING ||
class_hint_r->format != 8) class_hint_r->format != 8)
@ -191,8 +200,8 @@ xutil_get_class_hint(xcb_connection_t *conn, xcb_window_t win)
data = xcb_get_property_value(class_hint_r); data = xcb_get_property_value(class_hint_r);
len_name = strlen(data); len_name = a_strlen(data);
len_class = strlen(data + len_name + 1); len_class = a_strlen(data + len_name + 1);
ch->res_name = strndup(data, len_name); ch->res_name = strndup(data, len_name);
ch->res_class = strndup(data + len_name + 1, len_class); ch->res_class = strndup(data + len_name + 1, len_class);

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 xgettextprop(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 *, ssize_t);
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

@ -81,9 +81,9 @@ client_match_rule(Client *c, Rule *r)
if(r->xprop if(r->xprop
&& r->xpropval_r && r->xpropval_r
&& xgettextprop(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, ssizeof(buf)))
ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0); ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
return ret; return ret;