diff --git a/ewmh.c b/ewmh.c index 1a72953d..d0ff5e5c 100644 --- a/ewmh.c +++ b/ewmh.c @@ -187,18 +187,11 @@ ewmh_update_net_numbers_of_desktop(int phys_screen) void ewmh_update_net_current_desktop(int phys_screen) { - tag_array_t *tags = &globalconf.screens.tab[phys_screen].tags; - uint32_t count = 0; - tag_t **curtags = tags_get_current( &globalconf.screens.tab[phys_screen]); - - while(count < (uint32_t) tags->len && tags->tab[count] != curtags[0]) - count++; + uint32_t idx = tags_get_first_selected_index(&globalconf.screens.tab[phys_screen]); xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, xutil_screen_get(globalconf.connection, phys_screen)->root, - _NET_CURRENT_DESKTOP, CARDINAL, 32, 1, &count); - - p_delete(&curtags); + _NET_CURRENT_DESKTOP, CARDINAL, 32, 1, &idx); } void diff --git a/tag.c b/tag.c index c36311ba..22e0fb1a 100644 --- a/tag.c +++ b/tag.c @@ -206,25 +206,19 @@ is_client_tagged(client_t *c, tag_t *t) return false; } -/** Get the current tags for the specified screen. - * Returned pointer must be p_delete'd after. +/** Get the index of the first selected tag. * \param screen Screen. - * \return A double pointer of tag list finished with a NULL element. + * \return Its index. */ -tag_t ** -tags_get_current(screen_t *screen) +int +tags_get_first_selected_index(screen_t *screen) { - tag_t **out = p_new(tag_t *, screen->tags.len + 1); - int n = 0; - foreach(tag, screen->tags) if((*tag)->selected) - out[n++] = *tag; - - return out; + return tag_array_indexof(&screen->tags, tag); + return 0; } - /** Set a tag to be the only one viewed. * \param target the tag to see */ diff --git a/tag.h b/tag.h index b5178255..7154c3f5 100644 --- a/tag.h +++ b/tag.h @@ -38,7 +38,7 @@ struct tag client_array_t clients; }; -tag_t **tags_get_current(screen_t *); +int tags_get_first_selected_index(screen_t *); void tag_client(client_t *); void untag_client(client_t *, tag_t *); bool is_client_tagged(client_t *, tag_t *);