aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChong Yidong2011-05-28 20:45:00 -0400
committerChong Yidong2011-05-28 20:45:00 -0400
commit1dd3c2d9b2466eb6dc379da6a67074dbd4c13fa5 (patch)
treea812814e376414db37827f4298e375ff868ecdaf /src
parent8e6ca83dfede41bbc8d060a4aaa72f2a414f59ae (diff)
downloademacs-1dd3c2d9b2466eb6dc379da6a67074dbd4c13fa5.tar.gz
emacs-1dd3c2d9b2466eb6dc379da6a67074dbd4c13fa5.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/emacs.c10
-rw-r--r--src/frame.c9
-rw-r--r--src/xselect.c87
-rw-r--r--src/xterm.h1
5 files changed, 73 insertions, 45 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 1546348bfbf..6c56b878b01 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
12011-05-29 Chong Yidong <cyd@stupidchicken.com>
2
3 * xselect.c (x_clipboard_manager_save_frame)
4 (x_clipboard_manager_save_all): New functions.
5 (Fx_clipboard_manager_save): Lisp function deleted.
6
7 * emacs.c (Fkill_emacs): Call x_clipboard_manager_save_all.
8 * frame.c (delete_frame): Call x_clipboard_manager_save_frame.
9
10 * xterm.h: Update prototype.
11
12011-05-28 William Xu <william.xwl@gmail.com> 122011-05-28 William Xu <william.xwl@gmail.com>
2 13
3 * nsterm.m (ns_term_shutdown): Synchronize user defaults before 14 * nsterm.m (ns_term_shutdown): Synchronize user defaults before
diff --git a/src/emacs.c b/src/emacs.c
index 8c4490b0a52..090fddada5c 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1959,6 +1959,11 @@ sort_args (int argc, char **argv)
1959 xfree (priority); 1959 xfree (priority);
1960} 1960}
1961 1961
1962#ifdef HAVE_X_WINDOWS
1963/* Defined in xselect.c. */
1964extern void x_clipboard_manager_save_all (void);
1965#endif
1966
1962DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", 1967DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
1963 doc: /* Exit the Emacs job and kill it. 1968 doc: /* Exit the Emacs job and kill it.
1964If ARG is an integer, return ARG as the exit program code. 1969If 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. */)
1985 1990
1986 UNGCPRO; 1991 UNGCPRO;
1987 1992
1993#ifdef HAVE_X_WINDOWS
1994 /* Transfer any clipboards we own to the clipboard manager. */
1995 x_clipboard_manager_save_all ();
1996#endif
1997
1988 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil); 1998 shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
1989 1999
1990 /* If we have an auto-save list file, 2000 /* If we have an auto-save list file,
diff --git a/src/frame.c b/src/frame.c
index ce92a83b86c..74e222f85fc 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1347,7 +1347,14 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
1347 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame), 1347 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1348 pending_funcalls); 1348 pending_funcalls);
1349 else 1349 else
1350 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame); 1350 {
1351#ifdef HAVE_X_WINDOWS
1352 /* Also, save clipboard to the the clipboard manager. */
1353 x_clipboard_manager_save_frame (frame);
1354#endif
1355
1356 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1357 }
1351 1358
1352 /* The hook may sometimes (indirectly) cause the frame to be deleted. */ 1359 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1353 if (! FRAME_LIVE_P (f)) 1360 if (! FRAME_LIVE_P (f))
diff --git a/src/xselect.c b/src/xselect.c
index 8741cb89967..0f852a7c382 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -2107,6 +2107,7 @@ frame's display, or the first available X display. */)
2107 return (owner ? Qt : Qnil); 2107 return (owner ? Qt : Qnil);
2108} 2108}
2109 2109
2110
2110/* Send the clipboard manager a SAVE_TARGETS request with a 2111/* Send the clipboard manager a SAVE_TARGETS request with a
2111 UTF8_STRING property, as described by 2112 UTF8_STRING property, as described by
2112 http://www.freedesktop.org/wiki/ClipboardManager */ 2113 http://www.freedesktop.org/wiki/ClipboardManager */
@@ -2126,54 +2127,53 @@ x_clipboard_manager_save (struct x_display_info *dpyinfo,
2126 Qnil, frame); 2127 Qnil, frame);
2127} 2128}
2128 2129
2129DEFUN ("x-clipboard-manager-save", Fx_clipboard_manager_save, 2130/* Called from delete_frame: save any clipboard owned by FRAME to the
2130 Sx_clipboard_manager_save, 0, 1, 0, 2131 clipboard manager. Do nothing if FRAME does not own the clipboard,
2131 doc: /* Save the clipboard contents to the clipboard manager. 2132 or if no clipboard manager is present. */
2132This function is intended to run from `delete-frame-functions' and 2133
2133`kill-emacs-hook', to transfer clipboard data owned by Emacs to a 2134void
2134clipboard manager prior to deleting a frame or killing Emacs. 2135x_clipboard_manager_save_frame (Lisp_Object frame)
2135
2136FRAME specifies a frame owning a clipboard; do nothing if FRAME does
2137not own the clipboard, or if no clipboard manager is present. If
2138FRAME is nil, save all clipboard contents owned by Emacs. */)
2139 (Lisp_Object frame)
2140{ 2136{
2141 if (FRAMEP (frame)) 2137 struct frame *f;
2138
2139 if (FRAMEP (frame)
2140 && (f = XFRAME (frame), FRAME_X_P (f))
2141 && FRAME_LIVE_P (f))
2142 { 2142 {
2143 struct frame *f = XFRAME (frame); 2143 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2144 if (FRAME_LIVE_P (f) && FRAME_X_P (f)) 2144 Lisp_Object local_selection
2145 { 2145 = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
2146 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 2146
2147 Lisp_Object local_selection 2147 if (!NILP (local_selection)
2148 = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); 2148 && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection)))))
2149 2149 && XGetSelectionOwner (dpyinfo->display,
2150 if (!NILP (local_selection) 2150 dpyinfo->Xatom_CLIPBOARD_MANAGER))
2151 && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection))))) 2151 x_clipboard_manager_save (dpyinfo, frame);
2152 && XGetSelectionOwner (dpyinfo->display,
2153 dpyinfo->Xatom_CLIPBOARD_MANAGER))
2154 x_clipboard_manager_save (dpyinfo, frame);
2155 }
2156 } 2152 }
2157 else if (NILP (frame)) 2153}
2154
2155/* Called from Fkill_emacs: save any clipboard owned by FRAME to the
2156 clipboard manager. Do nothing if FRAME does not own the clipboard,
2157 or if no clipboard manager is present. */
2158
2159void
2160x_clipboard_manager_save_all (void)
2161{
2162 /* Loop through all X displays, saving owned clipboards. */
2163 struct x_display_info *dpyinfo;
2164 Lisp_Object local_selection, local_frame;
2165 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
2158 { 2166 {
2159 /* Loop through all X displays, saving owned clipboards. */ 2167 local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
2160 struct x_display_info *dpyinfo; 2168 if (NILP (local_selection)
2161 Lisp_Object local_selection, local_frame; 2169 || !XGetSelectionOwner (dpyinfo->display,
2162 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) 2170 dpyinfo->Xatom_CLIPBOARD_MANAGER))
2163 { 2171 continue;
2164 local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
2165 if (NILP (local_selection)
2166 || !XGetSelectionOwner (dpyinfo->display,
2167 dpyinfo->Xatom_CLIPBOARD_MANAGER))
2168 continue;
2169
2170 local_frame = XCAR (XCDR (XCDR (XCDR (local_selection))));
2171 if (FRAME_LIVE_P (XFRAME (local_frame)))
2172 x_clipboard_manager_save (dpyinfo, local_frame);
2173 }
2174 }
2175 2172
2176 return Qnil; 2173 local_frame = XCAR (XCDR (XCDR (XCDR (local_selection))));
2174 if (FRAME_LIVE_P (XFRAME (local_frame)))
2175 x_clipboard_manager_save (dpyinfo, local_frame);
2176 }
2177} 2177}
2178 2178
2179 2179
@@ -2586,7 +2586,6 @@ syms_of_xselect (void)
2586 defsubr (&Sx_disown_selection_internal); 2586 defsubr (&Sx_disown_selection_internal);
2587 defsubr (&Sx_selection_owner_p); 2587 defsubr (&Sx_selection_owner_p);
2588 defsubr (&Sx_selection_exists_p); 2588 defsubr (&Sx_selection_exists_p);
2589 defsubr (&Sx_clipboard_manager_save);
2590 2589
2591 defsubr (&Sx_get_atom_name); 2590 defsubr (&Sx_get_atom_name);
2592 defsubr (&Sx_send_client_message); 2591 defsubr (&Sx_send_client_message);
diff --git a/src/xterm.h b/src/xterm.h
index c44978d5386..2184794af4e 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1024,6 +1024,7 @@ extern Lisp_Object x_property_data_to_lisp (struct frame *,
1024 Atom, 1024 Atom,
1025 int, 1025 int,
1026 unsigned long); 1026 unsigned long);
1027extern void x_clipboard_manager_save_frame (Lisp_Object);
1027 1028
1028/* Defined in xfns.c */ 1029/* Defined in xfns.c */
1029 1030