Mercurial > mplayer.hg
annotate gui/wm/wsxdnd.c @ 36961:127804c3452d
Remove unnecessary #include.
author | ib |
---|---|
date | Mon, 24 Mar 2014 11:09:05 +0000 |
parents | eed2fb870f43 |
children | 1236a692d0c6 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
35666
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35656
diff
changeset
|
17 * |
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35656
diff
changeset
|
18 * based on: WindowMaker implementation, |
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35656
diff
changeset
|
19 * adopted for MPlayer |
26458 | 20 */ |
23077 | 21 |
22 #include <X11/Xlib.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 | |
35656 | 64 void wsXDNDMakeAwareness(wsWindow* win) { |
23077 | 65 long int xdnd_version = XDND_VERSION; |
35631 | 66 XChangeProperty (wsDisplay, win->WindowID, XA_XdndAware, XA_ATOM, |
23077 | 67 32, PropModeAppend, (char *)&xdnd_version, 1); |
68 } | |
69 | |
35656 | 70 void wsXDNDClearAwareness(wsWindow* win) { |
35631 | 71 XDeleteProperty (wsDisplay, win->WindowID, XA_XdndAware); |
23077 | 72 } |
73 | |
74 #define MAX_DND_FILES 64 | |
75 Bool | |
35656 | 76 wsXDNDProcessSelection(wsWindow* win, XEvent *event) |
23077 | 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; |
35631 | 99 XDND_FINISHED_TARGET_WIN(&xevent) = win->WindowID; |
23077 | 100 XSendEvent(wsDisplay, selowner, 0, 0, &xevent); |
101 | |
102 if (!delme){ | |
36694 | 103 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_GUI_MSG_DragAndDropNothing ); |
23077 | 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 */ |
35759 | 143 if(win->DNDHandler){ |
144 win->DNDHandler(num,files); | |
23077 | 145 } |
146 } | |
147 | |
148 free(delme); | |
149 return True; | |
150 } | |
151 | |
152 Bool | |
34470
571201af959c
Remove unused parameter from wsXDNDProcessClientMessage().
ib
parents:
33758
diff
changeset
|
153 wsXDNDProcessClientMessage(XClientMessageEvent *event) |
23077 | 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++){ | |
33757 | 168 if ((Atom) event->data.l[2+index] == ok) { |
23077 | 169 atom_support = ok; |
170 } | |
171 } | |
172 if (atom_support == None) { | |
36694 | 173 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_GUI_MSG_NotAFile0 ); |
23077 | 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 { | |
33758
fdf7cfbd2922
Use same data types for index variable and loop test variable.
ib
parents:
33757
diff
changeset
|
198 unsigned long i; |
23077 | 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) { |
33757 | 219 if ((Window) 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 } |