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.
This commit is contained in:
Chong Yidong 2011-05-28 20:45:00 -04:00
parent 8e6ca83dfe
commit 1dd3c2d9b2
8 changed files with 79 additions and 46 deletions

View file

@ -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.

View file

@ -1,3 +1,8 @@
2011-05-29 Chong Yidong <cyd@stupidchicken.com>
* select.el: Don't perform clipboard-manager saving in hooks;
leave the hooks empty.
2011-05-28 Leo Liu <sdl.web@gmail.com>
* replace.el (occur-menu-map, occur-edit-mode-map): New vars.

View file

@ -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

View file

@ -1,3 +1,14 @@
2011-05-29 Chong Yidong <cyd@stupidchicken.com>
* 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 <william.xwl@gmail.com>
* nsterm.m (ns_term_shutdown): Synchronize user defaults before

View file

@ -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,

View file

@ -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))

View file

@ -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.
/* 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. */
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)
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);
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);
}
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_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_frame = XCAR (XCDR (XCDR (XCDR (local_selection))));
if (FRAME_LIVE_P (XFRAME (local_frame)))
x_clipboard_manager_save (dpyinfo, local_frame);
}
return Qnil;
}
@ -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);

View file

@ -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 */