From 61fdd8cd406c79595fedf0c439f96441238c46cf Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 17 Mar 2014 15:33:28 +0100 Subject: [PATCH] ewmh: Factor out common code into a helper function Signed-off-by: Uli Schlachter --- ewmh.c | 57 ++++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/ewmh.c b/ewmh.c index daf0d692..5f3c5697 100644 --- a/ewmh.c +++ b/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);