Update to new xcb-util library.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Arnaud Fontaine 2008-09-09 16:14:36 +02:00 committed by Julien Danjou
parent 56471ca618
commit 00d8a0cddd
8 changed files with 117 additions and 144 deletions

View File

@ -149,7 +149,7 @@ scan(void)
if(!attr_r || attr_r->override_redirect
|| (attr_r->map_state != XCB_MAP_STATE_VIEWABLE && !has_awesome_prop)
|| (state == XCB_WM_WITHDRAWN_STATE && !has_awesome_prop))
|| (state == XCB_WM_STATE_WITHDRAWN && !has_awesome_prop))
{
geom_wins[i] = NULL;
p_delete(&attr_r);

View File

@ -137,11 +137,11 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED
pangocairo
xcb-randr
xcb-xinerama
xcb-event>=0.2.1
xcb-aux>=0.2.1
xcb-atom>=0.2.1
xcb-keysyms>=0.2.1
xcb-icccm>=0.2.1
xcb-event>=0.3.0
xcb-aux>=0.3.0
xcb-atom>=0.3.0
xcb-keysyms>=0.3.0
xcb-icccm>=0.3.0
cairo-xcb)
if(NOT AWESOME_REQUIRED_FOUND OR NOT AWESOME_COMMON_REQUIRED_FOUND)

147
client.c
View File

