*
* Copyright (c) Tuomo Valkonen 1999-2007.
*
- * 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 <X11/Xmd.h>
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);
}
}
-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);
}
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);
}
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);
}