diff options
| author | Chong Yidong | 2011-06-04 17:02:42 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-06-04 17:02:42 -0400 |
| commit | 4b80f6746dc824f1ec36a96abe684480ed06e62e (patch) | |
| tree | 7d00f349f4c2722d315a673aeb4692141d227457 /src | |
| parent | 99a33b77e15b9a075024701d060d912b2fd87caf (diff) | |
| download | emacs-4b80f6746dc824f1ec36a96abe684480ed06e62e.tar.gz emacs-4b80f6746dc824f1ec36a96abe684480ed06e62e.zip | |
Handle errors when saving to clipboard manager (Bug#8779).
* src/xselect.c (x_clipboard_manager_save): Remove redundant arg.
(x_clipboard_manager_save): Add return value.
(x_clipboard_manager_error_1, x_clipboard_manager_error_2): New
error handlers.
(x_clipboard_manager_save_frame, x_clipboard_manager_save_all):
Obey Vx_select_enable_clipboard_manager. Catch errors in
x_clipboard_manager_save (Bug#8779).
(Vx_select_enable_clipboard_manager): New variable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 11 | ||||
| -rw-r--r-- | src/xselect.c | 57 |
2 files changed, 59 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2ce41e3b35b..a75fecc3d8e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2011-06-04 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * xselect.c (x_clipboard_manager_save): Remove redundant arg. | ||
| 4 | (x_clipboard_manager_save): Add return value. | ||
| 5 | (x_clipboard_manager_error_1, x_clipboard_manager_error_2): New | ||
| 6 | error handlers. | ||
| 7 | (x_clipboard_manager_save_frame, x_clipboard_manager_save_all): | ||
| 8 | Obey Vx_select_enable_clipboard_manager. Catch errors in | ||
| 9 | x_clipboard_manager_save (Bug#8779). | ||
| 10 | (Vx_select_enable_clipboard_manager): New variable. | ||
| 11 | |||
| 1 | 2011-06-04 Dan Nicolaescu <dann@ics.uci.edu> | 12 | 2011-06-04 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 13 | ||
| 3 | * emacs.c (main): Warn when starting a GTK emacs in daemon mode. | 14 | * emacs.c (main): Warn when starting a GTK emacs in daemon mode. |
diff --git a/src/xselect.c b/src/xselect.c index 73ef4abc0a4..4e7c28fc9d8 100644 --- a/src/xselect.c +++ b/src/xselect.c | |||
| @@ -2108,15 +2108,14 @@ frame's display, or the first available X display. */) | |||
| 2108 | } | 2108 | } |
| 2109 | 2109 | ||
| 2110 | 2110 | ||
| 2111 | /* Send the clipboard manager a SAVE_TARGETS request with a | 2111 | /* Send clipboard manager a SAVE_TARGETS request with a UTF8_STRING |
| 2112 | UTF8_STRING property, as described by | 2112 | property (http://www.freedesktop.org/wiki/ClipboardManager). */ |
| 2113 | http://www.freedesktop.org/wiki/ClipboardManager */ | ||
| 2114 | 2113 | ||
| 2115 | static void | 2114 | static Lisp_Object |
| 2116 | x_clipboard_manager_save (struct x_display_info *dpyinfo, | 2115 | x_clipboard_manager_save (Lisp_Object frame) |
| 2117 | Lisp_Object frame) | ||
| 2118 | { | 2116 | { |
| 2119 | struct frame *f = XFRAME (frame); | 2117 | struct frame *f = XFRAME (frame); |
| 2118 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | ||
| 2120 | Atom data = dpyinfo->Xatom_UTF8_STRING; | 2119 | Atom data = dpyinfo->Xatom_UTF8_STRING; |
| 2121 | 2120 | ||
| 2122 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 2121 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
| @@ -2125,6 +2124,31 @@ x_clipboard_manager_save (struct x_display_info *dpyinfo, | |||
| 2125 | (unsigned char *) &data, 1); | 2124 | (unsigned char *) &data, 1); |
| 2126 | x_get_foreign_selection (QCLIPBOARD_MANAGER, QSAVE_TARGETS, | 2125 | x_get_foreign_selection (QCLIPBOARD_MANAGER, QSAVE_TARGETS, |
| 2127 | Qnil, frame); | 2126 | Qnil, frame); |
| 2127 | return Qt; | ||
| 2128 | } | ||
| 2129 | |||
| 2130 | /* Error handler for x_clipboard_manager_save_frame. */ | ||
| 2131 | |||
| 2132 | static Lisp_Object | ||
| 2133 | x_clipboard_manager_error_1 (Lisp_Object err) | ||
| 2134 | { | ||
| 2135 | Lisp_Object args[2]; | ||
| 2136 | args[0] = build_string ("X clipboard manager error: %s\n\ | ||
| 2137 | If the problem persists, set `x-select-enable-clipboard-manager' to nil."); | ||
| 2138 | args[1] = CAR (CDR (err)); | ||
| 2139 | Fmessage (2, args); | ||
| 2140 | return Qnil; | ||
| 2141 | } | ||
| 2142 | |||
| 2143 | /* Error handler for x_clipboard_manager_save_all. */ | ||
| 2144 | |||
| 2145 | static Lisp_Object | ||
| 2146 | x_clipboard_manager_error_2 (Lisp_Object err) | ||
| 2147 | { | ||
| 2148 | fprintf (stderr, "Error saving to X clipboard manager.\n\ | ||
| 2149 | If the problem persists, set `x-select-enable-clipboard-manager' \ | ||
| 2150 | to nil.\n"); | ||
| 2151 | return Qnil; | ||
| 2128 | } | 2152 | } |
| 2129 | 2153 | ||
| 2130 | /* Called from delete_frame: save any clipboard owned by FRAME to the | 2154 | /* Called from delete_frame: save any clipboard owned by FRAME to the |
| @@ -2136,7 +2160,8 @@ x_clipboard_manager_save_frame (Lisp_Object frame) | |||
| 2136 | { | 2160 | { |
| 2137 | struct frame *f; | 2161 | struct frame *f; |
| 2138 | 2162 | ||
| 2139 | if (FRAMEP (frame) | 2163 | if (!NILP (Vx_select_enable_clipboard_manager) |
| 2164 | && FRAMEP (frame) | ||
| 2140 | && (f = XFRAME (frame), FRAME_X_P (f)) | 2165 | && (f = XFRAME (frame), FRAME_X_P (f)) |
| 2141 | && FRAME_LIVE_P (f)) | 2166 | && FRAME_LIVE_P (f)) |
| 2142 | { | 2167 | { |
| @@ -2148,7 +2173,8 @@ x_clipboard_manager_save_frame (Lisp_Object frame) | |||
| 2148 | && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection))))) | 2173 | && EQ (frame, XCAR (XCDR (XCDR (XCDR (local_selection))))) |
| 2149 | && XGetSelectionOwner (dpyinfo->display, | 2174 | && XGetSelectionOwner (dpyinfo->display, |
| 2150 | dpyinfo->Xatom_CLIPBOARD_MANAGER)) | 2175 | dpyinfo->Xatom_CLIPBOARD_MANAGER)) |
| 2151 | x_clipboard_manager_save (dpyinfo, frame); | 2176 | internal_condition_case_1 (x_clipboard_manager_save, frame, Qt, |
| 2177 | x_clipboard_manager_error_1); | ||
| 2152 | } | 2178 | } |
| 2153 | } | 2179 | } |
| 2154 | 2180 | ||
| @@ -2162,6 +2188,10 @@ x_clipboard_manager_save_all (void) | |||
| 2162 | /* Loop through all X displays, saving owned clipboards. */ | 2188 | /* Loop through all X displays, saving owned clipboards. */ |
| 2163 | struct x_display_info *dpyinfo; | 2189 | struct x_display_info *dpyinfo; |
| 2164 | Lisp_Object local_selection, local_frame; | 2190 | Lisp_Object local_selection, local_frame; |
| 2191 | |||
| 2192 | if (NILP (Vx_select_enable_clipboard_manager)) | ||
| 2193 | return; | ||
| 2194 | |||
| 2165 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | 2195 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) |
| 2166 | { | 2196 | { |
| 2167 | local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); | 2197 | local_selection = LOCAL_SELECTION (QCLIPBOARD, dpyinfo); |
| @@ -2172,7 +2202,8 @@ x_clipboard_manager_save_all (void) | |||
| 2172 | 2202 | ||
| 2173 | local_frame = XCAR (XCDR (XCDR (XCDR (local_selection)))); | 2203 | local_frame = XCAR (XCDR (XCDR (XCDR (local_selection)))); |
| 2174 | if (FRAME_LIVE_P (XFRAME (local_frame))) | 2204 | if (FRAME_LIVE_P (XFRAME (local_frame))) |
| 2175 | x_clipboard_manager_save (dpyinfo, local_frame); | 2205 | internal_condition_case_1 (x_clipboard_manager_save, local_frame, |
| 2206 | Qt, x_clipboard_manager_error_2); | ||
| 2176 | } | 2207 | } |
| 2177 | } | 2208 | } |
| 2178 | 2209 | ||
| @@ -2641,6 +2672,14 @@ This hook doesn't let you change the behavior of Emacs's selection replies, | |||
| 2641 | it merely informs you that they have happened. */); | 2672 | it merely informs you that they have happened. */); |
| 2642 | Vx_sent_selection_functions = Qnil; | 2673 | Vx_sent_selection_functions = Qnil; |
| 2643 | 2674 | ||
| 2675 | DEFVAR_LISP ("x-select-enable-clipboard-manager", | ||
| 2676 | Vx_select_enable_clipboard_manager, | ||
| 2677 | doc: /* Whether to enable X clipboard manager support. | ||
| 2678 | If non-nil, then whenever Emacs is killed or an Emacs frame is deleted | ||
| 2679 | while owning the X clipboard, the clipboard contents are saved to the | ||
| 2680 | clipboard manager if one is present. */); | ||
| 2681 | Vx_select_enable_clipboard_manager = Qt; | ||
| 2682 | |||
| 2644 | DEFVAR_INT ("x-selection-timeout", x_selection_timeout, | 2683 | DEFVAR_INT ("x-selection-timeout", x_selection_timeout, |
| 2645 | doc: /* Number of milliseconds to wait for a selection reply. | 2684 | doc: /* Number of milliseconds to wait for a selection reply. |
| 2646 | If the selection owner doesn't reply in this time, we give up. | 2685 | If the selection owner doesn't reply in this time, we give up. |