module/i3: detect 'current' workspace while iterating workspaces

This commit is contained in:
Daniel Eklöf 2019-02-09 21:55:08 +01:00
parent 330ad48dfd
commit d631e47a5e

View file

@ -763,6 +763,8 @@ content(struct module *mod)
struct exposable *particles[m->workspaces.count + 1]; struct exposable *particles[m->workspaces.count + 1];
size_t particle_count = 0; size_t particle_count = 0;
struct exposable *current = NULL;
for (size_t i = 0; i < m->workspaces.count; i++) { for (size_t i = 0; i < m->workspaces.count; i++) {
const struct workspace *ws = &m->workspaces.v[i]; const struct workspace *ws = &m->workspaces.v[i];
const struct ws_content *template = NULL; const struct ws_content *template = NULL;
@ -776,11 +778,6 @@ content(struct module *mod)
template = ws_content_for_name(m, ""); template = ws_content_for_name(m, "");
} }
if (template == NULL) {
LOG_WARN("no ws template for %s, and no default template available", ws->name);
continue;
}
const char *state = const char *state =
ws->urgent ? "urgent" : ws->urgent ? "urgent" :
ws->visible ? ws->focused ? "focused" : "unfocused" : ws->visible ? ws->focused ? "focused" : "unfocused" :
@ -800,40 +797,25 @@ content(struct module *mod)
.count = 7, .count = 7,
}; };
if (ws->focused) {
const struct ws_content *cur = ws_content_for_name(m, "current");
current = cur->content->instantiate(cur->content, &tags);
}
if (template == NULL) {
LOG_WARN(
"no ws template for %s, and no default template available",
ws->name);
} else {
particles[particle_count++] = template->content->instantiate( particles[particle_count++] = template->content->instantiate(
template->content, &tags); template->content, &tags);
}
tag_set_destroy(&tags); tag_set_destroy(&tags);
} }
/* Find currently focused workspace */ if (current != NULL)
const struct workspace *ws = NULL; particles[particle_count++] = current;
size_t count = 0;
for (size_t i = 0; i < m->workspaces.count; i++) {
if (m->workspaces.v[i].focused) {
ws = &m->workspaces.v[i];
count++;
}
}
assert(count <= 1);
assert(count == 0 || ws != NULL);
const struct ws_content *template = ws_content_for_name(m, "current");
if (ws != NULL && template != NULL) {
struct tag_set tags = {
.tags = (struct tag *[]){
tag_new_string(mod, "application", ws->window.application),
tag_new_string(mod, "title", ws->window.title),
},
.count = 2,
};
particles[particle_count++] = template->content->instantiate(
template->content, &tags);
tag_set_destroy(&tags);
}
mtx_unlock(&mod->lock); mtx_unlock(&mod->lock);
return dynlist_exposable_new( return dynlist_exposable_new(