Skip to content

Commit 670555a

Browse files
committed
csd-background: Use gtk-layer-shell if available to run under
wayland. Current csd-background runs as an xwayland client and has special handling built in to muffin to 'make it work'. This will allow it to run as a native client, if muffin has the capability, and if csd-background has been built with support. ref: linuxmint/muffin#784 linuxmint/nemo#3684
1 parent bb4287d commit 670555a

9 files changed

Lines changed: 64 additions & 62 deletions

File tree

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Build-Depends:
1414
libfontconfig1-dev,
1515
libglib2.0-dev (>= 2.37.3),
1616
libgtk-3-dev (>= 3.9.10),
17+
libgtk-layer-shell-dev,
1718
libgudev-1.0-dev [linux-any],
1819
liblcms2-dev,
1920
libnotify-dev (>= 0.7.0),

debian/rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
1515
override_dh_auto_configure:
1616
dh_auto_configure -- \
1717
--libexecdir=/usr/libexec \
18+
-D gtk_layer_shell=true \
1819
$(CONFFLAGS)
1920

2021

meson.build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ if not get_option('use_logind').disabled()
8989
endif
9090
endif
9191

92+
gtk_layer_shell_enabled = get_option('gtk_layer_shell')
93+
gtk_layer_shell = dependency('', required: false)
94+
if gtk_layer_shell_enabled
95+
gtk_layer_shell = dependency('gtk-layer-shell-0', version: '>= 0.8', required: true)
96+
endif
97+
9298
cc = meson.get_compiler('c')
9399
math = cc.find_library('m', required: false)
94100

@@ -105,6 +111,9 @@ csd_conf.set_quoted('LIBEXECDIR', join_paths(prefix, libexecdir))
105111
csd_conf.set_quoted('SYSCONFDIR', sysconfdir)
106112
csd_conf.set_quoted('LIBDIR', libdir)
107113
csd_conf.set10('HAVE_TIMERFD', has_timerfd_create)
114+
if gtk_layer_shell_enabled
115+
csd_conf.set('HAVE_GTK_LAYER_SHELL', 1)
116+
endif
108117

109118
if gudev.found()
110119
cargs += '-DHAVE_GUDEV'

meson_options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ option(
7070
value: '/usr/share/zoneinfo/zone.tab',
7171
description: 'Path to tzdata zone.tab or zone1970.tab'
7272
)
73+
option(
74+
'gtk_layer_shell',
75+
type: 'boolean',
76+
value: false,
77+
description: 'Use gtk-layer-shell for native Wayland background windows'
78+
)

plugins/background/csd-background-manager.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct CsdBackgroundManagerPrivate
6464
static void csd_background_manager_finalize (GObject *object);
6565

6666
static void setup_bg (CsdBackgroundManager *manager);
67+
static void setup_monitors (CsdBackgroundManager *manager);
6768
static void connect_screen_signals (CsdBackgroundManager *manager);
6869

6970
G_DEFINE_TYPE (CsdBackgroundManager, csd_background_manager, G_TYPE_OBJECT)
@@ -181,6 +182,9 @@ static void
181182
on_screen_size_changed (GdkScreen *screen,
182183
CsdBackgroundManager *manager)
183184
{
185+
if (session_is_wayland ()) {
186+
setup_monitors (manager);
187+
}
184188

185189
draw_background (manager);
186190
}

plugins/background/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "config.h"
2+
13
#define NEW csd_background_manager_new
24
#define START csd_background_manager_start
35
#define STOP csd_background_manager_stop
@@ -12,8 +14,13 @@
1214
// Setting this to TRUE makes the plugin force GDK_SCALE=1
1315
#define FORCE_GDK_SCALE TRUE
1416

15-
// This plugin must run under x11/xwayland
17+
// Run as native Wayland client when gtk-layer-shell is available,
18+
// otherwise fall back to x11/xwayland
19+
#ifdef HAVE_GTK_LAYER_SHELL
20+
#define FORCE_X11_BACKEND FALSE
21+
#else
1622
#define FORCE_X11_BACKEND TRUE
23+
#endif
1724

1825
#include "csd-background-manager.h"
1926

plugins/background/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ background_deps = [
1313
libnotify,
1414
]
1515

