From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#51736: 29.0.50; [PATCH] Fix context menus appearing in the wrong location in xwidgets Date: Wed, 10 Nov 2021 09:24:54 +0800 Message-ID: <8735o4yf89.fsf@yahoo.com> References: <8735o4yf89.fsf.ref@yahoo.com> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19284"; mail-complaints-to="usenet@ciao.gmane.io" To: 51736@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 10 02:26:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkcNO-0004sn-VY for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Nov 2021 02:26:11 +0100 Original-Received: from localhost ([::1]:37080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkcNN-0007Mv-CS for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Nov 2021 20:26:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkcNG-0007MX-OV for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 20:26:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mkcNG-0003mr-F4 for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 20:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mkcNG-0000Zv-7r for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 20:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Nov 2021 01:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51736 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16365075182166 (code B ref -1); Wed, 10 Nov 2021 01:26:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Nov 2021 01:25:18 +0000 Original-Received: from localhost ([127.0.0.1]:36362 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkcMX-0000Ys-GR for submit@debbugs.gnu.org; Tue, 09 Nov 2021 20:25:17 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:38718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkcMU-0000YZ-4y for submit@debbugs.gnu.org; Tue, 09 Nov 2021 20:25:16 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkcMT-0007GY-Me for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 20:25:14 -0500 Original-Received: from sonic307-10.consmr.mail.ne1.yahoo.com ([66.163.190.33]:33576) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mkcML-0003Xd-VL for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 20:25:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1636507503; bh=/Ah+fGVuhTieCo4iMMmisPD/pki98gh2fIUh+ble7sU=; h=From:To:Subject:Date:References:From:Subject:Reply-To; b=YZYTTwx3rFG/nqYtj/SlQ6OtHpDD2+6j2F3G6KKgX0gVfIalmE+YxqOXoMaEf0BvNH6WkonbZpDGHNGIRYsVoqwnacuxGqeu/6WOnKXapEqJcScN2w20ZxaOo2P91bqf5/9wk98lyyYtwRu6ZTBbQXOx58S9gthXgGiNGJrTAfDGrDVW3l0iANATCGqy3GHrnRtus8t6XwpWoPvi81LLfL0CTs08MpGVJnmDiXiTN+FfgVOxXmSCV57T+8FkW7khKPnlpFZNEbyuGStwjCsSId5jahvyQ33aqG+DMclgaNX4bl7zOY+aeLDX1cVhsGDxrAD49gAyx5gnSlvculwiYA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1636507503; bh=1Ag7+kDoXuJ0+6Gh+1iPhjKcynf7s/YuHM0S3Zfdej2=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=HKg2fIxNCNMhmgRnJVc4SuVhUpdSmk2fprmuW4jLroLF/VWwteDr/yojvv4IjtxfSREEJhVkxs6wGN/QUjHcnBtjWeCVafauDm13ZXPMl8AkylDtnW0oPoxRtdTZbo3VJmDldH0Of1Vb2L0egfLNTqW9TUqRTYdWp/RXw9t/sX9SEzym1qsSVxlEA6EG5WObuBl1U+HwFVvttZcym/QV1VWi44pyJJUjzyOAYDK6Mc/btHJIYikcYw/XA5ZLpKwXJ6TZsQgKOhixvhsI3QSI+XkNXGZmC8z67/XZc0mCD8UEm31EtppEipLW3qCYQ+o96Taw3oBpoz3trQcRUiLUkA== X-YMail-OSG: 9yt4_0AVM1lFRApjLXgZXAn58rakGzUez70QmVrtnt.FbnenU6Bj7Sa6rx9IUmf oKgt55u.S.SjCdKILwj.E6X_EjMM_TJKAnHf5_orbKWyD3TxZiOpLKUT3cktXKAz2ZjPba9zgOve ZGFS_KVYQwaSL2gG60eHZluGuMN0oT6MZq6EXB_IA5job02ST5XHr8b2SGMaGCmNLI.Bkd3pwgBF mP1yKCRITaz2da89UzEIHJjE0PgP0ndK6pI2NsdcNj6DOcZRIjk5WyMfy5y6SP.Xf1rz6b_RoJw8 O00TNuMOjIcyl_jPLPW7oiBeVsZ.tCgnwIZCyHGRMf2eaWtxzSfs8ETPuaVrXKgK1YVpj.DL5jsu 8C0wt48zvsOJWRCIoJ8RXBVAiBK22rFA.rmGg_pYr0yxH2Iv59fwditwRibAJ_prcXUxQ8cSyMov npXPhCN7.0.U8s3RFUFnvBT8BSiNRNbI6qx1_r2SoBYA8c09TntlRGD7jSjNQBnW83zenLuk97.g 2bgMFV9lkmdJMSFZE0t5Tb6r5I89K5lO99Jjr18eRHmFVr3bVwqaCAvPxrX__DVNrh.DoToMm.lo UTqvrAoc.syOsNpshATyB9awEoPxMDh_cH5LHnqqLXd0L1s6eo7Aq8H1O8TTBGTUdAQYyv3uSfq7 jZKodxmHqnWlORoLW0Yfr6llzJrIPHOp73xEMdZ0HgYEWLCOgYXrpnektJ3ALXQnsA97KqPGP0f. H1GIjh7Ptc06jHTgXBcIl_PA_FeqiHmBhPZYnVS0GuEFG4yptnnwSKeDSfi3MeSDK0HPcch5NJKS s2OSGabX_AemKtJSd_OFzaUXv0Pn5h9Ob4CStwVc9F X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Wed, 10 Nov 2021 01:25:03 +0000 Original-Received: by kubenode507.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 81701926be79f670d33060393a5c0834; Wed, 10 Nov 2021 01:24:57 +0000 (UTC) X-Mailer: WebService/1.1.19306 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.190.33; envelope-from=luangruo@yahoo.com; helo=sonic307-10.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219497 Archived-At: --=-=-= Content-Type: text/plain Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Set-embedder-correctly-to-fix-menus-appearing-in-the.patch >From 6b6628065b18b1df313465f423b45fb516426811 Mon Sep 17 00:00:00 2001 From: Po Lu 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 --=-=-=--