diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-03-19 08:16:21 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-03-26 19:18:39 -0400 |
commit | d30acd6bccc76ab4f405cb729cd5ebce26e223dc (patch) | |
tree | 3d5351a05389963dc32734a0b2690dd8e0dd3081 | |
parent | 7a10a75c320f51a3ecb635c3874ab6787ed1aeaa (diff) | |
download | gtk+-d30acd6bccc76ab4f405cb729cd5ebce26e223dc.tar.gz |
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.
-rw-r--r-- | gtk/gtkpopup.c | 35 |
1 files 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 |