Skip to content

Commit 779ca6c

Browse files
committed
nemo-preview: Force x11 backend for wayland sessions.
This plugin really needs a rewrite or retirement (such as linuxmint/nemo#3650), but for now keep it working as an x11 client.
1 parent 2f61007 commit 779ca6c

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

nemo-preview/src/libnemo-preview/nemo-preview-utils.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,20 @@ nemo_preview_create_rounded_background (void)
9393
* nemo_preview_create_foreign_window:
9494
* @xid:
9595
*
96-
* Returns: (transfer full): a #GdkWindow
96+
* Returns: (transfer full) (nullable): a #GdkWindow, or %NULL if @xid can't be
97+
* looked up. Nemo sends 0 when it has no X11 window to parent us to.
9798
*/
9899
GdkWindow *
99100
nemo_preview_create_foreign_window (guint xid)
100101
{
101-
GdkWindow *retval;
102+
GdkDisplay *display = gdk_display_get_default ();
102103

103-
retval = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (),
104-
xid);
104+
/* gdk_x11_window_foreign_new_for_display() only checks for GDK_IS_DISPLAY,
105+
* so a wayland display would be cast to a GdkX11Display and crash. */
106+
if (xid == 0 || !GDK_IS_X11_DISPLAY (display))
107+
return NULL;
105108

106-
return retval;
109+
return gdk_x11_window_foreign_new_for_display (display, xid);
107110
}
108111

109112
/**

nemo-preview/src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ main (int argc, char **argv)
108108
GjsContext *js_context;
109109
GError *error;
110110

111+
/* Clutter, the ARGB visual and foreign window parenting are all X11 only,
112+
* so run under XWayland rather than fail on a wayland display. */
113+
g_setenv ("GDK_BACKEND", "x11", TRUE);
114+
g_setenv ("CLUTTER_BACKEND", "x11", TRUE);
115+
111116
#ifdef GDK_WINDOWING_X11
112117
XInitThreads ();
113118
#endif

0 commit comments

Comments
 (0)