10 typedef struct W_DNDTargetInfo
{
11 /* data types accepted for drops */
19 static Atom XDNDversion
= XDND_VERSION
;
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
);
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);
51 WMAddNotificationObserver(realizedObserver
,
52 /* just use as an id */
53 &view
->dragDestinationProcs
,
54 WMViewRealizedNotification
,
63 WMRegisterViewForDraggedTypes(WMView
*view
, char *acceptedTypes
[])
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
);
80 view
->droppableTypes
= types
;
82 W_SetXdndAwareProperty(W_VIEW_SCREEN(view
), view
, types
, typeCount
);
87 WMUnregisterViewDraggedTypes(WMView
*view
)
89 if (view
->droppableTypes
!= NULL
)
90 free(view
->droppableTypes
);
91 view
->droppableTypes
= NULL
;
94 /***********************************************************************/
97 static unsigned defDraggingEntered(WMView
*self
, WMDraggingInfo
*info
)
99 return WDOperationNone
;
102 static unsigned defDraggingUpdated(WMView
*self
, WMDraggingInfo
*info
)
104 return WDOperationNone
;
107 static void defDraggingExited(WMView
*self
, WMDraggingInfo
*info
)
111 static Bool
defPrepareForDragOperation(WMView
*self
, WMDraggingInfo
*info
)
116 static Bool
defPerformDragOperation(WMView
*self
, WMDraggingInfo
*info
)
121 static void defConcludeDragOperation(WMView
*self
, WMDraggingInfo
*info
)
128 WMSetViewDragDestinationProcs(WMView
*view
, WMDragDestinationProcs
*procs
)
130 if (view
->dragDestinationProcs
== NULL
) {
131 free(view
->dragDestinationProcs
);
132 view
->dragDestinationProcs
= wmalloc(sizeof(WMDragDestinationProcs
));
134 *view
->dragDestinationProcs
= *procs
;
136 /*XXX fill in non-implemented stuffs */
137 if (procs
->draggingEntered
== NULL
) {
138 view
->dragDestinationProcs
->draggingEntered
= defDraggingEntered
;
140 if (procs
->draggingUpdated
== NULL
) {
141 view
->dragDestinationProcs
->draggingUpdated
= defDraggingUpdated
;
143 if (procs
->draggingExited
== NULL
) {
144 view
->dragDestinationProcs
->draggingExited
= defDraggingExited
;
146 if (procs
->prepareForDragOperation
== NULL
) {
147 view
->dragDestinationProcs
->prepareForDragOperation
=
148 defPrepareForDragOperation
;
150 if (procs
->performDragOperation
== NULL
) {
151 view
->dragDestinationProcs
->performDragOperation
=
152 defPerformDragOperation
;
154 if (procs
->concludeDragOperation
== NULL
) {
155 view
->dragDestinationProcs
->concludeDragOperation
=
156 defConcludeDragOperation
;
166 WMPoint
WMGetDraggingInfoImageLocation(WMDraggingInfo
*info
)
168 return info
->imageLocation
;
174 receivedData(WMView
*view
, Atom selection
, Atom target
, Time timestamp
,
175 void *cdata
, WMData
*data
)
182 Bool
WMRequestDroppedData(WMView
*view
, WMDraggingInfo
*info
, char *type
,
183 WMDropDataCallback
*callback
)
185 WMScreen
*scr
= W_VIEW_SCREEN(view
);
187 if (info
->finished
) {
192 if (!WMRequestSelection(scr
->dragInfo
.destView
,
193 scr
->xdndSelectionAtom
,
194 XInternAtom(scr
->display
, type
, False
),
195 scr
->dragInfo
.timestamp
,
196 receivedData
, &scr
->dragInfo
)) {
197 wwarning("could not request data for dropped data");
199 /* send finished message */
200 sendClientMessage(scr
->display
, source
,
201 scr
->xdndFinishedAtom
,
202 scr
->dragInfo
.destinationWindow
,
206 /* send finished message */
207 sendClientMessage(scr
->display
, source
,
208 scr
->xdndFinishedAtom
,
209 scr
->dragInfo
.destinationWindow
,