* New function for explictly killing xwidgets [not found] <8735nz9vk9.fsf.ref@yahoo.com> @ 2021-11-14 5:04 ` Po Lu 2021-11-14 5:06 ` Po Lu 2021-11-14 7:13 ` Eli Zaretskii 0 siblings, 2 replies; 6+ messages in thread From: Po Lu @ 2021-11-14 5:04 UTC (permalink / raw) To: emacs-devel [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: 0001-Add-xwidget-kill.patch --] [-- Type: text/x-patch, Size: 5006 bytes --] From 60a3d0592c34a0fefc6246eb02b5f903273f49ab Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Sun, 14 Nov 2021 13:02:41 +0800 Subject: [PATCH] Add `xwidget-kill' * doc/lispref/display.texi (Xwidgets): Document changes. * src/xwidget.c (kill_xwidget, Fkill_xwidget): New function. (syms_of_xwidget): Define new subr. (kill_buffer_xwidgets): Use `kill_xwidget' instead. --- doc/lispref/display.texi | 14 +++++--- src/xwidget.c | 77 +++++++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 28 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index a8a7837a4a..3ab29dc591 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6806,10 +6806,11 @@ Xwidgets subprocesses with. The xwidget that is returned will be killed alongside its buffer -(@pxref{Killing Buffers}). Once it is killed, the xwidget may -continue to exist as a Lisp object and act as a @code{display} -property until all references to it are gone, but most actions that -can be performed on live xwidgets will no longer be available. +(@pxref{Killing Buffers}). You can also kill it using +@code{xwidget-kill}. Once it is killed, the xwidget may continue to +exist as a Lisp object and act as a @code{display} property until all +references to it are gone, but most actions that can be performed on +live xwidgets will no longer be available. @end defun @defun xwidgetp object @@ -6822,6 +6823,11 @@ Xwidgets hasn't been killed, and @code{nil} otherwise. @end defun +@defun kill-xwidget xwidget +This function kills @var{xwidget}, by removing it from its buffer and +releasing window system resources it holds. +@end defun + @defun xwidget-plist xwidget This function returns the property list of @var{xwidget}. @end defun diff --git a/src/xwidget.c b/src/xwidget.c index 609a231d4b..00fd1e47ca 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -76,6 +76,8 @@ #define XSETXWIDGET_VIEW(a, b) XSETPSEUDOVECTOR (a, b, PVEC_XWIDGET_VIEW) static struct xwidget_view *xwidget_view_lookup (struct xwidget *, struct window *); +static void kill_xwidget (struct xwidget *); + #ifdef USE_GTK static void webkit_view_load_changed_cb (WebKitWebView *, WebKitLoadEvent, @@ -2386,6 +2388,25 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +DEFUN ("kill-xwidget", Fkill_xwidget, Skill_xwidget, + 1, 1, 0, + doc: /* Kill live xwidget XWIDGET. +This releases all window system resources associated with XWIDGET, +removes it from `xwidget-list', and detaches it from its buffer. */) + (Lisp_Object xwidget) +{ + struct xwidget *xw; + + CHECK_LIVE_XWIDGET (xwidget); + xw = XXWIDGET (xwidget); + + block_input (); + kill_xwidget (xw); + unblock_input (); + + return Qnil; +} + #ifdef USE_GTK DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, Sxwidget_webkit_load_html, 2, 3, 0, @@ -2468,6 +2489,7 @@ syms_of_xwidget (void) #ifdef USE_GTK defsubr (&Sxwidget_webkit_load_html); #endif + defsubr (&Skill_xwidget); DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); @@ -2708,6 +2730,36 @@ kill_frame_xwidget_views (struct frame *f) } #endif +static void +kill_xwidget (struct xwidget *xw) +{ +#ifdef USE_GTK + xw->buffer = Qnil; + + if (xw->widget_osr && xw->widgetwindow_osr) + { + gtk_widget_destroy (xw->widget_osr); + gtk_widget_destroy (xw->widgetwindow_osr); + } + if (xw->find_text) + xfree (xw->find_text); + if (!NILP (xw->script_callbacks)) + for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) + { + Lisp_Object cb = AREF (xw->script_callbacks, idx); + if (!NILP (cb)) + xfree (xmint_pointer (XCAR (cb))); + ASET (xw->script_callbacks, idx, Qnil); + } + + xw->widget_osr = NULL; + xw->widgetwindow_osr = NULL; + xw->find_text = NULL; +#elif defined NS_IMPL_COCOA + nsxwidget_kill (xw); +#endif +} + /* Kill all xwidget in BUFFER. */ void kill_buffer_xwidgets (Lisp_Object buffer) @@ -2721,31 +2773,8 @@ kill_buffer_xwidgets (Lisp_Object buffer) { CHECK_LIVE_XWIDGET (xwidget); struct xwidget *xw = XXWIDGET (xwidget); - xw->buffer = Qnil; -#ifdef USE_GTK - if (xw->widget_osr && xw->widgetwindow_osr) - { - gtk_widget_destroy (xw->widget_osr); - gtk_widget_destroy (xw->widgetwindow_osr); - } - if (xw->find_text) - xfree (xw->find_text); - if (!NILP (xw->script_callbacks)) - for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) - { - Lisp_Object cb = AREF (xw->script_callbacks, idx); - if (!NILP (cb)) - xfree (xmint_pointer (XCAR (cb))); - ASET (xw->script_callbacks, idx, Qnil); - } - - xw->widget_osr = NULL; - xw->widgetwindow_osr = NULL; - xw->find_text = NULL; -#elif defined NS_IMPL_COCOA - nsxwidget_kill (xw); -#endif + kill_xwidget (xw); } } } -- 2.31.1 [-- Attachment #2: Type: text/plain, Size: 206 bytes --] I would like to install this change if everyone thinks it's fine. It adds a function `kill-xwidget', which allows Lisp code to kill a single xwidget without killing the buffer it is attached to. Thanks. ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: New function for explictly killing xwidgets 2021-11-14 5:04 ` New function for explictly killing xwidgets Po Lu @ 2021-11-14 5:06 ` Po Lu 2021-11-14 7:13 ` Eli Zaretskii 1 sibling, 0 replies; 6+ messages in thread From: Po Lu @ 2021-11-14 5:06 UTC (permalink / raw) To: emacs-devel Po Lu <luangruo@yahoo.com> writes: > Subject: [PATCH] Add `xwidget-kill' Sorry, the commit message is wrong: it should read `kill-xwidget'. Needless to say, I will fix that before it's pushed. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: New function for explictly killing xwidgets 2021-11-14 5:04 ` New function for explictly killing xwidgets Po Lu 2021-11-14 5:06 ` Po Lu @ 2021-11-14 7:13 ` Eli Zaretskii 2021-11-14 7:16 ` Po Lu 1 sibling, 1 reply; 6+ messages in thread From: Eli Zaretskii @ 2021-11-14 7:13 UTC (permalink / raw) To: Po Lu; +Cc: emacs-devel > From: Po Lu <luangruo@yahoo.com> > Date: Sun, 14 Nov 2021 13:04:54 +0800 > > * doc/lispref/display.texi (Xwidgets): Document changes. This should say "Document 'kill-xwidget'." > +DEFUN ("kill-xwidget", Fkill_xwidget, Skill_xwidget, > + 1, 1, 0, > + doc: /* Kill live xwidget XWIDGET. One of the two "xwidget"s is redundant. Our style in these cases is like this: Kill the specified XWIDGET. > + if (!NILP (xw->script_callbacks)) > + for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) It is better to use braces around the for-loop, although strictly speaking they aren't needed here. But the code reads easier with them. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: New function for explictly killing xwidgets 2021-11-14 7:13 ` Eli Zaretskii @ 2021-11-14 7:16 ` Po Lu 2021-11-14 7:57 ` Eli Zaretskii 0 siblings, 1 reply; 6+ messages in thread From: Po Lu @ 2021-11-14 7:16 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 771 bytes --] Eli Zaretskii <eliz@gnu.org> writes: >> From: Po Lu <luangruo@yahoo.com> >> Date: Sun, 14 Nov 2021 13:04:54 +0800 >> >> * doc/lispref/display.texi (Xwidgets): Document changes. > > This should say "Document 'kill-xwidget'." > >> +DEFUN ("kill-xwidget", Fkill_xwidget, Skill_xwidget, >> + 1, 1, 0, >> + doc: /* Kill live xwidget XWIDGET. > > One of the two "xwidget"s is redundant. Our style in these cases is > like this: > > Kill the specified XWIDGET. > >> + if (!NILP (xw->script_callbacks)) >> + for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) > > It is better to use braces around the for-loop, although strictly > speaking they aren't needed here. But the code reads easier with > them. Thanks, how does this look to you? [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-kill-xwidget.patch --] [-- Type: text/x-patch, Size: 5031 bytes --] From fc2282c058c58927afff78f42609a73583b4ddab Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Sun, 14 Nov 2021 13:02:41 +0800 Subject: [PATCH] Add `kill-xwidget' * doc/lispref/display.texi (Xwidgets): Document 'kill-xwidget'. * src/xwidget.c (kill_xwidget, Fkill_xwidget): New function. (syms_of_xwidget): Define new subr. (kill_buffer_xwidgets): Use `kill_xwidget' instead. --- doc/lispref/display.texi | 14 +++++-- src/xwidget.c | 81 ++++++++++++++++++++++++++++------------ 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index a8a7837a4a..3ab29dc591 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6806,10 +6806,11 @@ Xwidgets subprocesses with. The xwidget that is returned will be killed alongside its buffer -(@pxref{Killing Buffers}). Once it is killed, the xwidget may -continue to exist as a Lisp object and act as a @code{display} -property until all references to it are gone, but most actions that -can be performed on live xwidgets will no longer be available. +(@pxref{Killing Buffers}). You can also kill it using +@code{xwidget-kill}. Once it is killed, the xwidget may continue to +exist as a Lisp object and act as a @code{display} property until all +references to it are gone, but most actions that can be performed on +live xwidgets will no longer be available. @end defun @defun xwidgetp object @@ -6822,6 +6823,11 @@ Xwidgets hasn't been killed, and @code{nil} otherwise. @end defun +@defun kill-xwidget xwidget +This function kills @var{xwidget}, by removing it from its buffer and +releasing window system resources it holds. +@end defun + @defun xwidget-plist xwidget This function returns the property list of @var{xwidget}. @end defun diff --git a/src/xwidget.c b/src/xwidget.c index 609a231d4b..344016ed74 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -76,6 +76,8 @@ #define XSETXWIDGET_VIEW(a, b) XSETPSEUDOVECTOR (a, b, PVEC_XWIDGET_VIEW) static struct xwidget_view *xwidget_view_lookup (struct xwidget *, struct window *); +static void kill_xwidget (struct xwidget *); + #ifdef USE_GTK static void webkit_view_load_changed_cb (WebKitWebView *, WebKitLoadEvent, @@ -2386,6 +2388,25 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +DEFUN ("kill-xwidget", Fkill_xwidget, Skill_xwidget, + 1, 1, 0, + doc: /* Kill the specified XWIDGET. +This releases all window system resources associated with XWIDGET, +removes it from `xwidget-list', and detaches it from its buffer. */) + (Lisp_Object xwidget) +{ + struct xwidget *xw; + + CHECK_LIVE_XWIDGET (xwidget); + xw = XXWIDGET (xwidget); + + block_input (); + kill_xwidget (xw); + unblock_input (); + + return Qnil; +} + #ifdef USE_GTK DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, Sxwidget_webkit_load_html, 2, 3, 0, @@ -2468,6 +2489,7 @@ syms_of_xwidget (void) #ifdef USE_GTK defsubr (&Sxwidget_webkit_load_html); #endif + defsubr (&Skill_xwidget); DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); @@ -2708,6 +2730,40 @@ kill_frame_xwidget_views (struct frame *f) } #endif +static void +kill_xwidget (struct xwidget *xw) +{ +#ifdef USE_GTK + xw->buffer = Qnil; + + if (xw->widget_osr && xw->widgetwindow_osr) + { + gtk_widget_destroy (xw->widget_osr); + gtk_widget_destroy (xw->widgetwindow_osr); + } + + if (xw->find_text) + xfree (xw->find_text); + + if (!NILP (xw->script_callbacks)) + { + for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) + { + Lisp_Object cb = AREF (xw->script_callbacks, idx); + if (!NILP (cb)) + xfree (xmint_pointer (XCAR (cb))); + ASET (xw->script_callbacks, idx, Qnil); + } + } + + xw->widget_osr = NULL; + xw->widgetwindow_osr = NULL; + xw->find_text = NULL; +#elif defined NS_IMPL_COCOA + nsxwidget_kill (xw); +#endif +} + /* Kill all xwidget in BUFFER. */ void kill_buffer_xwidgets (Lisp_Object buffer) @@ -2721,31 +2777,8 @@ kill_buffer_xwidgets (Lisp_Object buffer) { CHECK_LIVE_XWIDGET (xwidget); struct xwidget *xw = XXWIDGET (xwidget); - xw->buffer = Qnil; - -#ifdef USE_GTK - if (xw->widget_osr && xw->widgetwindow_osr) - { - gtk_widget_destroy (xw->widget_osr); - gtk_widget_destroy (xw->widgetwindow_osr); - } - if (xw->find_text) - xfree (xw->find_text); - if (!NILP (xw->script_callbacks)) - for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) - { - Lisp_Object cb = AREF (xw->script_callbacks, idx); - if (!NILP (cb)) - xfree (xmint_pointer (XCAR (cb))); - ASET (xw->script_callbacks, idx, Qnil); - } - xw->widget_osr = NULL; - xw->widgetwindow_osr = NULL; - xw->find_text = NULL; -#elif defined NS_IMPL_COCOA - nsxwidget_kill (xw); -#endif + kill_xwidget (xw); } } } -- 2.31.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: New function for explictly killing xwidgets 2021-11-14 7:16 ` Po Lu @ 2021-11-14 7:57 ` Eli Zaretskii 2021-11-14 9:42 ` Po Lu 0 siblings, 1 reply; 6+ messages in thread From: Eli Zaretskii @ 2021-11-14 7:57 UTC (permalink / raw) To: Po Lu; +Cc: emacs-devel > From: Po Lu <luangruo@yahoo.com> > Cc: emacs-devel@gnu.org > Date: Sun, 14 Nov 2021 15:16:18 +0800 > > Thanks, how does this look to you? LGTM, thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: New function for explictly killing xwidgets 2021-11-14 7:57 ` Eli Zaretskii @ 2021-11-14 9:42 ` Po Lu 0 siblings, 0 replies; 6+ messages in thread From: Po Lu @ 2021-11-14 9:42 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel Eli Zaretskii <eliz@gnu.org> writes: >> From: Po Lu <luangruo@yahoo.com> >> Cc: emacs-devel@gnu.org >> Date: Sun, 14 Nov 2021 15:16:18 +0800 >> >> Thanks, how does this look to you? > > LGTM, thanks. Thanks, pushed. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-14 9:42 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <8735nz9vk9.fsf.ref@yahoo.com> 2021-11-14 5:04 ` New function for explictly killing xwidgets Po Lu 2021-11-14 5:06 ` Po Lu 2021-11-14 7:13 ` Eli Zaretskii 2021-11-14 7:16 ` Po Lu 2021-11-14 7:57 ` Eli Zaretskii 2021-11-14 9:42 ` Po Lu
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).