fix: miss clean workspace when monitor destroy

This commit is contained in:
DreamMaoMao 2025-06-19 11:19:49 +08:00
parent b211f50e27
commit 7549a33cf0
2 changed files with 30 additions and 16 deletions

View file

@ -95,7 +95,28 @@ static char *get_name_from_tag(unsigned int tag) {
return name;
}
static void remove_workspace(unsigned int tag, Monitor *m) {
void destroy_workspace(struct workspace *workspace) {
// 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);
}
void cleanup_workspaces_by_monitor(Monitor *m) {
struct workspace *workspace, *tmp;
wl_list_for_each_safe(workspace, tmp, &workspaces, link) {
if (workspace->m == m) {
destroy_workspace(workspace);
}
}
}
static void remove_workspace_by_tag(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) {
@ -122,22 +143,14 @@ static void remove_workspace(unsigned int tag, Monitor *m) {
}
}
// 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);
destroy_workspace(workspace);
return;
}
}
}
/* Internal API */
static void add_workspace(int tag, Monitor *m) {
static void add_workspace_by_tag(int tag, Monitor *m) {
char *name = get_name_from_tag(tag);
struct workspace *workspace = znew(*workspace);
workspace->name = xstrdup(name);

View file

@ -2991,6 +2991,7 @@ void cleanupmon(struct wl_listener *listener, void *data) {
// clean ext-workspaces grouplab
dwl_ext_workspace_group_output_leave(m->ext_group, m->wlr_output);
dwl_ext_workspace_group_destroy(m->ext_group);
cleanup_workspaces_by_monitor(m);
wl_list_remove(&m->destroy.link);
wl_list_remove(&m->frame.link);
@ -3501,7 +3502,7 @@ void createmon(struct wl_listener *listener, void *data) {
dwl_ext_workspace_group_output_enter(m->ext_group, m->wlr_output);
for (i = 1; i <= LENGTH(tags); i++) {
add_workspace(i, m);
add_workspace_by_tag(i, m);
}
printstatus();
@ -7060,13 +7061,13 @@ void toggleoverview(const Arg *arg) {
if (selmon->isoverview) {
for (i = 1; i <= LENGTH(tags); i++) {
remove_workspace(i, selmon);
remove_workspace_by_tag(i, selmon);
}
add_workspace(0, selmon);
add_workspace_by_tag(0, selmon);
} else {
remove_workspace(0, selmon);
remove_workspace_by_tag(0, selmon);
for (i = 1; i <= LENGTH(tags); i++) {
add_workspace(i, selmon);
add_workspace_by_tag(i, selmon);
}
}