diff --git a/src/ext-workspace/tag-worksapce.h b/src/ext-workspace/tag-worksapce.h index 7355eb08..06fabb7d 100644 --- a/src/ext-workspace/tag-worksapce.h +++ b/src/ext-workspace/tag-worksapce.h @@ -58,10 +58,12 @@ static void handle_ext_workspace_activate(struct wl_listener *listener, wlr_log(WLR_INFO, "ext activating workspace %s", workspace->name); } -/* Internal API */ -static void add_workspace(int tag, Monitor *m) { +static char *get_name_from_tag(unsigned int tag) { char *name = NULL; switch (tag) { + case 0: + name = "overview"; + break; case 1: name = "1"; break; @@ -90,6 +92,53 @@ static void add_workspace(int tag, Monitor *m) { name = "9"; break; } + return name; +} + +static void remove_workspace(unsigned int tag, Monitor *m) { + char *name = get_name_from_tag(tag); + struct workspace *workspace, *tmp; + wl_list_for_each_safe(workspace, tmp, &workspaces, link) { + if (strcmp(workspace->name, name) == 0 && workspace->m == m) { + // If this is the current workspace, we need to handle that + if (m->workspace_current == workspace) { + // Find another workspace to make current (maybe the overview?) + struct workspace *new_current = NULL; + if (!wl_list_empty(&workspaces)) { + struct workspace *first = + wl_container_of(workspaces.next, first, link); + if (first != workspace) { + new_current = first; + } else if (workspaces.next->next != &workspaces) { + new_current = wl_container_of(workspaces.next->next, + new_current, link); + } + } + m->workspace_current = new_current; + if (new_current) { + wlr_scene_node_set_enabled(&new_current->tree->node, true); + dwl_ext_workspace_set_active(new_current->ext_workspace, + true); + } + } + + // Clean up external workspace + wl_list_remove(&workspace->on_ext.activate.link); + dwl_ext_workspace_destroy(workspace->ext_workspace); + + // Remove from the list and free resources + wl_list_remove(&workspace->link); + wlr_scene_node_destroy(&workspace->tree->node); + free(workspace->name); + free(workspace); + return; + } + } +} + +/* Internal API */ +static void add_workspace(int tag, Monitor *m) { + char *name = get_name_from_tag(tag); struct workspace *workspace = znew(*workspace); workspace->name = xstrdup(name); workspace->tag = tag; diff --git a/src/maomao.c b/src/maomao.c index 8b6211bb..28883af8 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -5111,7 +5111,7 @@ void dwl_ext_workspace_printstatus(Monitor *m) { wl_list_for_each(w, &workspaces, link) { if (w && w->m == m) { - is_active = (w->tag == current_tag) && !m->isoverview; + is_active = (w->tag == current_tag) || m->isoverview; has_clients = tag_has_clients(w->tag); if (is_active) { dwl_ext_workspace_set_hidden(w->ext_workspace, false); @@ -7037,6 +7037,7 @@ void increase_proportion(const Arg *arg) { void toggleoverview(const Arg *arg) { Client *c; + int i; if (selmon->isoverview && ov_tab_mode && arg->i != -1 && selmon->sel) { focusstack(&(Arg){.i = 1}); @@ -7086,6 +7087,18 @@ void toggleoverview(const Arg *arg) { } } + if (selmon->isoverview) { + for (i = 1; i <= LENGTH(tags); i++) { + remove_workspace(i, selmon); + } + add_workspace(0, selmon); + } else { + remove_workspace(0, selmon); + for (i = 1; i <= LENGTH(tags); i++) { + add_workspace(i, selmon); + } + } + view(&(Arg){.ui = target}, false); if (ov_tab_mode && selmon->isoverview && selmon->sel) {