* bug#51736: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
[not found] <8735o4yf89.fsf.ref@yahoo.com>
@ 2021-11-10 1:24 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 5:30 ` bug#51736: " Po Lu
0 siblings, 1 reply; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 1:24 UTC (permalink / raw)
To: 51736
[-- Attachment #1: Type: text/plain, Size: 9 bytes --]
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Set-embedder-correctly-to-fix-menus-appearing-in-the.patch --]
[-- Type: text/x-patch, Size: 6221 bytes --]
From 6b6628065b18b1df313465f423b45fb516426811 Mon Sep 17 00:00:00 2001
From: Po Lu <luangruo@yahoo.com>
Date: Wed, 10 Nov 2021 09:22:38 +0800
Subject: [PATCH] Set embedder correctly to fix menus appearing in the wrong
location
* src/xwidget.c (record_osr_embedder, from_embedder, to_embedder): New
functions.
(Fmake_xwidget): Attach from-embedder and to-embedder signals.
(find_widget_for_offscreen_window): New function.
(xwidget_button, xwidget_motion_or_crossing): Set embedder on event.
(Fdelete_xwidget_view): Remove embedder status if applicable.
* src/xwidget.h (struct xwidget): New fields `embedder' and
`embedder-view'.
---
src/xwidget.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/xwidget.h | 2 +
2 files changed, 127 insertions(+)
diff --git a/src/xwidget.c b/src/xwidget.c
index 2587b658e7..d5a0a7879d 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -52,6 +52,9 @@ Copyright (C) 2011-2021 Free Software Foundation, Inc.
static GdkDevice *find_suitable_keyboard (struct frame *);
static gboolean webkit_script_dialog_cb (WebKitWebView *, WebKitScriptDialog *,
gpointer);
+static void record_osr_embedder (struct xwidget_view *);
+static void from_embedder (GdkWindow *, double, double, gpointer, gpointer, gpointer);
+static void to_embedder (GdkWindow *, double, double, gpointer, gpointer, gpointer);
#endif
static struct xwidget *
@@ -215,6 +218,12 @@ DEFUN ("make-xwidget",
gtk_widget_show (xw->widgetwindow_osr);
synthesize_focus_in_event (xw->widgetwindow_osr);
+
+ g_signal_connect (G_OBJECT (gtk_widget_get_window (xw->widgetwindow_osr)),
+ "from-embedder", G_CALLBACK (from_embedder), NULL);
+ g_signal_connect (G_OBJECT (gtk_widget_get_window (xw->widgetwindow_osr)),
+ "to-embedder", G_CALLBACK (to_embedder), NULL);
+
/* Store some xwidget data in the gtk widgets for convenient
retrieval in the event handlers. */
g_object_set_data (G_OBJECT (xw->widget_osr), XG_XWIDGET, xw);
@@ -457,6 +466,106 @@ xwidget_from_id (uint32_t id)
}
#ifdef USE_GTK
+static void
+record_osr_embedder (struct xwidget_view *view)
+{
+ struct xwidget *xw;
+ GdkWindow *window, *embedder;
+
+ xw = XXWIDGET (view->model);
+ window = gtk_widget_get_window (xw->widgetwindow_osr);
+ embedder = gtk_widget_get_window (FRAME_GTK_OUTER_WIDGET (view->frame));
+
+ gdk_offscreen_window_set_embedder (window, embedder);
+ xw->embedder = view->frame;
+ xw->embedder_view = view;
+}
+
+static struct xwidget *
+find_xwidget_for_offscreen_window (GdkWindow *window)
+{
+ Lisp_Object tem;
+ struct xwidget *xw;
+ GdkWindow *w;
+
+ for (tem = Vxwidget_list; CONSP (tem); tem = XCDR (tem))
+ {
+ if (XWIDGETP (XCAR (tem)))
+ {
+ xw = XXWIDGET (XCAR (tem));
+ w = gtk_widget_get_window (xw->widgetwindow_osr);
+
+ if (w == window)
+ return xw;
+ }
+ }
+
+ return NULL;
+}
+
+static void
+from_embedder (GdkWindow *window, double x, double y,
+ gpointer x_out_ptr, gpointer y_out_ptr,
+ gpointer user_data)
+{
+ double *xout = x_out_ptr;
+ double *yout = y_out_ptr;
+ struct xwidget *xw = find_xwidget_for_offscreen_window (window);
+ struct xwidget_view *xvw;
+ gint xoff, yoff;
+
+ if (!xw)
+ emacs_abort ();
+
+ xvw = xw->embedder_view;
+
+ if (!xvw)
+ {
+ *xout = x;
+ *yout = y;
+ }
+ else
+ {
+ gtk_widget_translate_coordinates (FRAME_GTK_WIDGET (xvw->frame),
+ FRAME_GTK_OUTER_WIDGET (xvw->frame),
+ 0, 0, &xoff, &yoff);
+
+ *xout = x - (xvw->x + xvw->clip_left) - xoff;
+ *yout = y - (xvw->y + xvw->clip_top) - yoff;
+ }
+}
+
+static void
+to_embedder (GdkWindow *window, double x, double y,
+ gpointer x_out_ptr, gpointer y_out_ptr,
+ gpointer user_data)
+{
+ double *xout = x_out_ptr;
+ double *yout = y_out_ptr;
+ struct xwidget *xw = find_xwidget_for_offscreen_window (window);
+ struct xwidget_view *xvw;
+ gint xoff, yoff;
+
+ if (!xw)
+ emacs_abort ();
+
+ xvw = xw->embedder_view;
+
+ if (!xvw)
+ {
+ *xout = x;
+ *yout = y;
+ }
+ else
+ {
+ gtk_widget_translate_coordinates (FRAME_GTK_WIDGET (xvw->frame),
+ FRAME_GTK_OUTER_WIDGET (xvw->frame),
+ 0, 0, &xoff, &yoff);
+
+ *xout = x + xvw->x + xvw->clip_left + xoff;
+ *yout = y + xvw->y + xvw->clip_top + yoff;
+ }
+}
static GdkDevice *
find_suitable_pointer (struct frame *f)
@@ -697,6 +806,8 @@ xwidget_button (struct xwidget_view *view,
bool down_p, int x, int y, int button,
int modifier_state, Time time)
{
+ record_osr_embedder (view);
+
if (button < 4 || button > 8)
xwidget_button_1 (view, down_p, x, y, button, modifier_state, time);
else
@@ -765,6 +876,7 @@ xwidget_motion_or_crossing (struct xwidget_view *view, const XEvent *event)
if (!target)
target = model->widget_osr;
+ record_osr_embedder (view);
xg_event->any.window = gtk_widget_get_window (target);
g_object_ref (xg_event->any.window); /* The window will be unrefed
later by gdk_event_free. */
@@ -1865,6 +1977,9 @@ DEFUN ("delete-xwidget-view",
CHECK_XWIDGET_VIEW (xwidget_view);
struct xwidget_view *xv = XXWIDGET_VIEW (xwidget_view);
#ifdef USE_GTK
+ struct xwidget *xw = XXWIDGET (xv->model);
+ GdkWindow *w;
+
if (xv->wdesc != None)
{
block_input ();
@@ -1874,6 +1989,16 @@ DEFUN ("delete-xwidget-view",
Fremhash (make_fixnum (xv->wdesc), x_window_to_xwv_map);
unblock_input ();
}
+
+ if (xw->embedder_view == xv)
+ {
+ w = gtk_widget_get_window (xw->widgetwindow_osr);
+
+ XXWIDGET (xv->model)->embedder_view = NULL;
+ XXWIDGET (xv->model)->embedder = NULL;
+
+ gdk_offscreen_window_set_embedder (w, NULL);
+ }
#elif defined NS_IMPL_COCOA
nsxwidget_delete_view (xv);
#endif
diff --git a/src/xwidget.h b/src/xwidget.h
index ad8b7c039c..6e6b39c8b4 100644
--- a/src/xwidget.h
+++ b/src/xwidget.h
@@ -68,6 +68,8 @@ #define XWIDGET_H_INCLUDED
/* For offscreen widgets, unused if not osr. */
GtkWidget *widget_osr;
GtkWidget *widgetwindow_osr;
+ struct frame *embedder;
+ struct xwidget_view *embedder_view;
guint hit_result;
#elif defined (NS_IMPL_COCOA)
# ifdef __OBJC__
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* bug#51736: Re: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 1:24 ` bug#51736: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-11-10 5:30 ` Po Lu
2021-11-10 5:57 ` Lars Ingebrigtsen
2021-11-10 5:57 ` bug#51736: " Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 2 replies; 8+ messages in thread
From: Po Lu @ 2021-11-10 5:30 UTC (permalink / raw)
To: 51736
Hmm, if nobody has a comment on this I'll push this change, because the
problem this solves is a pretty frustrating annoyance.
Does that look OK? Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#51736: Re: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 5:30 ` bug#51736: " Po Lu
@ 2021-11-10 5:57 ` Lars Ingebrigtsen
2021-11-10 5:59 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 5:57 ` bug#51736: " Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-10 5:57 UTC (permalink / raw)
To: Po Lu; +Cc: 51736
Po Lu <luangruo@yahoo.com> writes:
> Hmm, if nobody has a comment on this I'll push this change, because the
> problem this solves is a pretty frustrating annoyance.
>
> Does that look OK? Thanks.
Looks fine to me; please go ahead and push.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#51736: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 5:30 ` bug#51736: " Po Lu
2021-11-10 5:57 ` Lars Ingebrigtsen
@ 2021-11-10 5:57 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 0 replies; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 5:57 UTC (permalink / raw)
To: 51736
Po Lu <luangruo@yahoo.com> writes:
> Hmm, if nobody has a comment on this I'll push this change, because the
> problem this solves is a pretty frustrating annoyance.
>
> Does that look OK? Thanks.
I pushed it. If this is the wrong procedure for these things, please
let me know, apologies in advance.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#51736: Re: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 5:57 ` Lars Ingebrigtsen
@ 2021-11-10 5:59 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 6:01 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 5:59 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 51736
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Looks fine to me; please go ahead and push.
Lars, I (or git, I'm not sure) got mighty confused and pushed the wrong
branch/worktree to master. How do I rectify this problem? Thanks, and
many apologies.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#51736: Re: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 5:59 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-11-10 6:01 ` Lars Ingebrigtsen
2021-11-10 6:02 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-10 6:01 UTC (permalink / raw)
To: Po Lu; +Cc: 51736
Po Lu <luangruo@yahoo.com> writes:
>> Looks fine to me; please go ahead and push.
>
> Lars, I (or git, I'm not sure) got mighty confused and pushed the wrong
> branch/worktree to master. How do I rectify this problem? Thanks, and
> many apologies.
Oops. 😀
I think you just have to revert the commits.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#51736: Re: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 6:01 ` Lars Ingebrigtsen
@ 2021-11-10 6:02 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 6:04 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 6:02 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 51736
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Oops. 😀
>
> I think you just have to revert the commits.
Thanks, how do I do that? (Also, could my use of multiple git worktrees
cause this problem?)
I.E. can I do a reset and a force-push?
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#51736: Re: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets
2021-11-10 6:02 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-11-10 6:04 ` Lars Ingebrigtsen
0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-10 6:04 UTC (permalink / raw)
To: Po Lu; +Cc: 51736
Po Lu <luangruo@yahoo.com> writes:
> Thanks, how do I do that? (Also, could my use of multiple git worktrees
> cause this problem?)
git revert on each of the five commits.
> I.E. can I do a reset and a force-push?
No, that wouldn't allow people tracking the tree to continue working, if
I understand correctly.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-11-10 6:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <8735o4yf89.fsf.ref@yahoo.com>
2021-11-10 1:24 ` bug#51736: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 5:30 ` bug#51736: " Po Lu
2021-11-10 5:57 ` Lars Ingebrigtsen
2021-11-10 5:59 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 6:01 ` Lars Ingebrigtsen
2021-11-10 6:02 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 6:04 ` Lars Ingebrigtsen
2021-11-10 5:57 ` bug#51736: " Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).