Skip to content
Snippets Groups Projects
Commit bda335ab authored by Guido Gunther's avatar Guido Gunther :zzz:
Browse files

Merge branch 'background' into 'master'

Move backgound to PhoshLayerSurface

See merge request Librem5/phosh!71
parents ebcac7c2 f5d58115
No related branches found
No related tags found
No related merge requests found
......@@ -29,36 +29,32 @@ 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 *
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 */
......@@ -175,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");
......@@ -190,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)
{
......@@ -213,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);
}
......@@ -227,7 +239,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);
}
......@@ -8,11 +8,12 @@
#define PHOSH_BACKGROUND_H
#include <gtk/gtk.h>
#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 */
......@@ -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);
}
......
......@@ -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,
......
......@@ -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 |
......
......@@ -80,7 +80,7 @@ typedef struct
struct elem *panel;
/* Background */
struct elem *background;
GtkWidget *background;
/* Lockscreen */
struct elem *lockscreen; /* phone display lock screen */
......@@ -577,36 +577,25 @@ 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;
PhoshMonitor *monitor;
gint width, height;
background = calloc (1, sizeof *background);
background->window = phosh_background_new ();
monitor = phosh_monitor_manager_get_monitor (priv->monitor_manager, 0);
g_return_if_fail (monitor);
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,
priv->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
}
static void
css_setup (PhoshShell *self)
......@@ -744,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;
......@@ -802,10 +796,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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment