[gtk/wip/matthiasc/popup2: 43/93] popup: Use xdg-popup for relative placement
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup2: 43/93] popup: Use xdg-popup for relative placement
- Date: Mon, 25 Mar 2019 00:58:30 +0000 (UTC)
commit 9fbc7b67c5de13999963c4a0f5341abbbe4f5a15
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Mar 19 08:16:21 2019 -0400
popup: Use xdg-popup for relative placement
The initial placement is correct under both X and Wayland,
but a) the surface doesn't follow the parent under X when
it is moved, and it doesn't follow the attach point under
Wayland when it is resized.
gtk/gtkpopup.c | 35 +++++++++++------------------------
1 file changed, 11 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkpopup.c b/gtk/gtkpopup.c
index 1910cb124f..b1eeea5412 100644
--- a/gtk/gtkpopup.c
+++ b/gtk/gtkpopup.c
@@ -109,23 +109,13 @@ gtk_popup_move_resize (GtkPopup *popup)
gtk_widget_get_preferred_size (GTK_WIDGET (popup), NULL, &req);
gdk_surface_resize (priv->surface, req.width, req.height);
- rect.x = 0;
- rect.y = 0;
- rect.width = gtk_widget_get_width (priv->relative_to);
- rect.height = gtk_widget_get_height (priv->relative_to);
- gtk_widget_translate_coordinates (priv->relative_to,
- GTK_WIDGET (gtk_widget_get_root (priv->relative_to)),
- rect.x, rect.y, &rect.x, &rect.y);
-#if 0
+ gtk_widget_get_surface_allocation (priv->relative_to, &rect);
gdk_surface_move_to_rect (priv->surface,
&rect,
GDK_GRAVITY_SOUTH,
GDK_GRAVITY_NORTH,
GDK_ANCHOR_FLIP_Y,
0, 10);
-#else
- gdk_surface_move_resize (priv->surface, rect.x, rect.y, req.width, req.height);
-#endif
}
static void
@@ -215,10 +205,12 @@ gtk_popup_realize (GtkWidget *widget)
{
GtkPopup *popup = GTK_POPUP (widget);
GtkPopupPrivate *priv = gtk_popup_get_instance_private (popup);
- GdkRectangle allocation;
+ GdkRectangle parent_rect;
if (_gtk_widget_get_alloc_needed (widget))
{
+ GdkRectangle allocation;
+
allocation.x = 0;
allocation.y = 0;
allocation.width = 20; // FIXME
@@ -227,23 +219,17 @@ gtk_popup_realize (GtkWidget *widget)
gtk_widget_queue_resize (widget);
}
- gtk_widget_get_allocation (widget, &allocation);
+ gtk_widget_get_surface_allocation (priv->relative_to, &parent_rect);
-#if 0
- priv->surface = gdk_surface_new_popup (priv->display, &allocation);
- // TODO xdg-popop window type
+ priv->surface = gdk_surface_new_popup (priv->display, &parent_rect);
gdk_surface_set_transient_for (priv->surface, gtk_widget_get_surface (priv->relative_to));
gdk_surface_set_type_hint (priv->surface, GDK_SURFACE_TYPE_HINT_POPUP_MENU);
gdk_surface_move_to_rect (priv->surface,
- &allocation,
+ &parent_rect,
GDK_GRAVITY_SOUTH,
GDK_GRAVITY_NORTH,
GDK_ANCHOR_FLIP_Y,
0, 10);
-#else
- priv->surface = gdk_surface_new_toplevel (priv->display, 20, 20);
- gdk_surface_set_transient_for (priv->surface, gtk_widget_get_surface (priv->relative_to));
-#endif
gtk_widget_set_surface (widget, priv->surface);
g_signal_connect_swapped (priv->surface, "notify::state", G_CALLBACK (surface_state_changed), widget);
@@ -286,8 +272,6 @@ gtk_popup_move_focus (GtkWidget *widget,
static void
gtk_popup_show (GtkWidget *widget)
{
- GtkPopup *popup = GTK_POPUP (widget);
-
_gtk_widget_set_visible_flag (widget, TRUE);
gtk_css_node_validate (gtk_widget_get_css_node (widget));
gtk_widget_realize (widget);
@@ -564,7 +548,10 @@ size_changed (GtkWidget *widget,
int baseline,
GtkPopup *popup)
{
- gtk_popup_move_resize (popup);
+ GtkPopupPrivate *priv = gtk_popup_get_instance_private (popup);
+
+ if (priv->surface)
+ gtk_popup_move_resize (popup);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]