From 1dd3c2d9b2466eb6dc379da6a67074dbd4c13fa5 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sat, 28 May 2011 20:45:00 -0400 Subject: [PATCH] Move clipboard-manager functionality out of hooks. * lisp/select.el: Don't perform clipboard-manager saving in hooks; leave the hooks empty. * src/emacs.c (Fkill_emacs): Call x_clipboard_manager_save_all. * src/frame.c (delete_frame): Call x_clipboard_manager_save_frame. * src/xselect.c (x_clipboard_manager_save_frame) (x_clipboard_manager_save_all): New functions. (Fx_clipboard_manager_save): Lisp function deleted. * src/xterm.h: Update prototype. --- etc/NEWS | 4 +++ lisp/ChangeLog | 5 +++ lisp/select.el | 4 --- src/ChangeLog | 11 +++++++ src/emacs.c | 10 ++++++ src/frame.c | 9 +++++- src/xselect.c | 87 +++++++++++++++++++++++++------------------------- src/xterm.h | 1 + 8 files changed, 82 insertions(+), 49 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index e49b3d34c4..dc1f25ddd3 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -177,6 +177,8 @@ with Xft. To change font, use the X resource font, for example: Emacs.pane.menubar.font: Courier-12 ** On graphical displays, the mode-line no longer ends in dashes. +Also, the first dash (which does not indicate anything) is just +displayed as a space. ** On Nextstep/OSX, the menu bar can be hidden by customizing ns-auto-hide-menu-bar. @@ -386,6 +388,8 @@ between applications. *** Support for X cut buffers has been removed. +*** Support for X clipboard managers has been added. + ** New command `rectangle-number-lines', bound to `C-x r N', numbers the lines in the current rectangle. With an prefix argument, this prompts for a number to count from and for a format string. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ee03aeccb1..a236441a34 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2011-05-29 Chong Yidong + + * select.el: Don't perform clipboard-manager saving in hooks; + leave the hooks empty. + 2011-05-28 Leo Liu * replace.el (occur-menu-map, occur-edit-mode-map): New vars. diff --git a/lisp/select.el b/lisp/select.el index 5abbf8f795..10c8f0b1ef 100644 --- a/lisp/select.el +++ b/lisp/select.el @@ -395,10 +395,6 @@ This function returns the string \"emacs\"." (SAVE_TARGETS . xselect-convert-to-save-targets) (_EMACS_INTERNAL . xselect-convert-to-identity))) -(when (fboundp 'x-clipboard-manager-save) - (add-hook 'delete-frame-functions 'x-clipboard-manager-save) - (add-hook 'kill-emacs-hook 'x-clipboard-manager-save)) - (provide 'select) ;;; select.el ends here diff --git a/src/ChangeLog b/src/ChangeLog index 1546348bfb..6c56b878b0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2011-05-29 Chong Yidong + + * xselect.c (x_clipboard_manager_save_frame) + (x_clipboard_manager_save_all): New functions. + (Fx_clipboard_manager_save): Lisp function deleted. + + * emacs.c (Fkill_emacs): Call x_clipboard_manager_save_all. + * frame.c (delete_frame): Call x_clipboard_manager_save_frame. + + * xterm.h: Update prototype. + 2011-05-28 William Xu * nsterm.m (ns_term_shutdown): Synchronize user defaults before diff --git a/src/emacs.c b/src/emacs.c index 8c4490b0a5..090fddada5 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1959,6 +1959,11 @@ sort_args (int argc, char **argv) xfree (priority); } +#ifdef HAVE_X_WINDOWS +/* Defined in xselect.c. */ +extern void x_clipboard_manager_save_all (void); +#endif + DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", doc: /* Exit the Emacs job and kill it. If ARG is an integer, return ARG as the exit program code. @@ -1985,6 +1990,11 @@ all of which are called before Emacs is actually killed. */) UNGCPRO; +#ifdef HAVE_X_WINDOWS + /* Transfer any clipboards we own to the clipboard manager. */ + x_clipboard_manager_save_all (); +#endif + shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil); /* If we have an auto-save list file, diff --git a/src/frame.c b/src/frame.c index ce92a83b86..74e222f85f 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1347,7 +1347,14 @@ delete_frame (Lisp_Object frame, Lisp_Object force) = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame), pending_funcalls); else - safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame); + { +#ifdef HAVE_X_WINDOWS + /* Also, save clipboard to the the clipboard manager. */ + x_clipboard_manager_save_frame (frame); +#endif + + safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame); + } /* The hook may sometimes (indirectly) cause the frame to be deleted. */ if (! FRAME_LIVE_P (f)) diff --git a/src/xselect.c b/src/xselect.c index 8741cb8996..0f852a7c38 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -2107,6 +2107,7 @@ frame's display, or the first available X display. */) return (owner ? Qt : Qnil); } + /* Send the clipboard manager a SAVE_TARGETS request with a UTF8_STRING property, as described by http://www.freedesktop.org/wiki/ClipboardManager */ @@ -2126,54 +2127,53 @@ x_clipboard_manager_save (struct x_display_info *dpyinfo, Qnil, frame); } -DEFUN ("x-clipboard-manager-save", Fx_clipboard_manager_save, - Sx_clipboard_manager_save, 0, 1, 0, - doc: /* Save the clipboard contents to the clipboard manager. -This function is intended to run from `delete-frame-functions' and -`kill-emacs-hook', to transfer clipboard data owned by Emacs to a -clipboard manager prior to deleting a frame or killing Emacs. - -FRAME specifies a frame owning a clipboard; do nothing if FRAME does -not own the clipboard, or if no clipboard manager is present. If -FRAME is nil, save all clipboard contents owned by Emacs. */) - (Lisp_Object frame) +/* Called from delete_frame: save any clipboard owned by FRAME to the + clipboard manager. Do nothing if FRAME does not own the clipboard, + or if no clipboard manager is present. */ + +void +x_clipboard_manager_save_frame (Lisp_Object frame) { - if (FRAMEP (frame)) + struct frame *f; + + if (FRAMEP (frame) + && (f = XFRAME (frame), FRAME_X_P (f)) + && FRAME_LIVE_P (f)) { - struct frame *f = XFRAME (frame); - if (FRAME_LIVE_P (f) && FRAME_X_P (f)) - { - struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); - Lisp_Object local_selection - = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); - - if (!NILP (local_selection) - && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection))))) - && XGetSelectionOwner (dpyinfo->display, - dpyinfo->Xatom_CLIPBOARD_MANAGER)) - x_clipboard_manager_save (dpyinfo, frame); - } + struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); + Lisp_Object local_selection + = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); + + if (!NILP (local_selection) + && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection))))) + && XGetSelectionOwner (dpyinfo->display, + dpyinfo->Xatom_CLIPBOARD_MANAGER)) + x_clipboard_manager_save (dpyinfo, frame); } - else if (NILP (frame)) +} + +/* Called from Fkill_emacs: save any clipboard owned by FRAME to the + clipboard manager. Do nothing if FRAME does not own the clipboard, + or if no clipboard manager is present. */ + +void +x_clipboard_manager_save_all (void) +{ + /* Loop through all X displays, saving owned clipboards. */ + struct x_display_info *dpyinfo; + Lisp_Object local_selection, local_frame; + for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) { - /* Loop through all X displays, saving owned clipboards. */ - struct x_display_info *dpyinfo; - Lisp_Object local_selection, local_frame; - for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) - { - local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); - if (NILP (local_selection) - || !XGetSelectionOwner (dpyinfo->display, - dpyinfo->Xatom_CLIPBOARD_MANAGER)) - continue; - - local_frame = XCAR (XCDR (XCDR (XCDR (local_selection)))); - if (FRAME_LIVE_P (XFRAME (local_frame))) - x_clipboard_manager_save (dpyinfo, local_frame); - } - } + local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); + if (NILP (local_selection) + || !XGetSelectionOwner (dpyinfo->display, + dpyinfo->Xatom_CLIPBOARD_MANAGER)) + continue; - return Qnil; + local_frame = XCAR (XCDR (XCDR (XCDR (local_selection)))); + if (FRAME_LIVE_P (XFRAME (local_frame))) + x_clipboard_manager_save (dpyinfo, local_frame); + } } @@ -2586,7 +2586,6 @@ syms_of_xselect (void) defsubr (&Sx_disown_selection_internal); defsubr (&Sx_selection_owner_p); defsubr (&Sx_selection_exists_p); - defsubr (&Sx_clipboard_manager_save); defsubr (&Sx_get_atom_name); defsubr (&Sx_send_client_message); diff --git a/src/xterm.h b/src/xterm.h index c44978d538..2184794af4 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1024,6 +1024,7 @@ extern Lisp_Object x_property_data_to_lisp (struct frame *, Atom, int, unsigned long); +extern void x_clipboard_manager_save_frame (Lisp_Object); /* Defined in xfns.c */ -- 2.20.1