/* X Selection processing for Emacs.
Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003,
- 2004, 2005, 2006 Free Software Foundation, Inc.
+ 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
static Lisp_Object Vx_lost_selection_functions;
static Lisp_Object Vx_sent_selection_functions;
-/* Coding system for communicating with other X clients via cutbuffer,
- selection, and clipboard. */
-static Lisp_Object Vselection_coding_system;
-
-/* Coding system for the next communicating with other X clients. */
-static Lisp_Object Vnext_selection_coding_system;
-
static Lisp_Object Qforeign_selection;
/* If this is a smaller number than the max-request-size of the display,
incremental transfer stuff, but it might improve server performance. */
#define MAX_SELECTION_QUANTUM 0xFFFFFF
-#ifdef HAVE_X11R4
#define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100)
-#else
-#define SELECTION_QUANTUM(dpy) (((dpy)->max_request_size << 2) - 100)
-#endif
/* The timestamp of the last input event Emacs received from the X server. */
/* Defined in keyboard.c. */
if (!NILP (prev_value))
{
Lisp_Object rest; /* we know it's not the CAR, so it's easy. */
- for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
+ for (rest = Vselection_alist; CONSP (rest); rest = XCDR (rest))
if (EQ (prev_value, Fcar (XCDR (rest))))
{
XSETCDR (rest, Fcdr (XCDR (rest)));
DATA and SIZE describe the data to send, already converted.
FORMAT is the unit-size (in bits) of the data to be transmitted. */
+#ifdef TRACE_SELECTION
+static int x_reply_selection_request_cnt;
+#endif /* TRACE_SELECTION */
+
static void
x_reply_selection_request (event, format, data, size, type)
struct input_event *event;
#ifdef TRACE_SELECTION
{
- static int cnt;
char *sel = XGetAtomName (display, reply.selection);
char *tgt = XGetAtomName (display, reply.target);
- TRACE3 ("%s, target %s (%d)", sel, tgt, ++cnt);
+ TRACE3 ("%s, target %s (%d)", sel, tgt, ++x_reply_selection_request_cnt);
if (sel) XFree (sel);
if (tgt) XFree (tgt);
}
break;
/* Now wait for the requester to ack this chunk by deleting the
- property. This can run random lisp code or signal. */
+ property. This can run random lisp code or signal. */
TRACE1 ("Waiting for increment ACK (deletion of %s)",
XGetAtomName (display, reply.property));
wait_for_property_change (wait_object);
Atom type;
int nofree;
+ if (CONSP (converted_selection) && NILP (XCDR (converted_selection)))
+ {
+ x_decline_selection_request (event);
+ goto DONE2;
+ }
+
lisp_data_to_selection_data (SELECTION_EVENT_DISPLAY (event),
converted_selection,
&data, &type, &size, &format, &nofree);
if (!nofree)
xfree (data);
}
+
+ DONE2:
unbind_to (count, Qnil);
DONE:
TRACE0 ("x_handle_selection_clear");
+#ifdef MULTI_KBOARD
/* If the new selection owner is also Emacs,
don't clear the new selection. */
BLOCK_INPUT;
}
}
UNBLOCK_INPUT;
-
+#endif
+
selection_symbol = x_atom_to_symbol (display, selection);
local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
else
{
Lisp_Object rest;
- for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
+ for (rest = Vselection_alist; CONSP (rest); rest = XCDR (rest))
if (EQ (local_selection_data, Fcar (XCDR (rest))))
{
XSETCDR (rest, Fcdr (XCDR (rest)));
}
/* Delete elements after the beginning of Vselection_alist. */
- for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
+ for (rest = Vselection_alist; CONSP (rest); rest = XCDR (rest))
if (EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest))))))))
{
/* Let random Lisp code notice that the selection has been stolen. */
}
}
- /* Convert a single 16 or small 32 bit number to a Lisp_Int.
- If the number is > 16 bits, convert it to a cons of integers,
- 16 bits in each half.
+ /* Convert a single 16-bit number or a small 32-bit number to a Lisp_Int.
+ If the number is 32 bits and won't fit in a Lisp_Int,
+ convert it to a cons of integers, 16 bits in each half.
*/
else if (format == 32 && size == sizeof (int))
return long_to_cons (((unsigned int *) data) [0]);
ret = make_string (name, strlen (name));
if (atom && name) XFree (name);
- if (NILP (ret)) ret = make_string ("", 0);
+ if (NILP (ret)) ret = empty_unibyte_string;
UNBLOCK_INPUT;
else
error ("ATOM must be a symbol or a string");
- for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
+ for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
if (dpyinfo->x_dnd_atoms[i] == x_atom)
return Qnil;
- if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size)
+ if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size)
{
dpyinfo->x_dnd_atoms_size *= 2;
dpyinfo->x_dnd_atoms = xrealloc (dpyinfo->x_dnd_atoms,
int idata[5];
size_t i;
- for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
+ for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
if (dpyinfo->x_dnd_atoms[i] == event->message_type) break;
if (i == dpyinfo->x_dnd_atoms_length) return 0;
}
vec = Fmake_vector (make_number (4), Qnil);
- AREF (vec, 0) = SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f),
- event->message_type));
- AREF (vec, 1) = frame;
- AREF (vec, 2) = make_number (event->format);
- AREF (vec, 3) = x_property_data_to_lisp (f,
- data,
- event->message_type,
- event->format,
- size);
+ ASET (vec, 0, SYMBOL_NAME (x_atom_to_symbol (FRAME_X_DISPLAY (f),
+ event->message_type)));
+ ASET (vec, 1, frame);
+ ASET (vec, 2, make_number (event->format));
+ ASET (vec, 3, x_property_data_to_lisp (f,
+ data,
+ event->message_type,
+ event->format,
+ size));
mouse_position_for_drop (f, &x, &y);
bufp->kind = DRAG_N_DROP_EVENT;
it merely informs you that they have happened. */);
Vx_sent_selection_functions = Qnil;
- DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
- doc: /* Coding system for communicating with other X clients.
-When sending or receiving text via cut_buffer, selection, and clipboard,
-the text is encoded or decoded by this coding system.
-The default value is `compound-text-with-extensions'. */);
- Vselection_coding_system = intern ("compound-text-with-extensions");
-
- DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
- doc: /* Coding system for the next communication with other X clients.
-Usually, `selection-coding-system' is used for communicating with
-other X clients. But, if this variable is set, it is used for the
-next communication only. After the communication, this variable is
-set to nil. */);
- Vnext_selection_coding_system = Qnil;
-
DEFVAR_INT ("x-selection-timeout", &x_selection_timeout,
doc: /* Number of milliseconds to wait for a selection reply.
If the selection owner doesn't reply in this time, we give up.