all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Florian Rommel <mail@florommel.de>
To: 57224@debbugs.gnu.org
Subject: bug#57224: 29.0.50; PGTK: scroll-bar obscures child-frame
Date: Mon, 15 Aug 2022 17:15:00 +0200	[thread overview]
Message-ID: <cccec9abf33881add47f7b0d5be6d4f5e1a37e04.camel@florommel.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 1673 bytes --]

In PGTK, child frames may be obscured by scroll-bars. This happens when
the scrollbar is added after the child frame is created (e.g. by
creating new windows, etc.). The bug may in particular affect people
using child-frame-based completion packages, such as corfu, company-
box, or company-posframe.

From what I could see in the code, in contrast to X, PGTK adds child
frames to the parent frame's edit_widget which is a GtkFixed (see "x-
create-frame"). A GtkFixed doesn't have any defined z-order behavior.
However, widgets seem to get drawn in the order of the internal child
list. Unfortunately, there is no direct way to insert widgets at the
front of this list or otherwise manipulate the list apart from pushing
children to the end or removing them. So a (dirty) workaround would be
to remove all children, add the scrollbar and then add all the removed
widgets again, see the patch.
A better solution may involve something like a GtKOverlay but I don't
know if that's practical in the current implementation.

To replicate the bug in 'emacs -Q':
(progn
  (make-frame
   `((title . "childframe")
     (parent-frame . ,(selected-frame))
     (border-width . 3)
     (internal-border-width . 3)
     (child-frame-border-width . 3)
     (vertical-scroll-bars . nil)
     (horizontal-scroll-bars . nil)
     (menu-bar-lines . 0)
     (tool-bar-lines . 0)
     (tab-bar-lines . 0)
     (minibuffer . nil)
     (undecorated . t)
     (left . 0.5)
     (top . 0.5)
     (width . 20)
     (height . 20)
     (left-fringe . 0)
     (right-fringe . 0)
     (background-color . "blue")))
(split-window-right)
(split-window-right))


[-- Attachment #2: 0001-Fix-scroll-bars-obscuring-child-frames-in-PGTK.patch --]
[-- Type: text/x-patch, Size: 2594 bytes --]

From cb820ad1f0bd8d6827d05ec04b7b226fffdab7d8 Mon Sep 17 00:00:00 2001
From: Florian Rommel <mail@florommel.de>
Date: Mon, 15 Aug 2022 16:53:35 +0200
Subject: [PATCH] Fix scroll-bars obscuring child-frames in PGTK

* src/gtkutil.c (xg_finish_scroll_bar_creation, xg_xp_insert_widget):
Insert scroll-bar widget as the first child of the container.
---
 src/gtkutil.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/gtkutil.c b/src/gtkutil.c
index a6bba096a4..ac232fccd4 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -4495,6 +4495,50 @@ xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data)
 }
 #endif
 
+/* Workaround: Insert a widget at the front of the edit_widget (GtkFixed).
+   This is necessary for scrollbars to not obscure any child frames. */
+
+#ifdef HAVE_PGTK
+static void
+xg_xp_insert_widget (xp_output *output, GtkWidget *widget)
+{
+  struct widget_pos {
+    gint x;
+    gint y;
+  };
+
+  struct widget_pos *pos;
+  GList *list, *elem;
+  unsigned int idx;
+
+  list = gtk_container_get_children (GTK_CONTAINER (output->edit_widget));
+  pos = xmalloc (sizeof (struct widget_pos) * g_list_length (list));
+
+  for (elem = list, idx = 0; elem; elem = elem->next, idx++)
+    {
+      GtkWidget *w = elem->data;
+      struct widget_pos *p = &pos[idx];
+      gtk_container_child_get (GTK_CONTAINER (output->edit_widget), w,
+                               "x", &p->x, "y", &p->y, NULL);
+      g_object_ref (w);
+      gtk_container_remove (GTK_CONTAINER (output->edit_widget), w);
+    }
+
+  gtk_fixed_put (GTK_FIXED (output->edit_widget), widget, -1, -1);
+
+  for (elem = list, idx = 0; elem; elem = elem->next, idx++)
+    {
+      GtkWidget *w = elem->data;
+      struct widget_pos *p = &pos[idx];
+      gtk_fixed_put (GTK_FIXED (output->edit_widget), w, p->x, p->y);
+      g_object_unref (w);
+    }
+
+  xfree (pos);
+  g_list_free (list);
+}
+#endif
+
 #if defined HAVE_GTK3 && !defined HAVE_PGTK
 static void
 xg_scroll_bar_size_allocate_cb (GtkWidget *widget,
@@ -4571,7 +4615,11 @@ xg_finish_scroll_bar_creation (struct frame *f,
      also, which causes flicker.  Put an event box between the edit widget
      and the scroll bar, so the scroll bar instead draws itself on the
      event box window.  */
+#ifdef HAVE_PGTK
+  xg_xp_insert_widget (f->output_data.xp, webox);
+#else
   gtk_fixed_put (GTK_FIXED (f->output_data.xp->edit_widget), webox, -1, -1);
+#endif
   gtk_container_add (GTK_CONTAINER (webox), wscroll);
 
   xg_set_widget_bg (f, webox, FRAME_BACKGROUND_PIXEL (f));
-- 
2.37.1


             reply	other threads:[~2022-08-15 15:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 15:15 Florian Rommel [this message]
2022-08-16  1:00 ` bug#57224: 29.0.50; PGTK: scroll-bar obscures child-frame Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cccec9abf33881add47f7b0d5be6d4f5e1a37e04.camel@florommel.de \
    --to=mail@florommel.de \
    --cc=57224@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.