Get a client's property more intelligently

Previous, there was a round-trip after each request for a property since we
waited for the reply immediately. Instead, it makes a lot more sense to first
send all of the requests and then handle all the replies. This now takes only a
single round-trip for all the properties from client_update_properties().

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-08-09 13:54:49 +02:00
parent 84526dd630
commit 87237a197f
3 changed files with 64 additions and 36 deletions

View File

@ -427,6 +427,47 @@ client_focus(client_t *c)
client_set_focus(c, !c->nofocus); client_set_focus(c, !c->nofocus);
} }
static void
client_update_properties(client_t *c)
{
/* get all hints */
xcb_get_property_cookie_t wm_normal_hints = property_get_wm_normal_hints(c);
xcb_get_property_cookie_t wm_hints = property_get_wm_hints(c);
xcb_get_property_cookie_t wm_transient_for = property_get_wm_transient_for(c);
xcb_get_property_cookie_t wm_client_leader = property_get_wm_client_leader(c);
xcb_get_property_cookie_t wm_client_machine = property_get_wm_client_machine(c);
xcb_get_property_cookie_t wm_window_role = property_get_wm_window_role(c);
xcb_get_property_cookie_t net_wm_pid = property_get_net_wm_pid(c);
xcb_get_property_cookie_t net_wm_icon = property_get_net_wm_icon(c);
xcb_get_property_cookie_t wm_name = property_get_wm_name(c);
xcb_get_property_cookie_t net_wm_name = property_get_net_wm_name(c);
xcb_get_property_cookie_t wm_icon_name = property_get_wm_icon_name(c);
xcb_get_property_cookie_t net_wm_icon_name = property_get_net_wm_icon_name(c);
xcb_get_property_cookie_t wm_class = property_get_wm_class(c);
xcb_get_property_cookie_t wm_protocols = property_get_wm_protocols(c);
xcb_get_property_cookie_t opacity = xwindow_get_opacity_unchecked(c->window);
/* update strut */
ewmh_process_client_strut(c);
/* Now process all replies */
property_update_wm_normal_hints(c, wm_normal_hints);
property_update_wm_hints(c, wm_hints);
property_update_wm_transient_for(c, wm_transient_for);
property_update_wm_client_leader(c, wm_client_leader);
property_update_wm_client_machine(c, wm_client_machine);
property_update_wm_window_role(c, wm_window_role);
property_update_net_wm_pid(c, net_wm_pid);
property_update_net_wm_icon(c, net_wm_icon);
property_update_wm_name(c, wm_name);
property_update_net_wm_name(c, net_wm_name);
property_update_wm_icon_name(c, wm_icon_name);
property_update_net_wm_icon_name(c, net_wm_icon_name);
property_update_wm_class(c, wm_class);
property_update_wm_protocols(c, wm_protocols);
window_set_opacity(globalconf.L, -1, xwindow_get_opacity_from_cookie(opacity));
}
/** Manage a new client. /** Manage a new client.
* \param w The window. * \param w The window.
* \param wgeom Window geometry. * \param wgeom Window geometry.
@ -527,17 +568,8 @@ HANDLE_GEOM(height)
c->size_hints_honor = true; c->size_hints_honor = true;
luaA_object_emit_signal(globalconf.L, -1, "property::size_hints_honor", 0); luaA_object_emit_signal(globalconf.L, -1, "property::size_hints_honor", 0);
/* update hints */ /* update all properties */
property_update_wm_normal_hints(c, property_get_wm_normal_hints(c)); client_update_properties(c);
property_update_wm_hints(c, property_get_wm_hints(c));
property_update_wm_transient_for(c, property_get_wm_transient_for(c));
property_update_wm_client_leader(c, property_get_wm_client_leader(c));
property_update_wm_client_machine(c, property_get_wm_client_machine(c));
property_update_wm_window_role(c, property_get_wm_window_role(c));
property_update_net_wm_pid(c, property_get_net_wm_pid(c));
property_update_net_wm_icon(c, property_get_net_wm_icon(c));
window_set_opacity(globalconf.L, -1, xwindow_get_opacity(c->window));
/* Then check clients hints */ /* Then check clients hints */
ewmh_client_check_hints(c); ewmh_client_check_hints(c);
@ -545,17 +577,6 @@ HANDLE_GEOM(height)
/* Push client in stack */ /* Push client in stack */
client_raise(c); client_raise(c);
/* update window title */
property_update_wm_name(c, property_get_wm_name(c));
property_update_net_wm_name(c, property_get_net_wm_name(c));
property_update_wm_icon_name(c, property_get_wm_icon_name(c));
property_update_net_wm_icon_name(c, property_get_net_wm_icon_name(c));
property_update_wm_class(c, property_get_wm_class(c));
property_update_wm_protocols(c, property_get_wm_protocols(c));
/* update strut */
ewmh_process_client_strut(c);
ewmh_update_net_client_list(c->phys_screen); ewmh_update_net_client_list(c->phys_screen);
/* Always stay in NORMAL_STATE. Even though iconified seems more /* Always stay in NORMAL_STATE. Even though iconified seems more

View File

@ -146,6 +146,16 @@ xwindow_grabkeys(xcb_window_t win, key_array_t *keys)
xwindow_grabkey(win, *k); xwindow_grabkey(win, *k);
} }
/** Send a request for a window's opacity.
* \param win The window
* \return A cookie for xwindow_get_opacity_from_reply().
*/
xcb_get_property_cookie_t xwindow_get_opacity_unchecked(xcb_window_t win)
{
return xcb_get_property_unchecked(globalconf.connection, false, win,
_NET_WM_WINDOW_OPACITY, XCB_ATOM_CARDINAL, 0L, 1L);
}
/** Get the opacity of a window. /** Get the opacity of a window.
* \param win The window. * \param win The window.
* \return The opacity, between 0 and 1 or -1 or no opacity set. * \return The opacity, between 0 and 1 or -1 or no opacity set.
@ -153,32 +163,28 @@ xwindow_grabkeys(xcb_window_t win, key_array_t *keys)
double double
xwindow_get_opacity(xcb_window_t win) xwindow_get_opacity(xcb_window_t win)
{ {
double ret;
xcb_get_property_cookie_t prop_c = xcb_get_property_cookie_t prop_c =
xcb_get_property_unchecked(globalconf.connection, false, win, xwindow_get_opacity_unchecked(win);
_NET_WM_WINDOW_OPACITY, XCB_ATOM_CARDINAL, 0L, 1L); return xwindow_get_opacity_from_cookie(prop_c);
xcb_get_property_reply_t *prop_r =
xcb_get_property_reply(globalconf.connection, prop_c, NULL);
ret = xwindow_get_opacity_from_reply(prop_r);
p_delete(&prop_r);
return ret;
} }
/** Get the opacity of a window. /** Get the opacity of a window.
* \param prop_r A reply to a get property request for _NET_WM_WINDOW_OPACITY. * \param cookie A cookie for a reply to a get property request for _NET_WM_WINDOW_OPACITY.
* \return The opacity, between 0 and 1. * \return The opacity, between 0 and 1.
*/ */
double double
xwindow_get_opacity_from_reply(xcb_get_property_reply_t *prop_r) xwindow_get_opacity_from_cookie(xcb_get_property_cookie_t cookie)
{ {
xcb_get_property_reply_t *prop_r =
xcb_get_property_reply(globalconf.connection, cookie, NULL);
if(prop_r && prop_r->value_len && prop_r->format == 32) if(prop_r && prop_r->value_len && prop_r->format == 32)
{ {
uint32_t value = *(uint32_t *) xcb_get_property_value(prop_r); uint32_t value = *(uint32_t *) xcb_get_property_value(prop_r);
p_delete(&prop_r);
return (double) value / (double) 0xffffffff; return (double) value / (double) 0xffffffff;
} }
p_delete(&prop_r);
return -1; return -1;
} }

View File

@ -30,8 +30,9 @@ xcb_get_property_cookie_t xwindow_get_state_unchecked(xcb_window_t);
uint32_t xwindow_get_state_reply(xcb_get_property_cookie_t); uint32_t xwindow_get_state_reply(xcb_get_property_cookie_t);
void xwindow_configure(xcb_window_t, area_t, int); void xwindow_configure(xcb_window_t, area_t, int);
void xwindow_buttons_grab(xcb_window_t, button_array_t *); void xwindow_buttons_grab(xcb_window_t, button_array_t *);
xcb_get_property_cookie_t xwindow_get_opacity_unchecked(xcb_window_t);
double xwindow_get_opacity(xcb_window_t); double xwindow_get_opacity(xcb_window_t);
double xwindow_get_opacity_from_reply(xcb_get_property_reply_t *); double xwindow_get_opacity_from_cookie(xcb_get_property_cookie_t);
void xwindow_set_opacity(xcb_window_t, double); void xwindow_set_opacity(xcb_window_t, double);
void xwindow_grabkeys(xcb_window_t, key_array_t *); void xwindow_grabkeys(xcb_window_t, key_array_t *);
void xwindow_takefocus(xcb_window_t); void xwindow_takefocus(xcb_window_t);