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#51473: [PATCH] Enable xwidget scrolling optimizations, and other xwidgets improvements Date: Fri, 29 Oct 2021 21:18:14 +0800 Message-ID: <87mtmskm09.fsf@yahoo.com> References: <87zgqslafe.fsf.ref@yahoo.com> <87zgqslafe.fsf@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="14935"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: 51473@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 29 15:19:20 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 1mgRmy-0003iS-CC for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 29 Oct 2021 15:19:20 +0200 Original-Received: from localhost ([::1]:33788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgRmx-0008FE-Ej for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 29 Oct 2021 09:19:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgRmg-0008F1-UU for bug-gnu-emacs@gnu.org; Fri, 29 Oct 2021 09:19:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42616) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgRmg-0003Ip-Lv for bug-gnu-emacs@gnu.org; Fri, 29 Oct 2021 09:19:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mgRmg-0000gn-Hu for bug-gnu-emacs@gnu.org; Fri, 29 Oct 2021 09:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 29 Oct 2021 13:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51473 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51473-submit@debbugs.gnu.org id=B51473.16355135152561 (code B ref 51473); Fri, 29 Oct 2021 13:19:02 +0000 Original-Received: (at 51473) by debbugs.gnu.org; 29 Oct 2021 13:18:35 +0000 Original-Received: from localhost ([127.0.0.1]:54162 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgRmF-0000fE-Eu for submit@debbugs.gnu.org; Fri, 29 Oct 2021 09:18:35 -0400 Original-Received: from sonic316-20.consmr.mail.ne1.yahoo.com ([66.163.187.146]:39614) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgRmA-0000ep-Ni for 51473@debbugs.gnu.org; Fri, 29 Oct 2021 09:18:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1635513504; bh=Wrrt4fjk5D8Tu771Oat5sYZ/d9qTFxrk5D6/e5Wua1Q=; h=From:To:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=MRNxkB6KKOJrTGQqiFKqe1h6x33gJaRURgw3jT6Q/kO88QatkR85uwN6LnR6VkG3vCFdBSIKkJG9z1YYOy1Tza3yGyeMps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ZcwclI5TIIFfcS7TG8K8wSLxfbS0U.B_0Yxe1l4PA7cJKc b1rFxab.MXuWjxU.6eZAOnFbwafRVmJQDKyjfOmzAI3SMOLuBCvNv6sPtzUKWWS99BqNeSFjZM2t gUdPaS1KRRybxZnhnj3LV.kbB1WzX3bAcUgtjNMF0IhWlmq6tCWPWCNABx2lH12ZcKtgybYAzTVL gkk4OP0b_ZfHnkYkx0si3.qE5o3tnWswNurwI_KKYn9zafiFB7ak5iopDkLHr4VZFHHnkhs.RGEV RDehgyHTFFAUCjaiMECH9DcGj2lGy54z_HFpHz0TJFBhqYdnYUULPDxg27cPCTZaElqXZjYB5oL0 13d2CebYjdJXYjxR3_LjYD5eGgcdl_dhiryfT8CUOBYdEcW0YnLiRmttq9vujE9vUt_8rJ19cEw4 d7byUTme4a8VdN5.2LnwGmek5Ospdt07voddHa_cSsKXdT2YjaobNja0xg.Q8AuR_95agvNci18w ttdEjfcaNDX.33A6OkdUtsftrUzgMPysBkr.U.bkjV X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.ne1.yahoo.com with HTTP; Fri, 29 Oct 2021 13:18:24 +0000 Original-Received: by kubenode503.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 991ae618a639404a3a67302e7a924f91; Fri, 29 Oct 2021 13:18:18 +0000 (UTC) In-Reply-To: <87zgqslafe.fsf@yahoo.com> (Po Lu's message of "Fri, 29 Oct 2021 12:30:45 +0800") X-Mailer: WebService/1.1.19198 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:218546 Archived-At: --=-=-= Content-Type: text/plain Po Lu writes: > The attached changes fix flickering xwidgets by moving xwidget display > into a separate X window, and also enable the scrolling optimization for > xwidgets. > > Someone with access to a Mac will have to do the changes necessary for > xwidget scrolling to work correctly on macOS, as they don't work on > GNUstep in the first place. > > However, event passthrough doesn't work yet, and will require some > thought. But that would be a fantastic opportunity to clean up the > current xwidget event handling mess (and perhaps even define a mechanism > for Lisp code to send events into xwidgets, which would make integrating > them into the existing Emacs event model much easier.) Any thoughts? > > Thanks. And I missed something, you will also need the following patch for everything to function correctly: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-Destroy-xwidgets-when-destroying-frames.patch >From b490315aad58c704589fbb753de3238ce0d08819 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 29 Oct 2021 19:26:49 +0800 Subject: [PATCH 3/3] Destroy xwidgets when destroying frames * src/xterm.c (x_free_frame_resources): Make sure to kill xwidget views. * src/xwidget.c (Fmake_xwidget): Attach damage event signal. (offscreen_damage_event): Operate on xwidgets and not individual views. (xwidget_init_view): Don't attach damage event signal here. (Fdelete_xwidget_view): Destroy window correctly and stop removing damage event signal. (kill_frame_xwidget_views): New function. * src/xwidget.c (kill_frame_xwidget_views): New function. --- src/xterm.c | 4 ++++ src/xwidget.c | 52 +++++++++++++++++++++++++++++++++++---------------- src/xwidget.h | 1 + 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index b12c15cb7a..3e8cfb8b29 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -12210,6 +12210,10 @@ x_free_frame_resources (struct frame *f) xfree (f->shell_position); #else /* !USE_X_TOOLKIT */ +#ifdef HAVE_XWIDGETS + kill_frame_xwidget_views (f); +#endif + #ifdef USE_GTK xg_free_frame_widgets (f); #endif /* USE_GTK */ diff --git a/src/xwidget.c b/src/xwidget.c index 68188eba08..fe6640171c 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -46,6 +46,7 @@ Copyright (C) 2011-2021 Free Software Foundation, Inc. #ifdef USE_GTK static Lisp_Object x_window_to_xwv_map; +static gboolean offscreen_damage_event (GtkWidget *, GdkEvent *, gpointer); #endif static struct xwidget * @@ -193,6 +194,9 @@ DEFUN ("make-xwidget", xw); } + g_signal_connect (G_OBJECT (xw->widgetwindow_osr), "damage-event", + G_CALLBACK (offscreen_damage_event), xw); + unblock_input (); } #elif defined NS_IMPL_COCOA @@ -297,15 +301,20 @@ xv_do_draw (struct xwidget_view *xw, struct xwidget *w) It copies the bitmap from the off-screen instance. */ static gboolean offscreen_damage_event (GtkWidget *widget, GdkEvent *event, - gpointer xwidget_view) + gpointer xwidget) { - struct xwidget_view *xw = xwidget_view; - struct xwidget *w = XXWIDGET (xw->model); + block_input (); - if (xw->wdesc == None) - return FALSE; + for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail); + tail = XCDR (tail)) + { + struct xwidget_view *view = XXWIDGET_VIEW (XCAR (tail)); + + if (view->wdesc && XXWIDGET (view->model) == xwidget) + xv_do_draw (view, XXWIDGET (view->model)); + } - xv_do_draw (xw, w); + unblock_input (); return FALSE; } @@ -592,9 +601,6 @@ xwidget_init_view (struct xwidget *xww, xv->wdesc = None; xv->frame = s->f; - - g_signal_connect (G_OBJECT (xww->widgetwindow_osr), "damage-event", - G_CALLBACK (offscreen_damage_event), xv); #elif defined NS_IMPL_COCOA nsxwidget_init_view (xv, xww, s, x, y); nsxwidget_resize_view(xv, xww->width, xww->height); @@ -1102,15 +1108,9 @@ DEFUN ("delete-xwidget-view", if (xv->wdesc != None) { block_input (); - XDestroyWindow (xv->dpy, xv->wdesc); - /* xv->model still has signals pointing to the view. There can be - several views. Find the matching signals and delete them all. */ - g_signal_handlers_disconnect_matched (XXWIDGET (xv->model)->widgetwindow_osr, - G_SIGNAL_MATCH_DATA, - 0, 0, 0, 0, xv); - cairo_destroy (xv->cr_context); cairo_surface_destroy (xv->cr_surface); + XDestroyWindow (xv->dpy, xv->wdesc); Fremhash (make_fixnum (xv->wdesc), x_window_to_xwv_map); unblock_input (); } @@ -1456,6 +1456,26 @@ xwidget_end_redisplay (struct window *w, struct glyph_matrix *matrix) } } +#ifdef USE_GTK +void +kill_frame_xwidget_views (struct frame *f) +{ + Lisp_Object rem = Qnil; + + for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail); + tail = XCDR (tail)) + { + if (XXWIDGET_VIEW (XCAR (tail))->frame == f) + rem = Fcons (XCAR (tail), rem); + } + + for (; CONSP (rem); rem = XCDR (rem)) + { + Fdelete_xwidget_view (XCAR (rem)); + } +} +#endif + /* Kill all xwidget in BUFFER. */ void kill_buffer_xwidgets (Lisp_Object buffer) diff --git a/src/xwidget.h b/src/xwidget.h index 28098c0b09..f51921dbef 100644 --- a/src/xwidget.h +++ b/src/xwidget.h @@ -171,6 +171,7 @@ #define XG_XWIDGET_VIEW "emacs_xwidget_view" void xwidget_expose (struct xwidget_view *xv); extern struct xwidget *xwidget_from_id (uint32_t id); +extern void kill_frame_xwidget_views (struct frame *f); #else INLINE_HEADER_BEGIN INLINE void syms_of_xwidget (void) {} -- 2.31.1 --=-=-=--