Refactor setting of c->transient_for

This creates a new helper function for setting the transient_for property of a
client. This is a preparation for a following commit. No behaviour changes
intended.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-22 21:02:47 +01:00
parent a6dd6b4a20
commit 9907f804b2
3 changed files with 29 additions and 16 deletions

View File

@ -211,6 +211,32 @@ DO_CLIENT_SET_STRING_PROPERTY(role)
DO_CLIENT_SET_STRING_PROPERTY(machine)
#undef DO_CLIENT_SET_STRING_PROPERTY
void
client_find_transient_for(client_t *c, xcb_window_t trans)
{
int counter;
client_t *tc, *tmp;
tmp = tc = client_getbywin(trans);
/* Verify that there are no loops in the transient_for relation after we are done */
for(counter = 0; tmp != NULL && counter <= globalconf.stack.len; counter++)
{
if (tmp == c)
/* We arrived back at the client we started from, so there is a loop */
counter = globalconf.stack.len+1;
tmp = tmp->transient_for;
}
if (counter <= globalconf.stack.len)
{
lua_State *L = globalconf_get_lua_State();
luaA_object_push(L, c);
client_set_transient_for(L, -1, tc);
lua_pop(L, 1);
}
}
void
client_set_class_instance(lua_State *L, int cidx, const char *class, const char *instance)
{

View File

@ -181,6 +181,7 @@ void client_restore_enterleave_events(void);
void client_refresh_partial(client_t *, int16_t, int16_t, uint16_t, uint16_t);
void client_class_setup(lua_State *);
void client_send_configure(client_t *);
void client_find_transient_for(client_t *, xcb_window_t);
drawable_t *client_get_drawable(client_t *, int, int);
drawable_t *client_get_drawable_offset(client_t *, int *, int *);

View File

@ -105,32 +105,18 @@ property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie)
{
lua_State *L = globalconf_get_lua_State();
xcb_window_t trans;
int counter;
client_t *tc, *tmp;
if(!xcb_icccm_get_wm_transient_for_reply(globalconf.connection,
cookie,
&trans, NULL))
return;
tmp = tc = client_getbywin(trans);
luaA_object_push(L, c);
client_set_type(L, -1, WINDOW_TYPE_DIALOG);
client_set_above(L, -1, false);
/* Verify that there are no loops in the transient_for relation after we are done */
for(counter = 0; tmp != NULL && counter <= globalconf.stack.len; counter++)
{
if (tmp == c)
/* We arrived back at the client we started from, so there is a loop */
counter = globalconf.stack.len+1;
tmp = tmp->transient_for;
}
if (counter <= globalconf.stack.len)
client_set_transient_for(L, -1, tc);
lua_pop(L, 1);
client_find_transient_for(c, trans);
}
xcb_get_property_cookie_t