summaryrefslogtreecommitdiff
path: root/src/caja-desktop-window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/caja-desktop-window.c')
-rw-r--r--src/caja-desktop-window.c132
1 files changed, 108 insertions, 24 deletions
diff --git a/src/caja-desktop-window.c b/src/caja-desktop-window.c
index b5f7e9a5..6188fa63 100644
--- a/src/caja-desktop-window.c
+++ b/src/caja-desktop-window.c
@@ -29,7 +29,10 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
-
+#ifdef HAVE_WAYLAND
+#include <gdk/gdkwayland.h>
+#include <gtk-layer-shell/gtk-layer-shell.h>
+#endif
#include <eel/eel-background.h>
#include <eel/eel-vfs-extensions.h>
@@ -156,9 +159,23 @@ caja_desktop_window_screen_size_changed (GdkScreen *screen,
{
int width_request, height_request;
- GdkWindow *root_window;
- root_window = gdk_screen_get_root_window (screen);
- gdk_window_get_geometry (root_window, NULL, NULL, &width_request, &height_request);
+ GdkDisplay *display = gdk_screen_get_display (screen);
+ if (GDK_IS_X11_DISPLAY (display))
+ {
+ GdkWindow *root_window;
+ root_window = gdk_screen_get_root_window (screen);
+ gdk_window_get_geometry (root_window, NULL, NULL, &width_request, &height_request);
+ }
+ else
+ {
+ /*No root window or primary monitor in wayland unless compositors add it back*/
+ GdkRectangle geometry = {0};
+ GdkMonitor *monitor;
+ monitor = gdk_display_get_monitor (display, 0);
+ gdk_monitor_get_geometry (monitor, &geometry);
+ width_request = geometry.width;
+ height_request = geometry.height;
+ }
g_object_set (window,
"width_request", width_request,
@@ -174,10 +191,27 @@ caja_desktop_window_new (CajaApplication *application,
int width_request, height_request;
int scale;
- scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
-
- width_request = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
- height_request = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+ GdkDisplay *display = gdk_screen_get_display (screen);
+ if (GDK_IS_X11_DISPLAY (display))
+ {
+ scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
+ width_request = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+ height_request = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+ }
+ else
+ {
+ /*FIXME: There is no primary monitor in wayland itself
+ *compositors can implement this but as this is written
+ *only a few wayland compositors allow setting a primary monitor
+ *and they all do it differently. For now, use the first monitor
+ */
+ GdkRectangle geometry = {0};
+ GdkMonitor *monitor;
+ monitor = gdk_display_get_monitor (display, 0);
+ gdk_monitor_get_geometry (monitor, &geometry);
+ width_request = geometry.width;
+ height_request = geometry.height;
+ }
window = CAJA_DESKTOP_WINDOW
(gtk_widget_new (caja_desktop_window_get_type(),
@@ -191,11 +225,47 @@ caja_desktop_window_new (CajaApplication *application,
/* will cause the desktop window to open at the wrong size in gtk 3.20 */
gtk_window_set_default_size (GTK_WINDOW (window), -1, -1);
+ /*For wayland only
+ *Code taken from gtk-layer-shell simple-example.c
+ */
+#ifdef HAVE_WAYLAND
+ if (GDK_IS_WAYLAND_DISPLAY (display))
+ {
+ GtkWindow *gtkwin;
+ gtkwin = (GTK_WINDOW(window));
+
+ /* Before the window is first realized, set it up to be a layer surface */
+ gtk_layer_init_for_window (gtkwin);
+
+ /* Order below normal windows */
+ gtk_layer_set_layer (gtkwin, GTK_LAYER_SHELL_LAYER_BOTTOM);
+
+ gtk_layer_set_namespace (gtkwin, "desktop");
+
+ /*Anchor the desktop to all four corners
+ *This is much simpler than on x11 and
+ *should always render the desktop across
+ *all of the screen
+ */
+ gtk_layer_set_anchor (gtkwin, GTK_LAYER_SHELL_EDGE_TOP, TRUE);
+ gtk_layer_set_anchor (gtkwin, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
+ gtk_layer_set_anchor (gtkwin, GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
+ gtk_layer_set_anchor (gtkwin, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
+
+ /*Enable keyboard use on the desktop*/
+ gtk_layer_set_keyboard_mode (gtkwin, GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND);
+ }
+#endif
/* Special sawmill setting*/
GdkWindow *gdkwin;
- gtk_widget_realize (GTK_WIDGET (window));
+ if ((GDK_IS_X11_DISPLAY (display)))
+ gtk_widget_realize (GTK_WIDGET (window));
+ else
+ gtk_widget_show (GTK_WIDGET (window));
+
gdkwin = gtk_widget_get_window (GTK_WIDGET (window));
- if (gdk_window_ensure_native (gdkwin)) {
+ if ((GDK_IS_X11_DISPLAY (display)) && (gdk_window_ensure_native (gdkwin)))
+ {
Display *disp = GDK_DISPLAY_XDISPLAY (gdk_window_get_display (gdkwin));
XClassHint *xch = XAllocClassHint ();
xch->res_name = "desktop_window";
@@ -230,15 +300,21 @@ unrealize (GtkWidget *widget)
CajaDesktopWindow *window;
CajaDesktopWindowPrivate *details;
GdkWindow *root_window;
+ GdkDisplay *display;
window = CAJA_DESKTOP_WINDOW (widget);
details = window->details;
+ display = gtk_widget_get_display (widget);
- root_window = gdk_screen_get_root_window (
+ /*Avoid root window on wayland-it's not supposed to work*/
+ if (GDK_IS_X11_DISPLAY (display))
+ {
+ root_window = gdk_screen_get_root_window (
gtk_window_get_screen (GTK_WINDOW (window)));
- gdk_property_delete (root_window,
- gdk_atom_intern ("CAJA_DESKTOP_WINDOW_ID", TRUE));
+ gdk_property_delete (root_window,
+ gdk_atom_intern ("CAJA_DESKTOP_WINDOW_ID", TRUE));
+ }
if (details->size_changed_id != 0) {
g_signal_handler_disconnect (gtk_window_get_screen (GTK_WINDOW (window)),
@@ -249,6 +325,7 @@ unrealize (GtkWidget *widget)
GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->unrealize (widget);
}
+/*This should only be reached in x11*/
static void
set_wmspec_desktop_hint (GdkWindow *window)
{
@@ -262,18 +339,18 @@ set_wmspec_desktop_hint (GdkWindow *window)
GDK_PROP_MODE_REPLACE, (guchar *) &atom, 1);
}
+/*This should only be reached in x11*/
static void
set_desktop_window_id (CajaDesktopWindow *window,
GdkWindow *gdkwindow)
{
- /* Tuck the desktop windows xid in the root to indicate we own the desktop.
+ /* Tuck the desktop windows xid in the root to indicate we own the desktop in on x11
*/
Window window_xid;
GdkWindow *root_window;
root_window = gdk_screen_get_root_window (
gtk_window_get_screen (GTK_WINDOW (window)));
-
window_xid = GDK_WINDOW_XID (gdkwindow);
gdk_property_change (root_window,
@@ -289,17 +366,24 @@ realize (GtkWidget *widget)
CajaDesktopWindowPrivate *details;
window = CAJA_DESKTOP_WINDOW (widget);
details = window->details;
+ GdkDisplay *display;
/* Make sure we get keyboard events */
- gtk_widget_set_events (widget, gtk_widget_get_events (widget)
- | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
- /* Do the work of realizing. */
- GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->realize (widget);
+ display = gtk_widget_get_display (widget);
+ if (GDK_IS_X11_DISPLAY (display))
+ gtk_widget_set_events (widget, gtk_widget_get_events (widget)
+ | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
- /* This is the new way to set up the desktop window */
- set_wmspec_desktop_hint (gtk_widget_get_window (widget));
+ /*Do the work of realizing. */
+ GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->realize (widget);
- set_desktop_window_id (window, gtk_widget_get_window (widget));
+ /* This is the new way to set up the desktop window in x11 but not for wayland */
+ display = gtk_widget_get_display (widget);
+ if (GDK_IS_X11_DISPLAY (display))
+ {
+ set_wmspec_desktop_hint (gtk_widget_get_window (widget));
+ set_desktop_window_id (window, gtk_widget_get_window (widget));
+ }
details->size_changed_id =
g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size_changed",
@@ -311,7 +395,6 @@ draw (GtkWidget *widget,
cairo_t *cr)
{
eel_background_draw (widget, cr);
-
return GTK_WIDGET_CLASS (caja_desktop_window_parent_class)->draw (widget, cr);
}
@@ -332,7 +415,8 @@ caja_desktop_window_class_init (CajaDesktopWindowClass *klass)
wclass->realize = realize;
wclass->unrealize = unrealize;
wclass->map = map;
- wclass->draw = draw;
+ if (GDK_IS_X11_DISPLAY (gdk_display_get_default()))
+ wclass->draw = draw;
gtk_widget_class_set_accessible_type (wclass, CAJA_TYPE_DESKTOP_WINDOW_ACCESSIBLE);