@ -103,16 +103,19 @@ client_loadprops(client_t * c, screen_t *screen)
static bool
window_isprotodel(xcb_window_t win)
{
uint32_t i, n;
xcb_atom_t *protocols;
uint32_t i;
xcb_get_wm_protocols_reply_t protocols;
bool ret = false;
if(xcb_get_wm_protocols(globalconf.connection, win, &n, &protocols))
if(xcb_get_wm_protocols_reply(globalconf.connection,
xcb_get_wm_protocols_unchecked(globalconf.connection,
win, WM_PROTOCOLS),
&protocols, NULL))
{
for(i = 0; !ret && i < n; i++)
if(protocols[i] == WM_DELETE_WINDOW)
for(i = 0; !ret && i < protocols.atoms_len; i++)
if(protocols.atoms[i] == WM_DELETE_WINDOW)
ret = true;
p_delete(&protocols);
xcb_get_wm_protocols_reply_wipe(&protocols);
}
return ret;
}
@ -216,9 +219,9 @@ client_ban(client_t *c)
client_unfocus(c);
xcb_unmap_window(globalconf.connection, c->win);
if(c->ishidden)
window_state_set(c->win, XCB_WM_ICONIC_STATE);
window_state_set(c->win, XCB_WM_STATE_ICONIC);
else
window_state_set(c->win, XCB_WM_WITHDRAWN_STATE);
window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
if(c->titlebar && c->titlebar->position && c->titlebar->sw)
xcb_unmap_window(globalconf.connection, c->titlebar->sw->window);
}
@ -355,8 +358,8 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
xcb_get_property_cookie_t ewmh_icon_cookie;
client_t *c, *t = NULL;
xcb_window_t trans;
bool rettrans, retloadprops;
xcb_size_hints_t *u_size_hints;
bool rettrans, retloadprops, is_size_hints;
xcb_size_hints_t size_hints;
const uint32_t select_input_val[] =
{
XCB_EVENT_MASK_STRUCTURE_NOTIFY
@ -394,7 +397,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
c->icon = ewmh_window_icon_get_reply(ewmh_icon_cookie);
/* update hints */
u_size_hints = client_updatesizehints(c);
is_size_hints = client_updatesizehints(c, &size_hints);
client_updatewmhints(c);
/* Try to load props if any */
@ -405,7 +408,10 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
ewmh_check_client_hints(c);
/* check for transient and set tags like its parent */
if((rettrans = xcb_get_wm_transient_for(globalconf.connection, w, &trans))
if((rettrans = xcb_get_wm_transient_for_reply(globalconf.connection,
xcb_get_wm_transient_for_unchecked(globalconf.connection,
w),
&trans, NULL))
&& (t = client_getbywin(trans)))
{
tag_array_t *tags = &globalconf.screens[c->screen].tags;
@ -436,18 +442,15 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
if(c->floating_placement
&& !retloadprops
&& u_size_hints
&& !(xcb_size_hints_get_flags(u_size_hints) & (XCB_SIZE_US_POSITION_HINT
| XCB_SIZE_P_POSITION_HINT)))
&& is_size_hints
&& !(size_hints.flags & (XCB_SIZE_HINT_US_POSITION
| XCB_SIZE_HINT_P_POSITION)))
{
if(c->isfloating)
client_resize(c, c->floating_placement(c), false);
else
c->f_geometry = c->floating_placement(c);
}
if(u_size_hints)
xcb_free_size_hints(u_size_hints);
}
/** Compute client geometry with respect to its geometry hints.
@ -653,7 +656,7 @@ void
client_unban(client_t *c)
{
xcb_map_window(globalconf.connection, c->win);
window_state_set(c->win, XCB_WM_NORMAL_STATE);
window_state_set(c->win, XCB_WM_STATE_NORMAL);
if(c->titlebar && c->titlebar->sw && c->titlebar->position)
xcb_map_window(globalconf.connection, c->titlebar->sw->window);
}
@ -682,7 +685,7 @@ client_unmanage(client_t *c)
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
XCB_BUTTON_MASK_ANY);
window_state_set(c->win, XCB_WM_WITHDRAWN_STATE);
window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
xcb_flush(globalconf.connection);
xcb_ungrab_server(globalconf.connection);
@ -717,14 +720,13 @@ client_unmanage(client_t *c)
void
client_updatewmhints(client_t *c)
{
xcb_wm_hints_t *wmh;
uint32_t wm_hints_flags;
xcb_wm_hints_t wmh;
if((wmh = xcb_get_wm_hints(globalconf.connection, c->win)))
if(xcb_get_wm_hints_reply(globalconf.connection,
xcb_get_wm_hints_unchecked(globalconf.connection, c->win),
&wmh, NULL))
{
bool isurgent;
wm_hints_flags = xcb_wm_hints_get_flags(wmh);
isurgent = xcb_wm_hints_get_urgency(wmh);
bool isurgent = xcb_wm_hints_get_urgency(&wmh);
if(isurgent != c->isurgent)
{
c->isurgent = isurgent;
@ -735,13 +737,12 @@ client_updatewmhints(client_t *c)
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
}
if((wm_hints_flags & XCB_WM_STATE_HINT) &&
(xcb_wm_hints_get_initial_state(wmh) == XCB_WM_WITHDRAWN_STATE))
if((wmh.flags & XCB_WM_HINT_STATE) &&
wmh.initial_state == XCB_WM_STATE_WITHDRAWN)
{
client_setborder(c, 0);
c->skip = true;
}
xcb_free_wm_hints(wmh);
}
}
@ -749,45 +750,63 @@ client_updatewmhints(client_t *c)
* \param c The client.
* \return A pointer to a xcb_size_hints_t.
*/
xcb_size_hints_t *
client_updatesizehints(client_t *c)
bool
client_updatesizehints(client_t *c, xcb_size_hints_t *size_hints)
{
long msize;
xcb_size_hints_t *size;
uint32_t size_flags;
if(!xcb_get_wm_normal_hints_reply(globalconf.connection,
xcb_get_wm_normal_hints_unchecked(globalconf.connection,
c->win),
size_hints, NULL))
return false;
if(!(size = xcb_get_wm_normal_hints(globalconf.connection, c->win, &msize)))
return NULL;
size_flags = xcb_size_hints_get_flags(size);
if((size_flags & XCB_SIZE_P_SIZE_HINT))
xcb_size_hints_get_base_size(size, &c->basew, &c->baseh);
else if((size_flags & XCB_SIZE_P_MIN_SIZE_HINT))
xcb_size_hints_get_min_size(size, &c->basew, &c->baseh);
if((size_hints->flags & XCB_SIZE_HINT_P_SIZE))
{
c->basew = size_hints->base_width;
c->baseh = size_hints->base_height;
}
else if((size_hints->flags & XCB_SIZE_HINT_P_MIN_SIZE))
{
c->basew = size_hints->min_width;
c->baseh = size_hints->min_height;
}
else
c->basew = c->baseh = 0;
if((size_flags & XCB_SIZE_P_RESIZE_INC_HINT))
xcb_size_hints_get_increase(size, &c->incw, &c->inch);
if((size_hints->flags & XCB_SIZE_HINT_P_RESIZE_INC))
{
c->incw = size_hints->width_inc;
c->inch = size_hints->height_inc;
}
else
c->incw = c->inch = 0;
if((size_flags & XCB_SIZE_P_MAX_SIZE_HINT))
xcb_size_hints_get_max_size(size, &c->maxw, &c->maxh);
if((size_hints->flags & XCB_SIZE_HINT_P_MAX_SIZE))
{
c->maxw = size_hints->max_width;
c->maxh = size_hints->max_height;
}
else
c->maxw = c->maxh = 0;
if((size_flags & XCB_SIZE_P_MIN_SIZE_HINT))
xcb_size_hints_get_min_size(size, &c->minw, &c->minh);
else if((size_flags & XCB_SIZE_BASE_SIZE_HINT))
xcb_size_hints_get_base_size(size, &c->minw, &c->minh);
if((size_hints->flags & XCB_SIZE_HINT_P_MIN_SIZE))
{
c->minw = size_hints->min_width;
c->minh = size_hints->min_height;
}
else if((size_hints->flags & XCB_SIZE_HINT_BASE_SIZE))
{
c->minw = size_hints->base_width;
c->minh = size_hints->base_height;
}
else
c->minw = c->minh = 0;
if((size_flags & XCB_SIZE_P_ASPECT_HINT))
if((size_hints->flags & XCB_SIZE_HINT_P_ASPECT))
{
xcb_size_hints_get_min_aspect(size, &c->minax, &c->minay);
xcb_size_hints_get_max_aspect(size, &c->maxax, &c->maxay);
c->minax = size_hints->min_aspect_num;
c->minay = size_hints->min_aspect_den;
c->maxax = size_hints->max_aspect_num;
c->maxay = size_hints->max_aspect_den;
}
else
c->minax = c->maxax = c->minay = c->maxay = 0;
@ -799,7 +818,7 @@ client_updatesizehints(client_t *c)
c->hassizehints = !(!c->basew && !c->baseh && !c->incw && !c->inch
&& !c->maxw && !c->maxh && !c->minw && !c->minh
&& !c->minax && !c->maxax && !c->minax && !c->minay);
return size;
return true;
}
/** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not
@ -1275,7 +1294,7 @@ luaA_client_index(lua_State *L)
const char *buf = luaL_checklstring(L, 2, &len);
char *value;
void *data;
xutil_class_hint_t hint;
xcb_get_wm_class_reply_t hint;
xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r = NULL;
double d;
@ -1292,16 +1311,20 @@ luaA_client_index(lua_State *L)
lua_pushstring(L, (*c)->name);
break;
case A_TK_CLASS:
if(!xutil_class_hint_get(globalconf.connection, (*c)->win, &hint))
if(!xcb_get_wm_class_reply(globalconf.connection,
xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
&hint, NULL))
return 0;
lua_pushstring(L, hint.res_class);
xutil_class_hint_wipe(&hint);
lua_pushstring(L, hint.class);
xcb_get_wm_class_reply_wipe(&hint);
break;
case A_TK_INSTANCE:
if(!xutil_class_hint_get(globalconf.connection, (*c)->win, &hint))
if(!xcb_get_wm_class_reply(globalconf.connection,
xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
&hint, NULL))
return 0;
lua_pushstring(L, hint.res_name);
xutil_class_hint_wipe(&hint);
lua_pushstring(L, hint.name);
xcb_get_wm_class_reply_wipe(&hint);
break;
case A_TK_ROLE:
if(!xutil_text_prop_get(globalconf.connection, (*c)->win,

View File

@ -39,7 +39,7 @@ area_t client_geometry_hints(client_t *, area_t);
bool client_resize(client_t *, area_t, bool);
void client_unmanage(client_t *);
void client_updatewmhints(client_t *);
xcb_size_hints_t *client_updatesizehints(client_t *);
bool client_updatesizehints(client_t *, xcb_size_hints_t *);
bool client_updatetitle(client_t *);
void client_saveprops(client_t *);
void client_kill(client_t *);

View File

@ -26,6 +26,7 @@
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_icccm.h>
#include "common/util.h"
#include "common/xutil.h"
@ -43,19 +44,14 @@ bool
xutil_text_prop_get(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
char **text, ssize_t *len)
{
xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r;
prop_c = xcb_get_property_unchecked(conn, false,
w, atom,
XCB_GET_PROPERTY_TYPE_ANY,
0L, 1000000L);
prop_r = xcb_get_property_reply(conn, prop_c, NULL);
if(!prop_r || !prop_r->value_len || prop_r->format != 8)
xcb_get_text_property_reply_t reply;
if(!xcb_get_text_property_reply(conn,
xcb_get_text_property_unchecked(conn, w,
atom),
&reply, NULL) ||
!reply.name_len || reply.format != 8)
{
p_delete(&prop_r);
xcb_get_text_property_reply_wipe(&reply);
return false;
}
@ -64,14 +60,14 @@ xutil_text_prop_get(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
/* Check whether the returned property value is just an ascii
* string or utf8 string. At the moment it doesn't handle
* COMPOUND_TEXT and multibyte but it's not needed... */
if(prop_r->type == STRING || prop_r->type == UTF8_STRING)
if(reply.encoding == STRING || reply.encoding == UTF8_STRING)
{
void *prop_val = xcb_get_property_value(prop_r);
*text = p_new(char, prop_r->value_len + 1);
/* use memcpy() because prop_val may not be \0 terminated */
memcpy(*text, prop_val, prop_r->value_len);
(*text)[prop_r->value_len] = '\0';
*len = prop_r->value_len;
*text = p_new(char, reply.name_len + 1);
/* Use memcpy() because the property name is not be \0
* terminated */
memcpy(*text, reply.name, reply.name_len);
(*text)[reply.name_len] = '\0';
*len = reply.name_len;
}
else
{
@ -80,7 +76,7 @@ xutil_text_prop_get(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
}
}
p_delete(&prop_r);
xcb_get_text_property_reply_wipe(&reply);
return true;
}
@ -128,41 +124,6 @@ xutil_lock_mask_get(xcb_connection_t *connection,
p_delete(&modmap_r);
}
bool
xutil_class_hint_get(xcb_connection_t *conn, xcb_window_t win,
xutil_class_hint_t *ch)
{
xcb_get_property_reply_t *class_hint_r;
xcb_get_property_cookie_t class_hint_c;
char *data;
int len_name, len_class;
class_hint_c = xcb_get_property_unchecked(conn, false, win, WM_CLASS,
STRING, 0L, 2048L);
class_hint_r = xcb_get_property_reply(conn, class_hint_c, NULL);
if(!class_hint_r
|| class_hint_r->type != STRING
|| class_hint_r->format != 8)
{
p_delete(&class_hint_r);
return false;
}
data = xcb_get_property_value(class_hint_r);
len_name = a_strlen(data);
len_class = a_strlen(data + len_name + 1);
ch->res_name = a_strndup(data, len_name);
ch->res_class = a_strndup(data + len_name + 1, len_class);
p_delete(&class_hint_r);
return true;
}
/* Number of different errors */
#define ERRORS_NBR 256

