X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=ioncore%2Fselection.c;h=896a415bc64a3c112ec98da0fda3203e5cbf258d;hp=4bb8cd74bec2e9d64fe7ff20c6572f1c61eeb2c6;hb=HEAD;hpb=8366314611bf30a0f31d25bf5f5023186fa87692 diff --git a/ioncore/selection.c b/ioncore/selection.c index 4bb8cd7..896a415 100644 --- a/ioncore/selection.c +++ b/ioncore/selection.c @@ -1,12 +1,9 @@ /* * ion/ioncore/selection.c * - * Copyright (c) Tuomo Valkonen 1999-2006. + * Copyright (c) Tuomo Valkonen 1999-2009. * - * Ion is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. + * See the included file LICENSE for details. */ #include @@ -24,24 +21,66 @@ static int selection_length; static bool continuation_set=FALSE; static ExtlFn continuation; +#define CLIPATOM(X) XA_PRIMARY + +static Atom XA_COMPOUND_TEXT(Display *unused) +{ + static Atom a=None; + + if(a==None) + a=XInternAtom(ioncore_g.dpy, "COMPOUND_TEXT", False); + + return a; +} + + void ioncore_handle_selection_request(XSelectionRequestEvent *ev) { XSelectionEvent sev; + XTextProperty prop; const char *p[1]; + bool ok=FALSE; - if(selection_data==NULL) - return; + sev.property=None; + + if(selection_data==NULL || ev->property==None) + goto refuse; p[0]=selection_data; - xwindow_set_text_property(ev->requestor, ev->property, p, 1); + if(!ioncore_g.use_mb && ev->target==XA_STRING){ + Status st=XStringListToTextProperty((char **)p, 1, &prop); + ok=(st!=0); + }else if(ioncore_g.use_mb){ + XICCEncodingStyle style; + + if(ev->target==XA_STRING){ + style=XStringStyle; + ok=TRUE; + }else if(ev->target==XA_COMPOUND_TEXT(ioncore_g.dpy)){ + style=XCompoundTextStyle; + ok=TRUE; + } + + if(ok){ + int st=XmbTextListToTextProperty(ioncore_g.dpy, (char **)p, 1, + style, &prop); + ok=(st>=0); + } + } + if(ok){ + XSetTextProperty(ioncore_g.dpy, ev->requestor, &prop, ev->property); + sev.property=ev->property; + XFree(prop.value); + } + +refuse: sev.type=SelectionNotify; sev.requestor=ev->requestor; sev.selection=ev->selection; sev.target=ev->target; sev.time=ev->time; - sev.property=ev->property; XSendEvent(ioncore_g.dpy, ev->requestor, False, 0L, (XEvent*)&sev); } @@ -72,29 +111,13 @@ static void insert_selection(Window win, Atom prop) } -static void insert_cutbuffer(Window win) -{ - char *p; - int n; - - p=XFetchBytes(ioncore_g.dpy, &n); - - if(n<=0 || p==NULL) - return; - - ins(win, p, n); -} - - void ioncore_handle_selection(XSelectionEvent *ev) { Atom prop=ev->property; Window win=ev->requestor; WWindow *wwin; - if(prop==None){ - insert_cutbuffer(win); - }else{ + if(prop!=None){ insert_selection(win, prop); XDeleteProperty(ioncore_g.dpy, win, prop); } @@ -129,9 +152,7 @@ void ioncore_set_selection_n(const char *p, int n) selection_data[n]='\0'; selection_length=n; - XStoreBytes(ioncore_g.dpy, p, n); - - XSetSelectionOwner(ioncore_g.dpy, XA_PRIMARY, + XSetSelectionOwner(ioncore_g.dpy, CLIPATOM(ioncore_g.dpy), DefaultRootWindow(ioncore_g.dpy), CurrentTime); } @@ -159,15 +180,10 @@ void ioncore_request_selection_for(Window win) continuation_set=FALSE; } - if(ioncore_g.use_mb){ -#ifdef X_HAVE_UTF8_STRING - a=XInternAtom(ioncore_g.dpy, "UTF8_STRING", True); -#else - a=XInternAtom(ioncore_g.dpy, "COMPOUND_TEXT", True); -#endif - } + if(ioncore_g.use_mb) + a=XA_COMPOUND_TEXT(ioncore_g.dpy); - XConvertSelection(ioncore_g.dpy, XA_PRIMARY, a, + XConvertSelection(ioncore_g.dpy, CLIPATOM(ioncore_g.dpy), a, ioncore_g.atom_selection, win, CurrentTime); }