static void dndPosition(XClientMessageEvent *evt) { dprintf((stderr, "dndPosition\n")); if (xdndSourceWindow != xdndPosition_sourceWindow(evt)) { dprintf((stderr, "dndPosition: wrong source window\n")); return; } { Window root; unsigned int x, y, w, h, b, d; XGetGeometry(stDisplay, stWindow, &root, &x, &y, &w, &h, &b, &d); mousePosition.x= xdndPosition_rootX(evt) - x; mousePosition.y= xdndPosition_rootY(evt) - y; } if (xdndState == XdndStateEntered) { if (xdndWillAccept) recordDragEvent(DragEnter, 1); xdndState= XdndStateTracking; } if (xdndState != XdndStateTracking) { dprintf((stderr, "dndPosition: wrong state\n")); return; } if (xdndWillAccept) { Atom action= xdndPosition_action(evt); dprintf((stderr, " action = %ld %s\n", action, XGetAtomName(stDisplay, action))); xdndWillAccept= (action == XdndActionMove) | (action == XdndActionCopy) | (action == XdndActionLink) | (action == XdndActionAsk); } if (xdndWillAccept) { dprintf((stderr, "accepting\n")); dndSendStatus(evt->window, 1, XdndActionCopy); recordDragEvent(DragMove, 1); } else /* won't accept */ { dprintf((stderr, "not accepting\n")); dndSendStatus(evt->window, 0, XdndActionPrivate); } }
static enum XdndState dndInFinished(enum XdndState state) { fdebugf((stderr, "Internal signal DndInFinished (input)\n")); dndSendFinished(); recordDragEvent(DragLeave, 1); dndInDestroyTypes(); return XdndStateIdle; }
static enum XdndState dndInSelectionNotify(enum XdndState state, XSelectionEvent *evt) { fdebugf((stderr, "Receive SelectionNotify (input)\n")); if (evt->property != XdndSelectionAtom) return state; dndGetSelection(evt->requestor, evt->property); dndSendFinished(); recordDragEvent(DragLeave, 1); return XdndStateIdle; }
static enum XdndState dndInPosition(enum XdndState state, XClientMessageEvent *evt) { /*fdebugf((stderr, "Receive XdndPosition (input)\n"));*/ if (xdndSourceWindow != xdndPosition_sourceWindow(evt)) { fdebugf((stderr, "dndInPosition: wrong source window\n")); return XdndStateIdle; } getMousePosition(); if ((state != XdndStateEntered) && (state != XdndStateTracking)) { fdebugf((stderr, "dndInPosition: wrong state\n")); return XdndStateIdle; } if ((state == XdndStateEntered) && xdndWillAccept) recordDragEvent(DragEnter, 1); if (xdndWillAccept) { Atom action= xdndPosition_action(evt); /*fdebugf((stderr, " dndInPosition: action = %ld %s\n", action, XGetAtomName(stDisplay, action)));*/ xdndWillAccept= (action == XdndActionMove) | (action == XdndActionCopy) | (action == XdndActionLink) | (action == XdndActionAsk); } if (xdndWillAccept) { /*fdebugf((stderr, " dndInPosition: accepting\n"));*/ dndSendStatus(1, XdndActionCopy); recordDragEvent(DragMove, 1); } else /* won't accept */ { /*fdebugf((stderr, " dndInPosition: not accepting\n"));*/ dndSendStatus(0, XdndActionPrivate); } return XdndStateTracking; }
enum XdndState dndInDrop(enum XdndState state, XClientMessageEvent *evt) { fdebugf((stderr, "Receive XdndDrop (input)\n")); /* If there is "text/url-list" in xdndInTypes, the selection is * processed only in DropFilesEvent. But if none (file count == 0), * the selection is handled ClipboardExtendedPlugin. */ if (isUrlList == 0) { fdebugf((stderr, " dndInDrop: no url list\n")); recordDragEvent(DragDrop, 0); return state; } dndInDestroyTypes(); if (xdndSourceWindow != xdndDrop_sourceWindow(evt)) { fdebugf((stderr, " dndInDrop: wrong source window\n")); } else if (xdndWillAccept) { Window owner; fdebugf((stderr, " dndInDrop: converting selection\n")); if (!(owner= XGetSelectionOwner(stDisplay, XdndSelection))) fprintf(stderr, " dndInDrop: XGetSelectionOwner failed\n"); else XConvertSelection(stDisplay, XdndSelection, XdndTextUriList, XdndSelectionAtom, stWindow, xdndDrop_time(evt)); initDropFileNames(); } else { fdebugf((stderr, " dndInDrop: refusing selection -- finishing\n")); } dndSendFinished(); recordDragEvent(DragLeave, 1); return XdndStateIdle; }
/* Another application is requesting the selection. */ static enum XdndState dndOutSelectionRequest(enum XdndState state, XSelectionRequestEvent *req) { fdebugf((stderr, "Receive SelectionRequest for %s (output) owner: 0x%lx : requestor: 0x%lx\n", XGetAtomName(stDisplay, req->target), req->owner, req->requestor)); if (XdndStateOutAccepted != state) { /*printf("%i is not expected in SelectionRequest\n", state);*/ return state; } memcpy(&xdndOutRequestEvent, req, sizeof(xdndOutRequestEvent)); recordDragEvent(DragRequest, 1); return state; }
static void dndGetSelection(Window owner, Atom property) { unsigned long remaining; unsigned char *data= 0; Atom actual; int format; unsigned long count; if (Success != XGetWindowProperty(stDisplay, owner, property, 0, 65536, 1, AnyPropertyType, &actual, &format, &count, &remaining, &data)) fprintf(stderr, "dndGetSelection: XGetWindowProperty failed\n"); else if (remaining) /* a little violent perhaps */ fprintf(stderr, "dndGetSelection: XGetWindowProperty has more than 64K (why?)\n"); else { char *tokens= data; char *item= 0; while ((item= strtok(tokens, "\n\r"))) { dprintf((stderr, "got URI <%s>\n", item)); if (!strncmp(item, "file:", 5)) /*** xxx BOGUS -- just while image is broken ***/ { if (uxDropFileCount) uxDropFileNames= (char **)xrealloc(uxDropFileNames, (uxDropFileCount + 1) * sizeof(char *)); else uxDropFileNames= (char **)xcalloc(1, sizeof(char *)); uxDropFileNames[uxDropFileCount++]= uri2string(item); } tokens= 0; } if (uxDropFileCount) recordDragEvent(DragDrop, uxDropFileCount); dprintf((stderr, "+++ DROP %d\n", uxDropFileCount)); } XFree(data); }
static void generateSqueakDropEventIfDroppedFiles() { if (uxDropFileCount) recordDragEvent(DragDrop, uxDropFileCount); }
static enum XdndState dndInLeave(enum XdndState state) { fdebugf((stderr, "Receive XdndLeave (input)\n")); recordDragEvent(DragLeave, 1); return XdndStateIdle; }
static void dndLeave(XClientMessageEvent *evt) { dprintf((stderr, "dndLeave\n")); recordDragEvent(DragLeave, 1); xdndState= XdndStateIdle; }