Mercurial > mplayer.hg
comparison Gui/wm/wsxdnd.c @ 6967:0fa27966ac47
add xdnd support (from Gregory Kovriga <gkovriga@techunix.technion.ac.il>) and fix -subdelay bug
author | pontscho |
---|---|
date | Sun, 11 Aug 2002 13:12:38 +0000 |
parents | |
children | 7242f1840f8d |
comparison
equal
deleted
inserted
replaced
6966:2994bd73f35d | 6967:0fa27966ac47 |
---|---|
1 /* Took WindowMaker implementation and adopted for MPlayer */ | |
2 | |
3 | |
4 #include <X11/Xlib.h> | |
5 #include "ws.h" | |
6 #include "wsxdnd.h" | |
7 | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 | |
11 #include <X11/Xatom.h> | |
12 | |
13 | |
14 #define XDND_VERSION 3L | |
15 | |
16 Atom _XA_XdndAware; | |
17 Atom _XA_XdndEnter; | |
18 Atom _XA_XdndLeave; | |
19 Atom _XA_XdndDrop; | |
20 Atom _XA_XdndPosition; | |
21 Atom _XA_XdndStatus; | |
22 Atom _XA_XdndActionCopy; | |
23 Atom _XA_XdndSelection; | |
24 Atom _XA_XdndFinished; | |
25 | |
26 Atom atom_support; | |
27 | |
28 void wsXDNDInitialize() | |
29 { | |
30 | |
31 _XA_XdndAware = XInternAtom(wsDisplay, "XdndAware", False); | |
32 _XA_XdndEnter = XInternAtom(wsDisplay, "XdndEnter", False); | |
33 _XA_XdndLeave = XInternAtom(wsDisplay, "XdndLeave", False); | |
34 _XA_XdndDrop = XInternAtom(wsDisplay, "XdndDrop", False); | |
35 _XA_XdndPosition = XInternAtom(wsDisplay, "XdndPosition", False); | |
36 _XA_XdndStatus = XInternAtom(wsDisplay, "XdndStatus", False); | |
37 _XA_XdndActionCopy = XInternAtom(wsDisplay, "XdndActionCopy", False); | |
38 _XA_XdndSelection = XInternAtom(wsDisplay, "XdndSelection", False); | |
39 _XA_XdndFinished = XInternAtom(wsDisplay, "XdndFinished", False); | |
40 } | |
41 | |
42 void wsXDNDMakeAwareness(wsTWindow* window) { | |
43 long int xdnd_version = XDND_VERSION; | |
44 XChangeProperty (wsDisplay, window->WindowID, _XA_XdndAware, XA_ATOM, | |
45 32, PropModeAppend, (char *)&xdnd_version, 1); | |
46 } | |
47 | |
48 void wsXDNDClearAwareness(wsTWindow* window) { | |
49 XDeleteProperty (wsDisplay, window->WindowID, _XA_XdndAware); | |
50 } | |
51 | |
52 #define MAX_DND_FILES 64 | |
53 Bool | |
54 wsXDNDProcessSelection(wsTWindow* wnd, XEvent *event) | |
55 { | |
56 Atom ret_type; | |
57 int ret_format; | |
58 unsigned long ret_items; | |
59 unsigned long remain_byte; | |
60 char * delme; | |
61 XEvent xevent; | |
62 | |
63 Window selowner = XGetSelectionOwner(wsDisplay,_XA_XdndSelection); | |
64 | |
65 XGetWindowProperty(wsDisplay, event->xselection.requestor, | |
66 event->xselection.property, | |
67 0, 65536, True, atom_support, &ret_type, &ret_format, | |
68 &ret_items, &remain_byte, (unsigned char **)&delme); | |
69 | |
70 /*send finished*/ | |
71 memset (&xevent, 0, sizeof(xevent)); | |
72 xevent.xany.type = ClientMessage; | |
73 xevent.xany.display = wsDisplay; | |
74 xevent.xclient.window = selowner; | |
75 xevent.xclient.message_type = _XA_XdndFinished; | |
76 xevent.xclient.format = 32; | |
77 XDND_FINISHED_TARGET_WIN(&xevent) = wnd->WindowID; | |
78 XSendEvent(wsDisplay, selowner, 0, 0, &xevent); | |
79 | |
80 if (!delme){ | |
81 printf("D&D: Nothing returned!\n"); | |
82 return False; | |
83 } | |
84 | |
85 { | |
86 /* Handle dropped files */ | |
87 char * retain = delme; | |
88 char * files[MAX_DND_FILES]; | |
89 int num = 0; | |
90 /* | |
91 printf("Got: %s\n",delme); | |
92 */ | |
93 while(retain < delme + ret_items) { | |
94 if (!strncmp(retain,"file:",5)) { | |
95 /* add more 2 chars while removing 5 is harmless */ | |
96 retain+=5; | |
97 } | |
98 | |
99 /* add the "retain" to the list */ | |
100 files[num++]=retain; | |
101 | |
102 | |
103 /* now check for special characters */ | |
104 { | |
105 int newone = 0; | |
106 while(retain < (delme + ret_items)){ | |
107 if(*retain == '\r' || *retain == '\n'){ | |
108 *retain=0; | |
109 newone = 1; | |
110 } else { | |
111 if (newone) | |
112 break; | |
113 } | |
114 retain++; | |
115 } | |
116 } | |
117 | |
118 if (num >= MAX_DND_FILES) | |
119 break; | |
120 } | |
121 | |
122 /* Handle the files */ | |
123 if(wnd->DandDHandler){ | |
124 wnd->DandDHandler(num,files); | |
125 } | |
126 } | |
127 | |
128 free(delme); | |
129 } | |
130 | |
131 Bool | |
132 wsXDNDProcessClientMessage(wsTWindow* wnd, XClientMessageEvent *event) | |
133 { | |
134 /* test */ | |
135 /*{ | |
136 char * name = XGetAtomName(wsDisplay, event->message_type); | |
137 printf("Got %s\n",name); | |
138 XFree(name); | |
139 }*/ | |
140 | |
141 if (event->message_type == _XA_XdndEnter) { | |
142 Atom ok = XInternAtom(wsDisplay, "text/uri-list", False); | |
143 atom_support = None; | |
144 if ((event->data.l[1] & 1) == 0){ | |
145 int index; | |
146 for(index = 0; index <= 2 ; index++){ | |
147 if (event->data.l[2+index] == ok) { | |
148 atom_support = ok; | |
149 } | |
150 } | |
151 if (atom_support == None) { | |
152 printf("This doesn't seem as a file...\n"); | |
153 } | |
154 } else { | |
155 /* FIXME: need something else here */ | |
156 } | |
157 return True; | |
158 } | |
159 | |
160 if (event->message_type == _XA_XdndLeave) { | |
161 return True; | |
162 } | |
163 | |
164 if (event->message_type == _XA_XdndDrop) { | |
165 if (event->data.l[0] != XGetSelectionOwner(wsDisplay, _XA_XdndSelection)){ | |
166 puts("wierd selection owner? QT?"); | |
167 } | |
168 if (atom_support != None) { | |
169 XConvertSelection(wsDisplay, _XA_XdndSelection, atom_support, | |
170 _XA_XdndSelection, event->window, | |
171 CurrentTime); | |
172 } | |
173 return True; | |
174 } | |
175 | |
176 if (event->message_type == _XA_XdndPosition) { | |
177 Window srcwin = event->data.l[0]; | |
178 if (atom_support == None){ | |
179 return True; | |
180 } | |
181 | |
182 /* send response */ | |
183 { | |
184 XEvent xevent; | |
185 memset (&xevent, 0, sizeof(xevent)); | |
186 xevent.xany.type = ClientMessage; | |
187 xevent.xany.display = wsDisplay; | |
188 xevent.xclient.window = srcwin; | |
189 xevent.xclient.message_type = _XA_XdndStatus; | |
190 xevent.xclient.format = 32; | |
191 | |
192 XDND_STATUS_TARGET_WIN (&xevent) = event->window; | |
193 XDND_STATUS_WILL_ACCEPT_SET (&xevent, True); | |
194 XDND_STATUS_WANT_POSITION_SET(&xevent, True); | |
195 /* actually need smth real here */ | |
196 XDND_STATUS_RECT_SET(&xevent, 0, 0, 1024,768); | |
197 XDND_STATUS_ACTION(&xevent) = _XA_XdndActionCopy; | |
198 | |
199 XSendEvent(wsDisplay, srcwin, 0, 0, &xevent); | |
200 } | |
201 return True; | |
202 } | |
203 | |
204 return False; | |
205 } |