View File

@ -94,21 +94,6 @@
/* Server is defective */
#define XUTIL_BAD_IMPLEMENTATION 17
typedef struct
{
char *res_name;
char *res_class;
} xutil_class_hint_t;
static inline void
xutil_class_hint_wipe(xutil_class_hint_t *c)
{
p_delete(&c->res_name);
p_delete(&c->res_class);
}
bool xutil_class_hint_get(xcb_connection_t *, xcb_window_t, xutil_class_hint_t *);
bool xutil_text_prop_get(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **, ssize_t *);
void xutil_lock_mask_get(xcb_connection_t *, xcb_get_modifier_mapping_cookie_t,

12
event.c
View File

@ -519,6 +519,7 @@ event_handle_propertynotify(void *data __attribute__ ((unused)),
client_t *c;
xcb_window_t trans;
xembed_window_t *emwin;
xcb_size_hints_t size_hints;
if(ev->state == XCB_PROPERTY_DELETE)
return 0; /* ignore */
@ -528,13 +529,16 @@ event_handle_propertynotify(void *data __attribute__ ((unused)),
{
if(ev->atom == WM_TRANSIENT_FOR)
{
xcb_get_wm_transient_for(connection, c->win, &trans);
xcb_get_wm_transient_for_reply(connection,
xcb_get_wm_transient_for_unchecked(connection,
c->win),
&trans, NULL);
if(!c->isfloating
&& (c->isfloating = (client_getbywin(trans) != NULL)))
globalconf.screens[c->screen].need_arrange = true;
}
else if (ev->atom == WM_NORMAL_HINTS)
xcb_free_size_hints(client_updatesizehints(c));
client_updatesizehints(c, &size_hints);
else if (ev->atom == WM_HINTS)
client_updatewmhints(c);
else if(ev->atom == WM_NAME || ev->atom == _NET_WM_NAME)
@ -573,7 +577,7 @@ event_handle_unmapnotify(void *data __attribute__ ((unused)),
{
if(ev->event == xutil_screen_get(connection, c->phys_screen)->root
&& send_event
&& window_state_get_reply(window_state_get_unchecked(c->win)) == XCB_WM_NORMAL_STATE)
&& window_state_get_reply(window_state_get_unchecked(c->win)) == XCB_WM_STATE_NORMAL)
client_unmanage(c);
}
else if((em = xembed_getbywin(globalconf.embedded, ev->window)))
@ -637,7 +641,7 @@ event_handle_clientmessage(void *data __attribute__ ((unused)),
{
if((c = client_getbywin(ev->window))
&& ev->format == 32
&& ev->data.data32[0] == XCB_WM_ICONIC_STATE)
&& ev->data.data32[0] == XCB_WM_STATE_ICONIC)
{
c->ishidden = true;
globalconf.screens[c->screen].need_arrange = true;

View File

@ -140,7 +140,7 @@ systray_request_handle(xcb_window_t embed_win, int phys_screen, xembed_info_t *i
xcb_change_window_attributes(globalconf.connection, embed_win, XCB_CW_EVENT_MASK,
select_input_val);
window_state_set(embed_win, XCB_WM_WITHDRAWN_STATE);
window_state_set(embed_win, XCB_WM_STATE_WITHDRAWN);
xcb_reparent_window(globalconf.connection, embed_win,
globalconf.screens[phys_screen].systray.window,