diff --git a/src/ext-workspace/tag-worksapce.h b/src/ext-workspace/tag-worksapce.h index 28c3147b..470b4310 100644 --- a/src/ext-workspace/tag-worksapce.h +++ b/src/ext-workspace/tag-worksapce.h @@ -6,34 +6,19 @@ typedef struct Monitor Monitor; struct workspace { struct wl_list link; - - char *name; unsigned int tag; - struct wlr_scene_tree *tree; Monitor *m; - struct dwl_ext_workspace *ext_workspace; - struct { - struct wl_listener activate; - struct wl_listener deactivate; - struct wl_listener assign; - struct wl_listener remove; - } on_ext; + struct wl_listener activate; + struct wl_listener deactivate; + struct wl_listener assign; + struct wl_listener remove; }; struct dwl_ext_workspace_manager *ext_manager; -struct wl_list workspaces; /* struct workspace.link */ +struct wl_list workspaces; void workspaces_switch_to(struct workspace *target) { - if (target == target->m->workspace_current) { - return; - } - - wlr_scene_node_set_enabled(&target->m->workspace_current->tree->node, - false); - dwl_ext_workspace_set_active(target->m->workspace_current->ext_workspace, - false); - unsigned int tag; tag = 1 << (target->tag - 1); if (target->tag == 0) { @@ -42,68 +27,27 @@ void workspaces_switch_to(struct workspace *target) { } else { view(&(Arg){.ui = tag}, true); } - - wlr_scene_node_set_enabled(&target->tree->node, true); - target->m->workspace_last = target->m->workspace_current; - target->m->workspace_current = target; - dwl_ext_workspace_set_active(target->ext_workspace, true); } /* ext workspace handlers */ static void handle_ext_workspace_activate(struct wl_listener *listener, void *data) { struct workspace *workspace = - wl_container_of(listener, workspace, on_ext.activate); + wl_container_of(listener, workspace, activate); workspaces_switch_to(workspace); - wlr_log(WLR_INFO, "ext activating workspace %s", workspace->name); + wlr_log(WLR_INFO, "ext activating workspace %d", workspace->tag); } -static char *get_name_from_tag(unsigned int tag) { - char *name = NULL; - switch (tag) { - case 0: - name = "overview"; - break; - case 1: - name = "1"; - break; - case 2: - name = "2"; - break; - case 3: - name = "3"; - break; - case 4: - name = "4"; - break; - case 5: - name = "5"; - break; - case 6: - name = "6"; - break; - case 7: - name = "7"; - break; - case 8: - name = "8"; - break; - case 9: - name = "9"; - break; - } - return name; +static const char *get_name_from_tag(unsigned int tag) { + static const char *names[] = {"overview", "1", "2", "3", "4", + "5", "6", "7", "8", "9"}; + return (tag < sizeof(names) / sizeof(names[0])) ? names[tag] : NULL; } void destroy_workspace(struct workspace *workspace) { - // Clean up external workspace - wl_list_remove(&workspace->on_ext.activate.link); + wl_list_remove(&workspace->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); } @@ -120,60 +64,27 @@ static void remove_workspace_by_tag(unsigned int tag, Monitor *m) { struct workspace *workspace, *tmp; wl_list_for_each_safe(workspace, tmp, &workspaces, link) { if (workspace->tag == tag && 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); - } - } - destroy_workspace(workspace); return; } } } -/* Internal API */ static void add_workspace_by_tag(int tag, Monitor *m) { - char *name = get_name_from_tag(tag); + const char *name = get_name_from_tag(tag); + struct workspace *workspace = znew(*workspace); - workspace->name = xstrdup(name); + wl_list_append(&workspaces, &workspace->link); + workspace->tag = tag; workspace->m = m; - workspace->tree = wlr_scene_tree_create(ws_tree); - wl_list_append(&workspaces, &workspace->link); - if (!m->workspace_current) { - m->workspace_current = workspace; - } else { - wlr_scene_node_set_enabled(&workspace->tree->node, false); - } - - bool active = m->workspace_current == workspace; - workspace->ext_workspace = dwl_ext_workspace_create(ext_manager, /*id*/ NULL); dwl_ext_workspace_assign_to_group(workspace->ext_workspace, m->ext_group); dwl_ext_workspace_set_name(workspace->ext_workspace, name); - dwl_ext_workspace_set_active(workspace->ext_workspace, active); - - workspace->on_ext.activate.notify = handle_ext_workspace_activate; + workspace->activate.notify = handle_ext_workspace_activate; wl_signal_add(&workspace->ext_workspace->events.activate, - &workspace->on_ext.activate); + &workspace->activate); } void workspaces_init() { diff --git a/src/maomao.c b/src/maomao.c index b92ab92d..2cb8c652 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -388,9 +388,6 @@ struct Monitor { int gamma_lut_changed; int asleep; unsigned int visible_clients; - - struct workspace *workspace_current; - struct workspace *workspace_last; struct dwl_ext_workspace_group *ext_group; }; @@ -680,7 +677,6 @@ static struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; static struct wlr_backend *backend; static struct wlr_backend *headless_backend; static struct wlr_scene *scene; -struct wlr_scene_tree *ws_tree; static struct wlr_scene_tree *layers[NUM_LAYERS]; static struct wlr_renderer *drw; static struct wlr_allocator *alloc; @@ -6504,8 +6500,6 @@ void setup(void) { drag_icon = wlr_scene_tree_create(&scene->tree); wlr_scene_node_place_below(&drag_icon->node, &layers[LyrBlock]->node); - ws_tree = wlr_scene_tree_create(&scene->tree); - /* Create a renderer with the default implementation */ if (!(drw = wlr_renderer_autocreate(backend))) die("couldn't create renderer");