Skip to content

Commit

Permalink
Minor preperations for cosmic-workspaces implementation (#211)
Browse files Browse the repository at this point in the history
* wayland: verify versions for foreign-toplevel and xdg-output

* wayland/ipc.c: use single entry point for IPC

* workspaces: add _supported() and _set_name()
  • Loading branch information
Consolatis committed Aug 21, 2024
1 parent 407da69 commit 5aea03c
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 46 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ libsrc = [
'src/config/switcher.c',
'src/config/toplevel.c',
'src/wayland/foreign-toplevel.c',
'src/wayland/ipc.c',
'src/wayland/probe.c',
'src/wayland/xdg-output.c',
wayland_targets ]
Expand Down
5 changes: 2 additions & 3 deletions src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ static void pager_init ( Pager *self )

pagers = g_list_prepend(pagers, self);

if(ipc_get()!=IPC_SWAY && ipc_get()!=IPC_HYPR)
if(!workspaces_supported())
css_add_class(GTK_WIDGET(self), "hidden");

for(iter = workspace_get_list(); iter; iter=g_list_next(iter))
pager_item_new(GTK_WIDGET(self), iter->data);
flow_grid_invalidate(GTK_WIDGET(self));
Expand All @@ -64,7 +63,7 @@ void pager_add_pins ( GtkWidget *self, GList *pins )
g_return_if_fail(IS_PAGER(self));
priv = pager_get_instance_private(PAGER(self));

if(ipc_get()!=IPC_SWAY && ipc_get()!=IPC_HYPR)
if(!workspaces_supported())
{
g_list_free_full(pins, (GDestroyNotify)g_free);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <gdk/gdkwayland.h>

void foreign_toplevel_register (struct wl_registry *registry, uint32_t name);
void xdg_output_register (struct wl_registry *registry, uint32_t name);
void xdg_output_register (struct wl_registry *, uint32_t , uint32_t );
void layer_shell_register (struct wl_registry *, uint32_t , uint32_t );
void shm_register (struct wl_registry *registry, uint32_t name );
void wayland_monitor_probe ( void );
Expand All @@ -20,7 +20,7 @@ static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const gchar *interface, uint32_t version)
{
if (!g_strcmp0(interface,zxdg_output_manager_v1_interface.name))
xdg_output_register(registry,name);
xdg_output_register(registry, name, version);
else if (!g_strcmp0(interface, wl_shm_interface.name))
shm_register(registry, name);
else if (!g_strcmp0(interface, zwlr_layer_shell_v1_interface.name))
Expand Down
45 changes: 7 additions & 38 deletions src/wayland/foreign-toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "../wintree.h"
#include "wlr-foreign-toplevel-management-unstable-v1.h"

#define FOREIGN_TOPLEVEL_VERSION 3

typedef struct zwlr_foreign_toplevel_handle_v1 wlr_fth;
static struct zwlr_foreign_toplevel_manager_v1 *toplevel_manager;

Expand Down Expand Up @@ -199,51 +201,18 @@ static struct wintree_api ft_wintree_api = {
.focus = foreign_toplevel_focus
};

static void foreign_toplevel_register (struct wl_registry *registry,
uint32_t name)
void foreign_toplevel_register (struct wl_registry *registry,
uint32_t global, uint32_t version)
{
if(ipc_get())
return;

toplevel_manager = wl_registry_bind(registry, name,
&zwlr_foreign_toplevel_manager_v1_interface,3);
toplevel_manager = wl_registry_bind(registry, global,
&zwlr_foreign_toplevel_manager_v1_interface,
MIN(version, FOREIGN_TOPLEVEL_VERSION));

zwlr_foreign_toplevel_manager_v1_add_listener(toplevel_manager,
&toplevel_manager_impl, NULL);

wintree_api_register(&ft_wintree_api);
}

static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const gchar *interface, uint32_t version)
{
if (!g_strcmp0(interface,zwlr_foreign_toplevel_manager_v1_interface.name))
foreign_toplevel_register(registry,name);
}

static void handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name)
{
}

