From 6a7bf210a6c3789d518f9d79a185503debf3ee9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 16 Mar 2024 15:41:14 +0100 Subject: [PATCH 01/38] view: Make view-child a GObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use the same pattern as with PhocView and allow for public struct members so derived classes can access them easily. Since PhocView and PhocViewChild are still entangled we leave most of the member functions in PhocView for the moment. They'll be moved in follow up commits. We need to rename phoc_view_child_init() to not clash with the GObject init function. Signed-off-by: Guido Günther Part-of: --- src/meson.build | 2 + src/view-child-private.h | 82 ++++++++++++++++++++++++++++++++++++++++ src/view-child.c | 26 +++++++++++++ src/view.c | 16 ++++---- src/view.h | 42 +------------------- src/xdg_shell.c | 3 +- 6 files changed, 121 insertions(+), 50 deletions(-) create mode 100644 src/view-child-private.h create mode 100644 src/view-child.c diff --git a/src/meson.build b/src/meson.build index d9bfe3865..c8d4e5c3d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -92,6 +92,8 @@ sources = files( 'utils.h', 'view.c', 'view.h', + 'view-child.c', + 'view-child-private.h', 'view-deco.c', 'view-deco.h', 'virtual.c', diff --git a/src/view-child-private.h b/src/view-child-private.h new file mode 100644 index 000000000..085e848c8 --- /dev/null +++ b/src/view-child-private.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include +#include + +G_BEGIN_DECLS + +/** + * PhocViewChild: + * @link: Link to PhocView::child_surfaces + * @view: The [type@PhocView] this child belongs to + * @parent: (nullable): The parent of this child if another child + * @children: (nullable): children of this child + * + * A child of a [type@PhocView], e.g. a popup or subsurface + */ +typedef struct _PhocView PhocView; +typedef struct _PhocViewChild PhocViewChild; + +/* TODO: drop and use class virtual method */ +typedef struct _PhocViewChildInterface { + void (*get_pos)(PhocViewChild *child, int *sx, int *sy); + void (*destroy)(PhocViewChild *child); +} PhocViewChildInterface; + +struct _PhocViewChild { + GObject parent_instance; + + const PhocViewChildInterface *impl; + + PhocView *view; + PhocViewChild *parent; + GSList *children; + struct wlr_surface *wlr_surface; + struct wl_list link; // PhocViewPrivate::child_surfaces + bool mapped; + + struct wl_listener commit; + struct wl_listener new_subsurface; +}; + +typedef struct _PhocViewChildClass +{ + GObjectClass parent_class; + +} PhocViewChildClass; + +#define PHOC_TYPE_VIEW_CHILD (phoc_view_child_get_type ()) + +GType phoc_view_child_get_type (void); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (PhocViewChild, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (PhocViewChildClass, g_type_class_unref) +static inline PhocViewChild * PHOC_VIEW_CHILD (gpointer ptr) { + return G_TYPE_CHECK_INSTANCE_CAST (ptr, phoc_view_child_get_type (), PhocViewChild); } +static inline PhocViewChildClass * PHOC_VIEW_CHILD_CLASS (gpointer ptr) { + return G_TYPE_CHECK_CLASS_CAST (ptr, phoc_view_child_get_type (), PhocViewChildClass); } +static inline gboolean PHOC_IS_VIEW_CHILD (gpointer ptr) { + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, phoc_view_child_get_type ()); } +static inline gboolean PHOC_IS_VIEW_CHILD_CLASS (gpointer ptr) { + return G_TYPE_CHECK_CLASS_TYPE (ptr, phoc_view_child_get_type ()); } +static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { + return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_child_get_type (), PhocViewChildClass); } + +void phoc_view_child_setup (PhocViewChild *self, + const PhocViewChildInterface *impl, + PhocView *view, + struct wlr_surface *wlr_surface); +void phoc_view_child_destroy (PhocViewChild *self); +void phoc_view_child_apply_damage (PhocViewChild *self); +void phoc_view_child_damage_whole (PhocViewChild *self); +void phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface); +void phoc_view_child_unmap (PhocViewChild *self); + +G_END_DECLS diff --git a/src/view-child.c b/src/view-child.c new file mode 100644 index 000000000..1a4823cd7 --- /dev/null +++ b/src/view-child.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#define G_LOG_DOMAIN "phoc-view-child" + +#include "phoc-config.h" + +#include "view-child-private.h" + +G_DEFINE_TYPE (PhocViewChild, phoc_view_child, G_TYPE_OBJECT) + +static void +phoc_view_child_class_init (PhocViewChildClass *klass) +{ +} + + +static void +phoc_view_child_init (PhocViewChild *self) +{ +} diff --git a/src/view.c b/src/view.c index 470f68555..314d1ae29 100644 --- a/src/view.c +++ b/src/view.c @@ -18,6 +18,7 @@ #include "server.h" #include "utils.h" #include "timed-animation.h" +#include "view-child-private.h" #include "view-private.h" #define PHOC_ANIM_DURATION_WINDOW_FADE 150 @@ -932,10 +933,10 @@ phoc_view_child_unmap (PhocViewChild *child) void -phoc_view_child_init (PhocViewChild *child, - const PhocViewChildInterface *impl, - PhocView *view, - struct wlr_surface *wlr_surface) +phoc_view_child_setup (PhocViewChild *child, + const PhocViewChildInterface *impl, + PhocView *view, + struct wlr_surface *wlr_surface) { PhocViewPrivate *priv; @@ -1032,8 +1033,7 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa PhocSubsurface *subsurface = g_new0 (PhocSubsurface, 1); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_init (&subsurface->child, &subsurface_impl, - view, wlr_subsurface->surface); + phoc_view_child_setup (&subsurface->child, &subsurface_impl, view, wlr_subsurface->surface); subsurface->child.mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; @@ -1054,8 +1054,8 @@ phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface * subsurface->child.parent = child; child->children = g_slist_prepend (child->children, &subsurface->child); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_init (&subsurface->child, &subsurface_impl, child->view, - wlr_subsurface->surface); + phoc_view_child_setup (&subsurface->child, &subsurface_impl, child->view, + wlr_subsurface->surface); subsurface->child.mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; diff --git a/src/view.h b/src/view.h index c6c2de557..3aceb4f10 100644 --- a/src/view.h +++ b/src/view.h @@ -12,7 +12,6 @@ G_BEGIN_DECLS typedef struct _PhocBling PhocBling; -typedef struct _PhocView PhocView; typedef struct _PhocDesktop PhocDesktop; typedef struct _PhocOutput PhocOutput; @@ -54,6 +53,7 @@ typedef enum { */ /* TODO: we keep the struct public for now due to the list links but we should avoid other member access */ +typedef struct _PhocView PhocView; struct _PhocView { GObject parent_instance; @@ -139,36 +139,6 @@ static inline gboolean PHOC_IS_VIEW_CLASS (gpointer ptr) { static inline PhocViewClass * PHOC_VIEW_GET_CLASS (gpointer ptr) { return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_get_type (), PhocViewClass); } -typedef struct _PhocViewChild PhocViewChild; - -typedef struct _PhocViewChildInterface { - void (*get_pos)(PhocViewChild *child, int *sx, int *sy); - void (*destroy)(PhocViewChild *child); -} PhocViewChildInterface; - -/** - * PhocViewChild: - * @link: Link to PhocView::child_surfaces - * @view: The [type@PhocView] this child belongs to - * @parent: (nullable): The parent of this child if another child - * @children: (nullable): children of this child - * - * A child of a [type@PhocView], e.g. a popup or subsurface - */ -typedef struct _PhocViewChild { - const PhocViewChildInterface *impl; - - PhocView *view; - PhocViewChild *parent; - GSList *children; - struct wlr_surface *wlr_surface; - struct wl_list link; - bool mapped; - - struct wl_listener commit; - struct wl_listener new_subsurface; -} PhocViewChild; - void phoc_view_appear_activated (PhocView *view, bool activated); void phoc_view_activate (PhocView *self, bool activate); void phoc_view_damage_whole (PhocView *view); @@ -240,14 +210,4 @@ void phoc_view_add_bling (PhocView *self, PhocBling *bling); void phoc_view_remove_bling (PhocView *self, PhocBling *bling); GSList *phoc_view_get_blings (PhocView *self); -void phoc_view_child_init (PhocViewChild *child, - const PhocViewChildInterface *impl, - PhocView *view, - struct wlr_surface *wlr_surface); -void phoc_view_child_destroy (PhocViewChild *child); -void phoc_view_child_apply_damage (PhocViewChild *child); -void phoc_view_child_damage_whole (PhocViewChild *child); -void phoc_view_child_map (PhocViewChild *child, struct wlr_surface *wlr_surface); -void phoc_view_child_unmap (PhocViewChild *child); - G_END_DECLS diff --git a/src/xdg_shell.c b/src/xdg_shell.c index d3a860785..a825d8d15 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -14,6 +14,7 @@ #include "input.h" #include "server.h" #include "view.h" +#include "view-child-private.h" #include "utils.h" typedef struct _PhocXdgToplevelDecoration { @@ -162,7 +163,7 @@ phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) return NULL; popup->wlr_popup = wlr_popup; - phoc_view_child_init (&popup->child, &popup_impl, view, wlr_popup->base->surface); + phoc_view_child_setup (&popup->child, &popup_impl, view, wlr_popup->base->surface); popup->destroy.notify = popup_handle_destroy; wl_signal_add (&wlr_popup->base->events.destroy, &popup->destroy); -- GitLab From aa104abb1a45a64797c49b19ec028450318f4695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 16 Mar 2024 19:34:34 +0100 Subject: [PATCH 02/38] view-child: Add view and surface properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't take ref on the view yet as the current code doesn't transfer ownership either. We can improve on that once we have the objects in place. Signed-off-by: Guido Günther Part-of: --- src/view-child.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/view-child.c b/src/view-child.c index 1a4823cd7..d6f55155d 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -10,13 +10,106 @@ #include "phoc-config.h" +#include "view.h" #include "view-child-private.h" + +enum { + PROP_0, + PROP_VIEW, + PROP_WLR_SURFACE, + PROP_LAST_PROP +}; +static GParamSpec *props[PROP_LAST_PROP]; + + G_DEFINE_TYPE (PhocViewChild, phoc_view_child, G_TYPE_OBJECT) + +static void +phoc_view_child_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhocViewChild *self = PHOC_VIEW_CHILD (object); + + switch (property_id) { + case PROP_VIEW: + /* TODO: Should hold a ref */ + self->view = g_value_get_object (value); + break; + case PROP_WLR_SURFACE: + self->wlr_surface = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_view_child_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhocViewChild *self = PHOC_VIEW_CHILD (object); + + switch (property_id) { + case PROP_VIEW: + g_value_set_object (value, self->view); + break; + case PROP_WLR_SURFACE: + g_value_set_pointer (value, self->wlr_surface); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_view_child_constructed (GObject *object) +{ + G_OBJECT_CLASS (phoc_view_child_parent_class)->constructed (object); +} + + +static void +phoc_view_child_finalize (GObject *object) +{ + PhocViewChild *self = PHOC_VIEW_CHILD (object); + + self->view = NULL; + self->wlr_surface = NULL; + + G_OBJECT_CLASS (phoc_view_child_parent_class)->finalize (object); +} + + static void phoc_view_child_class_init (PhocViewChildClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = phoc_view_child_get_property; + object_class->set_property = phoc_view_child_set_property; + object_class->constructed = phoc_view_child_constructed; + object_class->finalize = phoc_view_child_finalize; + + props[PROP_VIEW] = + g_param_spec_object ("view", "", "", + PHOC_TYPE_VIEW, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + props[PROP_WLR_SURFACE] = + g_param_spec_pointer ("wlr-surface", "", "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } -- GitLab From 52756ad637be81a16cd9a899ef2114a0c888f09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 16 Mar 2024 20:01:49 +0100 Subject: [PATCH 03/38] xdg-shell: Make xdg-popup a minimal GObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code will move into xdg-suface later. Signed-off-by: Guido Günther Part-of: --- src/xdg_shell.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/xdg_shell.c b/src/xdg_shell.c index a825d8d15..0c92e3728 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -17,6 +17,7 @@ #include "view-child-private.h" #include "utils.h" + typedef struct _PhocXdgToplevelDecoration { struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration; PhocXdgSurface *surface; @@ -25,6 +26,7 @@ typedef struct _PhocXdgToplevelDecoration { struct wl_listener surface_commit; } PhocXdgToplevelDecoration; + typedef struct _PhocXdgPopup { PhocViewChild child; struct wlr_xdg_popup *wlr_popup; @@ -36,6 +38,11 @@ typedef struct _PhocXdgPopup { struct wl_listener reposition; } PhocXdgPopup; +#define PHOC_TYPE_XDG_POPUP (phoc_xdg_popup_get_type ()) +G_DECLARE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC, XDG_POPUP, PhocViewChild) +G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) + + static const PhocViewChildInterface popup_impl; static void @@ -154,6 +161,28 @@ popup_handle_reposition (struct wl_listener *listener, void *data) } +static void +phoc_xdg_popup_finalize (GObject *object) +{ + G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->finalize (object); +} + + +static void +phoc_xdg_popup_class_init (PhocXdgPopupClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = phoc_xdg_popup_finalize; +} + + +static void +phoc_xdg_popup_init (PhocXdgPopup *self) +{ +} + + PhocXdgPopup * phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) { -- GitLab From f5344d41ac5330b01114b250e7c5ecb525684372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 16 Mar 2024 20:07:32 +0100 Subject: [PATCH 04/38] xdg-shell: Create/destroy popup as GObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/xdg_shell.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 0c92e3728..e73fb7ffe 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -57,7 +57,7 @@ popup_destroy (PhocViewChild *child) wl_list_remove (&popup->map.link); wl_list_remove (&popup->destroy.link); - free (popup); + g_object_unref (child); } @@ -183,13 +183,20 @@ phoc_xdg_popup_init (PhocXdgPopup *self) } +static PhocXdgPopup * +phoc_xdg_popup_new (PhocView *view, struct wlr_surface *wlr_surface) +{ + return g_object_new (PHOC_TYPE_XDG_POPUP, + "view", view, + "wlr-surface", wlr_surface, + NULL); +} + + PhocXdgPopup * phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) { - PhocXdgPopup *popup = calloc (1, sizeof(PhocXdgPopup)); - - if (popup == NULL) - return NULL; + PhocXdgPopup *popup = phoc_xdg_popup_new (view, wlr_popup->base->surface); popup->wlr_popup = wlr_popup; phoc_view_child_setup (&popup->child, &popup_impl, view, wlr_popup->base->surface); -- GitLab From 11844039e278e5629b941cf179c90ad8ce8be69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 16 Mar 2024 20:47:24 +0100 Subject: [PATCH 05/38] view: Make subsurface a minimal GObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/view.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/view.c b/src/view.c index 314d1ae29..74e1ece02 100644 --- a/src/view.c +++ b/src/view.c @@ -77,7 +77,6 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhocView, phoc_view, G_TYPE_OBJECT) #define PHOC_VIEW_SELF(p) PHOC_PRIV_CONTAINER(PHOC_VIEW, PhocView, (p)) -static bool view_center (PhocView *view, PhocOutput *output); typedef struct _PhocSubsurface { PhocViewChild child; @@ -88,6 +87,13 @@ typedef struct _PhocSubsurface { struct wl_listener unmap; } PhocSubsurface; +#define PHOC_TYPE_SUBSURFACE (phoc_subsurface_get_type ()) +G_DECLARE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC, SUBSURFACE, PhocViewChild) +G_DEFINE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC_TYPE_VIEW_CHILD) + + +static bool view_center (PhocView *view, PhocOutput *output); + static struct wlr_foreign_toplevel_handle_v1 * phoc_view_get_toplevel_handle (PhocView *self) @@ -1027,6 +1033,38 @@ subsurface_handle_unmap (struct wl_listener *listener,void *data) } +static void +phoc_subsurface_finalize (GObject *object) +{ + G_OBJECT_CLASS (phoc_subsurface_parent_class)->finalize (object); +} + + +static void +phoc_subsurface_class_init (PhocSubsurfaceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = phoc_subsurface_finalize; +} + + +static void +phoc_subsurface_init (PhocSubsurface *self) +{ +} + + +static PhocSubsurface * +phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface) +{ + return g_object_new (PHOC_TYPE_SUBSURFACE, + "view", view, + "wlr-surface", wlr_surface, + NULL); +} + + static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface) { -- GitLab From 8aeace273e3265d8f3bf21cef6115a9201d35caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 16 Mar 2024 22:45:31 +0100 Subject: [PATCH 06/38] view: Create/destroy subsurfaces as GOjects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/view.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/view.c b/src/view.c index 74e1ece02..66a59b7df 100644 --- a/src/view.c +++ b/src/view.c @@ -996,7 +996,8 @@ subsurface_destroy (PhocViewChild *child) wl_list_remove (&subsurface->destroy.link); wl_list_remove (&subsurface->map.link); wl_list_remove (&subsurface->unmap.link); - g_free (subsurface); + + g_object_unref (subsurface); } @@ -1068,7 +1069,7 @@ phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface) static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface) { - PhocSubsurface *subsurface = g_new0 (PhocSubsurface, 1); + PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface->surface); subsurface->wlr_subsurface = wlr_subsurface; phoc_view_child_setup (&subsurface->child, &subsurface_impl, view, wlr_subsurface->surface); @@ -1087,7 +1088,7 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa static void phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface) { - PhocSubsurface *subsurface = g_new0 (PhocSubsurface, 1); + PhocSubsurface *subsurface = phoc_subsurface_new (child->view, wlr_subsurface->surface); subsurface->child.parent = child; child->children = g_slist_prepend (child->children, &subsurface->child); -- GitLab From 78c57406e5ef02522b19092c96188edd8d9bbb8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 11:18:14 +0100 Subject: [PATCH 07/38] view: Move PhocViewChild's public functions over too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We skip phoc_view_child_setup() for now as it accesses view's private data. Since we now have our own compilation unit we can rename `child` to `self` to ease readability. Signed-off-by: Guido Günther Part-of: --- src/view-child.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++- src/view.c | 94 -------------------------------------------- 2 files changed, 99 insertions(+), 95 deletions(-) diff --git a/src/view-child.c b/src/view-child.c index d6f55155d..cf7e9cdf9 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -10,7 +10,12 @@ #include "phoc-config.h" -#include "view.h" +#include "desktop.h" +#include "input.h" +#include "output.h" +#include "server.h" +#include "utils.h" +#include "view-private.h" #include "view-child-private.h" @@ -26,6 +31,19 @@ static GParamSpec *props[PROP_LAST_PROP]; G_DEFINE_TYPE (PhocViewChild, phoc_view_child, G_TYPE_OBJECT) +static bool +phoc_view_child_is_mapped (PhocViewChild *self) +{ + while (self) { + if (!self->mapped) + return false; + + self = self->parent; + } + return true; +} + + static void phoc_view_child_set_property (GObject *object, guint property_id, @@ -117,3 +135,83 @@ static void phoc_view_child_init (PhocViewChild *self) { } + +/** + * phoc_view_child_apply_damage: + * @self: A view child + * + * This is the equivalent of `phoc_view_apply_damage` but for [type@ViewChild]. + */ +void +phoc_view_child_apply_damage (PhocViewChild *self) +{ + if (!self || !phoc_view_child_is_mapped (self) || !phoc_view_is_mapped (self->view)) + return; + + phoc_view_apply_damage (self->view); +} + +/** + * phoc_view_child_damage_whole: + * @self: A view child + * + * This is the equivalent of [method@View.damage_whole] but for + * [type@ViewChild]. + */ +void +phoc_view_child_damage_whole (PhocViewChild *self) +{ + PhocOutput *output; + int sx, sy; + struct wlr_box view_box; + + if (!self || !phoc_view_child_is_mapped (self) || !phoc_view_is_mapped (self->view)) + return; + + phoc_view_get_box (self->view, &view_box); + self->impl->get_pos (self, &sx, &sy); + + wl_list_for_each (output, &self->view->desktop->outputs, link) { + struct wlr_box output_box; + wlr_output_layout_get_box (self->view->desktop->layout, output->wlr_output, &output_box); + phoc_output_damage_whole_local_surface (output, self->wlr_surface, + view_box.x + sx - output_box.x, + view_box.y + sy - output_box.y); + + } +} + + +void +phoc_view_child_unmap (PhocViewChild *self) +{ + PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); + + phoc_view_child_damage_whole (self); + phoc_input_update_cursor_focus (input); + self->mapped = false; +} + + +void +phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface) +{ + PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); + PhocView *view = self->view; + + self->mapped = true; + phoc_view_child_damage_whole (self); + + struct wlr_box box; + phoc_view_get_box (view, &box); + + PhocOutput *output; + wl_list_for_each (output, &view->desktop->outputs, link) { + bool intersects = wlr_output_layout_intersects (view->desktop->layout, + output->wlr_output, &box); + if (intersects) + phoc_utils_wlr_surface_enter_output (wlr_surface, output->wlr_output); + } + + phoc_input_update_cursor_focus (input); +} diff --git a/src/view.c b/src/view.c index 66a59b7df..937c6d72c 100644 --- a/src/view.c +++ b/src/view.c @@ -846,18 +846,6 @@ view_center (PhocView *view, PhocOutput *output) } -static bool -phoc_view_child_is_mapped (PhocViewChild *child) -{ - while (child) { - if (!child->mapped) { - return false; - } - child = child->parent; - } - return true; -} - static void phoc_view_child_handle_commit (struct wl_listener *listener, void *data) { @@ -903,41 +891,6 @@ phoc_view_child_init_subsurfaces (PhocViewChild *child, struct wlr_surface *surf } -void -phoc_view_child_map (PhocViewChild *child, struct wlr_surface *wlr_surface) -{ - PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); - PhocView *view = child->view; - - child->mapped = true; - phoc_view_child_damage_whole (child); - - struct wlr_box box; - phoc_view_get_box (view, &box); - - PhocOutput *output; - wl_list_for_each (output, &view->desktop->outputs, link) { - bool intersects = wlr_output_layout_intersects (view->desktop->layout, - output->wlr_output, &box); - if (intersects) - phoc_utils_wlr_surface_enter_output (wlr_surface, output->wlr_output); - } - - phoc_input_update_cursor_focus (input); -} - - -void -phoc_view_child_unmap (PhocViewChild *child) -{ - PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); - - phoc_view_child_damage_whole (child); - phoc_input_update_cursor_focus (input); - child->mapped = false; -} - - void phoc_view_child_setup (PhocViewChild *child, const PhocViewChildInterface *impl, @@ -2026,53 +1979,6 @@ phoc_view_child_destroy (PhocViewChild *child) child->impl->destroy(child); } -/* - * phoc_view_child_apply_damage: - * @child: A view child - * - * This is the equivalent of [method@Phoc.View.apply_damage] but for - * [struct@Phoc.ViewChild]. - */ -void -phoc_view_child_apply_damage (PhocViewChild *child) -{ - if (!child || !phoc_view_child_is_mapped (child) || !phoc_view_is_mapped (child->view)) - return; - - phoc_view_apply_damage (child->view); -} - -/** - * phoc_view_child_damage_whole: - * @child: A view child - * - * This is the equivalent of [method@Phoc.View.damage_whole] but for - * [struct@Phoc.ViewChild]. - */ -void -phoc_view_child_damage_whole (PhocViewChild *child) -{ - PhocOutput *output; - int sx, sy; - struct wlr_box view_box; - - if (!child || !phoc_view_child_is_mapped (child) || !phoc_view_is_mapped (child->view)) - return; - - phoc_view_get_box (child->view, &view_box); - child->impl->get_pos (child, &sx, &sy); - - wl_list_for_each (output, &child->view->desktop->outputs, link) { - struct wlr_box output_box; - wlr_output_layout_get_box (child->view->desktop->layout, output->wlr_output, &output_box); - phoc_output_damage_whole_local_surface (output, child->wlr_surface, - view_box.x + sx - output_box.x, - view_box.y + sy - output_box.y); - - } -} - - /** * phoc_view_set_scale_to_fit: * @self: The view -- GitLab From 0f11570818db4bd8db513e1491f2f88cdf4a98ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 11:24:33 +0100 Subject: [PATCH 08/38] view-child: Move most of phoc_view_child_destroy into finalize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For that we pull the `g_object_unref` from the custom destroy handlers into `phoc_view_child_destroy`. Signed-off-by: Guido Günther Part-of: --- src/view-child.c | 23 +++++++++++++++++++++++ src/view.c | 26 ++------------------------ src/xdg_shell.c | 2 -- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/view-child.c b/src/view-child.c index cf7e9cdf9..ed05a3bba 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -101,6 +101,29 @@ phoc_view_child_finalize (GObject *object) { PhocViewChild *self = PHOC_VIEW_CHILD (object); + if (phoc_view_child_is_mapped (self) && phoc_view_is_mapped (self->view)) + phoc_view_child_damage_whole (self); + + /* Remove from parent if it's also a PhocViewChild */ + if (self->parent != NULL) { + self->parent->children = g_slist_remove (self->parent->children, self); + self->parent = NULL; + } + + /* Detach us from all children */ + for (GSList *elem = self->children; elem; elem = elem->next) { + PhocViewChild *subchild = elem->data; + subchild->parent = NULL; + /* The subchild lost its parent, so it cannot see that the parent is unmapped. Unmap it directly */ + /* TODO: But then we won't damage them on destroy? */ + subchild->mapped = false; + } + g_clear_pointer (&self->children, g_slist_free); + + wl_list_remove (&self->link); + wl_list_remove (&self->commit.link); + wl_list_remove (&self->new_subsurface.link); + self->view = NULL; self->wlr_surface = NULL; diff --git a/src/view.c b/src/view.c index 937c6d72c..d1d8e248d 100644 --- a/src/view.c +++ b/src/view.c @@ -949,8 +949,6 @@ subsurface_destroy (PhocViewChild *child) wl_list_remove (&subsurface->destroy.link); wl_list_remove (&subsurface->map.link); wl_list_remove (&subsurface->unmap.link); - - g_object_unref (subsurface); } @@ -1954,29 +1952,9 @@ phoc_view_child_destroy (PhocViewChild *child) if (child == NULL) return; - if (phoc_view_child_is_mapped (child) && phoc_view_is_mapped (child->view)) - phoc_view_child_damage_whole (child); - - /* Remove from parent if it's also a PhocChild */ - if (child->parent != NULL) { - child->parent->children = g_slist_remove (child->parent->children, child); - child->parent = NULL; - } - - /* Detach us from all children */ - for (GSList *elem = child->children; elem; elem = elem->next) { - PhocViewChild *subchild = elem->data; - subchild->parent = NULL; - /* The subchild lost its parent, so it cannot see that the parent is unmapped. Unmap it directly */ - subchild->mapped = false; - } - g_clear_pointer (&child->children, g_slist_free); - - wl_list_remove(&child->link); - wl_list_remove(&child->commit.link); - wl_list_remove(&child->new_subsurface.link); - child->impl->destroy(child); + + g_object_unref (child); } /** diff --git a/src/xdg_shell.c b/src/xdg_shell.c index e73fb7ffe..777c21689 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -56,8 +56,6 @@ popup_destroy (PhocViewChild *child) wl_list_remove (&popup->unmap.link); wl_list_remove (&popup->map.link); wl_list_remove (&popup->destroy.link); - - g_object_unref (child); } -- GitLab From 3c242dc6178df054509f0e130e5eac1605590663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 11:51:56 +0100 Subject: [PATCH 09/38] view-child: Use GObject virtual functions for destroy and get_pos This allows us to drop the ViewChildInterface. Part-of: --- src/view-child-private.h | 23 +++++++++++---------- src/view-child.c | 22 +++++++++++++++++++- src/view.c | 44 +++++++++++----------------------------- src/xdg_shell.c | 35 +++++++++++--------------------- 4 files changed, 57 insertions(+), 67 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index 085e848c8..319f494e2 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -20,22 +20,14 @@ G_BEGIN_DECLS * @parent: (nullable): The parent of this child if another child * @children: (nullable): children of this child * - * A child of a [type@PhocView], e.g. a popup or subsurface + * A child of a [type@View], e.g. a popup or subsurface */ typedef struct _PhocView PhocView; -typedef struct _PhocViewChild PhocViewChild; - -/* TODO: drop and use class virtual method */ -typedef struct _PhocViewChildInterface { - void (*get_pos)(PhocViewChild *child, int *sx, int *sy); - void (*destroy)(PhocViewChild *child); -} PhocViewChildInterface; +typedef struct _PhocViewChild PhocViewChild; struct _PhocViewChild { GObject parent_instance; - const PhocViewChildInterface *impl; - PhocView *view; PhocViewChild *parent; GSList *children; @@ -47,10 +39,19 @@ struct _PhocViewChild { struct wl_listener new_subsurface; }; +/** + * PhocViewChildClass: + * @parent_class: The object class structure needs to be the first + * element in the widget class structure in order for the class mechanism + * to work correctly. This allows a PhocViewClass pointer to be cast to + * a GObjectClass pointer. + * @get_pos: Get the child's position relative to it's parent. + */ typedef struct _PhocViewChildClass { GObjectClass parent_class; + void (*get_pos) (PhocViewChild *self, int *sx, int *sy); } PhocViewChildClass; #define PHOC_TYPE_VIEW_CHILD (phoc_view_child_get_type ()) @@ -70,7 +71,6 @@ static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_child_get_type (), PhocViewChildClass); } void phoc_view_child_setup (PhocViewChild *self, - const PhocViewChildInterface *impl, PhocView *view, struct wlr_surface *wlr_surface); void phoc_view_child_destroy (PhocViewChild *self); @@ -78,5 +78,6 @@ void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); void phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface); void phoc_view_child_unmap (PhocViewChild *self); +void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); G_END_DECLS diff --git a/src/view-child.c b/src/view-child.c index ed05a3bba..64b55f82b 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -131,16 +131,27 @@ phoc_view_child_finalize (GObject *object) } +G_NORETURN +static void +phoc_view_child_get_pos_default (PhocViewChild *self, int *sx, int *sy) +{ + g_assert_not_reached (); +} + + static void phoc_view_child_class_init (PhocViewChildClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); object_class->get_property = phoc_view_child_get_property; object_class->set_property = phoc_view_child_set_property; object_class->constructed = phoc_view_child_constructed; object_class->finalize = phoc_view_child_finalize; + view_child_class->get_pos = phoc_view_child_get_pos_default; + props[PROP_VIEW] = g_param_spec_object ("view", "", "", PHOC_TYPE_VIEW, @@ -192,7 +203,7 @@ phoc_view_child_damage_whole (PhocViewChild *self) return; phoc_view_get_box (self->view, &view_box); - self->impl->get_pos (self, &sx, &sy); + phoc_view_child_get_pos (self, &sx, &sy); wl_list_for_each (output, &self->view->desktop->outputs, link) { struct wlr_box output_box; @@ -238,3 +249,12 @@ phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface) phoc_input_update_cursor_focus (input); } + + +void +phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy) +{ + g_assert (PHOC_IS_VIEW_CHILD (self)); + + PHOC_VIEW_CHILD_GET_CLASS (self)->get_pos (self, sx, sy); +} diff --git a/src/view.c b/src/view.c index d1d8e248d..99e1528de 100644 --- a/src/view.c +++ b/src/view.c @@ -893,14 +893,11 @@ phoc_view_child_init_subsurfaces (PhocViewChild *child, struct wlr_surface *surf void phoc_view_child_setup (PhocViewChild *child, - const PhocViewChildInterface *impl, PhocView *view, struct wlr_surface *wlr_surface) { PhocViewPrivate *priv; - g_assert (impl->destroy); - child->impl = impl; child->view = view; child->wlr_surface = wlr_surface; @@ -917,19 +914,15 @@ phoc_view_child_setup (PhocViewChild *child, } -static const PhocViewChildInterface subsurface_impl; - static void subsurface_get_pos (PhocViewChild *child, int *sx, int *sy) { struct wlr_surface *wlr_surface; struct wlr_subsurface *wlr_subsurface; - g_assert (child->impl == &subsurface_impl); - wlr_surface = child->wlr_surface; - if (child->parent && child->parent->impl && child->parent->impl->get_pos) - child->parent->impl->get_pos (child->parent, sx, sy); + if (child->parent) + phoc_view_child_get_pos (child->parent, sx, sy); else *sx = *sy = 0; @@ -940,24 +933,6 @@ subsurface_get_pos (PhocViewChild *child, int *sx, int *sy) } -static void -subsurface_destroy (PhocViewChild *child) -{ - PhocSubsurface *subsurface = (PhocSubsurface *)child; - - g_assert (child->impl == &subsurface_impl); - wl_list_remove (&subsurface->destroy.link); - wl_list_remove (&subsurface->map.link); - wl_list_remove (&subsurface->unmap.link); -} - - -static const PhocViewChildInterface subsurface_impl = { - .get_pos = subsurface_get_pos, - .destroy = subsurface_destroy, -}; - - static void subsurface_handle_destroy (struct wl_listener *listener, void *data) { @@ -988,6 +963,12 @@ subsurface_handle_unmap (struct wl_listener *listener,void *data) static void phoc_subsurface_finalize (GObject *object) { + PhocSubsurface *subsurface = PHOC_SUBSURFACE (object); + + wl_list_remove (&subsurface->destroy.link); + wl_list_remove (&subsurface->map.link); + wl_list_remove (&subsurface->unmap.link); + G_OBJECT_CLASS (phoc_subsurface_parent_class)->finalize (object); } @@ -996,8 +977,10 @@ static void phoc_subsurface_class_init (PhocSubsurfaceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); object_class->finalize = phoc_subsurface_finalize; + view_child_class->get_pos = subsurface_get_pos; } @@ -1023,7 +1006,7 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface->surface); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (&subsurface->child, &subsurface_impl, view, wlr_subsurface->surface); + phoc_view_child_setup (&subsurface->child, view, wlr_subsurface->surface); subsurface->child.mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; @@ -1044,8 +1027,7 @@ phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface * subsurface->child.parent = child; child->children = g_slist_prepend (child->children, &subsurface->child); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (&subsurface->child, &subsurface_impl, child->view, - wlr_subsurface->surface); + phoc_view_child_setup (&subsurface->child, child->view, wlr_subsurface->surface); subsurface->child.mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; @@ -1952,8 +1934,6 @@ phoc_view_child_destroy (PhocViewChild *child) if (child == NULL) return; - child->impl->destroy(child); - g_object_unref (child); } diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 777c21689..83ddd493a 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -43,22 +43,6 @@ G_DECLARE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC, XDG_POPUP, PhocViewChi G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) -static const PhocViewChildInterface popup_impl; - -static void -popup_destroy (PhocViewChild *child) -{ - g_assert (child->impl == &popup_impl); - PhocXdgPopup *popup = (PhocXdgPopup *)child; - - wl_list_remove (&popup->reposition.link); - wl_list_remove (&popup->new_popup.link); - wl_list_remove (&popup->unmap.link); - wl_list_remove (&popup->map.link); - wl_list_remove (&popup->destroy.link); -} - - static void popup_get_pos (PhocViewChild *child, int *sx, int *sy) { @@ -72,12 +56,6 @@ popup_get_pos (PhocViewChild *child, int *sx, int *sy) } -static const PhocViewChildInterface popup_impl = { - .get_pos = popup_get_pos, - .destroy = popup_destroy, -}; - - static void popup_unconstrain (PhocXdgPopup* popup) { @@ -162,6 +140,14 @@ popup_handle_reposition (struct wl_listener *listener, void *data) static void phoc_xdg_popup_finalize (GObject *object) { + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + wl_list_remove (&popup->reposition.link); + wl_list_remove (&popup->new_popup.link); + wl_list_remove (&popup->unmap.link); + wl_list_remove (&popup->map.link); + wl_list_remove (&popup->destroy.link); + G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->finalize (object); } @@ -170,8 +156,11 @@ static void phoc_xdg_popup_class_init (PhocXdgPopupClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); object_class->finalize = phoc_xdg_popup_finalize; + + view_child_class->get_pos = popup_get_pos; } @@ -197,7 +186,7 @@ phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) PhocXdgPopup *popup = phoc_xdg_popup_new (view, wlr_popup->base->surface); popup->wlr_popup = wlr_popup; - phoc_view_child_setup (&popup->child, &popup_impl, view, wlr_popup->base->surface); + phoc_view_child_setup (&popup->child, view, wlr_popup->base->surface); popup->destroy.notify = popup_handle_destroy; wl_signal_add (&wlr_popup->base->events.destroy, &popup->destroy); -- GitLab From 69f76945423f2d653fd7e7240314667c8a499391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 12:24:15 +0100 Subject: [PATCH 10/38] view-child: Move most of the ViewChild's setup into constructed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to drop more arguments from phoc_view_child_setup() as those are already passed to the object constructor. Signed-off-by: Guido Günther Part-of: --- src/view-child-private.h | 6 +++--- src/view-child.c | 27 +++++++++++++++++++++++++++ src/view.c | 40 ++++++---------------------------------- src/xdg_shell.c | 2 +- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index 319f494e2..f040f0866 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -70,14 +70,14 @@ static inline gboolean PHOC_IS_VIEW_CHILD_CLASS (gpointer ptr) { static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_child_get_type (), PhocViewChildClass); } -void phoc_view_child_setup (PhocViewChild *self, - PhocView *view, - struct wlr_surface *wlr_surface); +void phoc_view_child_setup (PhocViewChild *self); void phoc_view_child_destroy (PhocViewChild *self); void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); void phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface); void phoc_view_child_unmap (PhocViewChild *self); void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); +void phoc_view_child_subsurface_create (PhocViewChild *child, + struct wlr_subsurface *wlr_subsurface); G_END_DECLS diff --git a/src/view-child.c b/src/view-child.c index 64b55f82b..fe0dcfde2 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -89,10 +89,37 @@ phoc_view_child_get_property (GObject *object, } +static void +phoc_view_child_handle_new_subsurface (struct wl_listener *listener, void *data) +{ + PhocViewChild *self = wl_container_of (listener, self, new_subsurface); + struct wlr_subsurface *wlr_subsurface = data; + + phoc_view_child_subsurface_create (self, wlr_subsurface); +} + + +static void +phoc_view_child_handle_commit (struct wl_listener *listener, void *data) +{ + PhocViewChild *self = wl_container_of (listener, self, commit); + + phoc_view_child_apply_damage (self); +} + + static void phoc_view_child_constructed (GObject *object) { + PhocViewChild *self = PHOC_VIEW_CHILD (object); + G_OBJECT_CLASS (phoc_view_child_parent_class)->constructed (object); + + self->commit.notify = phoc_view_child_handle_commit; + wl_signal_add (&self->wlr_surface->events.commit, &self->commit); + + self->new_subsurface.notify = phoc_view_child_handle_new_subsurface; + wl_signal_add (&self->wlr_surface->events.new_subsurface, &self->new_subsurface); } diff --git a/src/view.c b/src/view.c index 99e1528de..de838a785 100644 --- a/src/view.c +++ b/src/view.c @@ -846,25 +846,8 @@ view_center (PhocView *view, PhocOutput *output) } -static void -phoc_view_child_handle_commit (struct wl_listener *listener, void *data) -{ - PhocViewChild *child = wl_container_of(listener, child, commit); - - phoc_view_child_apply_damage (child); -} - static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface); -static void phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface); - -static void -phoc_view_child_handle_new_subsurface (struct wl_listener *listener, void *data) -{ - PhocViewChild *child = wl_container_of(listener, child, new_subsurface); - struct wlr_subsurface *wlr_subsurface = data; - phoc_view_child_subsurface_create (child, wlr_subsurface); -} static void phoc_view_init_subsurfaces (PhocView *view, struct wlr_surface *surface) @@ -892,25 +875,14 @@ phoc_view_child_init_subsurfaces (PhocViewChild *child, struct wlr_surface *surf void -phoc_view_child_setup (PhocViewChild *child, - PhocView *view, - struct wlr_surface *wlr_surface) +phoc_view_child_setup (PhocViewChild *child) { PhocViewPrivate *priv; - child->view = view; - child->wlr_surface = wlr_surface; - - child->commit.notify = phoc_view_child_handle_commit; - wl_signal_add(&wlr_surface->events.commit, &child->commit); - - child->new_subsurface.notify = phoc_view_child_handle_new_subsurface; - wl_signal_add(&wlr_surface->events.new_subsurface, &child->new_subsurface); - - priv = phoc_view_get_instance_private (view); + priv = phoc_view_get_instance_private (child->view); wl_list_insert (&priv->child_surfaces, &child->link); - phoc_view_child_init_subsurfaces (child, wlr_surface); + phoc_view_child_init_subsurfaces (child, child->wlr_surface); } @@ -1006,7 +978,7 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface->surface); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (&subsurface->child, view, wlr_subsurface->surface); + phoc_view_child_setup (&subsurface->child); subsurface->child.mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; @@ -1019,7 +991,7 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa wl_signal_add (&wlr_subsurface->surface->events.unmap, &subsurface->unmap); } -static void +void phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface) { PhocSubsurface *subsurface = phoc_subsurface_new (child->view, wlr_subsurface->surface); @@ -1027,7 +999,7 @@ phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface * subsurface->child.parent = child; child->children = g_slist_prepend (child->children, &subsurface->child); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (&subsurface->child, child->view, wlr_subsurface->surface); + phoc_view_child_setup (&subsurface->child); subsurface->child.mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 83ddd493a..3433d4a27 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -186,7 +186,7 @@ phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) PhocXdgPopup *popup = phoc_xdg_popup_new (view, wlr_popup->base->surface); popup->wlr_popup = wlr_popup; - phoc_view_child_setup (&popup->child, view, wlr_popup->base->surface); + phoc_view_child_setup (&popup->child); popup->destroy.notify = popup_handle_destroy; wl_signal_add (&wlr_popup->base->events.destroy, &popup->destroy); -- GitLab From caa34de352d5187203477b0537a7875e2be79b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 12:36:50 +0100 Subject: [PATCH 11/38] view-child: Add map / unmap virtual methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to drop the implementation in the derived classes completely (while we could still override them if needed). Signed-off-by: Guido Günther Part-of: --- src/view-child-private.h | 8 +++- src/view-child.c | 99 ++++++++++++++++++++++++++-------------- src/view.c | 35 -------------- src/xdg_shell.c | 28 ------------ 4 files changed, 70 insertions(+), 100 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index f040f0866..dd91510fd 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -35,6 +35,8 @@ struct _PhocViewChild { struct wl_list link; // PhocViewPrivate::child_surfaces bool mapped; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener commit; struct wl_listener new_subsurface; }; @@ -45,12 +47,16 @@ struct _PhocViewChild { * element in the widget class structure in order for the class mechanism * to work correctly. This allows a PhocViewClass pointer to be cast to * a GObjectClass pointer. + * @map: Invoked on map. Chain up to parent. + * @unmap: Invoked on unmap. Chain up to parent. * @get_pos: Get the child's position relative to it's parent. */ typedef struct _PhocViewChildClass { GObjectClass parent_class; + void (*map) (PhocViewChild *self); + void (*unmap) (PhocViewChild *self); void (*get_pos) (PhocViewChild *self, int *sx, int *sy); } PhocViewChildClass; @@ -74,8 +80,6 @@ void phoc_view_child_setup (PhocViewChild *self); void phoc_view_child_destroy (PhocViewChild *self); void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); -void phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface); -void phoc_view_child_unmap (PhocViewChild *self); void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); void phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface); diff --git a/src/view-child.c b/src/view-child.c index fe0dcfde2..352b81685 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -89,6 +89,24 @@ phoc_view_child_get_property (GObject *object, } +static void +phoc_view_child_handle_map (struct wl_listener *listener, void *data) +{ + PhocViewChild *self = wl_container_of (listener, self, map); + + PHOC_VIEW_CHILD_GET_CLASS (self)->map (self); +} + + +static void +phoc_view_child_handle_unmap (struct wl_listener *listener, void *data) +{ + PhocViewChild *self = wl_container_of (listener, self, unmap); + + PHOC_VIEW_CHILD_GET_CLASS (self)->unmap (self); +} + + static void phoc_view_child_handle_new_subsurface (struct wl_listener *listener, void *data) { @@ -115,6 +133,12 @@ phoc_view_child_constructed (GObject *object) G_OBJECT_CLASS (phoc_view_child_parent_class)->constructed (object); + self->map.notify = phoc_view_child_handle_map; + wl_signal_add (&self->wlr_surface->events.map, &self->map); + + self->unmap.notify = phoc_view_child_handle_unmap; + wl_signal_add (&self->wlr_surface->events.unmap, &self->unmap); + self->commit.notify = phoc_view_child_handle_commit; wl_signal_add (&self->wlr_surface->events.commit, &self->commit); @@ -148,6 +172,9 @@ phoc_view_child_finalize (GObject *object) g_clear_pointer (&self->children, g_slist_free); wl_list_remove (&self->link); + + wl_list_remove (&self->map.link); + wl_list_remove (&self->unmap.link); wl_list_remove (&self->commit.link); wl_list_remove (&self->new_subsurface.link); @@ -158,6 +185,41 @@ phoc_view_child_finalize (GObject *object) } +static void +phoc_view_child_map_default (PhocViewChild *self) +{ + PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); + PhocView *view = self->view; + + self->mapped = true; + phoc_view_child_damage_whole (self); + + struct wlr_box box; + phoc_view_get_box (view, &box); + + PhocOutput *output; + wl_list_for_each (output, &view->desktop->outputs, link) { + bool intersects = wlr_output_layout_intersects (view->desktop->layout, + output->wlr_output, &box); + if (intersects) + phoc_utils_wlr_surface_enter_output (self->wlr_surface, output->wlr_output); + } + + phoc_input_update_cursor_focus (input); +} + + +static void +phoc_view_child_unmap_default (PhocViewChild *self) +{ + PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); + + phoc_view_child_damage_whole (self); + phoc_input_update_cursor_focus (input); + self->mapped = false; +} + + G_NORETURN static void phoc_view_child_get_pos_default (PhocViewChild *self, int *sx, int *sy) @@ -177,6 +239,8 @@ phoc_view_child_class_init (PhocViewChildClass *klass) object_class->constructed = phoc_view_child_constructed; object_class->finalize = phoc_view_child_finalize; + view_child_class->map = phoc_view_child_map_default; + view_child_class->unmap = phoc_view_child_unmap_default; view_child_class->get_pos = phoc_view_child_get_pos_default; props[PROP_VIEW] = @@ -243,41 +307,6 @@ phoc_view_child_damage_whole (PhocViewChild *self) } -void -phoc_view_child_unmap (PhocViewChild *self) -{ - PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); - - phoc_view_child_damage_whole (self); - phoc_input_update_cursor_focus (input); - self->mapped = false; -} - - -void -phoc_view_child_map (PhocViewChild *self, struct wlr_surface *wlr_surface) -{ - PhocInput *input = phoc_server_get_input (phoc_server_get_default ()); - PhocView *view = self->view; - - self->mapped = true; - phoc_view_child_damage_whole (self); - - struct wlr_box box; - phoc_view_get_box (view, &box); - - PhocOutput *output; - wl_list_for_each (output, &view->desktop->outputs, link) { - bool intersects = wlr_output_layout_intersects (view->desktop->layout, - output->wlr_output, &box); - if (intersects) - phoc_utils_wlr_surface_enter_output (wlr_surface, output->wlr_output); - } - - phoc_input_update_cursor_focus (input); -} - - void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy) { diff --git a/src/view.c b/src/view.c index de838a785..10f742d46 100644 --- a/src/view.c +++ b/src/view.c @@ -83,8 +83,6 @@ typedef struct _PhocSubsurface { struct wlr_subsurface *wlr_subsurface; struct wl_listener destroy; - struct wl_listener map; - struct wl_listener unmap; } PhocSubsurface; #define PHOC_TYPE_SUBSURFACE (phoc_subsurface_get_type ()) @@ -912,25 +910,6 @@ subsurface_handle_destroy (struct wl_listener *listener, void *data) phoc_view_child_destroy(&subsurface->child); } -static void -subsurface_handle_map (struct wl_listener *listener, void *data) -{ - PhocSubsurface *subsurface = wl_container_of (listener, subsurface, map); - - /* Chain up to parent */ - phoc_view_child_map (&subsurface->child, subsurface->wlr_subsurface->surface); -} - - -static void -subsurface_handle_unmap (struct wl_listener *listener,void *data) -{ - PhocSubsurface *subsurface = wl_container_of (listener, subsurface, unmap); - - /* Chain up to parent */ - phoc_view_child_unmap (&subsurface->child); -} - static void phoc_subsurface_finalize (GObject *object) @@ -938,8 +917,6 @@ phoc_subsurface_finalize (GObject *object) PhocSubsurface *subsurface = PHOC_SUBSURFACE (object); wl_list_remove (&subsurface->destroy.link); - wl_list_remove (&subsurface->map.link); - wl_list_remove (&subsurface->unmap.link); G_OBJECT_CLASS (phoc_subsurface_parent_class)->finalize (object); } @@ -983,12 +960,6 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa subsurface->destroy.notify = subsurface_handle_destroy; wl_signal_add (&wlr_subsurface->events.destroy, &subsurface->destroy); - - subsurface->map.notify = subsurface_handle_map; - wl_signal_add (&wlr_subsurface->surface->events.map, &subsurface->map); - - subsurface->unmap.notify = subsurface_handle_unmap; - wl_signal_add (&wlr_subsurface->surface->events.unmap, &subsurface->unmap); } void @@ -1005,12 +976,6 @@ phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface * subsurface->destroy.notify = subsurface_handle_destroy; wl_signal_add (&wlr_subsurface->events.destroy, &subsurface->destroy); - subsurface->map.notify = subsurface_handle_map; - wl_signal_add (&wlr_subsurface->surface->events.map, &subsurface->map); - - subsurface->unmap.notify = subsurface_handle_unmap; - wl_signal_add (&wlr_subsurface->surface->events.unmap, &subsurface->unmap); - phoc_view_child_damage_whole (&subsurface->child); } diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 3433d4a27..b525c40df 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -32,8 +32,6 @@ typedef struct _PhocXdgPopup { struct wlr_xdg_popup *wlr_popup; struct wl_listener destroy; - struct wl_listener map; - struct wl_listener unmap; struct wl_listener new_popup; struct wl_listener reposition; } PhocXdgPopup; @@ -95,24 +93,6 @@ popup_handle_destroy (struct wl_listener *listener, void *data) phoc_view_child_destroy (&popup->child); } -static void -popup_handle_map (struct wl_listener *listener, void *data) -{ - PhocXdgPopup *popup = wl_container_of (listener, popup, map); - - /* Chain up to parent */ - phoc_view_child_map (&popup->child, popup->child.wlr_surface); -} - -static void -popup_handle_unmap (struct wl_listener *listener, void *data) -{ - PhocXdgPopup *popup = wl_container_of (listener, popup, unmap); - - /* Chain up to parent */ - phoc_view_child_unmap (&popup->child); -} - static void popup_handle_new_popup (struct wl_listener *listener, void *data) @@ -144,8 +124,6 @@ phoc_xdg_popup_finalize (GObject *object) wl_list_remove (&popup->reposition.link); wl_list_remove (&popup->new_popup.link); - wl_list_remove (&popup->unmap.link); - wl_list_remove (&popup->map.link); wl_list_remove (&popup->destroy.link); G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->finalize (object); @@ -191,12 +169,6 @@ phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) popup->destroy.notify = popup_handle_destroy; wl_signal_add (&wlr_popup->base->events.destroy, &popup->destroy); - popup->map.notify = popup_handle_map; - wl_signal_add (&wlr_popup->base->surface->events.map, &popup->map); - - popup->unmap.notify = popup_handle_unmap; - wl_signal_add (&wlr_popup->base->surface->events.unmap, &popup->unmap); - popup->new_popup.notify = popup_handle_new_popup; wl_signal_add (&wlr_popup->base->events.new_popup, &popup->new_popup); -- GitLab From 20660aa833cce0234d7837ef6bfe9381dc57d125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 15:34:09 +0100 Subject: [PATCH 12/38] xdg-shell: Use popup constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thus we can drop phoc_xdg_popup_create(). The phoc_xdg_popup_new() invocations without consuming the return value look a bit odd but the ref is dropped in handle_destroy. This is the same pattern we use for other surface types. Signed-off-by: Guido Günther Part-of: --- src/xdg-surface-private.h | 2 +- src/xdg-surface.c | 2 +- src/xdg_shell.c | 119 ++++++++++++++++++++++++++++---------- 3 files changed, 90 insertions(+), 33 deletions(-) diff --git a/src/xdg-surface-private.h b/src/xdg-surface-private.h index 7514c2230..549796701 100644 --- a/src/xdg-surface-private.h +++ b/src/xdg-surface-private.h @@ -15,7 +15,7 @@ G_BEGIN_DECLS typedef struct _PhocXdgPopup PhocXdgPopup; typedef struct _PhocXdgToplevelDecoration PhocXdgToplevelDecoration; -PhocXdgPopup *phoc_xdg_popup_create (PhocView *view, +PhocXdgPopup *phoc_xdg_popup_new (PhocView *view, struct wlr_xdg_popup *wlr_popup); void phoc_xdg_surface_set_decoration (PhocXdgSurface *self, PhocXdgToplevelDecoration *decoration); diff --git a/src/xdg-surface.c b/src/xdg-surface.c index ae9392b81..dd836cb13 100644 --- a/src/xdg-surface.c +++ b/src/xdg-surface.c @@ -492,7 +492,7 @@ handle_new_popup (struct wl_listener *listener, void *data) PhocXdgSurface *self = wl_container_of (listener, self, new_popup); struct wlr_xdg_popup *wlr_popup = data; - phoc_xdg_popup_create (PHOC_VIEW (self), wlr_popup); + phoc_xdg_popup_new (PHOC_VIEW (self), wlr_popup); } diff --git a/src/xdg_shell.c b/src/xdg_shell.c index b525c40df..153839d91 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -18,6 +18,14 @@ #include "utils.h" +enum { + PROP_0, + PROP_WLR_POPUP, + PROP_LAST_PROP +}; +static GParamSpec *props[PROP_LAST_PROP]; + + typedef struct _PhocXdgToplevelDecoration { struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration; PhocXdgSurface *surface; @@ -28,7 +36,8 @@ typedef struct _PhocXdgToplevelDecoration { typedef struct _PhocXdgPopup { - PhocViewChild child; + PhocViewChild parent_instance; + struct wlr_xdg_popup *wlr_popup; struct wl_listener destroy; @@ -60,7 +69,7 @@ popup_unconstrain (PhocXdgPopup* popup) // get the output of the popup's positioner anchor point and convert it to // the toplevel parent's coordinate system and then pass it to // wlr_xdg_popup_unconstrain_from_box - PhocView *view = PHOC_VIEW (popup->child.view); + PhocView *view = PHOC_VIEW (PHOC_VIEW_CHILD (popup)->view); PhocOutput *output = phoc_desktop_layout_get_output (view->desktop, view->box.x, view->box.y); if (output == NULL) @@ -90,7 +99,7 @@ popup_handle_destroy (struct wl_listener *listener, void *data) { PhocXdgPopup *popup = wl_container_of (listener, popup, destroy); - phoc_view_child_destroy (&popup->child); + phoc_view_child_destroy (PHOC_VIEW_CHILD (popup)); } @@ -100,7 +109,7 @@ popup_handle_new_popup (struct wl_listener *listener, void *data) PhocXdgPopup *popup = wl_container_of (listener, popup, new_popup); struct wlr_xdg_popup *wlr_popup = data; - phoc_xdg_popup_create (popup->child.view, wlr_popup); + phoc_xdg_popup_new (PHOC_VIEW_CHILD (popup)->view, wlr_popup); } @@ -111,7 +120,67 @@ popup_handle_reposition (struct wl_listener *listener, void *data) /* clear the old popup positon */ /* TODO: this is too much damage */ - phoc_view_damage_whole (popup->child.view); + phoc_view_damage_whole (PHOC_VIEW_CHILD (popup)->view); + + popup_unconstrain (popup); +} + + +static void +phoc_xdg_popup_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + switch (property_id) { + case PROP_WLR_POPUP: + popup->wlr_popup = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_xdg_popup_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + switch (property_id) { + case PROP_WLR_POPUP: + g_value_set_pointer (value, popup->wlr_popup); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_xdg_popup_constructed (GObject *object) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->constructed (object); + + phoc_view_child_setup (PHOC_VIEW_CHILD (popup)); + + popup->destroy.notify = popup_handle_destroy; + wl_signal_add (&popup->wlr_popup->base->events.destroy, &popup->destroy); + + popup->new_popup.notify = popup_handle_new_popup; + wl_signal_add (&popup->wlr_popup->base->events.new_popup, &popup->new_popup); + + popup->reposition.notify = popup_handle_reposition; + wl_signal_add (&popup->wlr_popup->events.reposition, &popup->reposition); popup_unconstrain (popup); } @@ -136,9 +205,19 @@ phoc_xdg_popup_class_init (PhocXdgPopupClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); + object_class->constructed = phoc_xdg_popup_constructed; object_class->finalize = phoc_xdg_popup_finalize; + object_class->get_property = phoc_xdg_popup_get_property; + object_class->set_property = phoc_xdg_popup_set_property; view_child_class->get_pos = popup_get_pos; + + props[PROP_WLR_POPUP] = + g_param_spec_pointer ("wlr-popup", "", "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); + } @@ -148,39 +227,17 @@ phoc_xdg_popup_init (PhocXdgPopup *self) } -static PhocXdgPopup * -phoc_xdg_popup_new (PhocView *view, struct wlr_surface *wlr_surface) +PhocXdgPopup * +phoc_xdg_popup_new (PhocView *view, struct wlr_xdg_popup *wlr_xdg_popup) { return g_object_new (PHOC_TYPE_XDG_POPUP, "view", view, - "wlr-surface", wlr_surface, + "wlr-popup", wlr_xdg_popup, + "wlr-surface", wlr_xdg_popup->base->surface, NULL); } -PhocXdgPopup * -phoc_xdg_popup_create (PhocView *view, struct wlr_xdg_popup *wlr_popup) -{ - PhocXdgPopup *popup = phoc_xdg_popup_new (view, wlr_popup->base->surface); - - popup->wlr_popup = wlr_popup; - phoc_view_child_setup (&popup->child); - - popup->destroy.notify = popup_handle_destroy; - wl_signal_add (&wlr_popup->base->events.destroy, &popup->destroy); - - popup->new_popup.notify = popup_handle_new_popup; - wl_signal_add (&wlr_popup->base->events.new_popup, &popup->new_popup); - - popup->reposition.notify = popup_handle_reposition; - wl_signal_add (&wlr_popup->events.reposition, &popup->reposition); - - popup_unconstrain (popup); - - return popup; -} - - void handle_xdg_shell_surface (struct wl_listener *listener, void *data) { -- GitLab From 3da6508dbc6eb8e8859e2001cd79603827f4882a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 15:42:08 +0100 Subject: [PATCH 13/38] view-child: Drop phoc_view_child_destroy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can simply drop the only reference. Signed-off-by: Guido Günther Part-of: --- src/view-child-private.h | 1 - src/view.c | 23 ++++------------------- src/xdg_shell.c | 2 +- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index dd91510fd..5575d532b 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -77,7 +77,6 @@ static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_child_get_type (), PhocViewChildClass); } void phoc_view_child_setup (PhocViewChild *self); -void phoc_view_child_destroy (PhocViewChild *self); void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); diff --git a/src/view.c b/src/view.c index 10f742d46..a1ab1a72d 100644 --- a/src/view.c +++ b/src/view.c @@ -907,7 +907,8 @@ static void subsurface_handle_destroy (struct wl_listener *listener, void *data) { PhocSubsurface *subsurface = wl_container_of(listener, subsurface, destroy); - phoc_view_child_destroy(&subsurface->child); + + g_object_unref (subsurface); } @@ -1138,9 +1139,8 @@ phoc_view_unmap (PhocView *view) wl_list_remove (&priv->surface_new_subsurface.link); PhocViewChild *child, *tmp; - wl_list_for_each_safe(child, tmp, &priv->child_surfaces, link) { - phoc_view_child_destroy(child); - } + wl_list_for_each_safe (child, tmp, &priv->child_surfaces, link) + g_object_unref (child); if (phoc_view_is_fullscreen (view)) { phoc_output_damage_whole (priv->fullscreen_output); @@ -1859,21 +1859,6 @@ phoc_view_get_output (PhocView *view) return PHOC_OUTPUT (wlr_output->data); } -/** - * phoc_view_child_destroy: - * @child: The view child to destroy - * - * Destroys a view child freeing its resources. - */ -void -phoc_view_child_destroy (PhocViewChild *child) -{ - if (child == NULL) - return; - - g_object_unref (child); -} - /** * phoc_view_set_scale_to_fit: * @self: The view diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 153839d91..15aa913a2 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -99,7 +99,7 @@ popup_handle_destroy (struct wl_listener *listener, void *data) { PhocXdgPopup *popup = wl_container_of (listener, popup, destroy); - phoc_view_child_destroy (PHOC_VIEW_CHILD (popup)); + g_object_unref (popup); } -- GitLab From ce9d870c4a7ef30b34178ad8b95126a32f6f051d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 15:52:39 +0100 Subject: [PATCH 14/38] subsurface: Use casts instead of accessing `child` directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves readability and allows us to rename to parent_instance. Signed-off-by: Guido Günther Part-of: --- src/view.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/view.c b/src/view.c index a1ab1a72d..8b3b9363f 100644 --- a/src/view.c +++ b/src/view.c @@ -79,7 +79,8 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhocView, phoc_view, G_TYPE_OBJECT) typedef struct _PhocSubsurface { - PhocViewChild child; + PhocViewChild parent_instance; + struct wlr_subsurface *wlr_subsurface; struct wl_listener destroy; @@ -956,30 +957,33 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface->surface); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (&subsurface->child); - subsurface->child.mapped = wlr_subsurface->surface->mapped; + phoc_view_child_setup (PHOC_VIEW_CHILD (subsurface)); + PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; wl_signal_add (&wlr_subsurface->events.destroy, &subsurface->destroy); } + void phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface) { PhocSubsurface *subsurface = phoc_subsurface_new (child->view, wlr_subsurface->surface); - subsurface->child.parent = child; - child->children = g_slist_prepend (child->children, &subsurface->child); + PHOC_VIEW_CHILD (subsurface)->parent = child; + child->children = g_slist_prepend (child->children, subsurface); + subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (&subsurface->child); - subsurface->child.mapped = wlr_subsurface->surface->mapped; + phoc_view_child_setup (PHOC_VIEW_CHILD (subsurface)); + PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; wl_signal_add (&wlr_subsurface->events.destroy, &subsurface->destroy); - phoc_view_child_damage_whole (&subsurface->child); + phoc_view_child_damage_whole (PHOC_VIEW_CHILD (subsurface)); } + static void phoc_view_handle_surface_new_subsurface (struct wl_listener *listener, void *data) { -- GitLab From d6225ee48e82a5409d138ad2aa808db7232ac5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 17 Mar 2024 21:54:45 +0100 Subject: [PATCH 15/38] xdg-popup: Move popup class into it's own file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We might want to merge xdg-surface and xdg-popup back into an xdg-shell at some point as they serve the originate from the same Wayland protocol but let's have this split for now to disentangle xdg_shell. Signed-off-by: Guido Günther Part-of: --- src/meson.build | 2 + src/view-child-private.h | 2 +- src/xdg-popup.c | 234 ++++++++++++++++++++++++++++++++++++++ src/xdg-popup.h | 23 ++++ src/xdg-surface-private.h | 3 - src/xdg-surface.c | 1 + src/xdg_shell.c | 215 ---------------------------------- 7 files changed, 261 insertions(+), 219 deletions(-) create mode 100644 src/xdg-popup.c create mode 100644 src/xdg-popup.h diff --git a/src/meson.build b/src/meson.build index c8d4e5c3d..ece15d886 100644 --- a/src/meson.build +++ b/src/meson.build @@ -100,6 +100,8 @@ sources = files( 'virtual.h', 'xdg-activation-v1.c', 'xdg-activation-v1.h', + 'xdg-popup.c', + 'xdg-popup.h', 'xdg_shell.c', 'xdg-surface.c', 'xdg-surface.h', diff --git a/src/view-child-private.h b/src/view-child-private.h index 5575d532b..0da2b0392 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -20,7 +20,7 @@ G_BEGIN_DECLS * @parent: (nullable): The parent of this child if another child * @children: (nullable): children of this child * - * A child of a [type@View], e.g. a popup or subsurface + * A child of a [type@View], e.g. a [type@XdgPopup] or subsurface */ typedef struct _PhocView PhocView; diff --git a/src/xdg-popup.c b/src/xdg-popup.c new file mode 100644 index 000000000..63b708532 --- /dev/null +++ b/src/xdg-popup.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#define G_LOG_DOMAIN "phoc-xdg-popup" + +#include "phoc-config.h" + +#include +#include +#include +#include "cursor.h" +#include "desktop.h" +#include "input.h" +#include "server.h" +#include "view.h" +#include "view-child-private.h" +#include "utils.h" +#include "xdg-popup.h" + +enum { + PROP_0, + PROP_WLR_POPUP, + PROP_LAST_PROP +}; +static GParamSpec *props[PROP_LAST_PROP]; + +/** + * PhocXdgPopup: + * + * A popup as defined in the xdg-shell protocol + */ +typedef struct _PhocXdgPopup { + PhocViewChild parent_instance; + + struct wlr_xdg_popup *wlr_popup; + + struct wl_listener destroy; + struct wl_listener new_popup; + struct wl_listener reposition; +} PhocXdgPopup; + +G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) + + +static void +popup_get_pos (PhocViewChild *child, int *sx, int *sy) +{ + PhocXdgPopup *popup = (PhocXdgPopup *)child; + struct wlr_xdg_popup *wlr_popup = popup->wlr_popup; + + wlr_xdg_popup_get_toplevel_coords (wlr_popup, + wlr_popup->current.geometry.x - wlr_popup->base->current.geometry.x, + wlr_popup->current.geometry.y - wlr_popup->base->current.geometry.y, + sx, sy); +} + + +static void +popup_unconstrain (PhocXdgPopup* popup) +{ + /* get the output of the popup's positioner anchor point and convert it to + * the toplevel parent's coordinate system and then pass it to + * wlr_xdg_popup_unconstrain_from_box */ + PhocView *view = PHOC_VIEW (PHOC_VIEW_CHILD (popup)->view); + + PhocOutput *output = phoc_desktop_layout_get_output (view->desktop, view->box.x, view->box.y); + if (output == NULL) + return; + + struct wlr_box output_box; + wlr_output_layout_get_box (view->desktop->layout, output->wlr_output, &output_box); + struct wlr_box usable_area = output->usable_area; + usable_area.x += output_box.x; + usable_area.y += output_box.y; + + /* the output box expressed in the coordinate system of the toplevel parent + * of the popup */ + struct wlr_box output_toplevel_sx_box = { + .x = usable_area.x - view->box.x, + .y = usable_area.y - view->box.y, + .width = usable_area.width, + .height = usable_area.height, + }; + + wlr_xdg_popup_unconstrain_from_box (popup->wlr_popup, &output_toplevel_sx_box); +} + + +static void +popup_handle_destroy (struct wl_listener *listener, void *data) +{ + PhocXdgPopup *popup = wl_container_of (listener, popup, destroy); + + g_object_unref (popup); +} + + +static void +popup_handle_new_popup (struct wl_listener *listener, void *data) +{ + PhocXdgPopup *popup = wl_container_of (listener, popup, new_popup); + struct wlr_xdg_popup *wlr_popup = data; + + phoc_xdg_popup_new (PHOC_VIEW_CHILD (popup)->view, wlr_popup); +} + + +static void +popup_handle_reposition (struct wl_listener *listener, void *data) +{ + PhocXdgPopup *popup = wl_container_of (listener, popup, reposition); + + /* clear the old popup positon */ + /* TODO: this is too much damage */ + phoc_view_damage_whole (PHOC_VIEW_CHILD (popup)->view); + + popup_unconstrain (popup); +} + + +static void +phoc_xdg_popup_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + switch (property_id) { + case PROP_WLR_POPUP: + popup->wlr_popup = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_xdg_popup_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + switch (property_id) { + case PROP_WLR_POPUP: + g_value_set_pointer (value, popup->wlr_popup); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_xdg_popup_constructed (GObject *object) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->constructed (object); + + phoc_view_child_setup (PHOC_VIEW_CHILD (popup)); + + popup->destroy.notify = popup_handle_destroy; + wl_signal_add (&popup->wlr_popup->base->events.destroy, &popup->destroy); + + popup->new_popup.notify = popup_handle_new_popup; + wl_signal_add (&popup->wlr_popup->base->events.new_popup, &popup->new_popup); + + popup->reposition.notify = popup_handle_reposition; + wl_signal_add (&popup->wlr_popup->events.reposition, &popup->reposition); + + popup_unconstrain (popup); +} + + +static void +phoc_xdg_popup_finalize (GObject *object) +{ + PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + + wl_list_remove (&popup->reposition.link); + wl_list_remove (&popup->new_popup.link); + wl_list_remove (&popup->destroy.link); + + G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->finalize (object); +} + + +static void +phoc_xdg_popup_class_init (PhocXdgPopupClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); + + object_class->constructed = phoc_xdg_popup_constructed; + object_class->finalize = phoc_xdg_popup_finalize; + object_class->get_property = phoc_xdg_popup_get_property; + object_class->set_property = phoc_xdg_popup_set_property; + + view_child_class->get_pos = popup_get_pos; + + props[PROP_WLR_POPUP] = + g_param_spec_pointer ("wlr-popup", "", "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); +} + + +static void +phoc_xdg_popup_init (PhocXdgPopup *self) +{ +} + + +PhocXdgPopup * +phoc_xdg_popup_new (PhocView *view, struct wlr_xdg_popup *wlr_xdg_popup) +{ + return g_object_new (PHOC_TYPE_XDG_POPUP, + "view", view, + "wlr-popup", wlr_xdg_popup, + "wlr-surface", wlr_xdg_popup->base->surface, + NULL); +} diff --git a/src/xdg-popup.h b/src/xdg-popup.h new file mode 100644 index 000000000..68ae7d33a --- /dev/null +++ b/src/xdg-popup.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "view.h" +#include "view-child-private.h" + +#include + +G_BEGIN_DECLS + +#define PHOC_TYPE_XDG_POPUP (phoc_xdg_popup_get_type ()) + +G_DECLARE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC, XDG_POPUP, PhocViewChild) + +PhocXdgPopup *phoc_xdg_popup_new (PhocView *view, + struct wlr_xdg_popup *wlr_popup); + +G_END_DECLS diff --git a/src/xdg-surface-private.h b/src/xdg-surface-private.h index 549796701..9150c5ed0 100644 --- a/src/xdg-surface-private.h +++ b/src/xdg-surface-private.h @@ -12,11 +12,8 @@ G_BEGIN_DECLS -typedef struct _PhocXdgPopup PhocXdgPopup; typedef struct _PhocXdgToplevelDecoration PhocXdgToplevelDecoration; -PhocXdgPopup *phoc_xdg_popup_new (PhocView *view, - struct wlr_xdg_popup *wlr_popup); void phoc_xdg_surface_set_decoration (PhocXdgSurface *self, PhocXdgToplevelDecoration *decoration); PhocXdgToplevelDecoration * diff --git a/src/xdg-surface.c b/src/xdg-surface.c index dd836cb13..61abfb04b 100644 --- a/src/xdg-surface.c +++ b/src/xdg-surface.c @@ -13,6 +13,7 @@ #include "cursor.h" #include "server.h" #include "view-private.h" +#include "xdg-popup.h" #include "xdg-surface.h" #include "xdg-surface-private.h" diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 15aa913a2..59a486840 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -9,23 +9,11 @@ #include #include #include -#include "cursor.h" #include "desktop.h" -#include "input.h" #include "server.h" -#include "view.h" -#include "view-child-private.h" #include "utils.h" -enum { - PROP_0, - PROP_WLR_POPUP, - PROP_LAST_PROP -}; -static GParamSpec *props[PROP_LAST_PROP]; - - typedef struct _PhocXdgToplevelDecoration { struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration; PhocXdgSurface *surface; @@ -35,209 +23,6 @@ typedef struct _PhocXdgToplevelDecoration { } PhocXdgToplevelDecoration; -typedef struct _PhocXdgPopup { - PhocViewChild parent_instance; - - struct wlr_xdg_popup *wlr_popup; - - struct wl_listener destroy; - struct wl_listener new_popup; - struct wl_listener reposition; -} PhocXdgPopup; - -#define PHOC_TYPE_XDG_POPUP (phoc_xdg_popup_get_type ()) -G_DECLARE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC, XDG_POPUP, PhocViewChild) -G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) - - -static void -popup_get_pos (PhocViewChild *child, int *sx, int *sy) -{ - PhocXdgPopup *popup = (PhocXdgPopup *)child; - struct wlr_xdg_popup *wlr_popup = popup->wlr_popup; - - wlr_xdg_popup_get_toplevel_coords (wlr_popup, - wlr_popup->current.geometry.x - wlr_popup->base->current.geometry.x, - wlr_popup->current.geometry.y - wlr_popup->base->current.geometry.y, - sx, sy); -} - - -static void -popup_unconstrain (PhocXdgPopup* popup) -{ - // get the output of the popup's positioner anchor point and convert it to - // the toplevel parent's coordinate system and then pass it to - // wlr_xdg_popup_unconstrain_from_box - PhocView *view = PHOC_VIEW (PHOC_VIEW_CHILD (popup)->view); - - PhocOutput *output = phoc_desktop_layout_get_output (view->desktop, view->box.x, view->box.y); - if (output == NULL) - return; - - struct wlr_box output_box; - wlr_output_layout_get_box (view->desktop->layout, output->wlr_output, &output_box); - struct wlr_box usable_area = output->usable_area; - usable_area.x += output_box.x; - usable_area.y += output_box.y; - - // the output box expressed in the coordinate system of the toplevel parent - // of the popup - struct wlr_box output_toplevel_sx_box = { - .x = usable_area.x - view->box.x, - .y = usable_area.y - view->box.y, - .width = usable_area.width, - .height = usable_area.height, - }; - - wlr_xdg_popup_unconstrain_from_box (popup->wlr_popup, &output_toplevel_sx_box); -} - - -static void -popup_handle_destroy (struct wl_listener *listener, void *data) -{ - PhocXdgPopup *popup = wl_container_of (listener, popup, destroy); - - g_object_unref (popup); -} - - -static void -popup_handle_new_popup (struct wl_listener *listener, void *data) -{ - PhocXdgPopup *popup = wl_container_of (listener, popup, new_popup); - struct wlr_xdg_popup *wlr_popup = data; - - phoc_xdg_popup_new (PHOC_VIEW_CHILD (popup)->view, wlr_popup); -} - - -static void -popup_handle_reposition (struct wl_listener *listener, void *data) -{ - PhocXdgPopup *popup = wl_container_of (listener, popup, reposition); - - /* clear the old popup positon */ - /* TODO: this is too much damage */ - phoc_view_damage_whole (PHOC_VIEW_CHILD (popup)->view); - - popup_unconstrain (popup); -} - - -static void -phoc_xdg_popup_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); - - switch (property_id) { - case PROP_WLR_POPUP: - popup->wlr_popup = g_value_get_pointer (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - - -static void -phoc_xdg_popup_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); - - switch (property_id) { - case PROP_WLR_POPUP: - g_value_set_pointer (value, popup->wlr_popup); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - - -static void -phoc_xdg_popup_constructed (GObject *object) -{ - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); - - G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->constructed (object); - - phoc_view_child_setup (PHOC_VIEW_CHILD (popup)); - - popup->destroy.notify = popup_handle_destroy; - wl_signal_add (&popup->wlr_popup->base->events.destroy, &popup->destroy); - - popup->new_popup.notify = popup_handle_new_popup; - wl_signal_add (&popup->wlr_popup->base->events.new_popup, &popup->new_popup); - - popup->reposition.notify = popup_handle_reposition; - wl_signal_add (&popup->wlr_popup->events.reposition, &popup->reposition); - - popup_unconstrain (popup); -} - - -static void -phoc_xdg_popup_finalize (GObject *object) -{ - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); - - wl_list_remove (&popup->reposition.link); - wl_list_remove (&popup->new_popup.link); - wl_list_remove (&popup->destroy.link); - - G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->finalize (object); -} - - -static void -phoc_xdg_popup_class_init (PhocXdgPopupClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); - - object_class->constructed = phoc_xdg_popup_constructed; - object_class->finalize = phoc_xdg_popup_finalize; - object_class->get_property = phoc_xdg_popup_get_property; - object_class->set_property = phoc_xdg_popup_set_property; - - view_child_class->get_pos = popup_get_pos; - - props[PROP_WLR_POPUP] = - g_param_spec_pointer ("wlr-popup", "", "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, PROP_LAST_PROP, props); - -} - - -static void -phoc_xdg_popup_init (PhocXdgPopup *self) -{ -} - - -PhocXdgPopup * -phoc_xdg_popup_new (PhocView *view, struct wlr_xdg_popup *wlr_xdg_popup) -{ - return g_object_new (PHOC_TYPE_XDG_POPUP, - "view", view, - "wlr-popup", wlr_xdg_popup, - "wlr-surface", wlr_xdg_popup->base->surface, - NULL); -} - - void handle_xdg_shell_surface (struct wl_listener *listener, void *data) { -- GitLab From 873320a3e699a28bd6035a4fc77f9b78a13a22c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:09:12 +0100 Subject: [PATCH 16/38] xdg-popup: Use GObject generated casts consistently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/xdg-popup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 63b708532..2b6c1caa3 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -50,7 +50,7 @@ G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) static void popup_get_pos (PhocViewChild *child, int *sx, int *sy) { - PhocXdgPopup *popup = (PhocXdgPopup *)child; + PhocXdgPopup *popup = PHOC_XDG_POPUP (child); struct wlr_xdg_popup *wlr_popup = popup->wlr_popup; wlr_xdg_popup_get_toplevel_coords (wlr_popup, @@ -66,7 +66,7 @@ popup_unconstrain (PhocXdgPopup* popup) /* get the output of the popup's positioner anchor point and convert it to * the toplevel parent's coordinate system and then pass it to * wlr_xdg_popup_unconstrain_from_box */ - PhocView *view = PHOC_VIEW (PHOC_VIEW_CHILD (popup)->view); + PhocView *view = PHOC_VIEW_CHILD (popup)->view; PhocOutput *output = phoc_desktop_layout_get_output (view->desktop, view->box.x, view->box.y); if (output == NULL) -- GitLab From 39ea79a8b8f6e8957ec8f1238a6a2fcb231bb39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:14:15 +0100 Subject: [PATCH 17/38] xdg-shell: Move surface creation handler to xdg-surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/desktop.c | 2 +- src/desktop.h | 1 - src/xdg-surface.c | 34 ++++++++++++++++++++++++++++++++-- src/xdg-surface.h | 2 ++ src/xdg_shell.c | 29 ----------------------------- 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/desktop.c b/src/desktop.c index 1e2a5012b..d74f943d3 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -719,7 +719,7 @@ phoc_desktop_constructed (GObject *object) self->xdg_shell = wlr_xdg_shell_create(wl_display, PHOC_XDG_SHELL_VERSION); wl_signal_add(&self->xdg_shell->events.new_surface, &self->xdg_shell_surface); - self->xdg_shell_surface.notify = handle_xdg_shell_surface; + self->xdg_shell_surface.notify = phoc_handle_xdg_shell_surface; self->layer_shell = wlr_layer_shell_v1_create (wl_display, PHOC_LAYER_SHELL_VERSION); wl_signal_add(&self->layer_shell->events.new_surface, &self->layer_shell_surface); diff --git a/src/desktop.h b/src/desktop.h index 925cf171b..0484e3b52 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -139,7 +139,6 @@ PhocPhoshPrivate *phoc_desktop_get_phosh_private (PhocDesktop *s void phoc_desktop_notify_activity (PhocDesktop *self, PhocSeat *seat); -void handle_xdg_shell_surface(struct wl_listener *listener, void *data); void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data); void handle_layer_shell_surface(struct wl_listener *listener, void *data); diff --git a/src/xdg-surface.c b/src/xdg-surface.c index 61abfb04b..ce6990075 100644 --- a/src/xdg-surface.c +++ b/src/xdg-surface.c @@ -35,9 +35,10 @@ static GParamSpec *props[PROP_LAST_PROP]; /** * PhocXdgSurface: * - * An xdg surface. + * An xdg toplevel surface as defined in the xdg-shell protocol. For + * popups see [type@XdgPopup]. * - * For how to setup such an object see handle_xdg_shell_surface. + * For details on how to setup such an object see [func@handle_xdg_shell_surface]. */ typedef struct _PhocXdgSurface { PhocView view; @@ -692,3 +693,32 @@ phoc_xdg_surface_get_wlr_xdg_surface (PhocXdgSurface *self) return self->xdg_surface; } + + +void +phoc_handle_xdg_shell_surface (struct wl_listener *listener, void *data) +{ + struct wlr_xdg_surface *surface = data; + + g_assert (surface->role != WLR_XDG_SURFACE_ROLE_NONE); + if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { + g_debug ("new xdg popup"); + return; + } + + PhocDesktop *desktop = wl_container_of (listener, desktop, xdg_shell_surface); + g_debug ("new xdg toplevel: title=%s, app_id=%s", + surface->toplevel->title, surface->toplevel->app_id); + + wlr_xdg_surface_ping (surface); + PhocXdgSurface *phoc_surface = phoc_xdg_surface_new (surface); + + // Check for app-id override coming from gtk-shell + PhocGtkShell *gtk_shell = phoc_desktop_get_gtk_shell (desktop); + PhocGtkSurface *gtk_surface = phoc_gtk_shell_get_gtk_surface_from_wlr_surface (gtk_shell, + surface->surface); + if (gtk_surface && phoc_gtk_surface_get_app_id (gtk_surface)) + phoc_view_set_app_id (PHOC_VIEW (phoc_surface), phoc_gtk_surface_get_app_id (gtk_surface)); + else + phoc_view_set_app_id (PHOC_VIEW (phoc_surface), surface->toplevel->app_id); +} diff --git a/src/xdg-surface.h b/src/xdg-surface.h index f9b197fe6..ad380a2db 100644 --- a/src/xdg-surface.h +++ b/src/xdg-surface.h @@ -26,4 +26,6 @@ struct wlr_surface *phoc_xdg_surface_get_wlr_surface_at (PhocXdgSurface *self, double *sub_x, double *sub_y); +void phoc_handle_xdg_shell_surface (struct wl_listener *listener, void *data); + G_END_DECLS diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 59a486840..559f5d165 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -23,35 +23,6 @@ typedef struct _PhocXdgToplevelDecoration { } PhocXdgToplevelDecoration; -void -handle_xdg_shell_surface (struct wl_listener *listener, void *data) -{ - struct wlr_xdg_surface *surface = data; - - g_assert (surface->role != WLR_XDG_SURFACE_ROLE_NONE); - if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - g_debug ("new xdg popup"); - return; - } - - PhocDesktop *desktop = wl_container_of(listener, desktop, xdg_shell_surface); - g_debug ("new xdg toplevel: title=%s, app_id=%s", - surface->toplevel->title, surface->toplevel->app_id); - - wlr_xdg_surface_ping (surface); - PhocXdgSurface *phoc_surface = phoc_xdg_surface_new (surface); - - // Check for app-id override coming from gtk-shell - PhocGtkShell *gtk_shell = phoc_desktop_get_gtk_shell (desktop); - PhocGtkSurface *gtk_surface = phoc_gtk_shell_get_gtk_surface_from_wlr_surface (gtk_shell, - surface->surface); - if (gtk_surface && phoc_gtk_surface_get_app_id (gtk_surface)) - phoc_view_set_app_id (PHOC_VIEW (phoc_surface), phoc_gtk_surface_get_app_id (gtk_surface)); - else - phoc_view_set_app_id (PHOC_VIEW (phoc_surface), surface->toplevel->app_id); -} - - static void decoration_handle_destroy (struct wl_listener *listener, void *data) { -- GitLab From c98ecbe1e5f2d53f80b52661c225d26ac3bc1b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:21:32 +0100 Subject: [PATCH 18/38] xdg-surface: Tighten role check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/xdg-surface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xdg-surface.c b/src/xdg-surface.c index ce6990075..3278d144a 100644 --- a/src/xdg-surface.c +++ b/src/xdg-surface.c @@ -700,12 +700,12 @@ phoc_handle_xdg_shell_surface (struct wl_listener *listener, void *data) { struct wlr_xdg_surface *surface = data; - g_assert (surface->role != WLR_XDG_SURFACE_ROLE_NONE); if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - g_debug ("new xdg popup"); + g_debug ("New xdg popup"); return; } + g_assert (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); PhocDesktop *desktop = wl_container_of (listener, desktop, xdg_shell_surface); g_debug ("new xdg toplevel: title=%s, app_id=%s", surface->toplevel->title, surface->toplevel->app_id); -- GitLab From 367a76c780ccaae60bf3cc85b4bd88f13074c5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:23:43 +0100 Subject: [PATCH 19/38] xdg-shell: Rename to xdg-toplevel-decoration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That's the only bit handled in there now. This allows us to move decoration related bits into the matching header too. Signed-off-by: Guido Günther Part-of: --- .reuse/dep5 | 2 +- src/desktop.c | 3 ++- src/desktop.h | 1 - src/meson.build | 3 ++- src/xdg-surface-private.h | 7 +++---- src/xdg-surface.c | 1 + ...{xdg_shell.c => xdg-toplevel-decoration.c} | 9 ++++---- src/xdg-toplevel-decoration.h | 21 +++++++++++++++++++ 8 files changed, 34 insertions(+), 13 deletions(-) rename src/{xdg_shell.c => xdg-toplevel-decoration.c} (95%) create mode 100644 src/xdg-toplevel-decoration.h diff --git a/.reuse/dep5 b/.reuse/dep5 index 9faf247c6..41aaa1c95 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -67,7 +67,7 @@ Files: src/virtual.c src/virtual.h src/xcursor.h - src/xdg_shell.c + src/xdg-toplevel-decoration.c Copyright: The wlroots authors The Phoc authors diff --git a/src/desktop.c b/src/desktop.c index d74f943d3..059f03053 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -51,6 +51,7 @@ #include "layer-shell-effects.h" #include "xdg-surface.h" +#include "xdg-toplevel-decoration.h" #include "xwayland-surface.h" /* Maximum protocol versions we support */ @@ -782,7 +783,7 @@ phoc_desktop_constructed (GObject *object) wl_signal_add (&self->xdg_decoration_manager->events.new_toplevel_decoration, &self->xdg_toplevel_decoration); - self->xdg_toplevel_decoration.notify = handle_xdg_toplevel_decoration; + self->xdg_toplevel_decoration.notify = phoc_handle_xdg_toplevel_decoration; wlr_viewporter_create (wl_display); wlr_single_pixel_buffer_manager_v1_create (wl_display); wlr_fractional_scale_manager_v1_create (wl_display, PHOC_FRACTIONAL_SCALE_VERSION); diff --git a/src/desktop.h b/src/desktop.h index 0484e3b52..6938f2346 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -139,7 +139,6 @@ PhocPhoshPrivate *phoc_desktop_get_phosh_private (PhocDesktop *s void phoc_desktop_notify_activity (PhocDesktop *self, PhocSeat *seat); -void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data); void handle_layer_shell_surface(struct wl_listener *listener, void *data); gboolean phoc_desktop_is_privileged_protocol (PhocDesktop *self, diff --git a/src/meson.build b/src/meson.build index ece15d886..2ac969c0d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -102,9 +102,10 @@ sources = files( 'xdg-activation-v1.h', 'xdg-popup.c', 'xdg-popup.h', - 'xdg_shell.c', 'xdg-surface.c', 'xdg-surface.h', + 'xdg-toplevel-decoration.c', + 'xdg-toplevel-decoration.h', ) + phoc_anim_sources libphoc_generated_sources = [ phoc_config_h, diff --git a/src/xdg-surface-private.h b/src/xdg-surface-private.h index 9150c5ed0..75778c344 100644 --- a/src/xdg-surface-private.h +++ b/src/xdg-surface-private.h @@ -6,14 +6,13 @@ #pragma once -#include +#include "xdg-surface.h" +#include "xdg-toplevel-decoration.h" -#include +#include G_BEGIN_DECLS -typedef struct _PhocXdgToplevelDecoration PhocXdgToplevelDecoration; - void phoc_xdg_surface_set_decoration (PhocXdgSurface *self, PhocXdgToplevelDecoration *decoration); PhocXdgToplevelDecoration * diff --git a/src/xdg-surface.c b/src/xdg-surface.c index 3278d144a..942a7bbdf 100644 --- a/src/xdg-surface.c +++ b/src/xdg-surface.c @@ -16,6 +16,7 @@ #include "xdg-popup.h" #include "xdg-surface.h" #include "xdg-surface-private.h" +#include "xdg-toplevel-decoration.h" #include #include diff --git a/src/xdg_shell.c b/src/xdg-toplevel-decoration.c similarity index 95% rename from src/xdg_shell.c rename to src/xdg-toplevel-decoration.c index 559f5d165..9af2ec1f2 100644 --- a/src/xdg_shell.c +++ b/src/xdg-toplevel-decoration.c @@ -1,14 +1,13 @@ -#define G_LOG_DOMAIN "phoc-xdg-shell" +#define G_LOG_DOMAIN "phoc-xdg-toplevel-decoration" #include "phoc-config.h" -#include "xdg-surface.h" #include "xdg-surface-private.h" +#include "xdg-toplevel-decoration.h" #include #include -#include #include -#include +#include "xdg-surface.h" #include "desktop.h" #include "server.h" #include "utils.h" @@ -76,7 +75,7 @@ on_xdg_surface_destroy (PhocXdgSurface *surface, PhocXdgToplevelDecoration *deco void -handle_xdg_toplevel_decoration (struct wl_listener *listener, void *data) +phoc_handle_xdg_toplevel_decoration (struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data; PhocXdgSurface *xdg_surface = PHOC_XDG_SURFACE (wlr_decoration->toplevel->base->data); diff --git a/src/xdg-toplevel-decoration.h b/src/xdg-toplevel-decoration.h new file mode 100644 index 000000000..1af5ae3bd --- /dev/null +++ b/src/xdg-toplevel-decoration.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "xdg-surface.h" + +#include + +#include + +G_BEGIN_DECLS + +typedef struct _PhocXdgToplevelDecoration PhocXdgToplevelDecoration; + +void phoc_handle_xdg_toplevel_decoration (struct wl_listener *listener, void *data); + +G_END_DECLS -- GitLab From 01429b9d7ae8782ae38fb79c38191db0402a40b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:47:09 +0100 Subject: [PATCH 20/38] layer-shell: Move handler into layer-shell related header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We ought to rename the header too at some point but there's outstanding MRs we don't want to break. Signed-off-by: Guido Günther Part-of: --- src/desktop.c | 2 +- src/desktop.h | 3 --- src/layer_shell.c | 2 +- src/layers.h | 2 ++ 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/desktop.c b/src/desktop.c index 059f03053..ec85f8054 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -724,7 +724,7 @@ phoc_desktop_constructed (GObject *object) self->layer_shell = wlr_layer_shell_v1_create (wl_display, PHOC_LAYER_SHELL_VERSION); wl_signal_add(&self->layer_shell->events.new_surface, &self->layer_shell_surface); - self->layer_shell_surface.notify = handle_layer_shell_surface; + self->layer_shell_surface.notify = phoc_handle_layer_shell_surface; priv->layer_shell_effects = phoc_layer_shell_effects_new (); self->tablet_v2 = wlr_tablet_v2_create (wl_display); diff --git a/src/desktop.h b/src/desktop.h index 6938f2346..adff65cfe 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -138,8 +138,5 @@ PhocPhoshPrivate *phoc_desktop_get_phosh_private (PhocDesktop *s void phoc_desktop_notify_activity (PhocDesktop *self, PhocSeat *seat); - -void handle_layer_shell_surface(struct wl_listener *listener, void *data); - gboolean phoc_desktop_is_privileged_protocol (PhocDesktop *self, const struct wl_global *global); diff --git a/src/layer_shell.c b/src/layer_shell.c index 01dde2fde..1d21005da 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -851,7 +851,7 @@ handle_unmap (struct wl_listener *listener, void *data) void -handle_layer_shell_surface (struct wl_listener *listener, void *data) +phoc_handle_layer_shell_surface (struct wl_listener *listener, void *data) { struct wlr_layer_surface_v1 *wlr_layer_surface = data; PhocDesktop *desktop = wl_container_of (listener, desktop, layer_shell_surface); diff --git a/src/layers.h b/src/layers.h index 92b64b4b8..f36f6895d 100644 --- a/src/layers.h +++ b/src/layers.h @@ -60,4 +60,6 @@ void phoc_layer_shell_update_focus (void); void phoc_layer_shell_update_osk (PhocOutput *output, gboolean arrange); PhocLayerSurface *phoc_layer_shell_find_osk (PhocOutput *output); +void phoc_handle_layer_shell_surface (struct wl_listener *listener, void *data); + G_END_DECLS -- GitLab From 38365ba220d42d361902dd3a9a949af3f66211dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:53:09 +0100 Subject: [PATCH 21/38] output: Prefix handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now all public functions are properly namespaced. Signed-off-by: Guido Günther Part-of: --- src/desktop.c | 4 ++-- src/output.c | 4 ++-- src/output.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/desktop.c b/src/desktop.c index ec85f8054..fff1d4f63 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -802,9 +802,9 @@ phoc_desktop_constructed (GObject *object) self->pointer_gestures = wlr_pointer_gestures_v1_create (wl_display); self->output_manager_v1 = wlr_output_manager_v1_create (wl_display); - self->output_manager_apply.notify = handle_output_manager_apply; + self->output_manager_apply.notify = phoc_handle_output_manager_apply; wl_signal_add (&self->output_manager_v1->events.apply, &self->output_manager_apply); - self->output_manager_test.notify = handle_output_manager_test; + self->output_manager_test.notify = phoc_handle_output_manager_test; wl_signal_add (&self->output_manager_v1->events.test, &self->output_manager_test); self->output_power_manager_v1 = wlr_output_power_manager_v1_create (wl_display); diff --git a/src/output.c b/src/output.c index 4117dce1d..dd0b7cca4 100644 --- a/src/output.c +++ b/src/output.c @@ -1599,7 +1599,7 @@ output_manager_apply_config (PhocDesktop *desktop, void -handle_output_manager_apply (struct wl_listener *listener, void *data) +phoc_handle_output_manager_apply (struct wl_listener *listener, void *data) { PhocDesktop *desktop = wl_container_of (listener, desktop, output_manager_apply); struct wlr_output_configuration_v1 *config = data; @@ -1609,7 +1609,7 @@ handle_output_manager_apply (struct wl_listener *listener, void *data) void -handle_output_manager_test (struct wl_listener *listener, void *data) +phoc_handle_output_manager_test (struct wl_listener *listener, void *data) { PhocDesktop *desktop = wl_container_of (listener, desktop, output_manager_apply); struct wlr_output_configuration_v1 *config = data; diff --git a/src/output.h b/src/output.h index e4dbc273c..6c8cdff36 100644 --- a/src/output.h +++ b/src/output.h @@ -112,8 +112,8 @@ GList * phoc_output_get_layer_surfaces_for_layer (PhocOutput enum zwlr_layer_shell_v1_layer layer); /* signal handlers */ -void handle_output_manager_apply (struct wl_listener *listener, void *data); -void handle_output_manager_test (struct wl_listener *listener, void *data); +void phoc_handle_output_manager_apply (struct wl_listener *listener, void *data); +void phoc_handle_output_manager_test (struct wl_listener *listener, void *data); void phoc_output_handle_output_power_manager_set_mode (struct wl_listener *listener, void *data); void phoc_output_handle_gamma_control_set_gamma (struct wl_listener *listener, void *data); -- GitLab From 7fced8e3d59b98196ab06867e85127f01d5490af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 10:50:31 +0100 Subject: [PATCH 22/38] doc-check: Drop namespace exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Public methods are now properly prefixed. Signed-off-by: Guido Günther Part-of: --- helpers/doc-check | 1 - 1 file changed, 1 deletion(-) diff --git a/helpers/doc-check b/helpers/doc-check index c8368dfb6..595850f3d 100755 --- a/helpers/doc-check +++ b/helpers/doc-check @@ -9,7 +9,6 @@ meson compile -C "${DIR}" doc/phoc-doc |& tee "${LOG}" if grep -vE '('\ 'register as boxed type or \(skip\)'\ -'|symbol=.handle_.*Unknown namespace for symbol'\ '|wayland-server-core.h:.* syntax error, unexpected'\ '|argument pressed_keysyms: Unresolved type:'\ '|argument iterator: Unresolved type: .wlr_surface_iterator_func_t.'\ -- GitLab From 4844d836b94aee5ea5d1fc546b08d917e2ada715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 11:15:25 +0100 Subject: [PATCH 23/38] docs: Enable fatal warnings during doc build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure we no longer ignore links that became stale or are mistyped. See phosh commit 8c4724e44c6727f36bed4fd67e853bddf17b6ccd Signed-off-by: Guido Günther Part-of: --- doc/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/meson.build b/doc/meson.build index b238a0af5..7eb99bf65 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -35,6 +35,7 @@ custom_target('phoc-doc', '--output-dir=@OUTPUT@', '--no-namespace-dir', '--content-dir=@0@'.format(meson.current_source_dir()), + '--fatal-warnings', '@INPUT1@', ], depend_files: [ expand_content_md_files ], -- GitLab From a696047d1a071219793ae7ce1b83a6a1e6ade1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 11:34:23 +0100 Subject: [PATCH 24/38] view: Add and use phoc_view_add_child() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures the child doesn't access the view's private data. Signed-off-by: Guido Günther Part-of: --- src/view.c | 20 ++++++++++++++------ src/view.h | 3 +++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/view.c b/src/view.c index 8b3b9363f..a6f445473 100644 --- a/src/view.c +++ b/src/view.c @@ -876,10 +876,7 @@ phoc_view_child_init_subsurfaces (PhocViewChild *child, struct wlr_surface *surf void phoc_view_child_setup (PhocViewChild *child) { - PhocViewPrivate *priv; - - priv = phoc_view_get_instance_private (child->view); - wl_list_insert (&priv->child_surfaces, &child->link); + phoc_view_add_child (child->view, child); phoc_view_child_init_subsurfaces (child, child->wlr_surface); } @@ -2235,6 +2232,19 @@ phoc_view_arrange (PhocView *self, PhocOutput *output, gboolean center) view_center (self, output); } + +void +phoc_view_add_child (PhocView *self, PhocViewChild *child) +{ + PhocViewPrivate *priv; + + g_assert (PHOC_IS_VIEW (self)); + g_assert (PHOC_IS_VIEW_CHILD (child)); + + priv = phoc_view_get_instance_private (child->view); + wl_list_insert (&priv->child_surfaces, &child->link); +} + /** * phoc_view_set_always_on_top: * @self: a view @@ -2248,7 +2258,6 @@ phoc_view_set_always_on_top (PhocView *self, gboolean on_top) PhocViewPrivate *priv; g_assert (PHOC_IS_VIEW (self)); - priv = phoc_view_get_instance_private (self); priv->always_on_top = on_top; @@ -2268,7 +2277,6 @@ phoc_view_is_always_on_top (PhocView *self) PhocViewPrivate *priv; g_assert (PHOC_IS_VIEW (self)); - priv = phoc_view_get_instance_private (self); return priv->always_on_top; diff --git a/src/view.h b/src/view.h index 3aceb4f10..90b08a5ac 100644 --- a/src/view.h +++ b/src/view.h @@ -1,5 +1,7 @@ #pragma once +#include "view-child-private.h" + #include #include #include @@ -209,5 +211,6 @@ gboolean phoc_view_get_tiled_box (PhocView *self, void phoc_view_add_bling (PhocView *self, PhocBling *bling); void phoc_view_remove_bling (PhocView *self, PhocBling *bling); GSList *phoc_view_get_blings (PhocView *self); +void phoc_view_add_child (PhocView *self, PhocViewChild *child); G_END_DECLS -- GitLab From 52fa05097d410a3eb233db44be0278b3c1d078e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 11:44:12 +0100 Subject: [PATCH 25/38] view-child: Move adding to parent's list into constructed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One more bit to get rid of phoc_view_child_setup(). Signed-off-by: Guido Günther Part-of: --- src/view-child.c | 2 ++ src/view.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/view-child.c b/src/view-child.c index 352b81685..28d490b14 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -144,6 +144,8 @@ phoc_view_child_constructed (GObject *object) self->new_subsurface.notify = phoc_view_child_handle_new_subsurface; wl_signal_add (&self->wlr_surface->events.new_subsurface, &self->new_subsurface); + + phoc_view_add_child (self->view, self); } diff --git a/src/view.c b/src/view.c index a6f445473..ae5ce28bd 100644 --- a/src/view.c +++ b/src/view.c @@ -876,8 +876,6 @@ phoc_view_child_init_subsurfaces (PhocViewChild *child, struct wlr_surface *surf void phoc_view_child_setup (PhocViewChild *child) { - phoc_view_add_child (child->view, child); - phoc_view_child_init_subsurfaces (child, child->wlr_surface); } -- GitLab From 41887f37648b1e791f823c566e3c720667215641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 12:25:11 +0100 Subject: [PATCH 26/38] view-child: Move subsurface creation to constructed too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to drop phoc_view_child_setup(). The only view child private method left in view.c is phoc_view_child_subsurface_create() which we can remove once subsurface creation becomes public. Signed-off-by: Guido Günther Part-of: --- src/view-child-private.h | 1 - src/view-child.c | 15 +++++++++++++++ src/view.c | 21 --------------------- src/xdg-popup.c | 2 -- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index 0da2b0392..bcc34c0f0 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -76,7 +76,6 @@ static inline gboolean PHOC_IS_VIEW_CHILD_CLASS (gpointer ptr) { static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_child_get_type (), PhocViewChildClass); } -void phoc_view_child_setup (PhocViewChild *self); void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); diff --git a/src/view-child.c b/src/view-child.c index 28d490b14..11d5bb717 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -31,6 +31,19 @@ static GParamSpec *props[PROP_LAST_PROP]; G_DEFINE_TYPE (PhocViewChild, phoc_view_child, G_TYPE_OBJECT) +static void +phoc_view_child_init_subsurfaces (PhocViewChild *self, struct wlr_surface *surface) +{ + struct wlr_subsurface *subsurface; + + wl_list_for_each (subsurface, &surface->current.subsurfaces_below, current.link) + phoc_view_child_subsurface_create (self, subsurface); + + wl_list_for_each (subsurface, &surface->current.subsurfaces_above, current.link) + phoc_view_child_subsurface_create (self, subsurface); +} + + static bool phoc_view_child_is_mapped (PhocViewChild *self) { @@ -146,6 +159,8 @@ phoc_view_child_constructed (GObject *object) wl_signal_add (&self->wlr_surface->events.new_subsurface, &self->new_subsurface); phoc_view_add_child (self->view, self); + + phoc_view_child_init_subsurfaces (self, self->wlr_surface); } diff --git a/src/view.c b/src/view.c index ae5ce28bd..60361daec 100644 --- a/src/view.c +++ b/src/view.c @@ -860,25 +860,6 @@ phoc_view_init_subsurfaces (PhocView *view, struct wlr_surface *surface) phoc_view_subsurface_create (view, subsurface); } -static void -phoc_view_child_init_subsurfaces (PhocViewChild *child, struct wlr_surface *surface) -{ - struct wlr_subsurface *subsurface; - - wl_list_for_each (subsurface, &surface->current.subsurfaces_below, current.link) - phoc_view_child_subsurface_create (child, subsurface); - - wl_list_for_each (subsurface, &surface->current.subsurfaces_above, current.link) - phoc_view_child_subsurface_create (child, subsurface); -} - - -void -phoc_view_child_setup (PhocViewChild *child) -{ - phoc_view_child_init_subsurfaces (child, child->wlr_surface); -} - static void subsurface_get_pos (PhocViewChild *child, int *sx, int *sy) @@ -952,7 +933,6 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface->surface); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (PHOC_VIEW_CHILD (subsurface)); PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; @@ -969,7 +949,6 @@ phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface * child->children = g_slist_prepend (child->children, subsurface); subsurface->wlr_subsurface = wlr_subsurface; - phoc_view_child_setup (PHOC_VIEW_CHILD (subsurface)); PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 2b6c1caa3..190736235 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -168,8 +168,6 @@ phoc_xdg_popup_constructed (GObject *object) G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->constructed (object); - phoc_view_child_setup (PHOC_VIEW_CHILD (popup)); - popup->destroy.notify = popup_handle_destroy; wl_signal_add (&popup->wlr_popup->base->events.destroy, &popup->destroy); -- GitLab From 95a1ac53d13f82d077ad88c41d436b7948b5777b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 12:25:11 +0100 Subject: [PATCH 27/38] subsurface: Move into it's own file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This disentangles subsurface handling from view handling (positioning, window state, etc) Signed-off-by: Guido Günther Part-of: --- src/meson.build | 2 ++ src/subsurface.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ src/subsurface.h | 29 +++++++++++++++++++ src/view.c | 73 +----------------------------------------------- 4 files changed, 103 insertions(+), 72 deletions(-) create mode 100644 src/subsurface.c create mode 100644 src/subsurface.h diff --git a/src/meson.build b/src/meson.build index 2ac969c0d..58bbe6f94 100644 --- a/src/meson.build +++ b/src/meson.build @@ -80,6 +80,8 @@ sources = files( 'server.h', 'settings.c', 'settings.h', + 'subsurface.c', + 'subsurface.h', 'switch.c', 'switch.h', 'tablet.c', diff --git a/src/subsurface.c b/src/subsurface.c new file mode 100644 index 000000000..531bea337 --- /dev/null +++ b/src/subsurface.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Author: Guido Günther + */ + +#define G_LOG_DOMAIN "phoc-subsurface" + +#include "phoc-config.h" + +#include "subsurface.h" + +G_DEFINE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC_TYPE_VIEW_CHILD) + +static void +subsurface_get_pos (PhocViewChild *child, int *sx, int *sy) +{ + struct wlr_surface *wlr_surface; + struct wlr_subsurface *wlr_subsurface; + + wlr_surface = child->wlr_surface; + if (child->parent) + phoc_view_child_get_pos (child->parent, sx, sy); + else + *sx = *sy = 0; + + wlr_subsurface = wlr_subsurface_try_from_wlr_surface (wlr_surface); + g_assert (wlr_subsurface); + *sx += wlr_subsurface->current.x; + *sy += wlr_subsurface->current.y; +} + + +static void +phoc_subsurface_finalize (GObject *object) +{ + PhocSubsurface *self = PHOC_SUBSURFACE (object); + + wl_list_remove (&self->destroy.link); + + G_OBJECT_CLASS (phoc_subsurface_parent_class)->finalize (object); +} + + +static void +phoc_subsurface_class_init (PhocSubsurfaceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); + + object_class->finalize = phoc_subsurface_finalize; + view_child_class->get_pos = subsurface_get_pos; +} + + +static void +phoc_subsurface_init (PhocSubsurface *self) +{ +} + + +PhocSubsurface * +phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface) +{ + return g_object_new (PHOC_TYPE_SUBSURFACE, + "view", view, + "wlr-surface", wlr_surface, + NULL); +} diff --git a/src/subsurface.h b/src/subsurface.h new file mode 100644 index 000000000..d52d62ce2 --- /dev/null +++ b/src/subsurface.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "view-child-private.h" + +#include + +G_BEGIN_DECLS + +#define PHOC_TYPE_SUBSURFACE (phoc_subsurface_get_type ()) + +G_DECLARE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC, SUBSURFACE, PhocViewChild) + +typedef struct _PhocSubsurface { + PhocViewChild parent_instance; + + struct wlr_subsurface *wlr_subsurface; + + struct wl_listener destroy; +} PhocSubsurface; + +PhocSubsurface *phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface); + +G_END_DECLS diff --git a/src/view.c b/src/view.c index 60361daec..b52d43146 100644 --- a/src/view.c +++ b/src/view.c @@ -16,6 +16,7 @@ #include "input.h" #include "seat.h" #include "server.h" +#include "subsurface.h" #include "utils.h" #include "timed-animation.h" #include "view-child-private.h" @@ -74,23 +75,8 @@ typedef struct _PhocViewPrivate { } PhocViewPrivate; G_DEFINE_TYPE_WITH_PRIVATE (PhocView, phoc_view, G_TYPE_OBJECT) - #define PHOC_VIEW_SELF(p) PHOC_PRIV_CONTAINER(PHOC_VIEW, PhocView, (p)) - -typedef struct _PhocSubsurface { - PhocViewChild parent_instance; - - struct wlr_subsurface *wlr_subsurface; - - struct wl_listener destroy; -} PhocSubsurface; - -#define PHOC_TYPE_SUBSURFACE (phoc_subsurface_get_type ()) -G_DECLARE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC, SUBSURFACE, PhocViewChild) -G_DEFINE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC_TYPE_VIEW_CHILD) - - static bool view_center (PhocView *view, PhocOutput *output); @@ -861,25 +847,6 @@ phoc_view_init_subsurfaces (PhocView *view, struct wlr_surface *surface) } -static void -subsurface_get_pos (PhocViewChild *child, int *sx, int *sy) -{ - struct wlr_surface *wlr_surface; - struct wlr_subsurface *wlr_subsurface; - - wlr_surface = child->wlr_surface; - if (child->parent) - phoc_view_child_get_pos (child->parent, sx, sy); - else - *sx = *sy = 0; - - wlr_subsurface = wlr_subsurface_try_from_wlr_surface (wlr_surface); - g_assert (wlr_subsurface); - *sx += wlr_subsurface->current.x; - *sy += wlr_subsurface->current.y; -} - - static void subsurface_handle_destroy (struct wl_listener *listener, void *data) { @@ -889,44 +856,6 @@ subsurface_handle_destroy (struct wl_listener *listener, void *data) } -static void -phoc_subsurface_finalize (GObject *object) -{ - PhocSubsurface *subsurface = PHOC_SUBSURFACE (object); - - wl_list_remove (&subsurface->destroy.link); - - G_OBJECT_CLASS (phoc_subsurface_parent_class)->finalize (object); -} - - -static void -phoc_subsurface_class_init (PhocSubsurfaceClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); - - object_class->finalize = phoc_subsurface_finalize; - view_child_class->get_pos = subsurface_get_pos; -} - - -static void -phoc_subsurface_init (PhocSubsurface *self) -{ -} - - -static PhocSubsurface * -phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface) -{ - return g_object_new (PHOC_TYPE_SUBSURFACE, - "view", view, - "wlr-surface", wlr_surface, - NULL); -} - - static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface) { -- GitLab From ef054307b78f1fb39161c382f1230e2a3924049f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 13:18:51 +0100 Subject: [PATCH 28/38] subsurface: Add and use wlr-subsurface property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther Part-of: --- src/subsurface.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- src/subsurface.h | 2 +- src/view.c | 6 ++--- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/subsurface.c b/src/subsurface.c index 531bea337..11e5cbc99 100644 --- a/src/subsurface.c +++ b/src/subsurface.c @@ -12,6 +12,15 @@ #include "subsurface.h" + +enum { + PROP_0, + PROP_WLR_SUBSURFACE, + PROP_LAST_PROP +}; +static GParamSpec *props[PROP_LAST_PROP]; + + G_DEFINE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC_TYPE_VIEW_CHILD) static void @@ -33,6 +42,44 @@ subsurface_get_pos (PhocViewChild *child, int *sx, int *sy) } +static void +phoc_subsurface_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + PhocSubsurface *self = PHOC_SUBSURFACE (object); + + switch (property_id) { + case PROP_WLR_SUBSURFACE: + self->wlr_subsurface = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void +phoc_subsurface_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + PhocSubsurface *self = PHOC_SUBSURFACE (object); + + switch (property_id) { + case PROP_WLR_SUBSURFACE: + g_value_set_pointer (value, self->wlr_subsurface); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + static void phoc_subsurface_finalize (GObject *object) { @@ -51,7 +98,16 @@ phoc_subsurface_class_init (PhocSubsurfaceClass *klass) PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); object_class->finalize = phoc_subsurface_finalize; + object_class->get_property = phoc_subsurface_get_property; + object_class->set_property = phoc_subsurface_set_property; + view_child_class->get_pos = subsurface_get_pos; + + props[PROP_WLR_SUBSURFACE] = + g_param_spec_pointer ("wlr-subsurface", "", "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } @@ -62,10 +118,11 @@ phoc_subsurface_init (PhocSubsurface *self) PhocSubsurface * -phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface) +phoc_subsurface_new (PhocView *view, struct wlr_subsurface *wlr_subsurface) { return g_object_new (PHOC_TYPE_SUBSURFACE, "view", view, - "wlr-surface", wlr_surface, + "wlr-surface", wlr_subsurface->surface, + "wlr-subsurface", wlr_subsurface, NULL); } diff --git a/src/subsurface.h b/src/subsurface.h index d52d62ce2..cd8ad0823 100644 --- a/src/subsurface.h +++ b/src/subsurface.h @@ -24,6 +24,6 @@ typedef struct _PhocSubsurface { struct wl_listener destroy; } PhocSubsurface; -PhocSubsurface *phoc_subsurface_new (PhocView *view, struct wlr_surface *wlr_surface); +PhocSubsurface *phoc_subsurface_new (PhocView *view, struct wlr_subsurface *wlr_subsurface); G_END_DECLS diff --git a/src/view.c b/src/view.c index b52d43146..7f9ebebab 100644 --- a/src/view.c +++ b/src/view.c @@ -859,9 +859,8 @@ subsurface_handle_destroy (struct wl_listener *listener, void *data) static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface) { - PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface->surface); + PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface); - subsurface->wlr_subsurface = wlr_subsurface; PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; @@ -872,12 +871,11 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa void phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface) { - PhocSubsurface *subsurface = phoc_subsurface_new (child->view, wlr_subsurface->surface); + PhocSubsurface *subsurface = phoc_subsurface_new (child->view, wlr_subsurface); PHOC_VIEW_CHILD (subsurface)->parent = child; child->children = g_slist_prepend (child->children, subsurface); - subsurface->wlr_subsurface = wlr_subsurface; PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; subsurface->destroy.notify = subsurface_handle_destroy; -- GitLab From c6115768894e019150f505932f5977b1f82e91a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 13:30:01 +0100 Subject: [PATCH 29/38] subsurface: Move setup into constructed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes subsurface creation for views and view-children more alike. Signed-off-by: Guido Günther Part-of: --- src/subsurface.c | 25 +++++++++++++++++++++++++ src/view.c | 21 +-------------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/subsurface.c b/src/subsurface.c index 11e5cbc99..c916c1bd2 100644 --- a/src/subsurface.c +++ b/src/subsurface.c @@ -80,6 +80,30 @@ phoc_subsurface_get_property (GObject *object, } +static void +subsurface_handle_destroy (struct wl_listener *listener, void *data) +{ + PhocSubsurface *self = wl_container_of(listener, self, destroy); + + g_object_unref (self); +} + + + +static void +phoc_subsurface_constructed (GObject *object) +{ + PhocSubsurface *self = PHOC_SUBSURFACE (object); + + G_OBJECT_CLASS (phoc_subsurface_parent_class)->constructed (object); + + PHOC_VIEW_CHILD (self)->mapped = self->wlr_subsurface->surface->mapped; + + self->destroy.notify = subsurface_handle_destroy; + wl_signal_add (&self->wlr_subsurface->events.destroy, &self->destroy); +} + + static void phoc_subsurface_finalize (GObject *object) { @@ -97,6 +121,7 @@ phoc_subsurface_class_init (PhocSubsurfaceClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); PhocViewChildClass *view_child_class = PHOC_VIEW_CHILD_CLASS (klass); + object_class->constructed = phoc_subsurface_constructed; object_class->finalize = phoc_subsurface_finalize; object_class->get_property = phoc_subsurface_get_property; object_class->set_property = phoc_subsurface_set_property; diff --git a/src/view.c b/src/view.c index 7f9ebebab..47cbd07eb 100644 --- a/src/view.c +++ b/src/view.c @@ -847,24 +847,10 @@ phoc_view_init_subsurfaces (PhocView *view, struct wlr_surface *surface) } -static void -subsurface_handle_destroy (struct wl_listener *listener, void *data) -{ - PhocSubsurface *subsurface = wl_container_of(listener, subsurface, destroy); - - g_object_unref (subsurface); -} - - static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface) { - PhocSubsurface *subsurface = phoc_subsurface_new (view, wlr_subsurface); - - PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; - - subsurface->destroy.notify = subsurface_handle_destroy; - wl_signal_add (&wlr_subsurface->events.destroy, &subsurface->destroy); + phoc_subsurface_new (view, wlr_subsurface); } @@ -876,11 +862,6 @@ phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface * PHOC_VIEW_CHILD (subsurface)->parent = child; child->children = g_slist_prepend (child->children, subsurface); - PHOC_VIEW_CHILD (subsurface)->mapped = wlr_subsurface->surface->mapped; - - subsurface->destroy.notify = subsurface_handle_destroy; - wl_signal_add (&wlr_subsurface->events.destroy, &subsurface->destroy); - phoc_view_child_damage_whole (PHOC_VIEW_CHILD (subsurface)); } -- GitLab From 4467eb34764c1f4b62e49d104eabb2013b7056a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 13:32:57 +0100 Subject: [PATCH 30/38] view-child: Move subsurface creation out of view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With subsurface being it's own class we can now move this bit over to PhocViewChild too. Signed-off-by: Guido Günther Part-of: --- src/view-child-private.h | 2 -- src/view-child.c | 13 +++++++++++++ src/view.c | 12 ------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index bcc34c0f0..ca7e5c148 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -79,7 +79,5 @@ static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); -void phoc_view_child_subsurface_create (PhocViewChild *child, - struct wlr_subsurface *wlr_subsurface); G_END_DECLS diff --git a/src/view-child.c b/src/view-child.c index 11d5bb717..000755106 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -14,6 +14,7 @@ #include "input.h" #include "output.h" #include "server.h" +#include "subsurface.h" #include "utils.h" #include "view-private.h" #include "view-child-private.h" @@ -31,6 +32,18 @@ static GParamSpec *props[PROP_LAST_PROP]; G_DEFINE_TYPE (PhocViewChild, phoc_view_child, G_TYPE_OBJECT) +static void +phoc_view_child_subsurface_create (PhocViewChild *self, struct wlr_subsurface *wlr_subsurface) +{ + PhocSubsurface *subsurface = phoc_subsurface_new (self->view, wlr_subsurface); + + PHOC_VIEW_CHILD (subsurface)->parent = self; + self->children = g_slist_prepend (self->children, subsurface); + + phoc_view_child_damage_whole (PHOC_VIEW_CHILD (subsurface)); +} + + static void phoc_view_child_init_subsurfaces (PhocViewChild *self, struct wlr_surface *surface) { diff --git a/src/view.c b/src/view.c index 47cbd07eb..5f9ff0cff 100644 --- a/src/view.c +++ b/src/view.c @@ -854,18 +854,6 @@ phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurfa } -void -phoc_view_child_subsurface_create (PhocViewChild *child, struct wlr_subsurface *wlr_subsurface) -{ - PhocSubsurface *subsurface = phoc_subsurface_new (child->view, wlr_subsurface); - - PHOC_VIEW_CHILD (subsurface)->parent = child; - child->children = g_slist_prepend (child->children, subsurface); - - phoc_view_child_damage_whole (PHOC_VIEW_CHILD (subsurface)); -} - - static void phoc_view_handle_surface_new_subsurface (struct wl_listener *listener, void *data) { -- GitLab From 84c18f541eee7362e667d57ad118f19cb161b83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 13:34:39 +0100 Subject: [PATCH 31/38] subsurface: Make struct private MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neither view nor view-child require direct member access anymore. Signed-off-by: Guido Günther Part-of: --- src/subsurface.c | 15 ++++++++++++++- src/subsurface.h | 8 -------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/subsurface.c b/src/subsurface.c index c916c1bd2..bacd215d6 100644 --- a/src/subsurface.c +++ b/src/subsurface.c @@ -20,6 +20,19 @@ enum { }; static GParamSpec *props[PROP_LAST_PROP]; +/** + * PhocSubsurface: + * + * A subsurface attached to a [type@View] or [type@ViewChild]. + */ +typedef struct _PhocSubsurface { + PhocViewChild parent_instance; + + struct wlr_subsurface *wlr_subsurface; + + struct wl_listener destroy; +} PhocSubsurface; + G_DEFINE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC_TYPE_VIEW_CHILD) @@ -83,7 +96,7 @@ phoc_subsurface_get_property (GObject *object, static void subsurface_handle_destroy (struct wl_listener *listener, void *data) { - PhocSubsurface *self = wl_container_of(listener, self, destroy); + PhocSubsurface *self = wl_container_of (listener, self, destroy); g_object_unref (self); } diff --git a/src/subsurface.h b/src/subsurface.h index cd8ad0823..07123400d 100644 --- a/src/subsurface.h +++ b/src/subsurface.h @@ -16,14 +16,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (PhocSubsurface, phoc_subsurface, PHOC, SUBSURFACE, PhocViewChild) -typedef struct _PhocSubsurface { - PhocViewChild parent_instance; - - struct wlr_subsurface *wlr_subsurface; - - struct wl_listener destroy; -} PhocSubsurface; - PhocSubsurface *phoc_subsurface_new (PhocView *view, struct wlr_subsurface *wlr_subsurface); G_END_DECLS -- GitLab From 0a6c2931db1b017b4d623fde503535a587c89033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 13:37:03 +0100 Subject: [PATCH 32/38] view: Use subsurface constructor directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fact that we don't store the ref isn't ideal. At some point we want to move the `handle_destroy` handlers to their containers and drop the ref there. This isn't worse than before though, it's just more visible. Signed-off-by: Guido Günther Part-of: --- src/view.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/view.c b/src/view.c index 5f9ff0cff..54e8e6d9b 100644 --- a/src/view.c +++ b/src/view.c @@ -831,26 +831,16 @@ view_center (PhocView *view, PhocOutput *output) } -static void phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface); - - static void phoc_view_init_subsurfaces (PhocView *view, struct wlr_surface *surface) { struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->current.subsurfaces_below, current.link) - phoc_view_subsurface_create (view, subsurface); + phoc_subsurface_new (view, subsurface); wl_list_for_each(subsurface, &surface->current.subsurfaces_above, current.link) - phoc_view_subsurface_create (view, subsurface); -} - - -static void -phoc_view_subsurface_create (PhocView *view, struct wlr_subsurface *wlr_subsurface) -{ - phoc_subsurface_new (view, wlr_subsurface); + phoc_subsurface_new (view, subsurface); } @@ -861,7 +851,7 @@ phoc_view_handle_surface_new_subsurface (struct wl_listener *listener, void *dat PhocView *self = PHOC_VIEW_SELF (priv); struct wlr_subsurface *wlr_subsurface = data; - phoc_view_subsurface_create (self, wlr_subsurface); + phoc_subsurface_new (self, wlr_subsurface); } static gchar * @@ -939,12 +929,11 @@ phoc_view_map (PhocView *self, struct wlr_surface *surface) self->wlr_surface = surface; struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &self->wlr_surface->current.subsurfaces_below, current.link) { - phoc_view_subsurface_create(self, subsurface); - } - wl_list_for_each(subsurface, &self->wlr_surface->current.subsurfaces_above, current.link) { - phoc_view_subsurface_create(self, subsurface); - } + wl_list_for_each(subsurface, &self->wlr_surface->current.subsurfaces_below, current.link) + phoc_subsurface_new (self, subsurface); + + wl_list_for_each(subsurface, &self->wlr_surface->current.subsurfaces_above, current.link) + phoc_subsurface_new (self, subsurface); phoc_view_init_subsurfaces (self, surface); priv->surface_new_subsurface.notify = phoc_view_handle_surface_new_subsurface; -- GitLab From d5966afe1172c6ef1c40e56501004803bc5489b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 14:25:51 +0100 Subject: [PATCH 33/38] popup: Use self consistently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When these bits were part of view.c we used `popup` to not confuse with `self` meaning `view`. This can be fixed now. Let's do this now since there can't be any outstanding MRs touching this file. Signed-off-by: Guido Günther Part-of: --- src/xdg-popup.c | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 190736235..52d231203 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -50,8 +50,8 @@ G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) static void popup_get_pos (PhocViewChild *child, int *sx, int *sy) { - PhocXdgPopup *popup = PHOC_XDG_POPUP (child); - struct wlr_xdg_popup *wlr_popup = popup->wlr_popup; + PhocXdgPopup *self = PHOC_XDG_POPUP (child); + struct wlr_xdg_popup *wlr_popup = self->wlr_popup; wlr_xdg_popup_get_toplevel_coords (wlr_popup, wlr_popup->current.geometry.x - wlr_popup->base->current.geometry.x, @@ -61,12 +61,12 @@ popup_get_pos (PhocViewChild *child, int *sx, int *sy) static void -popup_unconstrain (PhocXdgPopup* popup) +popup_unconstrain (PhocXdgPopup* self) { /* get the output of the popup's positioner anchor point and convert it to * the toplevel parent's coordinate system and then pass it to * wlr_xdg_popup_unconstrain_from_box */ - PhocView *view = PHOC_VIEW_CHILD (popup)->view; + PhocView *view = PHOC_VIEW_CHILD (self)->view; PhocOutput *output = phoc_desktop_layout_get_output (view->desktop, view->box.x, view->box.y); if (output == NULL) @@ -87,39 +87,39 @@ popup_unconstrain (PhocXdgPopup* popup) .height = usable_area.height, }; - wlr_xdg_popup_unconstrain_from_box (popup->wlr_popup, &output_toplevel_sx_box); + wlr_xdg_popup_unconstrain_from_box (self->wlr_popup, &output_toplevel_sx_box); } static void popup_handle_destroy (struct wl_listener *listener, void *data) { - PhocXdgPopup *popup = wl_container_of (listener, popup, destroy); + PhocXdgPopup *self = wl_container_of (listener, self, destroy); - g_object_unref (popup); + g_object_unref (self); } static void popup_handle_new_popup (struct wl_listener *listener, void *data) { - PhocXdgPopup *popup = wl_container_of (listener, popup, new_popup); + PhocXdgPopup *self = wl_container_of (listener, self, new_popup); struct wlr_xdg_popup *wlr_popup = data; - phoc_xdg_popup_new (PHOC_VIEW_CHILD (popup)->view, wlr_popup); + phoc_xdg_popup_new (PHOC_VIEW_CHILD (self)->view, wlr_popup); } static void popup_handle_reposition (struct wl_listener *listener, void *data) { - PhocXdgPopup *popup = wl_container_of (listener, popup, reposition); + PhocXdgPopup *self = wl_container_of (listener, self, reposition); /* clear the old popup positon */ /* TODO: this is too much damage */ - phoc_view_damage_whole (PHOC_VIEW_CHILD (popup)->view); + phoc_view_damage_whole (PHOC_VIEW_CHILD (self)->view); - popup_unconstrain (popup); + popup_unconstrain (self); } @@ -129,11 +129,11 @@ phoc_xdg_popup_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + PhocXdgPopup *self = PHOC_XDG_POPUP (object); switch (property_id) { case PROP_WLR_POPUP: - popup->wlr_popup = g_value_get_pointer (value); + self->wlr_popup = g_value_get_pointer (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -148,11 +148,11 @@ phoc_xdg_popup_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + PhocXdgPopup *self = PHOC_XDG_POPUP (object); switch (property_id) { case PROP_WLR_POPUP: - g_value_set_pointer (value, popup->wlr_popup); + g_value_set_pointer (value, self->wlr_popup); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -164,31 +164,31 @@ phoc_xdg_popup_get_property (GObject *object, static void phoc_xdg_popup_constructed (GObject *object) { - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + PhocXdgPopup *self = PHOC_XDG_POPUP (object); G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->constructed (object); - popup->destroy.notify = popup_handle_destroy; - wl_signal_add (&popup->wlr_popup->base->events.destroy, &popup->destroy); + self->destroy.notify = popup_handle_destroy; + wl_signal_add (&self->wlr_popup->base->events.destroy, &self->destroy); - popup->new_popup.notify = popup_handle_new_popup; - wl_signal_add (&popup->wlr_popup->base->events.new_popup, &popup->new_popup); + self->new_popup.notify = popup_handle_new_popup; + wl_signal_add (&self->wlr_popup->base->events.new_popup, &self->new_popup); - popup->reposition.notify = popup_handle_reposition; - wl_signal_add (&popup->wlr_popup->events.reposition, &popup->reposition); + self->reposition.notify = popup_handle_reposition; + wl_signal_add (&self->wlr_popup->events.reposition, &self->reposition); - popup_unconstrain (popup); + popup_unconstrain (self); } static void phoc_xdg_popup_finalize (GObject *object) { - PhocXdgPopup *popup = PHOC_XDG_POPUP (object); + PhocXdgPopup *self = PHOC_XDG_POPUP (object); - wl_list_remove (&popup->reposition.link); - wl_list_remove (&popup->new_popup.link); - wl_list_remove (&popup->destroy.link); + wl_list_remove (&self->reposition.link); + wl_list_remove (&self->new_popup.link); + wl_list_remove (&self->destroy.link); G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->finalize (object); } -- GitLab From a4f54ab81e801090ba9018f2ce7303e87a106a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 14:46:13 +0100 Subject: [PATCH 34/38] popup: Wait for commit before unconstraining popup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a critical: [types/xdg_shell/wlr_xdg_surface.c:169] A configure is scheduled for an uninitialized xdg_surface [address] Signed-off-by: Guido Günther Part-of: --- src/xdg-popup.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 52d231203..697e9030c 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -42,6 +42,7 @@ typedef struct _PhocXdgPopup { struct wl_listener destroy; struct wl_listener new_popup; struct wl_listener reposition; + struct wl_listener surface_commit; } PhocXdgPopup; G_DEFINE_FINAL_TYPE (PhocXdgPopup, phoc_xdg_popup, PHOC_TYPE_VIEW_CHILD) @@ -123,6 +124,16 @@ popup_handle_reposition (struct wl_listener *listener, void *data) } +static void +popup_handle_surface_commit (struct wl_listener *listener, void *data) +{ + PhocXdgPopup *self = wl_container_of (listener, self, surface_commit); + + if (self->wlr_popup->base->initial_commit) + popup_unconstrain (self); +} + + static void phoc_xdg_popup_set_property (GObject *object, guint property_id, @@ -165,6 +176,7 @@ static void phoc_xdg_popup_constructed (GObject *object) { PhocXdgPopup *self = PHOC_XDG_POPUP (object); + struct wlr_xdg_surface *xdg_surface = self->wlr_popup->base; G_OBJECT_CLASS (phoc_xdg_popup_parent_class)->constructed (object); @@ -177,7 +189,8 @@ phoc_xdg_popup_constructed (GObject *object) self->reposition.notify = popup_handle_reposition; wl_signal_add (&self->wlr_popup->events.reposition, &self->reposition); - popup_unconstrain (self); + wl_signal_add (&xdg_surface->surface->events.commit, &self->surface_commit); + self->surface_commit.notify = popup_handle_surface_commit; } @@ -186,6 +199,7 @@ phoc_xdg_popup_finalize (GObject *object) { PhocXdgPopup *self = PHOC_XDG_POPUP (object); + wl_list_remove (&self->surface_commit.link); wl_list_remove (&self->reposition.link); wl_list_remove (&self->new_popup.link); wl_list_remove (&self->destroy.link); -- GitLab From c3385a05d3894b9e15f7becfaa8dbfa01faa4c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 18 Mar 2024 15:18:10 +0100 Subject: [PATCH 35/38] view-child: Add and use view property getter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This looks a bit nicer. Signed-off-by: Guido Günther Part-of: --- src/view-child-private.h | 1 + src/view-child.c | 16 ++++++++++++++++ src/xdg-popup.c | 6 +++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/view-child-private.h b/src/view-child-private.h index ca7e5c148..f406640d7 100644 --- a/src/view-child-private.h +++ b/src/view-child-private.h @@ -76,6 +76,7 @@ static inline gboolean PHOC_IS_VIEW_CHILD_CLASS (gpointer ptr) { static inline PhocViewChildClass * PHOC_VIEW_CHILD_GET_CLASS (gpointer ptr) { return G_TYPE_INSTANCE_GET_CLASS (ptr, phoc_view_child_get_type (), PhocViewChildClass); } +PhocView * phoc_view_child_get_view (PhocViewChild *self); void phoc_view_child_apply_damage (PhocViewChild *self); void phoc_view_child_damage_whole (PhocViewChild *self); void phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy); diff --git a/src/view-child.c b/src/view-child.c index 000755106..c1a5f79e8 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -344,3 +344,19 @@ phoc_view_child_get_pos (PhocViewChild *self, int *sx, int *sy) PHOC_VIEW_CHILD_GET_CLASS (self)->get_pos (self, sx, sy); } + +/** + * phoc_view_child_get_view: + * @self: A view child + * + * Get the view this child belongs to. + * + * Returns: (transfer none): The containing view + */ +PhocView * +phoc_view_child_get_view (PhocViewChild *self) +{ + g_assert (PHOC_IS_VIEW_CHILD (self)); + + return self->view; +} diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 697e9030c..6beed2ad9 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -67,7 +67,7 @@ popup_unconstrain (PhocXdgPopup* self) /* get the output of the popup's positioner anchor point and convert it to * the toplevel parent's coordinate system and then pass it to * wlr_xdg_popup_unconstrain_from_box */ - PhocView *view = PHOC_VIEW_CHILD (self)->view; + PhocView *view = phoc_view_child_get_view (PHOC_VIEW_CHILD (self)); PhocOutput *output = phoc_desktop_layout_get_output (view->desktop, view->box.x, view->box.y); if (output == NULL) @@ -107,7 +107,7 @@ popup_handle_new_popup (struct wl_listener *listener, void *data) PhocXdgPopup *self = wl_container_of (listener, self, new_popup); struct wlr_xdg_popup *wlr_popup = data; - phoc_xdg_popup_new (PHOC_VIEW_CHILD (self)->view, wlr_popup); + phoc_xdg_popup_new (phoc_view_child_get_view (PHOC_VIEW_CHILD (self)), wlr_popup); } @@ -118,7 +118,7 @@ popup_handle_reposition (struct wl_listener *listener, void *data) /* clear the old popup positon */ /* TODO: this is too much damage */ - phoc_view_damage_whole (PHOC_VIEW_CHILD (self)->view); + phoc_view_damage_whole (phoc_view_child_get_view (PHOC_VIEW_CHILD (self))); popup_unconstrain (self); } -- GitLab From 00559721f0b134dc51eb94556ef5ebb99d802151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 19 Mar 2024 12:57:52 +0100 Subject: [PATCH 36/38] popup: Avoid line break MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gbp-Dch: Ignore Signed-off-by: Guido Günther Part-of: --- src/xdg-popup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/xdg-popup.c b/src/xdg-popup.c index 6beed2ad9..51d898eb1 100644 --- a/src/xdg-popup.c +++ b/src/xdg-popup.c @@ -53,10 +53,11 @@ popup_get_pos (PhocViewChild *child, int *sx, int *sy) { PhocXdgPopup *self = PHOC_XDG_POPUP (child); struct wlr_xdg_popup *wlr_popup = self->wlr_popup; + struct wlr_xdg_surface *base = self->wlr_popup->base; wlr_xdg_popup_get_toplevel_coords (wlr_popup, - wlr_popup->current.geometry.x - wlr_popup->base->current.geometry.x, - wlr_popup->current.geometry.y - wlr_popup->base->current.geometry.y, + wlr_popup->current.geometry.x - base->current.geometry.x, + wlr_popup->current.geometry.y - base->current.geometry.y, sx, sy); } -- GitLab From c63503ed89eda2144567e6e8758be31dd9eeba3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 19 Mar 2024 13:06:50 +0100 Subject: [PATCH 37/38] output: Drop superfluous 'local' from damage helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The names are long enough already Signed-off-by: Guido Günther Part-of: --- src/layer-shell-effects.c | 8 ++++---- src/layer-surface.c | 6 ++++-- src/layer_shell.c | 41 +++++++++++++++++++++++---------------- src/output.c | 14 +++++++------ src/output.h | 8 ++++---- src/view-child.c | 8 ++++---- 6 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/layer-shell-effects.c b/src/layer-shell-effects.c index 9527a37ac..2c4edc9ff 100644 --- a/src/layer-shell-effects.c +++ b/src/layer-shell-effects.c @@ -498,10 +498,10 @@ alpha_surface_handle_commit (struct wl_listener *listener, void *data) phoc_layer_surface_get_output (layer_surface); output = phoc_layer_surface_get_output (layer_surface); - phoc_output_damage_whole_local_surface (output, - layer_surface->layer_surface->surface, - layer_surface->geo.x, layer_surface->geo.y); - + phoc_output_damage_whole_surface (output, + layer_surface->layer_surface->surface, + layer_surface->geo.x, + layer_surface->geo.y); } diff --git a/src/layer-surface.c b/src/layer-surface.c index 426aa10ae..0cec2d21f 100644 --- a/src/layer-surface.c +++ b/src/layer-surface.c @@ -202,8 +202,10 @@ phoc_layer_surface_unmap (PhocLayerSurface *self) wlr_output = layer_surface->output; if (wlr_output != NULL) { - phoc_output_damage_whole_local_surface(wlr_output->data, layer_surface->surface, - self->geo.x, self->geo.y); + phoc_output_damage_whole_surface (wlr_output->data, + layer_surface->surface, + self->geo.x, + self->geo.y); } } diff --git a/src/layer_shell.c b/src/layer_shell.c index 1d21005da..6e18eb8ce 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -401,13 +401,19 @@ handle_surface_commit (struct wl_listener *listener, void *data) bool geo_changed = memcmp (&old_geo, &layer_surface->geo, sizeof (struct wlr_box)) != 0; if (geo_changed || layer_changed) { - phoc_output_damage_whole_local_surface (output, wlr_layer_surface->surface, - old_geo.x, old_geo.y); - phoc_output_damage_whole_local_surface (output, wlr_layer_surface->surface, - layer_surface->geo.x, layer_surface->geo.y); + phoc_output_damage_whole_surface (output, + wlr_layer_surface->surface, + old_geo.x, + old_geo.y); + phoc_output_damage_whole_surface (output, + wlr_layer_surface->surface, + layer_surface->geo.x, + layer_surface->geo.y); } else { - phoc_output_damage_from_local_surface (output, wlr_layer_surface->surface, - layer_surface->geo.x, layer_surface->geo.y); + phoc_output_damage_from_surface (output, + wlr_layer_surface->surface, + layer_surface->geo.x, + layer_surface->geo.y); } } } @@ -490,9 +496,9 @@ popup_damage (PhocLayerPopup *layer_popup, bool whole) return; if (whole) - phoc_output_damage_whole_local_surface (output, surface, ox, oy); + phoc_output_damage_whole_surface (output, surface, ox, oy); else - phoc_output_damage_from_local_surface (output, surface, ox, oy); + phoc_output_damage_from_surface (output, surface, ox, oy); } @@ -656,13 +662,13 @@ subsurface_damage (PhocLayerSubsurface *subsurface, bool whole) int ox = subsurface->wlr_subsurface->current.x + layer->geo.x; int oy = subsurface->wlr_subsurface->current.y + layer->geo.y; if (whole) { - phoc_output_damage_whole_local_surface (output, - subsurface->wlr_subsurface->surface, - ox, oy); + phoc_output_damage_whole_surface (output, + subsurface->wlr_subsurface->surface, + ox, oy); } else { - phoc_output_damage_from_local_surface (output, - subsurface->wlr_subsurface->surface, - ox, oy); + phoc_output_damage_from_surface (output, + subsurface->wlr_subsurface->surface, + ox, oy); } } @@ -815,9 +821,10 @@ handle_map (struct wl_listener *listener, void *data) layer_surface->new_subsurface.notify = handle_new_subsurface; wl_signal_add (&wlr_layer_surface->surface->events.new_subsurface, &layer_surface->new_subsurface); - phoc_output_damage_whole_local_surface (output, - wlr_layer_surface->surface, layer_surface->geo.x, - layer_surface->geo.y); + phoc_output_damage_whole_surface (output, + wlr_layer_surface->surface, + layer_surface->geo.x, + layer_surface->geo.y); phoc_utils_wlr_surface_enter_output (wlr_layer_surface->surface, output->wlr_output); diff --git a/src/output.c b/src/output.c index dd0b7cca4..96331e53c 100644 --- a/src/output.c +++ b/src/output.c @@ -1490,10 +1490,10 @@ phoc_output_damage_whole_drag_icon (PhocOutput *self, PhocDragIcon *icon) } void -phoc_output_damage_whole_local_surface (PhocOutput *self, - struct wlr_surface *surface, - double ox, - double oy) +phoc_output_damage_whole_surface (PhocOutput *self, + struct wlr_surface *surface, + double ox, + double oy) { bool whole = true; @@ -1502,8 +1502,10 @@ phoc_output_damage_whole_local_surface (PhocOutput *self, } void -phoc_output_damage_from_local_surface (PhocOutput *self, struct wlr_surface - *surface, double ox, double oy) +phoc_output_damage_from_surface (PhocOutput *self, + struct wlr_surface *surface, + double ox, + double oy) { bool whole = false; diff --git a/src/output.h b/src/output.h index 6c8cdff36..94c1d46ef 100644 --- a/src/output.h +++ b/src/output.h @@ -123,10 +123,10 @@ void phoc_output_damage_whole (PhocOutput *output); void phoc_output_damage_from_view (PhocOutput *self, PhocView *view, bool whole); void phoc_output_damage_whole_drag_icon (PhocOutput *self, PhocDragIcon *icon); -void phoc_output_damage_from_local_surface (PhocOutput *self, struct wlr_surface *surface, double - ox, double oy); -void phoc_output_damage_whole_local_surface (PhocOutput *self, struct wlr_surface *surface, - double ox, double oy); +void phoc_output_damage_from_surface (PhocOutput *self, struct wlr_surface *surface, + double ox, double oy); +void phoc_output_damage_whole_surface (PhocOutput *self, struct wlr_surface *surface, + double ox, double oy); void phoc_output_update_shell_reveal (PhocOutput *self); void phoc_output_force_shell_reveal (PhocOutput *self, gboolean force); diff --git a/src/view-child.c b/src/view-child.c index c1a5f79e8..decda3931 100644 --- a/src/view-child.c +++ b/src/view-child.c @@ -329,10 +329,10 @@ phoc_view_child_damage_whole (PhocViewChild *self) wl_list_for_each (output, &self->view->desktop->outputs, link) { struct wlr_box output_box; wlr_output_layout_get_box (self->view->desktop->layout, output->wlr_output, &output_box); - phoc_output_damage_whole_local_surface (output, self->wlr_surface, - view_box.x + sx - output_box.x, - view_box.y + sy - output_box.y); - + phoc_output_damage_whole_surface (output, + self->wlr_surface, + view_box.x + sx - output_box.x, + view_box.y + sy - output_box.y); } } -- GitLab From cd5b131f1fbdcdf73acb550ca279b11a69f4a09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 23 Mar 2024 19:36:04 +0100 Subject: [PATCH 38/38] view: Don't init subsurfaces twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code in phoc_view_init_subsurfaces() does as same things the code in map() just above the invocation does. Fixes: c2e903e6 ("view: Move subsurface initialization to separate function") which added the function but didn't remove the code in _map(). Signed-off-by: Guido Günther Part-of: --- src/view.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/view.c b/src/view.c index 54e8e6d9b..fc4837eae 100644 --- a/src/view.c +++ b/src/view.c @@ -928,14 +928,7 @@ phoc_view_map (PhocView *self, struct wlr_surface *surface) g_assert (self->wlr_surface == NULL); self->wlr_surface = surface; - struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &self->wlr_surface->current.subsurfaces_below, current.link) - phoc_subsurface_new (self, subsurface); - - wl_list_for_each(subsurface, &self->wlr_surface->current.subsurfaces_above, current.link) - phoc_subsurface_new (self, subsurface); - - phoc_view_init_subsurfaces (self, surface); + phoc_view_init_subsurfaces (self, self->wlr_surface); priv->surface_new_subsurface.notify = phoc_view_handle_surface_new_subsurface; wl_signal_add (&self->wlr_surface->events.new_subsurface, &priv->surface_new_subsurface); -- GitLab