]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cosmic-workspaces: labwc integration
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 23 Jul 2024 23:04:44 +0000 (01:04 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 3 Aug 2024 16:25:23 +0000 (18:25 +0200)
include/labwc.h
include/workspaces.h
src/output.c
src/workspaces.c

index 3439a0994e9a75b19bf0eb385716a57526672dcf..9b6d1a21af39574be5484b934fab5c98df75bc11 100644 (file)
@@ -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;
index a558a00ecd7f0404d2d3557f556a1299da76a46b..9bae5190c36a138753b14131bd47443ca63adbb3 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <stdbool.h>
 #include <wayland-util.h>
+#include <wayland-server-core.h>
 
 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);
index 8ba8225a27207316c2d588db331eab57b95fb23e..d92f45b0ead371aeca2775779eef1e14a5a7a78b 100644 (file)
@@ -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
index 8e9b912f67845c4eeaf7a68a4516256ffa72baf0..41336ce19b5736c512c4e96d6c5502026c7c8a02 100644 (file)
 #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;
        }