Skip to content

Commit 31d939d

Browse files
committed
csd-background: Check for layer-shell support before choosing which
Gdk backends to allow. We want to allow wayland *only* if it supports the layer-shell protocol.
1 parent 670555a commit 31d939d

7 files changed

Lines changed: 123 additions & 2 deletions

File tree

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Build-Depends:
2525
libsystemd-dev [linux-any],
2626
libupower-glib-dev (>= 0.99.11),
2727
libwacom-dev (>= 0.4) [!s390x !hurd-any !kfreebsd-any],
28+
libwayland-dev,
2829
libx11-dev,
2930
libxext-dev,
3031
libxi-dev,

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ endif
9191

9292
gtk_layer_shell_enabled = get_option('gtk_layer_shell')
9393
gtk_layer_shell = dependency('', required: false)
94+
wayland_client = dependency('', required: false)
9495
if gtk_layer_shell_enabled
9596
gtk_layer_shell = dependency('gtk-layer-shell-0', version: '>= 0.8', required: true)
97+
wayland_client = dependency('wayland-client', required: true)
9698
endif
9799

98100
cc = meson.get_compiler('c')

plugins/background/main.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "config.h"
22

3+
#include <glib.h>
4+
#include <gdk/gdk.h>
5+
36
#define NEW csd_background_manager_new
47
#define START csd_background_manager_start
58
#define STOP csd_background_manager_stop
@@ -14,9 +17,21 @@
1417
// Setting this to TRUE makes the plugin force GDK_SCALE=1
1518
#define FORCE_GDK_SCALE TRUE
1619

17-
// Run as native Wayland client when gtk-layer-shell is available,
18-
// otherwise fall back to x11/xwayland
20+
// When gtk-layer-shell is available, check at runtime if the compositor
21+
// supports wlr-layer-shell. If not, fall back to X11/XWayland.
1922
#ifdef HAVE_GTK_LAYER_SHELL
23+
#include "wayland-utils.h"
24+
25+
static void
26+
pre_gtk_init (void)
27+
{
28+
if (!csd_check_layer_shell_support ()) {
29+
g_message ("csd-background: wlr-layer-shell not supported, using X11 backend");
30+
gdk_set_allowed_backends ("x11");
31+
}
32+
}
33+
34+
#define PRE_GTK_INIT pre_gtk_init
2035
#define FORCE_X11_BACKEND FALSE
2136
#else
2237
#define FORCE_X11_BACKEND TRUE

plugins/common/daemon-skeleton-gtk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#define INIT_LIBNOTIFY FALSE
3232
#endif
3333

34+
#ifndef PRE_GTK_INIT
35+
#define PRE_GTK_INIT()
36+
#endif
37+
3438
#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager"
3539
#define GNOME_SESSION_DBUS_PATH "/org/gnome/SessionManager"
3640
#define GNOME_SESSION_CLIENT_PRIVATE_NAME "org.gnome.SessionManager.ClientPrivate"
@@ -210,6 +214,8 @@ main (int argc, char **argv)
210214
g_type_ensure (G_TYPE_DBUS_CONNECTION);
211215
g_type_ensure (G_TYPE_DBUS_PROXY);
212216

217+
PRE_GTK_INIT();
218+
213219
if (FORCE_X11_BACKEND) {
214220
const gchar *setup_display = getenv ("GNOME_SETUP_DISPLAY");
215221
if (setup_display && *setup_display != '\0')

plugins/common/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ common_deps = [
1212
xi,
1313
]
1414

15+
if gtk_layer_shell_enabled
16+
common_sources += 'wayland-utils.c'
17+
common_deps += wayland_client
18+
endif
19+
1520
common_inc = include_directories('.')
1621

1722
common_lib = static_library(

plugins/common/wayland-utils.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* wayland-utils.c - Wayland utility functions for CSD plugins
2+
*
3+
* Copyright (C) 2026 Linux Mint
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*/
10+
11+
#include "config.h"
12+
#include "wayland-utils.h"
13+
14+
#include <wayland-client.h>
15+
16+
static gboolean layer_shell_available = FALSE;
17+
18+
static void
19+
registry_handle_global (void *data,
20+
struct wl_registry *registry,
21+
uint32_t name,
22+
const char *interface,
23+
uint32_t version)
24+
{
25+
if (g_strcmp0 (interface, "zwlr_layer_shell_v1") == 0)
26+
layer_shell_available = TRUE;
27+
}
28+
29+
static void
30+
registry_handle_global_remove (void *data,
31+
struct wl_registry *registry,
32+
uint32_t name)
33+
{
34+
}
35+
36+
static const struct wl_registry_listener registry_listener = {
37+
registry_handle_global,
38+
registry_handle_global_remove,
39+
};
40+
41+
/**
42+
* csd_check_layer_shell_support:
43+
*
44+
* Check if wlr-layer-shell protocol is supported by connecting to the
45+
* Wayland display and checking the registry. This can be called before
46+
* gtk_init() unlike gtk_layer_is_supported().
47+
*
48+
* Returns: %TRUE if layer shell is available, %FALSE otherwise
49+
*/
50+
gboolean
51+
csd_check_layer_shell_support (void)
52+
{
53+
struct wl_display *display;
54+
struct wl_registry *registry;
55+
56+
layer_shell_available = FALSE;
57+
58+
display = wl_display_connect (NULL);
59+
if (!display)
60+
return FALSE;
61+
62+
registry = wl_display_get_registry (display);
63+
wl_registry_add_listener (registry, &registry_listener, NULL);
64+
wl_display_roundtrip (display);
65+
66+
wl_registry_destroy (registry);
67+
wl_display_disconnect (display);
68+
69+
return layer_shell_available;
70+
}

plugins/common/wayland-utils.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* wayland-utils.h - Wayland utility functions for CSD plugins
2+
*
3+
* Copyright (C) 2026 Linux Mint
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*/
10+
11+
#ifndef __WAYLAND_UTILS_H
12+
#define __WAYLAND_UTILS_H
13+
14+
#include <glib.h>
15+
16+
G_BEGIN_DECLS
17+
18+
gboolean csd_check_layer_shell_support (void);
19+
20+
G_END_DECLS
21+
22+
#endif /* __WAYLAND_UTILS_H */

0 commit comments

Comments
 (0)