Skip to content

Commit b624914

Browse files
committed
Implement gtk-layer-shell.
- Relies on layer-shell for scale changes and resizing to workarea, ignores Cinnamon proxy in Wayland mode. - If layer-shell is not supported by the compositor, resorts to x11 backend. (This is checked directly using wl_display, before gtk_init() runs) - nemo-icon-info: Add widget scale factor as part of the cache key. It's possible for nemo-desktop-windows to have different scale factors, and icon sizing if affected in these situations. Tested in: Cinnamon, labwc.
1 parent 0269902 commit b624914

16 files changed

Lines changed: 247 additions & 32 deletions

config.h.meson.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#mesondefine HAVE_SELINUX
2020
// Define to enable pango-1.44 fixes
2121
#mesondefine HAVE_PANGO_144
22+
// Define to use gtk-layer-shell
23+
#mesondefine HAVE_GTK_LAYER_SHELL
2224

2325

2426

debian/control

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ Build-Depends:
2121
libgsf-1-dev,
2222
libgtk-3-dev (>= 3.10),
2323
libgtk-3-doc,
24+
libgtk-layer-shell-dev,
2425
libjson-glib-dev (>= 1.6),
2526
libpango1.0-dev,
2627
libx11-dev,
2728
libxapp-dev (>= 2.0.0),
2829
libxext-dev,
2930
libxrender-dev,
31+
libwayland-dev,
3032
meson,
3133
python3,
3234
python3-gi,

debian/rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CONFIGURE_EXTRA_FLAGS = \
88
--buildtype=debugoptimized \
99
-D deprecated_warnings=false \
1010
-D gtk_doc=true \
11+
-D gtk_layer_shell=true \
1112
-D selinux=false
1213

1314
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-z,defs -Wl,-O1 -Wl,--as-needed

eel/eel-gtk-extensions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
251251
eel_gtk_window_set_initial_geometry (window, geometry_flags, left, top, width, height);
252252
}
253253

