From efcb54b78cfc4f396531cdac6af37e183bc9ee53 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 12 Feb 2012 01:35:10 +0100 Subject: [PATCH] updated for version 7.3.440 Problem: Vim does not support UTF8_STRING for the X selection. Solution: Add UTF8_STRING atom support. (Alex Efros) Use it only when 'encoding' is set to Unicode. --- src/ui.c | 43 +++++++++++++++++++++++++++++++++---------- src/version.c | 2 ++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/ui.c b/src/ui.c index 7322f15f0..4c4c2eefb 100644 --- a/src/ui.c +++ b/src/ui.c @@ -1917,6 +1917,7 @@ open_app_context() static Atom vim_atom; /* Vim's own special selection format */ #ifdef FEAT_MBYTE static Atom vimenc_atom; /* Vim's extended selection format */ +static Atom utf8_atom; #endif static Atom compound_text_atom; static Atom text_atom; @@ -1930,6 +1931,7 @@ x11_setup_atoms(dpy) vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False); #ifdef FEAT_MBYTE vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False); + utf8_atom = XInternAtom(dpy, "UTF8_STRING", False); #endif compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); text_atom = XInternAtom(dpy, "TEXT", False); @@ -2074,7 +2076,11 @@ clip_x11_request_selection_cb(w, success, sel_atom, type, value, length, } #endif - else if (*type == compound_text_atom || ( + else if (*type == compound_text_atom +#ifdef FEAT_MBYTE + || *type == utf8_atom +#endif + || ( #ifdef FEAT_MBYTE enc_dbcs != 0 && #endif @@ -2128,7 +2134,7 @@ clip_x11_request_selection(myShell, dpy, cbd) #else 1 #endif - ; i < 5; i++) + ; i < 6; i++) { switch (i) { @@ -2136,10 +2142,18 @@ clip_x11_request_selection(myShell, dpy, cbd) case 0: type = vimenc_atom; break; #endif case 1: type = vim_atom; break; - case 2: type = compound_text_atom; break; - case 3: type = text_atom; break; +#ifdef FEAT_MBYTE + case 2: type = utf8_atom; break; +#endif + case 3: type = compound_text_atom; break; + case 4: type = text_atom; break; default: type = XA_STRING; } +#ifdef FEAT_MBYTE + if (type == utf8_atom && !enc_utf8) + /* Only request utf-8 when 'encoding' is utf8. */ + continue; +#endif success = MAYBE; XtGetSelectionValue(myShell, cbd->sel_atom, type, clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); @@ -2230,18 +2244,23 @@ clip_x11_convert_selection_cb(w, sel_atom, target, type, value, length, format) { Atom *array; - if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 6))) == NULL) + if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 7))) == NULL) return False; *value = (XtPointer)array; i = 0; - array[i++] = XA_STRING; array[i++] = targets_atom; #ifdef FEAT_MBYTE array[i++] = vimenc_atom; #endif array[i++] = vim_atom; +#ifdef FEAT_MBYTE + if (enc_utf8) + array[i++] = utf8_atom; +#endif + array[i++] = XA_STRING; array[i++] = text_atom; array[i++] = compound_text_atom; + *type = XA_ATOM; /* This used to be: *format = sizeof(Atom) * 8; but that caused * crashes on 64 bit machines. (Peter Derr) */ @@ -2253,6 +2272,7 @@ clip_x11_convert_selection_cb(w, sel_atom, target, type, value, length, format) if ( *target != XA_STRING #ifdef FEAT_MBYTE && *target != vimenc_atom + && *target != utf8_atom #endif && *target != vim_atom && *target != text_atom @@ -2282,13 +2302,16 @@ clip_x11_convert_selection_cb(w, sel_atom, target, type, value, length, format) return False; } - if (*target == XA_STRING) + if (*target == XA_STRING +#ifdef FEAT_MBYTE + || (*target == utf8_atom && enc_utf8) +#endif + ) { mch_memmove(result, string, (size_t)(*length)); - *type = XA_STRING; + *type = *target; } - else if (*target == compound_text_atom - || *target == text_atom) + else if (*target == compound_text_atom || *target == text_atom) { XTextProperty text_prop; char *string_nt = (char *)alloc((unsigned)*length + 1); diff --git a/src/version.c b/src/version.c index 22a799826..251966446 100644 --- a/src/version.c +++ b/src/version.c @@ -714,6 +714,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 440, /**/ 439, /**/ -- 2.40.0