From eca17b2228fe29f618935e40741d580f94f9c99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 15:46:40 +0200 Subject: [PATCH 1/6] PhoshLockshield: Fix incorrect object type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther --- src/lockshield.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lockshield.c b/src/lockshield.c index dd0177fc3..897cbbe36 100644 --- a/src/lockshield.c +++ b/src/lockshield.c @@ -89,7 +89,7 @@ GtkWidget * phosh_lockshield_new (gpointer layer_shell, gpointer wl_output) { - return g_object_new (PHOSH_TYPE_LAYER_SURFACE, + return g_object_new (PHOSH_TYPE_LOCKSHIELD, "layer-shell", layer_shell, "wl-output", wl_output, "anchor", ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | -- GitLab From 69c2531f7f68e83b2819f16886fd2df4486a36e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 21:55:30 +0200 Subject: [PATCH 2/6] PhoshLayerSurface: Emit signal when layer surface receives wayland's configure event This allows derived classes to e.g. adjust layout when we know the final size. --- src/layersurface.c | 24 ++++++++++++++++++++++++ src/layersurface.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/layersurface.c b/src/layersurface.c index ceb1634b2..b9d60e7f2 100644 --- a/src/layersurface.c +++ b/src/layersurface.c @@ -26,6 +26,13 @@ enum { }; static GParamSpec *props[PHOSH_LAYER_SURFACE_PROP_LAST_PROP]; +enum { + CONFIGURED, + N_SIGNALS +}; +static guint signals [N_SIGNALS]; + + typedef struct { struct wl_surface *wl_surface; struct zwlr_layer_surface_v1 *layer_surface; @@ -53,6 +60,8 @@ static void layer_surface_configure(void *data, gtk_window_resize (GTK_WINDOW (self), width, height); zwlr_layer_surface_v1_ack_configure(surface, serial); gtk_widget_show_all (GTK_WIDGET (self)); + + g_signal_emit (self, signals[CONFIGURED], 0); } @@ -303,6 +312,21 @@ phosh_layer_surface_class_init (PhoshLayerSurfaceClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PHOSH_LAYER_SURFACE_PROP_LAST_PROP, props); + + /** + * PhoshLayersurface::configured + * @self: The #PhoshLayersurface instance. + * + * This signal is emitted once we received the configure event from the + * compositor. + */ + signals[CONFIGURED] = + g_signal_new ("configured", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (PhoshLayerSurfaceClass, configured), + NULL, NULL, NULL, + G_TYPE_NONE, 0); } diff --git a/src/layersurface.h b/src/layersurface.h index 3166e2453..57c07b4ef 100644 --- a/src/layersurface.h +++ b/src/layersurface.h @@ -21,6 +21,10 @@ G_DECLARE_DERIVABLE_TYPE (PhoshLayerSurface, phosh_layer_surface, PHOSH, LAYER_S struct _PhoshLayerSurfaceClass { GtkWindowClass parent_class; + + /* Signals + */ + void (*configured) (PhoshLayerSurface *self); }; GtkWidget * phosh_layer_surface_new (gpointer layer_shell, -- GitLab From 78e63e84eb9e4408e223b52e949d9ff4040f27fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 15:46:40 +0200 Subject: [PATCH 3/6] background: Unbreak compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther --- src/phosh.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/phosh.c b/src/phosh.c index a99a67844..a8d448766 100644 --- a/src/phosh.c +++ b/src/phosh.c @@ -577,14 +577,20 @@ panel_create (PhoshShell *self) } -#if 0 /* https://github.com/swaywm/wlroots/issues/897 */ + static void background_create (PhoshShell *self) { + +#ifdef WITH_PHOSH_BACKGROUND PhoshShellPrivate *priv = phosh_shell_get_instance_private (self); GdkWindow *gdk_window; struct elem *background; gint width, height; + PhoshMonitor *monitor; + + monitor = phosh_monitor_manager_get_monitor (priv->monitor_manager, 0); + g_return_if_fail (monitor); background = calloc (1, sizeof *background); background->window = phosh_background_new (); @@ -597,7 +603,7 @@ background_create (PhoshShell *self) background->layer_surface = zwlr_layer_shell_v1_get_layer_surface(priv->layer_shell, background->wl_surface, - priv->output, + monitor->wl_output, ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "phosh"); zwlr_layer_surface_v1_set_anchor(background->layer_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM); @@ -605,8 +611,8 @@ background_create (PhoshShell *self) zwlr_layer_surface_v1_add_listener(background->layer_surface, &layer_surface_listener, background); wl_surface_commit(background->wl_surface); priv->background = background; -} #endif +} static void css_setup (PhoshShell *self) @@ -802,10 +808,7 @@ phosh_shell_constructed (GObject *object) css_setup (self); panel_create (self); /* Create background after panel since it needs the panel's size */ -#if 0 - /* https://github.com/swaywm/wlroots/issues/897 */ background_create (self); -#endif lockscreen_prepare (self); } -- GitLab From e6b0687773edb433e48122720998f6bb28af10b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 15:46:40 +0200 Subject: [PATCH 4/6] background: Turn into PhoshSurfaceLayer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther --- src/background.c | 24 ++++++++++++++++++++---- src/background.h | 5 +++-- src/phosh.c | 32 ++++++++++---------------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/background.c b/src/background.c index 6b196ae12..5063c0036 100644 --- a/src/background.c +++ b/src/background.c @@ -29,11 +29,11 @@ typedef struct typedef struct _PhoshBackground { - GtkWindow parent; + PhoshLayerSurface parent; } PhoshBackground; -G_DEFINE_TYPE_WITH_PRIVATE (PhoshBackground, phosh_background, GTK_TYPE_WINDOW) +G_DEFINE_TYPE_WITH_PRIVATE (PhoshBackground, phosh_background, PHOSH_TYPE_LAYER_SURFACE) static GdkPixbuf * @@ -227,7 +227,23 @@ phosh_background_init (PhoshBackground *self) GtkWidget * -phosh_background_new (void) +phosh_background_new (gpointer layer_shell, + gpointer wl_output, + guint width, + guint height) { - return g_object_new (PHOSH_TYPE_BACKGROUND, NULL); + return g_object_new (PHOSH_TYPE_BACKGROUND, + "layer-shell", layer_shell, + "wl-output", wl_output, + "width", width, + "height", height, + "anchor", (ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT), + "layer", ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, + "kbd-interactivity", FALSE, + "exclusive-zone", -1, + "namespace", "phosh background", + NULL); } diff --git a/src/background.h b/src/background.h index 2edd27f5b..11359b5a6 100644 --- a/src/background.h +++ b/src/background.h @@ -8,11 +8,12 @@ #define PHOSH_BACKGROUND_H #include +#include "layersurface.h" #define PHOSH_TYPE_BACKGROUND (phosh_background_get_type()) -G_DECLARE_FINAL_TYPE (PhoshBackground, phosh_background, PHOSH, BACKGROUND, GtkWindow) +G_DECLARE_FINAL_TYPE (PhoshBackground, phosh_background, PHOSH, BACKGROUND, PhoshLayerSurface) -GtkWidget * phosh_background_new (void); +GtkWidget *phosh_background_new (gpointer layer_shell, gpointer wl_output, guint width, guint height); #endif /* PHOSH_BACKGROUND_H */ diff --git a/src/phosh.c b/src/phosh.c index a8d448766..359e56cad 100644 --- a/src/phosh.c +++ b/src/phosh.c @@ -80,7 +80,7 @@ typedef struct struct elem *panel; /* Background */ - struct elem *background; + GtkWidget *background; /* Lockscreen */ struct elem *lockscreen; /* phone display lock screen */ @@ -584,33 +584,16 @@ background_create (PhoshShell *self) #ifdef WITH_PHOSH_BACKGROUND PhoshShellPrivate *priv = phosh_shell_get_instance_private (self); - GdkWindow *gdk_window; - struct elem *background; - gint width, height; PhoshMonitor *monitor; + gint width, height; monitor = phosh_monitor_manager_get_monitor (priv->monitor_manager, 0); g_return_if_fail (monitor); - - background = calloc (1, sizeof *background); - background->window = phosh_background_new (); - phosh_shell_get_usable_area (self, NULL, NULL, &width, &height); + /* set it up as the background */ - gdk_window = gtk_widget_get_window (background->window); - gdk_wayland_window_set_use_custom_surface (gdk_window); - background->wl_surface = gdk_wayland_window_get_wl_surface (gdk_window); - background->layer_surface = - zwlr_layer_shell_v1_get_layer_surface(priv->layer_shell, - background->wl_surface, - monitor->wl_output, - ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, - "phosh"); - zwlr_layer_surface_v1_set_anchor(background->layer_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM); - zwlr_layer_surface_v1_set_size(background->layer_surface, width, height); - zwlr_layer_surface_v1_add_listener(background->layer_surface, &layer_surface_listener, background); - wl_surface_commit(background->wl_surface); - priv->background = background; + priv->background = phosh_background_new ( + priv->layer_shell, monitor->wl_output, width, height); #endif } @@ -750,6 +733,11 @@ phosh_shell_dispose (GObject *object) PhoshShell *self = PHOSH_SHELL (object); PhoshShellPrivate *priv = phosh_shell_get_instance_private(self); + if (priv->background) { + gtk_widget_destroy (priv->background); + priv->background = NULL; + } + if (priv->shields) { g_ptr_array_free (priv->shields, TRUE); priv->shields = NULL; -- GitLab From ba9eacfb8a938f368482028ccc164d1c7649d3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 16:08:48 +0200 Subject: [PATCH 5/6] PhoshBackground: Scale according to window size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the background's setup independet from the phosh global which isn't fully setup yet. It also allows for easier testing. Signed-off-by: Guido Günther --- src/background.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/background.c b/src/background.c index 5063c0036..83d0be5a7 100644 --- a/src/background.c +++ b/src/background.c @@ -37,28 +37,24 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhoshBackground, phosh_background, PHOSH_TYPE_LAYER_ static GdkPixbuf * -image_background (GdkPixbuf *image) +image_background (GdkPixbuf *image, guint width, guint height) { - gint orig_width, orig_height, width, height; + gint orig_width, orig_height; gint final_width, final_height; - gint x, y, off_x, off_y; + gint off_x, off_y; gdouble ratio_horiz, ratio_vert, ratio; GdkPixbuf *bg, *scaled_bg; const gchar *xpm_data[] = {"1 1 1 1", "_ c WebGrey", "_"}; - phosh_shell_get_usable_area (phosh(), &x, &y, &width, &height); bg = gdk_pixbuf_new_from_xpm_data (xpm_data); scaled_bg = gdk_pixbuf_scale_simple (bg, width, /* since we can't offset the pixmap */ - height + y, + height + PHOSH_PANEL_HEIGHT, GDK_INTERP_BILINEAR); g_object_unref (bg); - /* FIXME: we should allow more modes - none, wallpaper, centered, scaled, stretched, zoom - I think GNOME calls this zoom: - */ + /* FIXME: use libgnome-desktop's background handling instead */ orig_width = gdk_pixbuf_get_width (image); orig_height = gdk_pixbuf_get_height (image); ratio_horiz = (double) width / orig_width; @@ -92,6 +88,7 @@ load_background (PhoshBackground *self, GdkPixbuf *image = NULL; const gchar *xpm_data[] = {"1 1 1 1", "_ c WebGrey", "_"}; GError *err = NULL; + gint width, height; if (priv->pixbuf) { g_object_unref (priv->pixbuf); @@ -115,7 +112,8 @@ load_background (PhoshBackground *self, if (!image) image = gdk_pixbuf_new_from_xpm_data (xpm_data); - priv->pixbuf = image_background (image); + gtk_window_get_size (GTK_WINDOW (self), &width, &height); + priv->pixbuf = image_background (image, width, height); g_object_unref (image); /* force background redraw */ -- GitLab From f5d581156433166b384d3c6092c3e96e10c433c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 21:56:22 +0200 Subject: [PATCH 6/6] PhoshBackground: Delay background scaling until we receive the configure event We don't know the actual size of the surface before that. --- src/background.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/background.c b/src/background.c index 83d0be5a7..fa52bcc73 100644 --- a/src/background.c +++ b/src/background.c @@ -173,8 +173,6 @@ phosh_background_constructed (GObject *object) priv->settings = g_settings_new ("org.gnome.desktop.background"); g_signal_connect (priv->settings, "changed::picture-uri", G_CALLBACK (background_setting_changed_cb), self); - /* Load background initially */ - background_setting_changed_cb (priv->settings, "picture-uri", self); /* Window properties */ gtk_window_set_title (GTK_WINDOW (self), "phosh background"); @@ -188,6 +186,18 @@ phosh_background_constructed (GObject *object) } +static void +phosh_background_configured (PhoshBackground *self) +{ + PhoshBackgroundPrivate *priv = phosh_background_get_instance_private (self); + + g_signal_chain_from_overridden_handler (self, 0); + + /* Load background initially */ + background_setting_changed_cb (priv->settings, "picture-uri", self); +} + + static void phosh_background_finalize (GObject *object) { @@ -211,6 +221,10 @@ phosh_background_class_init (PhoshBackgroundClass *klass) object_class->constructed = phosh_background_constructed; object_class->finalize = phosh_background_finalize; + + g_signal_override_class_handler ("configured", + PHOSH_TYPE_LAYER_SURFACE, + (GCallback) phosh_background_configured); } -- GitLab