aboutsummaryrefslogtreecommitdiffstats
path: root/src/xselect.c
diff options
context:
space:
mode:
authorStefan Monnier2010-09-13 16:40:48 +0200
committerStefan Monnier2010-09-13 16:40:48 +0200
commitcc390e46c7ba95b76ea133d98fd386214cd01709 (patch)
treeead4400d22bd07214b782ff7e46e79d473fac419 /src/xselect.c
parentc566235d981eba73c88bbff00b6a1d88360b6e9f (diff)
parentc5fe4acb5fb456d6e8e147d8bc7981ce56c5c03d (diff)
downloademacs-cc390e46c7ba95b76ea133d98fd386214cd01709.tar.gz
emacs-cc390e46c7ba95b76ea133d98fd386214cd01709.zip
Merge from trunk
Diffstat (limited to 'src/xselect.c')
-rw-r--r--src/xselect.c248
1 files changed, 3 insertions, 245 deletions
diff --git a/src/xselect.c b/src/xselect.c
index 9f15c7c2d99..7479f245a77 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -83,8 +83,6 @@ static void lisp_data_to_selection_data (Display *, Lisp_Object,
83 unsigned char **, Atom *, 83 unsigned char **, Atom *,
84 unsigned *, int *, int *); 84 unsigned *, int *, int *);
85static Lisp_Object clean_local_selection_data (Lisp_Object); 85static Lisp_Object clean_local_selection_data (Lisp_Object);
86static void initialize_cut_buffers (Display *, Window);
87
88 86
89/* Printing traces to stderr. */ 87/* Printing traces to stderr. */
90 88
@@ -105,9 +103,7 @@ static void initialize_cut_buffers (Display *, Window);
105#endif 103#endif
106 104
107 105
108#define CUT_BUFFER_SUPPORT 106Lisp_Object QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP,
109
110Lisp_Object QPRIMARY, QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP,
111 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL, 107 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL,
112 QATOM_PAIR; 108 QATOM_PAIR;
113 109
@@ -116,11 +112,6 @@ Lisp_Object QUTF8_STRING; /* This is a type of selection. */
116 112
117Lisp_Object Qcompound_text_with_extensions; 113Lisp_Object Qcompound_text_with_extensions;
118 114
119#ifdef CUT_BUFFER_SUPPORT
120Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3,
121 QCUT_BUFFER4, QCUT_BUFFER5, QCUT_BUFFER6, QCUT_BUFFER7;
122#endif
123
124static Lisp_Object Vx_lost_selection_functions; 115static Lisp_Object Vx_lost_selection_functions;
125static Lisp_Object Vx_sent_selection_functions; 116static Lisp_Object Vx_sent_selection_functions;
126static Lisp_Object Qforeign_selection; 117static Lisp_Object Qforeign_selection;
@@ -270,16 +261,6 @@ symbol_to_x_atom (struct x_display_info *dpyinfo, Display *display, Lisp_Object
270 if (EQ (sym, QEMACS_TMP)) return dpyinfo->Xatom_EMACS_TMP; 261 if (EQ (sym, QEMACS_TMP)) return dpyinfo->Xatom_EMACS_TMP;
271 if (EQ (sym, QTARGETS)) return dpyinfo->Xatom_TARGETS; 262 if (EQ (sym, QTARGETS)) return dpyinfo->Xatom_TARGETS;
272 if (EQ (sym, QNULL)) return dpyinfo->Xatom_NULL; 263 if (EQ (sym, QNULL)) return dpyinfo->Xatom_NULL;
273#ifdef CUT_BUFFER_SUPPORT
274 if (EQ (sym, QCUT_BUFFER0)) return XA_CUT_BUFFER0;
275 if (EQ (sym, QCUT_BUFFER1)) return XA_CUT_BUFFER1;
276 if (EQ (sym, QCUT_BUFFER2)) return XA_CUT_BUFFER2;
277 if (EQ (sym, QCUT_BUFFER3)) return XA_CUT_BUFFER3;
278 if (EQ (sym, QCUT_BUFFER4)) return XA_CUT_BUFFER4;
279 if (EQ (sym, QCUT_BUFFER5)) return XA_CUT_BUFFER5;
280 if (EQ (sym, QCUT_BUFFER6)) return XA_CUT_BUFFER6;
281 if (EQ (sym, QCUT_BUFFER7)) return XA_CUT_BUFFER7;
282#endif
283 if (!SYMBOLP (sym)) abort (); 264 if (!SYMBOLP (sym)) abort ();
284 265
285 TRACE1 (" XInternAtom %s", (char *) SDATA (SYMBOL_NAME (sym))); 266 TRACE1 (" XInternAtom %s", (char *) SDATA (SYMBOL_NAME (sym)));
@@ -315,24 +296,6 @@ x_atom_to_symbol (Display *dpy, Atom atom)
315 return QINTEGER; 296 return QINTEGER;
316 case XA_ATOM: 297 case XA_ATOM:
317 return QATOM; 298 return QATOM;
318#ifdef CUT_BUFFER_SUPPORT
319 case XA_CUT_BUFFER0:
320 return QCUT_BUFFER0;
321 case XA_CUT_BUFFER1:
322 return QCUT_BUFFER1;
323 case XA_CUT_BUFFER2:
324 return QCUT_BUFFER2;
325 case XA_CUT_BUFFER3:
326 return QCUT_BUFFER3;
327 case XA_CUT_BUFFER4:
328 return QCUT_BUFFER4;
329 case XA_CUT_BUFFER5:
330 return QCUT_BUFFER5;
331 case XA_CUT_BUFFER6:
332 return QCUT_BUFFER6;
333 case XA_CUT_BUFFER7:
334 return QCUT_BUFFER7;
335#endif
336 } 299 }
337 300
338 dpyinfo = x_display_info_for_display (dpy); 301 dpyinfo = x_display_info_for_display (dpy);
@@ -2258,195 +2221,6 @@ and t is the same as `SECONDARY'. */)
2258} 2221}
2259 2222
2260 2223
2261#ifdef CUT_BUFFER_SUPPORT
2262
2263/* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
2264static void
2265initialize_cut_buffers (Display *display, Window window)
2266{
2267 unsigned char *data = (unsigned char *) "";
2268 BLOCK_INPUT;
2269#define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
2270 PropModeAppend, data, 0)
2271 FROB (XA_CUT_BUFFER0);
2272 FROB (XA_CUT_BUFFER1);
2273 FROB (XA_CUT_BUFFER2);
2274 FROB (XA_CUT_BUFFER3);
2275 FROB (XA_CUT_BUFFER4);
2276 FROB (XA_CUT_BUFFER5);
2277 FROB (XA_CUT_BUFFER6);
2278 FROB (XA_CUT_BUFFER7);
2279#undef FROB
2280 UNBLOCK_INPUT;
2281}
2282
2283
2284#define CHECK_CUT_BUFFER(symbol) \
2285 do { CHECK_SYMBOL ((symbol)); \
2286 if (!EQ((symbol), QCUT_BUFFER0) && !EQ((symbol), QCUT_BUFFER1) \
2287 && !EQ((symbol), QCUT_BUFFER2) && !EQ((symbol), QCUT_BUFFER3) \
2288 && !EQ((symbol), QCUT_BUFFER4) && !EQ((symbol), QCUT_BUFFER5) \
2289 && !EQ((symbol), QCUT_BUFFER6) && !EQ((symbol), QCUT_BUFFER7)) \
2290 signal_error ("Doesn't name a cut buffer", (symbol)); \
2291 } while (0)
2292
2293DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal,
2294 Sx_get_cut_buffer_internal, 1, 1, 0,
2295 doc: /* Returns the value of the named cut buffer (typically CUT_BUFFER0). */)
2296 (Lisp_Object buffer)
2297{
2298 Window window;
2299 Atom buffer_atom;
2300 unsigned char *data = NULL;
2301 int bytes;
2302 Atom type;
2303 int format;
2304 unsigned long size;
2305 Lisp_Object ret;
2306 Display *display;
2307 struct x_display_info *dpyinfo;
2308 struct frame *sf = SELECTED_FRAME ();
2309
2310 check_x ();
2311
2312 if (! FRAME_X_P (sf))
2313 return Qnil;
2314
2315 display = FRAME_X_DISPLAY (sf);
2316 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
2317 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2318 CHECK_CUT_BUFFER (buffer);
2319 buffer_atom = symbol_to_x_atom (dpyinfo, display, buffer);
2320
2321 x_get_window_property (display, window, buffer_atom, &data, &bytes,
2322 &type, &format, &size, 0);
2323
2324 if (!data || !format)
2325 {
2326 xfree (data);
2327 return Qnil;
2328 }
2329
2330 if (format != 8 || type != XA_STRING)
2331 signal_error ("Cut buffer doesn't contain 8-bit data",
2332 list2 (x_atom_to_symbol (display, type),
2333 make_number (format)));
2334
2335 ret = (bytes ? make_unibyte_string ((char *) data, bytes) : Qnil);
2336 /* Use xfree, not XFree, because x_get_window_property
2337 calls xmalloc itself. */
2338 xfree (data);
2339 return ret;
2340}
2341
2342
2343DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal,
2344 Sx_store_cut_buffer_internal, 2, 2, 0,
2345 doc: /* Sets the value of the named cut buffer (typically CUT_BUFFER0). */)
2346 (Lisp_Object buffer, Lisp_Object string)
2347{
2348 Window window;
2349 Atom buffer_atom;
2350 unsigned char *data;
2351 int bytes;
2352 int bytes_remaining;
2353 int max_bytes;
2354 Display *display;
2355 struct frame *sf = SELECTED_FRAME ();
2356
2357 check_x ();
2358
2359 if (! FRAME_X_P (sf))
2360 return Qnil;
2361
2362 display = FRAME_X_DISPLAY (sf);
2363 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2364
2365 max_bytes = SELECTION_QUANTUM (display);
2366 if (max_bytes > MAX_SELECTION_QUANTUM)
2367 max_bytes = MAX_SELECTION_QUANTUM;
2368
2369 CHECK_CUT_BUFFER (buffer);
2370 CHECK_STRING (string);
2371 buffer_atom = symbol_to_x_atom (FRAME_X_DISPLAY_INFO (sf),
2372 display, buffer);
2373 data = (unsigned char *) SDATA (string);
2374 bytes = SBYTES (string);
2375 bytes_remaining = bytes;
2376
2377 if (! FRAME_X_DISPLAY_INFO (sf)->cut_buffers_initialized)
2378 {
2379 initialize_cut_buffers (display, window);
2380 FRAME_X_DISPLAY_INFO (sf)->cut_buffers_initialized = 1;
2381 }
2382
2383 BLOCK_INPUT;
2384
2385 /* Don't mess up with an empty value. */
2386 if (!bytes_remaining)
2387 XChangeProperty (display, window, buffer_atom, XA_STRING, 8,
2388 PropModeReplace, data, 0);
2389
2390 while (bytes_remaining)
2391 {
2392 int chunk = (bytes_remaining < max_bytes
2393 ? bytes_remaining : max_bytes);
2394 XChangeProperty (display, window, buffer_atom, XA_STRING, 8,
2395 (bytes_remaining == bytes
2396 ? PropModeReplace
2397 : PropModeAppend),
2398 data, chunk);
2399 data += chunk;
2400 bytes_remaining -= chunk;
2401 }
2402 UNBLOCK_INPUT;
2403 return string;
2404}
2405
2406
2407DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal,
2408 Sx_rotate_cut_buffers_internal, 1, 1, 0,
2409 doc: /* Rotate the values of the cut buffers by N steps.
2410Positive N means shift the values forward, negative means backward. */)
2411 (Lisp_Object n)
2412{
2413 Window window;
2414 Atom props[8];
2415 Display *display;
2416 struct frame *sf = SELECTED_FRAME ();
2417
2418 check_x ();
2419
2420 if (! FRAME_X_P (sf))
2421 return Qnil;
2422
2423 display = FRAME_X_DISPLAY (sf);
2424 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2425 CHECK_NUMBER (n);
2426 if (XINT (n) == 0)
2427 return n;
2428 if (! FRAME_X_DISPLAY_INFO (sf)->cut_buffers_initialized)
2429 {
2430 initialize_cut_buffers (display, window);
2431 FRAME_X_DISPLAY_INFO (sf)->cut_buffers_initialized = 1;
2432 }
2433
2434 props[0] = XA_CUT_BUFFER0;
2435 props[1] = XA_CUT_BUFFER1;
2436 props[2] = XA_CUT_BUFFER2;
2437 props[3] = XA_CUT_BUFFER3;
2438 props[4] = XA_CUT_BUFFER4;
2439 props[5] = XA_CUT_BUFFER5;
2440 props[6] = XA_CUT_BUFFER6;
2441 props[7] = XA_CUT_BUFFER7;
2442 BLOCK_INPUT;
2443 XRotateWindowProperties (display, window, props, 8, XINT (n));
2444 UNBLOCK_INPUT;
2445 return n;
2446}
2447
2448#endif
2449
2450/*********************************************************************** 2224/***********************************************************************
2451 Drag and drop support 2225 Drag and drop support
2452***********************************************************************/ 2226***********************************************************************/
@@ -2596,6 +2370,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2596{ 2370{
2597 struct frame *f = check_x_frame (frame); 2371 struct frame *f = check_x_frame (frame);
2598 char *name = 0; 2372 char *name = 0;
2373 char empty[] = "";
2599 Lisp_Object ret = Qnil; 2374 Lisp_Object ret = Qnil;
2600 Display *dpy = FRAME_X_DISPLAY (f); 2375 Display *dpy = FRAME_X_DISPLAY (f);
2601 Atom atom; 2376 Atom atom;
@@ -2612,7 +2387,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2612 2387
2613 BLOCK_INPUT; 2388 BLOCK_INPUT;
2614 x_catch_errors (dpy); 2389 x_catch_errors (dpy);
2615 name = atom ? XGetAtomName (dpy, atom) : ""; 2390 name = atom ? XGetAtomName (dpy, atom) : empty;
2616 had_errors = x_had_errors_p (dpy); 2391 had_errors = x_had_errors_p (dpy);
2617 x_uncatch_errors (); 2392 x_uncatch_errors ();
2618 2393
@@ -2849,12 +2624,6 @@ syms_of_xselect (void)
2849 defsubr (&Sx_selection_owner_p); 2624 defsubr (&Sx_selection_owner_p);
2850 defsubr (&Sx_selection_exists_p); 2625 defsubr (&Sx_selection_exists_p);
2851 2626
2852#ifdef CUT_BUFFER_SUPPORT
2853 defsubr (&Sx_get_cut_buffer_internal);
2854 defsubr (&Sx_store_cut_buffer_internal);
2855 defsubr (&Sx_rotate_cut_buffers_internal);
2856#endif
2857
2858 defsubr (&Sx_get_atom_name); 2627 defsubr (&Sx_get_atom_name);
2859 defsubr (&Sx_send_client_message); 2628 defsubr (&Sx_send_client_message);
2860 defsubr (&Sx_register_dnd_atom); 2629 defsubr (&Sx_register_dnd_atom);
@@ -2936,17 +2705,6 @@ A value of 0 means wait as long as necessary. This is initialized from the
2936 Qcompound_text_with_extensions = intern_c_string ("compound-text-with-extensions"); 2705 Qcompound_text_with_extensions = intern_c_string ("compound-text-with-extensions");
2937 staticpro (&Qcompound_text_with_extensions); 2706 staticpro (&Qcompound_text_with_extensions);
2938 2707
2939#ifdef CUT_BUFFER_SUPPORT
2940 QCUT_BUFFER0 = intern_c_string ("CUT_BUFFER0"); staticpro (&QCUT_BUFFER0);
2941 QCUT_BUFFER1 = intern_c_string ("CUT_BUFFER1"); staticpro (&QCUT_BUFFER1);
2942 QCUT_BUFFER2 = intern_c_string ("CUT_BUFFER2"); staticpro (&QCUT_BUFFER2);
2943 QCUT_BUFFER3 = intern_c_string ("CUT_BUFFER3"); staticpro (&QCUT_BUFFER3);
2944 QCUT_BUFFER4 = intern_c_string ("CUT_BUFFER4"); staticpro (&QCUT_BUFFER4);
2945 QCUT_BUFFER5 = intern_c_string ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5);
2946 QCUT_BUFFER6 = intern_c_string ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6);
2947 QCUT_BUFFER7 = intern_c_string ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7);
2948#endif
2949
2950 Qforeign_selection = intern_c_string ("foreign-selection"); 2708 Qforeign_selection = intern_c_string ("foreign-selection");
2951 staticpro (&Qforeign_selection); 2709 staticpro (&Qforeign_selection);
2952} 2710}