[gtk/adaptive-emojichooser: 3/3] popover: Try to not exceed monitor bounds
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/adaptive-emojichooser: 3/3] popover: Try to not exceed monitor bounds
- Date: Tue, 22 Dec 2020 03:53:50 +0000 (UTC)
commit c4dbdea0ec31a63ddbd94105cde6f6ea8b56edd1
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 21 22:46:52 2020 -0500
popover: Try to not exceed monitor bounds
When the natural size of the popover exceeds
the monitor width, clamp it to fit on screen.
This gives the Emoji chooser a chance to
work on phone screens.
Fixes: #3307
gtk/gtkpopover.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index c087f58dc5..e372ba70a7 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -560,14 +560,35 @@ static gboolean
present_popup (GtkPopover *popover)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
- GtkRequisition req;
+ GtkRequisition min, nat;
GdkPopupLayout *layout;
+ GtkRoot *root;
+ GdkSurface *surface;
+ GdkMonitor *monitor;
+ GdkRectangle rect;
+ int width, height;
layout = create_popup_layout (popover);
- gtk_widget_get_preferred_size (GTK_WIDGET (popover), NULL, &req);
+ gtk_widget_get_preferred_size (GTK_WIDGET (popover), &min, &nat);
+
+ root = gtk_widget_get_root (gtk_widget_get_parent (GTK_WIDGET (popover)));
+ surface = gtk_native_get_surface (GTK_NATIVE (root));
+ monitor = gdk_display_get_monitor_at_surface (gdk_surface_get_display (surface), surface);
+ gdk_monitor_get_geometry (monitor, &rect);
+
+ if (rect.width >= nat.width)
+ {
+ width = nat.width;
+ height = nat.height;
+ }
+ else
+ {
+ width = CLAMP (nat.width, min.width, rect.width);
+ height = CLAMP (nat.height, min.height, rect.height);
+ }
+
if (gdk_popup_present (GDK_POPUP (priv->surface),
- MAX (req.width, 1),
- MAX (req.height, 1),
+ width, height,
layout))
{
update_popover_layout (popover, layout);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]