} else if (e->type == FocusIn) { Focused(1);
} else if (e->type == FocusOut) { Focused(0);
- } else if (e->type == SelectionNotify) {
- XSelectionEvent* xsn = (XSelectionEvent*)(e);
- if (xsn->property == None) org::xwt::plat::POSIX::clipboard = JvNewStringLatin1("", 0);
- else {
- Atom returntype;
- int returnformat;
- unsigned long numitems;
- unsigned char* ret;
- unsigned long bytes_after;
- XGetWindowProperty(display, xsn->requestor, xsn->property, 0, 4096,
- True, AnyPropertyType, &returntype, &returnformat,
- &numitems, &bytes_after, &ret);
- org::xwt::plat::POSIX::clipboard =
- (returntype == None ? JvNewStringLatin1("", 0) : JvNewStringLatin1((char*)ret, strlen((char*)ret)));
- }
- org::xwt::plat::POSIX::waiting_for_selection_event->release();
-
- } else if (e->type == SelectionRequest) {
- XSelectionRequestEvent* xsr = (XSelectionRequestEvent*)(e);
- XSelectionEvent xsn;
- xsn.type = SelectionNotify;
- xsn.serial = xsr->serial;
- xsn.send_event = True;
- xsn.display = display;
- xsn.requestor = xsr->requestor;
- xsn.selection = xsr->selection;
- xsn.target = xsr->target;
- xsn.property = xsr->property;
- xsn.time = xsr->time;
-
- int len = min(1024, JvGetStringUTFLength(org::xwt::plat::POSIX::clipboard));
- char buf[len + 1];
- JvGetStringUTFRegion(org::xwt::plat::POSIX::clipboard, 0, len, buf);
- buf[len] = '\0';
-
- XChangeProperty(display, xsr->requestor, xsr->property, xsr->target, 8, PropModeReplace, (unsigned char*)buf, len + 1);
- XSendEvent(display, xsr->requestor, True, 0, (XEvent*)(&xsn));
-
} else if (e->type == KeyPress || e->type == KeyRelease) {
XKeyEvent *xbe = (XKeyEvent*)(e);
}
}
+static void dispatchSelectionEvent(XEvent* e) {
+ if (e->type == SelectionNotify) {
+ XSelectionEvent* xsn = (XSelectionEvent*)(e);
+ if (xsn->property == None) org::xwt::plat::POSIX::clipboard = JvNewStringLatin1("", 0);
+ else {
+ Atom returntype;
+ int returnformat;
+ unsigned long numitems;
+ unsigned char* ret;
+ unsigned long bytes_after;
+ XGetWindowProperty(display, xsn->requestor, xsn->property, 0, 4096,
+ True, AnyPropertyType, &returntype, &returnformat,
+ &numitems, &bytes_after, &ret);
+ org::xwt::plat::POSIX::clipboard =
+ (returntype == None ? JvNewStringLatin1("", 0) : JvNewStringLatin1((char*)ret, strlen((char*)ret)));
+ }
+ org::xwt::plat::POSIX::waiting_for_selection_event->release();
+
+ } else if (e->type == SelectionRequest) {
+ XSelectionRequestEvent* xsr = (XSelectionRequestEvent*)(e);
+ XSelectionEvent xsn;
+ xsn.type = SelectionNotify;
+ xsn.serial = xsr->serial;
+ xsn.send_event = True;
+ xsn.display = display;
+ xsn.requestor = xsr->requestor;
+ xsn.selection = xsr->selection;
+ xsn.target = xsr->target;
+ xsn.property = xsr->property;
+ xsn.time = xsr->time;
+
+ int len = min(1024, JvGetStringUTFLength(org::xwt::plat::POSIX::clipboard));
+ char buf[len + 1];
+ JvGetStringUTFRegion(org::xwt::plat::POSIX::clipboard, 0, len, buf);
+ buf[len] = '\0';
+
+ XChangeProperty(display, xsr->requestor, xsr->property, xsr->target, 8, PropModeReplace, (unsigned char*)buf, len + 1);
+ XSendEvent(display, xsr->requestor, True, 0, (XEvent*)(&xsn));
+ }
+}
+
void org::xwt::plat::POSIX::eventThread() {
XEvent e;
while(true) {
XNextEvent(display, &e);
- org::xwt::plat::POSIX$X11Surface* surface =
- (org::xwt::plat::POSIX$X11Surface*)windowToSurfaceMap->get(new java::lang::Long(((XAnyEvent*)&e)->window));
- if (surface != NULL) surface->dispatchEvent((gnu::gcj::RawData*)&e);
+ if (e.type == SelectionNotify || e.type == SelectionRequest) {
+ dispatchSelectionEvent(&e);
+ } else {
+ org::xwt::plat::POSIX$X11Surface* surface =
+ (org::xwt::plat::POSIX$X11Surface*)windowToSurfaceMap->get(new java::lang::Long(((XAnyEvent*)&e)->window));
+ if (surface != NULL) surface->dispatchEvent((gnu::gcj::RawData*)&e);
+ }
}
}