ewmh: Factor out common code into a helper function
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
bbe86e4e25
commit
61fdd8cd40
57
ewmh.c
57
ewmh.c
|
@ -359,6 +359,30 @@ ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
|
|||
lua_pop(globalconf.L, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
ewmh_process_desktop(client_t *c, uint32_t desktop)
|
||||
{
|
||||
int idx = desktop;
|
||||
if(desktop == 0xffffffff)
|
||||
c->sticky = true;
|
||||
else if (idx >= 0 && idx < globalconf.tags.len)
|
||||
for(int i = 0; i < globalconf.tags.len; i++)
|
||||
if(idx == i)
|
||||
{
|
||||
luaA_object_push(globalconf.L, globalconf.tags.tab[i]);
|
||||
tag_client(c);
|
||||
}
|
||||
else
|
||||
untag_client(c, globalconf.tags.tab[i]);
|
||||
else
|
||||
/* Value out of bounds, just give it the first tag */
|
||||
if (globalconf.tags.len > 0)
|
||||
{
|
||||
luaA_object_push(globalconf.L, globalconf.tags.tab[0]);
|
||||
tag_client(c);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ewmh_process_client_message(xcb_client_message_event_t *ev)
|
||||
{
|
||||
|
@ -383,17 +407,7 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
|
|||
{
|
||||
if((c = client_getbywin(ev->window)))
|
||||
{
|
||||
if(ev->data.data32[0] == 0xffffffff)
|
||||
c->sticky = true;
|
||||
else
|
||||
for(int i = 0; i < globalconf.tags.len; i++)
|
||||
if((int)ev->data.data32[0] == i)
|
||||
{
|
||||
luaA_object_push(globalconf.L, globalconf.tags.tab[i]);
|
||||
tag_client(c);
|
||||
}
|
||||
else
|
||||
untag_client(c, globalconf.tags.tab[i]);
|
||||
ewmh_process_desktop(c, ev->data.data32[0]);
|
||||
}
|
||||
}
|
||||
else if(ev->type == _NET_WM_STATE)
|
||||
|
@ -485,7 +499,6 @@ ewmh_client_check_hints(client_t *c)
|
|||
{
|
||||
xcb_atom_t *state;
|
||||
void *data = NULL;
|
||||
int desktop;
|
||||
xcb_get_property_cookie_t c0, c1, c2;
|
||||
xcb_get_property_reply_t *reply;
|
||||
|
||||
|
@ -502,25 +515,7 @@ ewmh_client_check_hints(client_t *c)
|
|||
reply = xcb_get_property_reply(globalconf.connection, c0, NULL);
|
||||
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
|
||||
{
|
||||
desktop = *(uint32_t *) data;
|
||||
if(desktop == -1)
|
||||
c->sticky = true;
|
||||
else if (desktop >= 0 && desktop < globalconf.tags.len)
|
||||
for(int i = 0; i < globalconf.tags.len; i++)
|
||||
if(desktop == i)
|
||||
{
|
||||
luaA_object_push(globalconf.L, globalconf.tags.tab[i]);
|
||||
tag_client(c);
|
||||
}
|
||||
else
|
||||
untag_client(c, globalconf.tags.tab[i]);
|
||||
else
|
||||
/* Value out of bounds, just give it the first tag */
|
||||
if (globalconf.tags.len > 0)
|
||||
{
|
||||
luaA_object_push(globalconf.L, globalconf.tags.tab[0]);
|
||||
tag_client(c);
|
||||
}
|
||||
ewmh_process_desktop(c, *(uint32_t *) data);
|
||||
}
|
||||
|
||||
p_delete(&reply);
|
||||
|
|
Loading…
Reference in New Issue