diff options
| author | Po Lu | 2021-11-14 13:02:41 +0800 |
|---|---|---|
| committer | Po Lu | 2021-11-14 17:42:16 +0800 |
| commit | 609bc1d33ad81f9f2ffa0ff34522cfdb743d2dbb (patch) | |
| tree | 65024847dcebe2bcd51848ffbee23c08cbecf1b1 | |
| parent | 06632fbaf81900143aec988a846ee18e33a85e50 (diff) | |
| download | emacs-609bc1d33ad81f9f2ffa0ff34522cfdb743d2dbb.tar.gz emacs-609bc1d33ad81f9f2ffa0ff34522cfdb743d2dbb.zip | |
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.
| -rw-r--r-- | doc/lispref/display.texi | 14 | ||||
| -rw-r--r-- | src/xwidget.c | 81 |
2 files changed, 67 insertions, 28 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index a8a7837a4a0..3ab29dc5912 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -6806,10 +6806,11 @@ widget that the newly created widget should share settings and | |||
| 6806 | subprocesses with. | 6806 | subprocesses with. |
| 6807 | 6807 | ||
| 6808 | The xwidget that is returned will be killed alongside its buffer | 6808 | The xwidget that is returned will be killed alongside its buffer |
| 6809 | (@pxref{Killing Buffers}). Once it is killed, the xwidget may | 6809 | (@pxref{Killing Buffers}). You can also kill it using |
| 6810 | continue to exist as a Lisp object and act as a @code{display} | 6810 | @code{xwidget-kill}. Once it is killed, the xwidget may continue to |
| 6811 | property until all references to it are gone, but most actions that | 6811 | exist as a Lisp object and act as a @code{display} property until all |
| 6812 | can be performed on live xwidgets will no longer be available. | 6812 | references to it are gone, but most actions that can be performed on |
| 6813 | live xwidgets will no longer be available. | ||
| 6813 | @end defun | 6814 | @end defun |
| 6814 | 6815 | ||
| 6815 | @defun xwidgetp object | 6816 | @defun xwidgetp object |
| @@ -6822,6 +6823,11 @@ This function returns @code{t} if @var{object} is an xwidget that | |||
| 6822 | hasn't been killed, and @code{nil} otherwise. | 6823 | hasn't been killed, and @code{nil} otherwise. |
| 6823 | @end defun | 6824 | @end defun |
| 6824 | 6825 | ||
| 6826 | @defun kill-xwidget xwidget | ||
| 6827 | This function kills @var{xwidget}, by removing it from its buffer and | ||
| 6828 | releasing window system resources it holds. | ||
| 6829 | @end defun | ||
| 6830 | |||
| 6825 | @defun xwidget-plist xwidget | 6831 | @defun xwidget-plist xwidget |
| 6826 | This function returns the property list of @var{xwidget}. | 6832 | This function returns the property list of @var{xwidget}. |
| 6827 | @end defun | 6833 | @end defun |
diff --git a/src/xwidget.c b/src/xwidget.c index 609a231d4bb..344016ed744 100644 --- a/src/xwidget.c +++ b/src/xwidget.c | |||
| @@ -76,6 +76,8 @@ allocate_xwidget_view (void) | |||
| 76 | 76 | ||
| 77 | static struct xwidget_view *xwidget_view_lookup (struct xwidget *, | 77 | static struct xwidget_view *xwidget_view_lookup (struct xwidget *, |
| 78 | struct window *); | 78 | struct window *); |
| 79 | static void kill_xwidget (struct xwidget *); | ||
| 80 | |||
| 79 | #ifdef USE_GTK | 81 | #ifdef USE_GTK |
| 80 | static void webkit_view_load_changed_cb (WebKitWebView *, | 82 | static void webkit_view_load_changed_cb (WebKitWebView *, |
| 81 | WebKitLoadEvent, | 83 | WebKitLoadEvent, |
| @@ -2386,6 +2388,25 @@ using `xwidget-webkit-search'. */) | |||
| 2386 | return Qnil; | 2388 | return Qnil; |
| 2387 | } | 2389 | } |
| 2388 | 2390 | ||
| 2391 | DEFUN ("kill-xwidget", Fkill_xwidget, Skill_xwidget, | ||
| 2392 | 1, 1, 0, | ||
| 2393 | doc: /* Kill the specified XWIDGET. | ||
| 2394 | This releases all window system resources associated with XWIDGET, | ||
| 2395 | removes it from `xwidget-list', and detaches it from its buffer. */) | ||
| 2396 | (Lisp_Object xwidget) | ||
| 2397 | { | ||
| 2398 | struct xwidget *xw; | ||
| 2399 | |||
| 2400 | CHECK_LIVE_XWIDGET (xwidget); | ||
| 2401 | xw = XXWIDGET (xwidget); | ||
| 2402 | |||
| 2403 | block_input (); | ||
| 2404 | kill_xwidget (xw); | ||
| 2405 | unblock_input (); | ||
| 2406 | |||
| 2407 | return Qnil; | ||
| 2408 | } | ||
| 2409 | |||
| 2389 | #ifdef USE_GTK | 2410 | #ifdef USE_GTK |
| 2390 | DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, | 2411 | DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, |
| 2391 | Sxwidget_webkit_load_html, 2, 3, 0, | 2412 | Sxwidget_webkit_load_html, 2, 3, 0, |
| @@ -2468,6 +2489,7 @@ syms_of_xwidget (void) | |||
| 2468 | #ifdef USE_GTK | 2489 | #ifdef USE_GTK |
| 2469 | defsubr (&Sxwidget_webkit_load_html); | 2490 | defsubr (&Sxwidget_webkit_load_html); |
| 2470 | #endif | 2491 | #endif |
| 2492 | defsubr (&Skill_xwidget); | ||
| 2471 | 2493 | ||
| 2472 | DEFSYM (QCxwidget, ":xwidget"); | 2494 | DEFSYM (QCxwidget, ":xwidget"); |
| 2473 | DEFSYM (QCtitle, ":title"); | 2495 | DEFSYM (QCtitle, ":title"); |
| @@ -2708,6 +2730,40 @@ kill_frame_xwidget_views (struct frame *f) | |||
| 2708 | } | 2730 | } |
| 2709 | #endif | 2731 | #endif |
| 2710 | 2732 | ||
| 2733 | static void | ||
| 2734 | kill_xwidget (struct xwidget *xw) | ||
| 2735 | { | ||
| 2736 | #ifdef USE_GTK | ||
| 2737 | xw->buffer = Qnil; | ||
| 2738 | |||
| 2739 | if (xw->widget_osr && xw->widgetwindow_osr) | ||
| 2740 | { | ||
| 2741 | gtk_widget_destroy (xw->widget_osr); | ||
| 2742 | gtk_widget_destroy (xw->widgetwindow_osr); | ||
| 2743 | } | ||
| 2744 | |||
| 2745 | if (xw->find_text) | ||
| 2746 | xfree (xw->find_text); | ||
| 2747 | |||
| 2748 | if (!NILP (xw->script_callbacks)) | ||
| 2749 | { | ||
| 2750 | for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) | ||
| 2751 | { | ||
| 2752 | Lisp_Object cb = AREF (xw->script_callbacks, idx); | ||
| 2753 | if (!NILP (cb)) | ||
| 2754 | xfree (xmint_pointer (XCAR (cb))); | ||
| 2755 | ASET (xw->script_callbacks, idx, Qnil); | ||
| 2756 | } | ||
| 2757 | } | ||
| 2758 | |||
| 2759 | xw->widget_osr = NULL; | ||
| 2760 | xw->widgetwindow_osr = NULL; | ||
| 2761 | xw->find_text = NULL; | ||
| 2762 | #elif defined NS_IMPL_COCOA | ||
| 2763 | nsxwidget_kill (xw); | ||
| 2764 | #endif | ||
| 2765 | } | ||
| 2766 | |||
| 2711 | /* Kill all xwidget in BUFFER. */ | 2767 | /* Kill all xwidget in BUFFER. */ |
| 2712 | void | 2768 | void |
| 2713 | kill_buffer_xwidgets (Lisp_Object buffer) | 2769 | kill_buffer_xwidgets (Lisp_Object buffer) |
| @@ -2721,31 +2777,8 @@ kill_buffer_xwidgets (Lisp_Object buffer) | |||
| 2721 | { | 2777 | { |
| 2722 | CHECK_LIVE_XWIDGET (xwidget); | 2778 | CHECK_LIVE_XWIDGET (xwidget); |
| 2723 | struct xwidget *xw = XXWIDGET (xwidget); | 2779 | struct xwidget *xw = XXWIDGET (xwidget); |
| 2724 | xw->buffer = Qnil; | ||
| 2725 | |||
| 2726 | #ifdef USE_GTK | ||
| 2727 | if (xw->widget_osr && xw->widgetwindow_osr) | ||
| 2728 | { | ||
| 2729 | gtk_widget_destroy (xw->widget_osr); | ||
| 2730 | gtk_widget_destroy (xw->widgetwindow_osr); | ||
| 2731 | } | ||
| 2732 | if (xw->find_text) | ||
| 2733 | xfree (xw->find_text); | ||
| 2734 | if (!NILP (xw->script_callbacks)) | ||
| 2735 | for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++) | ||
| 2736 | { | ||
| 2737 | Lisp_Object cb = AREF (xw->script_callbacks, idx); | ||
| 2738 | if (!NILP (cb)) | ||
| 2739 | xfree (xmint_pointer (XCAR (cb))); | ||
| 2740 | ASET (xw->script_callbacks, idx, Qnil); | ||
| 2741 | } | ||
| 2742 | 2780 | ||
| 2743 | xw->widget_osr = NULL; | 2781 | kill_xwidget (xw); |
| 2744 | xw->widgetwindow_osr = NULL; | ||
| 2745 | xw->find_text = NULL; | ||
| 2746 | #elif defined NS_IMPL_COCOA | ||
| 2747 | nsxwidget_kill (xw); | ||
| 2748 | #endif | ||
| 2749 | } | 2782 | } |
| 2750 | } | 2783 | } |
| 2751 | } | 2784 | } |