254+
/* nemo-desktop only runs on Wayland when gtk-layer-shell is available
255+
* (checked in nemo-desktop-main.c before gtk_init), so a TRUE return
256+
* here also implies layer-shell support. */
254257
gboolean
255258
eel_check_is_wayland (void)
256259
{

libnemo-private/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ if libselinux_enabled
9898
nemo_private_deps += libselinux
9999
endif
100100

101+
if gtk_layer_shell_enabled
102+
nemo_private_deps += gtk_layer_shell
103+
endif
104+
101105
nemo_private_lib = static_library('nemo-private',
102106
nemo_private_sources,
103107
dependencies: nemo_private_deps,

libnemo-private/nemo-desktop-utils.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
*
2020
*/
2121

22+
#include <config.h>
2223
#include "nemo-desktop-utils.h"
2324

25+
#include <eel/eel-gtk-extensions.h>
26+
27+
#ifdef HAVE_GTK_LAYER_SHELL
28+
#include <gtk-layer-shell/gtk-layer-shell.h>
29+
#endif
30+
2431
static GdkScreen *default_screen = NULL;
2532

2633
static void
@@ -181,3 +188,33 @@ nemo_desktop_utils_get_scale_factor (void)
181188
return (gint) scale;
182189
}
183190

191+
gboolean
192+
nemo_desktop_utils_configure_layer_shell (GtkWindow *window,
193+
gint monitor_num,
194+
gboolean keyboard_on_demand)
195+
{
196+
if (eel_check_is_wayland ()) {
197+
#ifdef HAVE_GTK_LAYER_SHELL
198+
GdkDisplay *display = gdk_display_get_default ();
199+
GdkMonitor *monitor = gdk_display_get_monitor (display, monitor_num);
200+
201+
gtk_layer_set_layer (window, GTK_LAYER_SHELL_LAYER_BOTTOM);
202+
gtk_layer_set_namespace (window, "nemo-desktop");
203+
gtk_layer_set_keyboard_mode (window,
204+
keyboard_on_demand ? GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND
205+
: GTK_LAYER_SHELL_KEYBOARD_MODE_NONE);
206+
gtk_layer_set_exclusive_zone (window, 0);
207+
gtk_layer_set_anchor (window, GTK_LAYER_SHELL_EDGE_TOP, TRUE);
208+
gtk_layer_set_anchor (window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
209+
gtk_layer_set_anchor (window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
210+
gtk_layer_set_anchor (window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
211+
212+
if (monitor) {
213+
gtk_layer_set_monitor (window, monitor);
214+
}
215+
#endif
216+
return TRUE;
217+
}
218+
219+
return FALSE;
220+
}

libnemo-private/nemo-desktop-utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ gint nemo_desktop_utils_get_num_monitors (void);
3535
gboolean nemo_desktop_utils_get_monitor_cloned (gint monitor, gint x_primary);
3636
gint nemo_desktop_utils_get_scale_factor (void);
3737

38+
gboolean nemo_desktop_utils_configure_layer_shell (GtkWindow *window,
39+
gint monitor_num,
40+
gboolean keyboard_on_demand);
41+
3842
G_END_DECLS
3943

4044
#endif

libnemo-private/nemo-icon-container.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,28 @@ nemo_icon_container_search_position_func (NemoIconContainer *container,
36203620
if (nemo_icon_container_get_is_desktop (container)) {
36213621
x = cont_x + cont_width - requisition.width;
36223622
y = cont_y + cont_height - requisition.height;
3623+
3624+
if (eel_check_is_wayland ()) {
3625+
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
3626+
GdkWindow *parent_window = gtk_widget_get_window (toplevel);
3627+
gint parent_x, parent_y;
3628+
3629+
gdk_window_get_origin (parent_window, &parent_x, &parent_y);
3630+
3631+
GdkRectangle anchor_rect = {
3632+
x - parent_x,
3633+
y - parent_y,
3634+
1, 1
3635+
};
3636+
3637+
gdk_window_move_to_rect (gtk_widget_get_window (search_dialog),
3638+
&anchor_rect,
3639+
GDK_GRAVITY_NORTH_WEST,
3640+
GDK_GRAVITY_NORTH_WEST,
3641+
0,
3642+
0, 0);
3643+
return;
3644+
}
36233645
} else {
36243646
if (cont_x + cont_width > monitor.x + monitor.width) {
36253647
x = monitor.x + monitor.width - requisition.width;
@@ -4082,6 +4104,17 @@ nemo_icon_container_ensure_interactive_directory (NemoIconContainer *container)
40824104
gtk_container_add (GTK_CONTAINER (vbox), container->details->search_entry);
40834105

40844106
gtk_widget_realize (container->details->search_entry);
4107+
4108+
if (eel_check_is_wayland () && nemo_icon_container_get_is_desktop (container)) {
4109+
GdkRectangle anchor_rect = { 0, 0, 1, 1 };
4110+
4111+
gdk_window_move_to_rect (gtk_widget_get_window (container->details->search_window),
4112+
&anchor_rect,
4113+
GDK_GRAVITY_NORTH_WEST,
4114+
GDK_GRAVITY_NORTH_WEST,
4115+
0,
4116+
0, 0);
4117+
}
40854118
}
40864119

40874120
/* Pops up the interactive search entry. If keybinding is TRUE then the user

libnemo-private/nemo-icon-info.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ nemo_icon_info_new_for_icon_info (GtkIconInfo *icon_info,
168168
typedef struct {
169169
GIcon *icon;
170170
int size;
171+
int scale;
171172
} IconKey;
172173

173174
static GHashTable *loadable_icon_cache = NULL;
@@ -253,25 +254,27 @@ nemo_icon_info_clear_caches (void)
253254
static guint
254255
icon_key_hash (IconKey *key)
255256
{
256-
return g_icon_hash (key->icon) ^ key->size;
257+
return g_icon_hash (key->icon) ^ key->size ^ key->scale;
257258
}
258259

259260
static gboolean
260261
icon_key_equal (const IconKey *a,
261262
const IconKey *b)
262263
{
263264
return a->size == b->size &&
265+
a->scale == b->scale &&
264266
g_icon_equal (a->icon, b->icon);
265267
}
266268

267269
static IconKey *
268-
icon_key_new (GIcon *icon, int size)
270+
icon_key_new (GIcon *icon, int size, int scale)
269271
{
270272
IconKey *key;
271273

272274
key = g_new0 (IconKey, 1);
273275
key->icon = g_object_ref (icon);
274276
key->size = size;
277+
key->scale = scale;
275278

276279
return key;
277280
}
@@ -311,6 +314,7 @@ nemo_icon_info_lookup (GIcon *icon,
311314

312315
lookup_key.icon = icon;
313316
lookup_key.size = size;
317+
lookup_key.scale = scale;
314318

315319
icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
316320
if (icon_info) {
@@ -344,7 +348,7 @@ nemo_icon_info_lookup (GIcon *icon,
344348

345349
icon_info = nemo_icon_info_new_for_pixbuf (pixbuf, scale);
346350

347-
key = icon_key_new (icon, size);
351+
key = icon_key_new (icon, size, scale);
348352
g_hash_table_insert (loadable_icon_cache, key, icon_info);
349353

350354
g_clear_object (&pixbuf);
@@ -363,6 +367,7 @@ nemo_icon_info_lookup (GIcon *icon,
363367

364368
lookup_key.icon = icon;
365369
lookup_key.size = size;
370+
lookup_key.scale = scale;
366371

367372
icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
368373
if (icon_info) {
@@ -388,7 +393,7 @@ nemo_icon_info_lookup (GIcon *icon,
388393
icon_info = nemo_icon_info_new_for_icon_info (gtkicon_info, scale);
389394
g_object_unref (gtkicon_info);
390395

391-
key = icon_key_new (icon, size);
396+
key = icon_key_new (icon, size, scale);
392397
g_hash_table_insert (themed_icon_cache, key, icon_info);
393398

394399
return nemo_icon_info_ref (icon_info);

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ if libselinux_enabled
133133
endif
134134
conf.set('HAVE_SELINUX', libselinux_enabled)
135135

136+
gtk_layer_shell_enabled = get_option('gtk_layer_shell')
137+
if gtk_layer_shell_enabled
138+
gtk_layer_shell = dependency('gtk-layer-shell-0', version: '>=0.8', required: true)
139+
wayland_client = dependency('wayland-client', required: true)
140+
conf.set('HAVE_GTK_LAYER_SHELL', gtk_layer_shell.found())
141+
endif
142+
136143
# make sure pango development files are installed
137144
pango = dependency('pango', version: '>=1.40.0')
138145
# check for newer pango for necessary workarounds
@@ -201,6 +208,7 @@ message('\n'.join(['',
201208
' exempi support: @0@'.format(exempi_enabled),
202209
' Tracker support: @0@'.format(tracker_enabled),
203210
' Wayland support: @0@'.format(cc.has_header('gdk/gdkwayland.h', dependencies: gtk)),
211+
' gtk-layer-shell: @0@'.format(gtk_layer_shell_enabled),
204212
'',
205213
' nemo-extension documentation: @0@'.format(gtkdoc_enabled),
206214
' nemo-extension introspection: @0@'.format(true),

0 commit comments

Comments
 (0)