Mercurial > mplayer.hg
annotate gui/wm/wsxdnd.c @ 29946:54bacf6a38ca
Update the SuperH VEU vidix driver with code that calls fsync() after each
frame to make sure the frame is flushed in case of deferred io.
Patch by Magnus Damm, damm opensource se
author | cehoyos |
---|---|
date | Thu, 10 Dec 2009 23:16:08 +0000 |
parents | 0f1b5b68af32 |
children | 9198f711233e |
rev | line source |
---|---|
26458 | 1 /* |
2 * WindowMaker implementation adopted for MPlayer | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
23077 | 20 |
21 #include <X11/Xlib.h> | |
22 #include "ws.h" | |
23 #include "wsxdnd.h" | |
24 | |
25 #include <stdio.h> | |
26 #include <stdlib.h> | |
27 #include <string.h> | |
28 | |
29 #include <X11/Xatom.h> | |
30 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
25619
diff
changeset
|
31 #include "mp_msg.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
25619
diff
changeset
|
32 #include "help_mp.h" |
23077 | 33 |
34 #define XDND_VERSION 3L | |
35 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
36 Atom XA_XdndAware; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
37 Atom XA_XdndEnter; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
38 Atom XA_XdndLeave; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
39 Atom XA_XdndDrop; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
40 Atom XA_XdndPosition; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
41 Atom XA_XdndStatus; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
42 Atom XA_XdndActionCopy; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
43 Atom XA_XdndSelection; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
44 Atom XA_XdndFinished; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
45 Atom XA_XdndTypeList; |
23077 | 46 |
47 Atom atom_support; | |
48 | |
49 void wsXDNDInitialize(void) | |
50 { | |
51 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
52 XA_XdndAware = XInternAtom(wsDisplay, "XdndAware", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
53 XA_XdndEnter = XInternAtom(wsDisplay, "XdndEnter", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
54 XA_XdndLeave = XInternAtom(wsDisplay, "XdndLeave", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
55 XA_XdndDrop = XInternAtom(wsDisplay, "XdndDrop", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
56 XA_XdndPosition = XInternAtom(wsDisplay, "XdndPosition", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
57 XA_XdndStatus = XInternAtom(wsDisplay, "XdndStatus", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
58 XA_XdndActionCopy = XInternAtom(wsDisplay, "XdndActionCopy", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
59 XA_XdndSelection = XInternAtom(wsDisplay, "XdndSelection", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
60 XA_XdndFinished = XInternAtom(wsDisplay, "XdndFinished", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
61 XA_XdndTypeList = XInternAtom(wsDisplay, "XdndTypeList", False); |
23077 | 62 } |
63 | |
64 void wsXDNDMakeAwareness(wsTWindow* window) { | |
65 long int xdnd_version = XDND_VERSION; | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
66 XChangeProperty (wsDisplay, window->WindowID, XA_XdndAware, XA_ATOM, |
23077 | 67 32, PropModeAppend, (char *)&xdnd_version, 1); |
68 } | |
69 | |
70 void wsXDNDClearAwareness(wsTWindow* window) { | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
71 XDeleteProperty (wsDisplay, window->WindowID, XA_XdndAware); |
23077 | 72 } |
73 | |
74 #define MAX_DND_FILES 64 | |
75 Bool | |
76 wsXDNDProcessSelection(wsTWindow* wnd, XEvent *event) | |
77 { | |
78 Atom ret_type; | |
79 int ret_format; | |
80 unsigned long ret_items; | |
81 unsigned long remain_byte; | |
82 char * delme; | |
83 XEvent xevent; | |
84 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
85 Window selowner = XGetSelectionOwner(wsDisplay,XA_XdndSelection); |
23077 | 86 |
87 XGetWindowProperty(wsDisplay, event->xselection.requestor, | |
88 event->xselection.property, | |
89 0, 65536, True, atom_support, &ret_type, &ret_format, | |
90 &ret_items, &remain_byte, (unsigned char **)&delme); | |
91 | |
92 /*send finished*/ | |
93 memset (&xevent, 0, sizeof(xevent)); | |
94 xevent.xany.type = ClientMessage; | |
95 xevent.xany.display = wsDisplay; | |
96 xevent.xclient.window = selowner; | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
97 xevent.xclient.message_type = XA_XdndFinished; |
23077 | 98 xevent.xclient.format = 32; |
99 XDND_FINISHED_TARGET_WIN(&xevent) = wnd->WindowID; | |
100 XSendEvent(wsDisplay, selowner, 0, 0, &xevent); | |
101 | |
102 if (!delme){ | |
103 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_WS_DDNothing ); | |
104 return False; | |
105 } | |
106 | |
107 { | |
108 /* Handle dropped files */ | |
109 char * retain = delme; | |
110 char * files[MAX_DND_FILES]; | |
111 int num = 0; | |
112 | |
113 while(retain < delme + ret_items) { | |
114 if (!strncmp(retain,"file:",5)) { | |
115 /* add more 2 chars while removing 5 is harmless */ | |
116 retain+=5; | |
117 } | |
118 | |
119 /* add the "retain" to the list */ | |
120 files[num++]=retain; | |
121 | |
122 | |
123 /* now check for special characters */ | |
124 { | |
125 int newone = 0; | |
126 while(retain < (delme + ret_items)){ | |
127 if(*retain == '\r' || *retain == '\n'){ | |
128 *retain=0; | |
129 newone = 1; | |
130 } else { | |
131 if (newone) | |
132 break; | |
133 } | |
134 retain++; | |
135 } | |
136 } | |
137 | |
138 if (num >= MAX_DND_FILES) | |
139 break; | |
140 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
141 |
23077 | 142 /* Handle the files */ |
143 if(wnd->DandDHandler){ | |
144 wnd->DandDHandler(num,files); | |
145 } | |
146 } | |
147 | |
148 free(delme); | |
149 return True; | |
150 } | |
151 | |
152 Bool | |
153 wsXDNDProcessClientMessage(wsTWindow* wnd, XClientMessageEvent *event) | |
154 { | |
155 /* test */ | |
156 /*{ | |
157 char * name = XGetAtomName(wsDisplay, event->message_type); | |
158 printf("Got %s\n",name); | |
159 XFree(name); | |
160 }*/ | |
161 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
162 if (event->message_type == XA_XdndEnter) { |
23077 | 163 Atom ok = XInternAtom(wsDisplay, "text/uri-list", False); |
164 atom_support = None; | |
165 if ((event->data.l[1] & 1) == 0){ | |
166 int index; | |
167 for(index = 0; index <= 2 ; index++){ | |
168 if (event->data.l[2+index] == ok) { | |
169 atom_support = ok; | |
170 } | |
171 } | |
172 if (atom_support == None) { | |
173 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_WS_NotAFile ); | |
174 } | |
175 } else { | |
176 /* need to check the whole list here */ | |
177 unsigned long ret_left = 1; | |
178 int offset = 0; | |
179 Atom* ret_buff; | |
180 Atom ret_type; | |
181 int ret_format; | |
182 unsigned long ret_items; | |
183 | |
184 /* while there is data left...*/ | |
185 while(ret_left && atom_support == None){ | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
186 XGetWindowProperty(wsDisplay,event->data.l[0],XA_XdndTypeList, |
23077 | 187 offset,256,False,XA_ATOM,&ret_type, |
188 &ret_format,&ret_items,&ret_left, | |
189 (unsigned char**)&ret_buff); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
190 |
23077 | 191 /* sanity checks...*/ |
192 if(ret_buff == NULL || ret_type != XA_ATOM || ret_format != 8*sizeof(Atom)){ | |
193 XFree(ret_buff); | |
194 break; | |
195 } | |
196 /* now chek what we've got */ | |
197 { | |
198 int i; | |
199 for(i=0; i<ret_items; i++){ | |
200 if(ret_buff[i] == ok){ | |
201 atom_support = ok; | |
202 break; | |
203 } | |
204 } | |
205 } | |
206 /* maybe next time ... */ | |
207 XFree(ret_buff); | |
208 offset += 256; | |
209 } | |
210 } | |
211 return True; | |
212 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
213 |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
214 if (event->message_type == XA_XdndLeave) { |
23077 | 215 return True; |
216 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
217 |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
218 if (event->message_type == XA_XdndDrop) { |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
219 if (event->data.l[0] != XGetSelectionOwner(wsDisplay, XA_XdndSelection)){ |
23077 | 220 puts("Wierd selection owner... QT?"); |
221 } | |
222 if (atom_support != None) { | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
223 XConvertSelection(wsDisplay, XA_XdndSelection, atom_support, |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
224 XA_XdndSelection, event->window, |
23077 | 225 CurrentTime); |
226 } | |
227 return True; | |
228 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
229 |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
230 if (event->message_type == XA_XdndPosition) { |
23077 | 231 Window srcwin = event->data.l[0]; |
232 if (atom_support == None){ | |
233 return True; | |
234 } | |
235 | |
236 /* send response */ | |
237 { | |
238 XEvent xevent; | |
239 memset (&xevent, 0, sizeof(xevent)); | |
240 xevent.xany.type = ClientMessage; | |
241 xevent.xany.display = wsDisplay; | |
242 xevent.xclient.window = srcwin; | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
243 xevent.xclient.message_type = XA_XdndStatus; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
244 xevent.xclient.format = 32; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
245 |
23077 | 246 XDND_STATUS_TARGET_WIN (&xevent) = event->window; |
247 XDND_STATUS_WILL_ACCEPT_SET (&xevent, True); | |
248 XDND_STATUS_WANT_POSITION_SET(&xevent, True); | |
249 /* actually need smth real here */ | |
250 XDND_STATUS_RECT_SET(&xevent, 0, 0, 1024,768); | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
251 XDND_STATUS_ACTION(&xevent) = XA_XdndActionCopy; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
252 |
23077 | 253 XSendEvent(wsDisplay, srcwin, 0, 0, &xevent); |
254 } | |
255 return True; | |
256 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
257 |
23077 | 258 return False; |
259 } |