From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Tue, 23 Jul 2024 23:04:44 +0000 (+0200) Subject: cosmic-workspaces: labwc integration X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=904e0d2e97a24b1a79ed5db3b06278021efb836d;p=proto%2Flabwc.git cosmic-workspaces: labwc integration --- diff --git a/include/labwc.h b/include/labwc.h index 3439a099..9b6d1a21 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -301,6 +301,11 @@ struct server { struct wl_list all; /* struct workspace.link */ struct workspace *current; struct workspace *last; + struct lab_cosmic_workspace_manager *cosmic_manager; + struct lab_cosmic_workspace_group *cosmic_group; + struct { + struct wl_listener layout_output_added; + } on; } workspaces; struct wl_list outputs; diff --git a/include/workspaces.h b/include/workspaces.h index a558a00e..9bae5190 100644 --- a/include/workspaces.h +++ b/include/workspaces.h @@ -4,6 +4,7 @@ #include #include +#include struct seat; struct server; @@ -19,6 +20,13 @@ struct workspace { char *name; struct wlr_scene_tree *tree; + + struct lab_cosmic_workspace *cosmic_workspace; + struct { + struct wl_listener activate; + struct wl_listener deactivate; + struct wl_listener remove; + } on; }; void workspaces_init(struct server *server); diff --git a/src/output.c b/src/output.c index 8ba8225a..d92f45b0 100644 --- a/src/output.c +++ b/src/output.c @@ -26,6 +26,7 @@ #include "node.h" #include "output-state.h" #include "output-virtual.h" +#include "protocols/cosmic-workspaces.h" #include "regions.h" #include "view.h" #include "xwayland.h" @@ -276,6 +277,9 @@ add_output_to_layout(struct server *server, struct output *output) wlr_scene_output_layout_add_output(server->scene_layout, layout_output, output->scene_output); } + + lab_cosmic_workspace_group_output_enter( + server->workspaces.cosmic_group, output->wlr_output); } static void @@ -567,6 +571,10 @@ output_config_apply(struct server *server, if (need_to_remove) { regions_evacuate_output(output); + + lab_cosmic_workspace_group_output_leave( + server->workspaces.cosmic_group, output->wlr_output); + /* * At time of writing, wlr_output_layout_remove() * indirectly destroys the wlr_scene_output, but diff --git a/src/workspaces.c b/src/workspaces.c index 8e9b912f..41336ce1 100644 --- a/src/workspaces.c +++ b/src/workspaces.c @@ -15,10 +15,13 @@ #include "common/mem.h" #include "input/keyboard.h" #include "labwc.h" +#include "protocols/cosmic-workspaces.h" #include "view.h" #include "workspaces.h" #include "xwayland.h" +#define COSMIC_WORKSPACES_VERSION 1 + /* Internal helpers */ static size_t parse_workspace_index(const char *name) @@ -172,6 +175,15 @@ _osd_update(struct server *server) } } +/* cosmic workspace handlers */ +static void +handle_workspace_activate(struct wl_listener *listener, void *data) +{ + struct workspace *workspace = wl_container_of(listener, workspace, on.activate); + workspaces_switch_to(workspace, /* update_focus */ true); + wlr_log(WLR_INFO, "activating workspace %s", workspace->name); +} + /* Internal API */ static void add_workspace(struct server *server, const char *name) @@ -186,6 +198,15 @@ add_workspace(struct server *server, const char *name) } else { wlr_scene_node_set_enabled(&workspace->tree->node, false); } + + bool active = server->workspaces.current == workspace; + workspace->cosmic_workspace = lab_cosmic_workspace_create(server->workspaces.cosmic_group); + lab_cosmic_workspace_set_name(workspace->cosmic_workspace, name); + lab_cosmic_workspace_set_active(workspace->cosmic_workspace, active); + lab_cosmic_workspace_set_hidden(workspace->cosmic_workspace, !active); + + workspace->on.activate.notify = handle_workspace_activate; + wl_signal_add(&workspace->cosmic_workspace->events.activate, &workspace->on.activate); } static struct workspace * @@ -260,6 +281,13 @@ _osd_show(struct server *server) void workspaces_init(struct server *server) { + server->workspaces.cosmic_manager = lab_cosmic_workspace_manager_create( + server->wl_display, /* capabilities */ CW_CAP_WS_ACTIVATE, + COSMIC_WORKSPACES_VERSION); + + server->workspaces.cosmic_group = lab_cosmic_workspace_group_create( + server->workspaces.cosmic_manager); + wl_list_init(&server->workspaces.all); struct workspace *conf; @@ -286,6 +314,11 @@ workspaces_switch_to(struct workspace *target, bool update_focus) wlr_scene_node_set_enabled( &server->workspaces.current->tree->node, false); + lab_cosmic_workspace_set_active( + server->workspaces.current->cosmic_workspace, false); + lab_cosmic_workspace_set_hidden( + server->workspaces.current->cosmic_workspace, true); + /* Move Omnipresent views to new workspace */ struct view *view; enum lab_view_criteria criteria = @@ -331,6 +364,9 @@ workspaces_switch_to(struct workspace *target, bool update_focus) /* Ensure that only currently visible fullscreen windows hide the top layer */ desktop_update_top_layer_visiblity(server); + + lab_cosmic_workspace_set_active(target->cosmic_workspace, true); + lab_cosmic_workspace_set_hidden(target->cosmic_workspace, false); } void @@ -395,6 +431,8 @@ destroy_workspace(struct workspace *workspace) wlr_scene_node_destroy(&workspace->tree->node); zfree(workspace->name); wl_list_remove(&workspace->link); + + lab_cosmic_workspace_destroy(workspace->cosmic_workspace); free(workspace); } @@ -429,6 +467,8 @@ workspaces_reconfigure(struct server *server) actual_workspace->name, configured_workspace->name); free(actual_workspace->name); actual_workspace->name = xstrdup(configured_workspace->name); + lab_cosmic_workspace_set_name( + actual_workspace->cosmic_workspace, actual_workspace->name); } actual_workspace_link = actual_workspace_link->next; }