Skip to content

Commit

Permalink
wayland: initial support for showing the desktop
Browse files Browse the repository at this point in the history
* Wayland: Support rendering the desktop

*Wayland support is optional via the --enable-wayland option

* eel-editable-label-c: remove unused variable

This was leftover from earlier code compatable only with x11

* Fix gtk-layer-shell-0 version check, improve error message when Wayland requested but not found
  • Loading branch information
lukefromdc authored Jul 8, 2023
1 parent df25aef commit c1b2e77
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 93 deletions.
4 changes: 4 additions & 0 deletions .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ requires:
- libgirepository1.0-dev
- libglib2.0-dev
- libgtk-3-dev
- libgtk-layer-shell-dev
- libmate-desktop-dev
- libnotify-dev
- libpango1.0-dev
Expand All @@ -62,6 +63,8 @@ requires:
- cppcheck-htmlreport
- git
- gcc
- gtk3-devel
- gtk-layer-shell-devel
- make
- redhat-rpm-config
- dbus-glib-devel
Expand Down Expand Up @@ -95,6 +98,7 @@ requires:
- libgirepository1.0-dev
- libglib2.0-dev
- libgtk-3-dev
- libgtk-layer-shell-dev
- libmate-desktop-dev
- libnotify-dev
- libpango1.0-dev
Expand Down
32 changes: 29 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ(2.60)

dnl ===========================================================================

m4_define(gdkpixbuf_minver, 2.36.5)
m4_define(gdkpixbuf_minver, 2.36.5)
m4_define(glib_minver, 2.58.1)
m4_define(gio_minver, 2.50.0)
m4_define(mate_desktop_minver, 1.17.3)
Expand All @@ -13,6 +13,7 @@ m4_define(exif_minver, 0.6.14)
m4_define(exempi_minver, 1.99.5)
m4_define(gail_minver, 3.0.0)
m4_define(notify_minver, 0.7.0)
m4_define(gtk_layer_shell_minver, 0.8.0)


dnl 1. If the library code has changed at all since last release, then increment revision.
Expand Down Expand Up @@ -177,7 +178,31 @@ if test "x$enable_xmp" != "xno"; then
AC_SUBST(EXEMPI_LIBS)
fi

dnl ==========================================================================
dnl **************************************************************************
dnl Whether or not to build with wayland support and check for gtk-layer-shell
dnl **************************************************************************


AC_ARG_ENABLE(wayland,
[AS_HELP_STRING([--enable-wayland],
[Explicitly enable or disable Wayland support
(default is to enable only if Wayland client development library is detected)])],
[enable_wayland=$enableval],
[enable_wayland=auto])

# Check if we have gtk-layer-shell installed, and thus should build with Wayland support
have_wayland=no
m4_define([WAYLAND_DEPS], [gtk-layer-shell-0 >= gtk_layer_shell_minver wayland-client])
AS_IF([test "x$enable_wayland" = "xyes"],
[PKG_CHECK_MODULES([WAYLAND], [WAYLAND_DEPS], [have_wayland=yes])],
[test "x$enable_wayland" != "xno"],
[PKG_CHECK_MODULES([WAYLAND], [WAYLAND_DEPS], [have_wayland=yes], [have_wayland=no])])

AM_CONDITIONAL(ENABLE_WAYLAND, [test "x$have_wayland" = "xyes"])

if test "x$have_wayland" = "xyes"; then
AC_DEFINE(HAVE_WAYLAND, 1, [Have the Wayland development library])
fi

dnl ****************************
dnl *** Check for libselinux ***
Expand Down Expand Up @@ -240,7 +265,7 @@ AC_SUBST(LIBCAJA_EXTENSION_LIBS)

dnl core caja
PKG_CHECK_MODULES(GMODULE, gmodule-2.0, [GMODULE_ADD="gmodule-2.0"],[GMODULE_ADD=""])
CORE_MODULES="glib-2.0 $GMODULE_ADD mate-desktop-2.0 gthread-2.0 gio-2.0 gio-unix-2.0 gail-3.0 libxml-2.0 $EXTRA_CORE_MODULES gtk+-3.0 x11"
CORE_MODULES="glib-2.0 $GMODULE_ADD mate-desktop-2.0 gthread-2.0 gio-2.0 gio-unix-2.0 gail-3.0 libxml-2.0 gtk+-3.0 x11"
CORE_CFLAGS="`$PKG_CONFIG --cflags $CORE_MODULES`"
AC_SUBST(CORE_CFLAGS)
CORE_LIBS="`$PKG_CONFIG --libs $CORE_MODULES`"
Expand Down Expand Up @@ -323,6 +348,7 @@ Configure summary:
PackageKit support: $msg_packagekit
Native Language support: $USE_NLS
Self check: $msg_self_check
Wayland support: ${have_wayland}

