Changed: #1038 Implement copy/paste for Linux

This commit is contained in:
kervala 2010-10-17 23:25:09 +02:00
parent 45a9a519db
commit 5a5ea67ca7

View file

@ -664,7 +664,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
case SelectionNotify: case SelectionNotify:
{ {
Atom target = event.xselection.target; Atom target = event.xselection.target;
Atom actualType = 0; Atom actualType = 0;
int actualFormat = 0; int actualFormat = 0;
unsigned long nitems = 0, bytesLeft = 0; unsigned long nitems = 0, bytesLeft = 0;
@ -673,19 +673,19 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
if (target == XA_TARGETS || target == XA_ATOM) if (target == XA_TARGETS || target == XA_ATOM)
{ {
Atom *supportedTargets = NULL; Atom *supportedTargets = NULL;
// list NeL selection properties // list NeL selection properties
if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&supportedTargets) != Success) if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&supportedTargets) != Success)
return false; return false;
if (bytesLeft > 0) if (bytesLeft > 0)
{ {
nlwarning("Paste: Supported TARGETS list too long."); nlwarning("Paste: Supported TARGETS list too long.");
} }
Atom bestTarget = 0; Atom bestTarget = 0;
sint bestTargetElect = 0; sint bestTargetElect = 0;
// Elect best type // Elect best type
for (uint i=0; i < nitems; i++) for (uint i=0; i < nitems; i++)
{ {
@ -715,22 +715,22 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
nlwarning("Paste buffer is not a text buffer."); nlwarning("Paste buffer is not a text buffer.");
return false; return false;
} }
// request string conversion // request string conversion
XConvertSelection(_dpy, XA_CLIPBOARD, bestTarget, XA_NEL_SEL, _win, CurrentTime); XConvertSelection(_dpy, XA_CLIPBOARD, bestTarget, XA_NEL_SEL, _win, CurrentTime);
} }
else if (target == XA_UTF8_STRING || target == XA_STRING) else if (target == XA_UTF8_STRING || target == XA_STRING)
{ {
uint8 *data = NULL; uint8 *data = NULL;
// get selection // get selection
if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&data) != Success) if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&data) != Success)
return false; return false;
ucstring text; ucstring text;
std::string tmpData = (const char*)data; std::string tmpData = (const char*)data;
XFree(data); XFree(data);
// convert buffer to ucstring // convert buffer to ucstring
if (target == XA_UTF8_STRING) if (target == XA_UTF8_STRING)
{ {
@ -752,17 +752,17 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
{ {
nlwarning("Unknow target %u", (uint)target); nlwarning("Unknow target %u", (uint)target);
} }
break; break;
} }
case FocusIn: case FocusIn:
// keyboard focus // keyboard focus
server->postEvent (new CEventSetFocus (true, this)); // server->postEvent (new CEventSetFocus (true, this));
if (_ic) XSetICFocus(_ic); if (_ic) XSetICFocus(_ic);
break; break;
case FocusOut: case FocusOut:
// keyboard focus // keyboard focus
server->postEvent (new CEventSetFocus (false, this)); // server->postEvent (new CEventSetFocus (false, this));
if (_ic) XUnsetICFocus(_ic); if (_ic) XUnsetICFocus(_ic);
break; break;
case KeymapNotify: case KeymapNotify:
@ -776,10 +776,10 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
createIM(); createIM();
break; break;
case ClientMessage: case ClientMessage:
if ((xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) // if ((xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW))
{ // {
server->postEvent (new CEventDestroyWindow (this)); // server->postEvent (new CEventDestroyWindow (this));
} // }
break; break;
default: default:
// nlinfo("UnknownEvent"); // nlinfo("UnknownEvent");