Fixed some focus related problems when switching workspaces, including the
[wmaker-crm.git] / WINGs / dragdestination.c
blobf7b209a10bfc5923cf04a1c10e9447d4b21b8a26
3 #include <X11/Xatom.h>
5 #include "WINGsP.h"
8 /* dropping */
10 typedef struct W_DNDTargetInfo {
11 /* data types accepted for drops */
12 Atom *dropTypes;
13 int dropTypeCount;
16 } DNDTargetInfo;
19 static Atom XDNDversion = XDND_VERSION;
22 static void
23 realizedObserver(void *self, WMNotification *notif)
25 WMView *view = (WMView*)WMGetNotificationObject(notif);
27 XChangeProperty(W_VIEW_SCREEN(view)->display, W_VIEW_DRAWABLE(view),
28 W_VIEW_SCREEN(view)->xdndAwareAtom,
29 XA_ATOM, 32, PropModeReplace,
30 (unsigned char*)&XDNDversion, 1);
32 WMRemoveNotificationObserver(self);
36 void
37 W_SetXdndAwareProperty(WMScreen *scr, WMView *view, Atom *types, int typeCount)
39 Display *dpy = scr->display;
41 view = W_TopLevelOfView(view);
43 if (!view->flags.xdndHintSet) {
44 view->flags.xdndHintSet = 1;
46 if (view->flags.realized) {
47 XChangeProperty(dpy, W_VIEW_DRAWABLE(view), scr->xdndAwareAtom,
48 XA_ATOM, 32, PropModeReplace,
49 (unsigned char*)&XDNDversion, 1);
50 } else {
51 WMAddNotificationObserver(realizedObserver,
52 /* just use as an id */
53 &view->dragDestinationProcs,
54 WMViewRealizedNotification,
55 view);
62 void
63 WMRegisterViewForDraggedTypes(WMView *view, char *acceptedTypes[])
65 Atom *types;
66 int typeCount;
67 int i;
69 typeCount = 0;
70 while (acceptedTypes[typeCount++]);
72 types = wmalloc(sizeof(Atom)*(typeCount+1));
74 for (i = 0; i < typeCount; i++) {
75 types[i] = XInternAtom(W_VIEW_SCREEN(view)->display,
76 acceptedTypes[i], False);
78 types[i] = 0;
80 view->droppableTypes = types;
82 W_SetXdndAwareProperty(W_VIEW_SCREEN(view), view, types, typeCount);
86 void
87 WMUnregisterViewDraggedTypes(WMView *view)
89 if (view->droppableTypes != NULL)
90 wfree(view->droppableTypes);
91 view->droppableTypes = NULL;
94 /***********************************************************************/
97 static unsigned
98 defDraggingEntered(WMView *self, WMDraggingInfo *info)
100 printf("%x drag entered\n", W_VIEW_DRAWABLE(self));
101 return WDOperationNone;
104 static unsigned
105 defDraggingUpdated(WMView *self, WMDraggingInfo *info)
107 printf("%x drag update\n", W_VIEW_DRAWABLE(self));
108 return WDOperationNone;
111 static void
112 defDraggingExited(WMView *self, WMDraggingInfo *info)
114 printf("%x drag exit\n", W_VIEW_DRAWABLE(self));
117 static Bool
118 defPrepareForDragOperation(WMView *self, WMDraggingInfo *info)
120 printf("%x drag prepare\n", W_VIEW_DRAWABLE(self));
121 return False;
124 static Bool
125 defPerformDragOperation(WMView *self, WMDraggingInfo *info)
127 printf("%x drag perform\n", W_VIEW_DRAWABLE(self));
128 return False;
131 static void
132 defConcludeDragOperation(WMView *self, WMDraggingInfo *info)
134 printf("%x drag conclude\n", W_VIEW_DRAWABLE(self));
139 void
140 WMSetViewDragDestinationProcs(WMView *view, WMDragDestinationProcs *procs)
142 if (view->dragDestinationProcs == NULL) {
143 view->dragDestinationProcs = wmalloc(sizeof(WMDragDestinationProcs));
144 } else {
145 free(view->dragDestinationProcs);
147 *view->dragDestinationProcs = *procs;
149 /*XXX fill in non-implemented stuffs */
150 if (procs->draggingEntered == NULL) {
151 view->dragDestinationProcs->draggingEntered = defDraggingEntered;
153 if (procs->draggingUpdated == NULL) {
154 view->dragDestinationProcs->draggingUpdated = defDraggingUpdated;
156 if (procs->draggingExited == NULL) {
157 view->dragDestinationProcs->draggingExited = defDraggingExited;
159 if (procs->prepareForDragOperation == NULL) {
160 view->dragDestinationProcs->prepareForDragOperation =
161 defPrepareForDragOperation;
163 if (procs->performDragOperation == NULL) {
164 view->dragDestinationProcs->performDragOperation =
165 defPerformDragOperation;
167 if (procs->concludeDragOperation == NULL) {
168 view->dragDestinationProcs->concludeDragOperation =
169 defConcludeDragOperation;
175 WMPoint
176 WMGetDraggingInfoImageLocation(WMDraggingInfo *info)
178 return info->imageLocation;
183 static void
184 receivedData(WMView *view, Atom selection, Atom target, Time timestamp,
185 void *cdata, WMData *data)
192 Bool
193 WMRequestDroppedData(WMView *view, WMDraggingInfo *info, char *type,
194 WMDropDataCallback *callback)
196 #if 0
197 WMScreen *scr = W_VIEW_SCREEN(view);
198 if (info->finished) {
199 return False;
202 if (type != NULL) {
203 if (!WMRequestSelection(scr->dragInfo.destView,
204 scr->xdndSelectionAtom,
205 XInternAtom(scr->display, type, False),
206 scr->dragInfo.timestamp,
207 receivedData, &scr->dragInfo)) {
208 wwarning("could not request data for dropped data");
210 /* send finished message */
211 sendClientMessage(scr->display, source,
212 scr->xdndFinishedAtom,
213 scr->dragInfo.destinationWindow,
214 0, 0, 0, 0);
216 } else {
217 /* send finished message */
218 sendClientMessage(scr->display, source,
219 scr->xdndFinishedAtom,
220 scr->dragInfo.destinationWindow,
221 0, 0, 0, 0);
223 #endif