From 1bcfa73217c46e34de776417ded5003625e1705f Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Wed, 15 Nov 2000 22:21:02 +0000 Subject: [PATCH] Wed Nov 15 14:20:13 PST 2000 Michael Jennings As requested by Chris Morton , I added support for the SunCut, SunCopy, SunPaste, and SunFront keys. The 1st 3 operate on the xclipboard-managed "ClipBoard" buffer. The SunFront key will activate Eterm's "steal focus" mechanism. SVN revision: 3891 --- ChangeLog | 8 ++++++++ src/screen.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- src/screen.h | 11 +++++++++++ src/term.c | 8 ++++++-- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18a99cb..6596ae0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3969,3 +3969,11 @@ Tue Nov 14 17:17:53 PST 2000 Michael Jennings this will not work with those themes. ------------------------------------------------------------------------------- +Wed Nov 15 14:20:13 PST 2000 Michael Jennings + + As requested by Chris Morton , I added + support for the SunCut, SunCopy, SunPaste, and SunFront keys. The 1st + 3 operate on the xclipboard-managed "ClipBoard" buffer. The SunFront + key will activate Eterm's "steal focus" mechanism. + +------------------------------------------------------------------------------- diff --git a/src/screen.c b/src/screen.c index 6d0e17a..2a2d253 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2364,7 +2364,7 @@ PasteIt(unsigned char *data, unsigned int nitems) * EXT: SelectionNotify */ void -selection_paste(Window win, unsigned prop, int Delete) +selection_paste(Window win, unsigned prop, int delete) { long nread; unsigned long bytes_after, nitems; @@ -2375,7 +2375,7 @@ selection_paste(Window win, unsigned prop, int Delete) if (prop == None) return; for (nread = 0, bytes_after = 1; bytes_after > 0;) { - if ((XGetWindowProperty(Xdisplay, win, prop, (nread / 4), PROP_SIZE, Delete, AnyPropertyType, &actual_type, &actual_fmt, &nitems, &bytes_after, &data) != Success)) { + if ((XGetWindowProperty(Xdisplay, win, prop, (nread / 4), PROP_SIZE, delete, AnyPropertyType, &actual_type, &actual_fmt, &nitems, &bytes_after, &data) != Success)) { if (data != NULL) { XFree(data); } @@ -2441,6 +2441,46 @@ selection_request(Time tm, int x, int y) } } +void +selection_copy(Atom selection, Atom prop, char *str, size_t len) +{ + XSetSelectionOwner(Xdisplay, selection, TermWin.vt, CurrentTime); + if (XGetSelectionOwner(Xdisplay, XA_PRIMARY) != TermWin.vt) { + print_error("Can't take ownership of primary selection\n"); + } + XChangeProperty(Xdisplay, Xroot, prop, XA_STRING, 8, PropModeReplace, str, len); +} + +void +selection_copy_to_clipboard(void) +{ + if (selection.text) { + selection_copy(X_CLIPBOARD_SELECTION, X_CLIPBOARD_PROP, selection.text, selection.len); + } +} + +void +selection_paste_from_clipboard(void) +{ + Atom select, type; + + select = X_CLIPBOARD_SELECTION; + if (XGetSelectionOwner(Xdisplay, select) == None) { + selection_paste(Xroot, X_CLIPBOARD_PROP, False); + } else { + type = XInternAtom(Xdisplay, "VT_SELECTION", False); +#if defined(MULTI_CHARSET) && defined(HAVE_X11_XMU_ATOMS_H) + if (encoding_method != LATIN1) { + XConvertSelection(Xdisplay, select, XA_COMPOUND_TEXT(Xdisplay), type, TermWin.vt, CurrentTime); + } else { + XConvertSelection(Xdisplay, select, XA_STRING, type, TermWin.vt, CurrentTime); + } +#else + XConvertSelection(Xdisplay, select, XA_STRING, type, TermWin.vt, CurrentTime); +#endif + } +} + /* * Clear the current selection from the screen rendition list */ @@ -2664,12 +2704,10 @@ selection_make(Time tm) selection.text = new_selection_text; selection.screen = current_screen; - XSetSelectionOwner(Xdisplay, XA_PRIMARY, TermWin.vt, tm); - if (XGetSelectionOwner(Xdisplay, XA_PRIMARY) != TermWin.vt) - print_error("can't get primary selection\n"); - XChangeProperty(Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, - PropModeReplace, selection.text, selection.len); + selection_copy(XA_PRIMARY, XA_CUT_BUFFER0, selection.text, selection.len); D_SELECT(("selection.len=%d\n", selection.len)); + return; + tm = 0; } /* diff --git a/src/screen.h b/src/screen.h index 462fa7f..d678aeb 100644 --- a/src/screen.h +++ b/src/screen.h @@ -16,6 +16,14 @@ #include #include "startup.h" +#ifdef XA_CLIPBOARD +# define X_CLIPBOARD_SELECTION XA_CLIPBOARD(Xdisplay) +# define X_CLIPBOARD_PROP XA_CLIPBOARD(Xdisplay) +#else +# define X_CLIPBOARD_SELECTION XA_PRIMARY +# define X_CLIPBOARD_PROP XA_CUT_BUFFER0 +#endif + /************ Macros and Definitions ************/ #define WRAP_CHAR (MAX_COLS + 1) #define PROP_SIZE 4096 @@ -279,6 +287,9 @@ extern void selection_check(void); extern void PasteIt(unsigned char *, unsigned int); extern void selection_paste(Window, unsigned, int); extern void selection_request(Time, int, int); +extern void selection_copy(Atom, Atom, char *, size_t); +extern void selection_copy_to_clipboard(void); +extern void selection_paste_from_clipboard(void); extern void selection_reset(void); extern void selection_clear(void); extern void selection_setclr(int, int, int, int, int); diff --git a/src/term.c b/src/term.c index 29f8cf2..8f7963a 100644 --- a/src/term.c +++ b/src/term.c @@ -296,16 +296,20 @@ lookup_key(XEvent * ev) } #endif -#ifdef HAVE_X11_SUNKEYSYM_H +#if defined(HAVE_X11_SUNKEYSYM_H) && defined(HAVE_X11_XMU_ATOMS_H) switch (keysym) { case SunXK_Copy: case SunXK_Cut: + selection_copy_to_clipboard(); + LK_RET(); break; case SunXK_Paste: - selection_request(ev->xkey.time, ev->xkey.x, ev->xkey.y); + selection_paste_from_clipboard(); LK_RET(); break; case SunXK_Front: + xterm_seq(XTerm_Takeover, ""); + LK_RET(); break; default: break;