caja-extension documentation: ${enable_gtk_doc}
caja-extension introspection: ${found_introspection}
Expand Down
22 changes: 15 additions & 7 deletions eel/eel-background.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ free_background_surface (EelBackground *self)
it will live forever, so we need to kill it manually.
If set as root background it will be killed next time the
background is changed. */
if (self->details->unset_root_surface)
if (GDK_IS_X11_DISPLAY (gdk_display_get_default()) && (self->details->unset_root_surface))
{
XKillClient (cairo_xlib_surface_get_display (surface),
cairo_xlib_surface_get_drawable (surface));
Expand Down Expand Up @@ -312,7 +312,7 @@ drawable_get_adjusted_size (EelBackground *self,
{
GdkScreen *screen = gtk_widget_get_screen (self->details->widget);
GdkDisplay *display = gdk_screen_get_display (screen);
if (GDK_IS_X11_DISPLAY (display))
if (GDK_IS_X11_DISPLAY (display))
{
gint scale = gtk_widget_get_scale_factor (self->details->widget);
*width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
Expand Down Expand Up @@ -433,8 +433,8 @@ set_root_surface (EelBackground *self,
self->details->bg_surface = mate_bg_create_surface (self->details->bg, window,
width, height, TRUE);
}

if (self->details->bg_surface != NULL)
GdkDisplay *display = gdk_screen_get_display (screen);
if ((GDK_IS_X11_DISPLAY (display)) && (self->details->bg_surface != NULL))
mate_bg_set_surface_as_root (screen, self->details->bg_surface);
}

Expand Down Expand Up @@ -649,7 +649,7 @@ widget_realized_setup (GtkWidget *widget,
}

GdkScreen *screen = gtk_widget_get_screen (widget);
GdkWindow *window = gdk_screen_get_root_window (screen);
GdkDisplay *display = gdk_screen_get_display (screen);

if (self->details->screen_size_handler > 0)
{
Expand All @@ -665,8 +665,16 @@ widget_realized_setup (GtkWidget *widget,
self->details->screen_monitors_handler =
g_signal_connect (screen, "monitors-changed", G_CALLBACK (screen_size_changed), self);

self->details->use_common_surface =
(gdk_window_get_visual (window) == gtk_widget_get_visual (widget)) ? TRUE : FALSE;
if (GDK_IS_X11_DISPLAY (display))
{
GdkWindow *window = gdk_screen_get_root_window (screen);
self->details->use_common_surface =
(gdk_window_get_visual (window) == gtk_widget_get_visual (widget)) ? TRUE : FALSE;
}
else /*Wayland is always composited*/
{
self->details->use_common_surface = TRUE;
}

init_fade (self);
}
Expand Down
2 changes: 0 additions & 2 deletions eel/eel-editable-label.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,6 @@ eel_editable_label_ensure_layout (EelEditableLabel *label,
else
{
gint wrap_width;
gint scale;

pango_layout_set_width (label->layout, -1);
pango_layout_get_extents (label->layout, NULL, &logical_rect);
Expand All @@ -1039,7 +1038,6 @@ eel_editable_label_ensure_layout (EelEditableLabel *label,
longest_paragraph = width;

wrap_width = get_label_wrap_width (label);
scale = gtk_widget_get_scale_factor (widget);
width = MIN (width, wrap_width);
width = MIN (width,
PANGO_SCALE * (gdk_screen_width () + 1) / 2);
Expand Down
36 changes: 20 additions & 16 deletions eel/eel-gtk-extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,27 @@ sanity_check_window_position (int *left, int *top)
* that it might be obscured by the panel.
*
*/
root_window = gdk_screen_get_root_window (gdk_screen_get_default());
display = gdk_display_get_default ();
gdk_monitor_get_workarea(gdk_display_get_monitor_at_window (display, root_window), &workarea);
*top = CLAMP (*top, 0, workarea.height - MINIMUM_ON_SCREEN_HEIGHT);

/* FIXME bugzilla.eazel.com 669:
* If window has negative left coordinate, set_uposition sends it
* somewhere else entirely. Not sure what level contains this bug (XWindows?).
* Hacked around by pinning the left edge to zero, which just means you
* can't set a window to be partly off the left of the screen using
* this routine.
*/
/* Make sure the left edge of the window isn't off the right edge of
* the screen, or so close to the right edge that it might be
* obscured by the panel.
*/
*left = CLAMP (*left, 0, workarea.width - MINIMUM_ON_SCREEN_WIDTH);
/*This is x11 only, there is no root window in wayland*/
if (GDK_IS_X11_DISPLAY (display))
{
root_window = gdk_screen_get_root_window (gdk_screen_get_default());
gdk_monitor_get_workarea(gdk_display_get_monitor_at_window (display, root_window), &workarea);
*top = CLAMP (*top, 0, workarea.height - MINIMUM_ON_SCREEN_HEIGHT);

/* FIXME bugzilla.eazel.com 669:
* If window has negative left coordinate, set_uposition sends it
* somewhere else entirely. Not sure what level contains this bug (XWindows?).
* Hacked around by pinning the left edge to zero, which just means you
* can't set a window to be partly off the left of the screen using
* this routine.
*/
/* Make sure the left edge of the window isn't off the right edge of
* the screen, or so close to the right edge that it might be
* obscured by the panel.
*/
*left = CLAMP (*left, 0, workarea.width - MINIMUM_ON_SCREEN_WIDTH);
}
}

static void
Expand Down
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ LDADD = \
-lnotify
$(NULL)

if ENABLE_WAYLAND
LDADD += \
$(WAYLAND_LIBS)
endif

dbus_freedesktop_built_sources = \
caja-freedesktop-generated.c \
caja-freedesktop-generated.h
Expand Down
43 changes: 23 additions & 20 deletions src/caja-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,44 +634,47 @@ selection_get_cb (GtkWidget *widget,
static GtkWidget *
get_desktop_manager_selection (GdkDisplay *display)
{
/*FIXME: for Wayland we need a new desktop canvas anyway
*so when that is ready we will need to add a wayland code
*path here to support it
*/
if (GDK_IS_X11_DISPLAY (display)){
char selection_name[32];
GdkAtom selection_atom;
Window selection_owner;
GtkWidget *selection_widget;

g_snprintf (selection_name, sizeof (selection_name), "_NET_DESKTOP_MANAGER_S0");
selection_atom = gdk_atom_intern (selection_name, FALSE);
char selection_name[32];
GdkAtom selection_atom;
Window selection_owner;
GtkWidget *selection_widget;

g_snprintf (selection_name, sizeof (selection_name), "_NET_DESKTOP_MANAGER_S0");
selection_atom = gdk_atom_intern (selection_name, FALSE);
if (GDK_IS_X11_DISPLAY (display))
{
selection_owner = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display),
gdk_x11_atom_to_xatom_for_display (display,
selection_atom));
if (selection_owner != None)
{
return NULL;
}
}
selection_widget = gtk_invisible_new_for_screen (gdk_display_get_default_screen (display));
/* We need this for gdk_x11_get_server_time() */
gtk_widget_add_events (selection_widget, GDK_PROPERTY_CHANGE_MASK);

selection_widget = gtk_invisible_new_for_screen (gdk_display_get_default_screen (display));
/* We need this for gdk_x11_get_server_time() */
gtk_widget_add_events (selection_widget, GDK_PROPERTY_CHANGE_MASK);

if (GDK_IS_X11_DISPLAY (display))
{
if (gtk_selection_owner_set_for_display (display,
selection_widget,
selection_atom,
gdk_x11_get_server_time (gtk_widget_get_window (selection_widget))))
{

g_signal_connect (selection_widget, "selection_get",
G_CALLBACK (selection_get_cb), NULL);
G_CALLBACK (selection_get_cb), NULL);
return selection_widget;
}

gtk_widget_destroy (selection_widget);
}
else
{
g_signal_connect (selection_widget, "selection_get",
G_CALLBACK (selection_get_cb), NULL);
return selection_widget;
}

gtk_widget_destroy (selection_widget);

return NULL;
}
Expand Down
Loading

0 comments on commit c1b2e77

Please sign in to comment.