16+
if gtk_layer_shell_enabled
17+
background_deps += gtk_layer_shell
18+
endif
19+
1620
executable(
1721
'csd-background',
1822
background_sources,

plugins/background/monitor-background.c

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,14 @@
1111
#include <glib/gstdio.h>
1212
#include <gtk/gtk.h>
1313

14+
#ifdef HAVE_GTK_LAYER_SHELL
15+
#include <gtk-layer-shell/gtk-layer-shell.h>
16+
#endif
17+
1418
#include "monitor-background.h"
1519

1620
G_DEFINE_TYPE (MonitorBackground, monitor_background, G_TYPE_OBJECT)
1721

18-
enum {
19-
INVALIDATED,
20-
N_SIGNALS
21-
};
22-
23-
static guint signals[N_SIGNALS] = { 0 };
24-
25-
static void
26-
invalidate_mb (MonitorBackground *mb)
27-
{
28-
mb->valid = FALSE;
29-
30-
g_signal_emit (mb, signals[INVALIDATED], 0);
31-
}
32-
33-
static void
34-
on_gdk_monitor_dispose (gpointer data,
35-
GObject *monitor)
36-
{
37-
MonitorBackground *mb = MONITOR_BACKGROUND (data);
38-
invalidate_mb (mb);
39-
}
40-
41-
static void
42-
on_gdk_monitor_invalidate (gpointer data)
43-
{
44-
MonitorBackground *mb = MONITOR_BACKGROUND (data);
45-
invalidate_mb (mb);
46-
}
47-
4822
static void
4923
on_window_realized (GtkWidget *widget,
5024
gpointer user_data)
@@ -60,14 +34,33 @@ static void
6034
build_monitor_background (MonitorBackground *mb)
6135
{
6236
GdkRectangle geometry;
37+
#ifdef HAVE_GTK_LAYER_SHELL
38+
gboolean use_layer_shell = gtk_layer_is_supported ();
39+
#else
40+
gboolean use_layer_shell = FALSE;
41+
#endif
6342

6443
mb->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
65-
gtk_window_set_type_hint (GTK_WINDOW (mb->window), GDK_WINDOW_TYPE_HINT_DESKTOP);
6644
gtk_window_set_decorated (GTK_WINDOW (mb->window), FALSE);
6745

68-
// Set keep below so muffin recognizes the backgrounds and keeps them
69-
// at the bottom of the bottom window layer (under file managers, etc..)
70-
gtk_window_set_keep_below (GTK_WINDOW (mb->window), TRUE);
46+
#ifdef HAVE_GTK_LAYER_SHELL
47+
if (use_layer_shell) {
48+
gtk_layer_init_for_window (GTK_WINDOW (mb->window));
49+
gtk_layer_set_layer (GTK_WINDOW (mb->window), GTK_LAYER_SHELL_LAYER_BACKGROUND);
50+
gtk_layer_set_namespace (GTK_WINDOW (mb->window), "csd-background");
51+
gtk_layer_set_keyboard_mode (GTK_WINDOW (mb->window), GTK_LAYER_SHELL_KEYBOARD_MODE_NONE);
52+
gtk_layer_set_exclusive_zone (GTK_WINDOW (mb->window), -1);
53+
gtk_layer_set_anchor (GTK_WINDOW (mb->window), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
54+
gtk_layer_set_anchor (GTK_WINDOW (mb->window), GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
55+
gtk_layer_set_anchor (GTK_WINDOW (mb->window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
56+
gtk_layer_set_anchor (GTK_WINDOW (mb->window), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
57+
gtk_layer_set_monitor (GTK_WINDOW (mb->window), mb->monitor);
58+
} else
59+
#endif
60+
{
61+
gtk_window_set_type_hint (GTK_WINDOW (mb->window), GDK_WINDOW_TYPE_HINT_DESKTOP);
62+
gtk_window_set_keep_below (GTK_WINDOW (mb->window), TRUE);
63+
}
7164

7265
mb->stack = gtk_stack_new ();
7366
g_object_set (mb->stack,
@@ -81,16 +74,17 @@ build_monitor_background (MonitorBackground *mb)
8174
mb->width = geometry.width;
8275
mb->height = geometry.height;
8376

84-
gtk_window_set_default_size (GTK_WINDOW (mb->window), geometry.width, geometry.height);
77+
if (!use_layer_shell) {
78+
gtk_window_set_default_size (GTK_WINDOW (mb->window), geometry.width, geometry.height);
79+
g_signal_connect (mb->window, "realize", G_CALLBACK (on_window_realized), mb);
80+
}
8581

86-
g_signal_connect (mb->window, "realize", G_CALLBACK (on_window_realized), mb);
8782
gtk_widget_show_all (mb->window);
8883
}
8984

9085
static void
9186
monitor_background_init (MonitorBackground *mb)
9287
{
93-
mb->valid = TRUE;
9488
}
9589

9690
static void
@@ -117,13 +111,6 @@ monitor_background_class_init (MonitorBackgroundClass *klass)
117111

118112
gobject_class->dispose = monitor_background_dispose;
119113
gobject_class->finalize = monitor_background_finalize;
120-
121-
signals[INVALIDATED] = g_signal_new ("invalidated",
122-
G_OBJECT_CLASS_TYPE (gobject_class),
123-
G_SIGNAL_RUN_LAST,
124-
0,
125-
NULL, NULL, NULL,
126-
G_TYPE_NONE, 0);
127114
}
128115

129116
MonitorBackground *
@@ -133,9 +120,6 @@ monitor_background_new (gint index, GdkMonitor *monitor)
133120
mb->monitor_index = index;
134121
mb->monitor = monitor;
135122

136-
g_object_weak_ref (G_OBJECT (monitor), (GWeakNotify) on_gdk_monitor_dispose, mb);
137-
g_signal_connect_swapped (monitor, "invalidate", G_CALLBACK (on_gdk_monitor_invalidate), mb);
138-
139123
build_monitor_background (mb);
140124

141125
return mb;
@@ -144,12 +128,6 @@ monitor_background_new (gint index, GdkMonitor *monitor)
144128
GtkImage *
145129
monitor_background_get_pending_image (MonitorBackground *mb)
146130
{
147-
if (!mb->valid)
148-
{
149-
g_warning ("Asked for pending image when monitor is no longer valid");
150-
return NULL;
151-
}
152-
153131
if (!mb->pending)
154132
{
155133
mb->pending = gtk_image_new ();
@@ -165,12 +143,6 @@ monitor_background_show_next_image (MonitorBackground *mb)
165143
{
166144
g_return_if_fail (mb->pending != NULL);
167145

168-
if (!mb->valid)
169-
{
170-
g_warning ("Asked for pending image when monitor is no longer valid");
171-
return;
172-
}
173-
174146
GtkWidget *tmp;
175147

176148
tmp = mb->current;

plugins/background/monitor-background.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ struct _MonitorBackground
2020
GtkWidget *current;
2121
GtkWidget *pending;
2222

23-
gboolean valid;
24-
2523
gint monitor_index;
2624
gint width;
2725
gint height;

0 commit comments

Comments
 (0)