static const struct wl_registry_listener registry_listener = {
.global = handle_global,
.global_remove = handle_global_remove
};

void wayland_ipc_init ( void )
{
struct wl_display *wdisp;
struct wl_registry *registry;

wdisp = gdk_wayland_display_get_wl_display(gdk_display_get_default());
if(!wdisp)
g_error("Can't get wayland display\n");

registry = wl_display_get_registry(wdisp);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(wdisp);

wl_display_roundtrip(wdisp);
wl_display_roundtrip(wdisp);
}
44 changes: 44 additions & 0 deletions src/wayland/ipc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* This entire file is licensed under GNU General Public License v3.0
*
* Copyright 2022- sfwbar maintainers
*/

#include <gdk/gdkwayland.h>
#include "wlr-foreign-toplevel-management-unstable-v1.h"

void foreign_toplevel_register(struct wl_registry *registry,
uint32_t global, uint32_t version);

static void handle_global(void *data, struct wl_registry *registry,
uint32_t global, const gchar *interface, uint32_t version)
{
if (!g_strcmp0(interface,zwlr_foreign_toplevel_manager_v1_interface.name))
foreign_toplevel_register(registry, global, version);
}

static void handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name)
{
}

static const struct wl_registry_listener registry_listener = {
.global = handle_global,
.global_remove = handle_global_remove
};

void wayland_ipc_init ( void )
{
struct wl_display *wdisp;
struct wl_registry *registry;

wdisp = gdk_wayland_display_get_wl_display(gdk_display_get_default());
if(!wdisp)
g_error("Can't get wayland display\n");

registry = wl_display_get_registry(wdisp);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(wdisp);

wl_display_roundtrip(wdisp);
wl_display_roundtrip(wdisp);
}
10 changes: 8 additions & 2 deletions src/wayland/xdg-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ gboolean xdg_output_check ( void )
return TRUE;
}

void xdg_output_register (struct wl_registry *registry, uint32_t name)
void xdg_output_register (struct wl_registry *registry,
uint32_t global, uint32_t version)
{
GdkDisplay *display;
gint i,n;

if (version < ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
g_warning("Compositor does not support xdg-output protocol version %u",
ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
return;
}

xdg_output_manager = wl_registry_bind(registry, name,
xdg_output_manager = wl_registry_bind(registry, global,
&zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
if(!xdg_output_manager)
return;
Expand Down
15 changes: 14 additions & 1 deletion src/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ static GHashTable *actives;

void workspace_api_register ( struct workspace_api *new )
{
api = *new;
if (!api.set_workspace)
api = *new;
}

gboolean workspaces_supported ( void )
{
return api.set_workspace != NULL;
}

void workspace_ref ( gpointer id )
Expand Down Expand Up @@ -188,6 +194,13 @@ void workspace_set_focus ( gpointer id )
taskbar_shell_invalidate_all();
}

void workspace_set_name ( workspace_t *ws, const gchar *name )
{
g_free(ws->name);
ws->name = g_strdup(name);
pager_invalidate_all(ws);
}

void workspace_new ( workspace_t *new )
{
workspace_t *ws;
Expand Down
3 changes: 3 additions & 0 deletions src/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ struct workspace_api {

#define PAGER_PIN_ID (GINT_TO_POINTER(-1))

gboolean workspaces_supported( void );

void workspace_new ( workspace_t *new );
void workspace_set_focus ( gpointer id );
void workspace_set_name ( workspace_t *ws, const gchar *name );
void workspace_set_active ( workspace_t *ws, const gchar *output );
gpointer workspace_get_active ( GtkWidget *widget );
gboolean workspace_is_focused ( workspace_t *ws );
Expand Down

0 comments on commit 5aea03c

Please sign in to comment.