Mercurial > mplayer.hg
annotate gui/wm/wsxdnd.c @ 36084:64825e4a3fed
Remove pointless code.
The URL dialog widget will be destroyed after a selection has been made,
and urlEntries will be freed and rebuilt every time the URL dialog
widget is created (newly). So it makes no sense to prepend any data to
the GList that never will be used.
author | ib |
---|---|
date | Mon, 29 Apr 2013 11:21:23 +0000 |
parents | afb55738b1b7 |
children | eed2fb870f43 |
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 "ws.h" | |
24 #include "wsxdnd.h" | |
25 | |
26 #include <stdio.h> | |
27 #include <stdlib.h> | |
28 #include <string.h> | |
29 | |
30 #include <X11/Xatom.h> | |
31 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
25619
diff
changeset
|
32 #include "mp_msg.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
25619
diff
changeset
|
33 #include "help_mp.h" |
23077 | 34 |
35 #define XDND_VERSION 3L | |
36 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
37 Atom XA_XdndAware; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
38 Atom XA_XdndEnter; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
39 Atom XA_XdndLeave; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
40 Atom XA_XdndDrop; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
41 Atom XA_XdndPosition; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
42 Atom XA_XdndStatus; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
43 Atom XA_XdndActionCopy; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
44 Atom XA_XdndSelection; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
45 Atom XA_XdndFinished; |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
46 Atom XA_XdndTypeList; |
23077 | 47 |
48 Atom atom_support; | |
49 | |
50 void wsXDNDInitialize(void) | |
51 { | |
52 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
53 XA_XdndAware = XInternAtom(wsDisplay, "XdndAware", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
54 XA_XdndEnter = XInternAtom(wsDisplay, "XdndEnter", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
55 XA_XdndLeave = XInternAtom(wsDisplay, "XdndLeave", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
56 XA_XdndDrop = XInternAtom(wsDisplay, "XdndDrop", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
57 XA_XdndPosition = XInternAtom(wsDisplay, "XdndPosition", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
58 XA_XdndStatus = XInternAtom(wsDisplay, "XdndStatus", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
59 XA_XdndActionCopy = XInternAtom(wsDisplay, "XdndActionCopy", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
60 XA_XdndSelection = XInternAtom(wsDisplay, "XdndSelection", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
61 XA_XdndFinished = XInternAtom(wsDisplay, "XdndFinished", False); |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
62 XA_XdndTypeList = XInternAtom(wsDisplay, "XdndTypeList", False); |
23077 | 63 } |
64 | |
35656 | 65 void wsXDNDMakeAwareness(wsWindow* win) { |
23077 | 66 long int xdnd_version = XDND_VERSION; |
35631 | 67 XChangeProperty (wsDisplay, win->WindowID, XA_XdndAware, XA_ATOM, |
23077 | 68 32, PropModeAppend, (char *)&xdnd_version, 1); |
69 } | |
70 | |
35656 | 71 void wsXDNDClearAwareness(wsWindow* win) { |
35631 | 72 XDeleteProperty (wsDisplay, win->WindowID, XA_XdndAware); |
23077 | 73 } |
74 | |
75 #define MAX_DND_FILES 64 | |
76 Bool | |
35656 | 77 wsXDNDProcessSelection(wsWindow* win, XEvent *event) |
23077 | 78 { |
79 Atom ret_type; | |
80 int ret_format; | |
81 unsigned long ret_items; | |
82 unsigned long remain_byte; | |
83 char * delme; | |
84 XEvent xevent; | |
85 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
86 Window selowner = XGetSelectionOwner(wsDisplay,XA_XdndSelection); |
23077 | 87 |
88 XGetWindowProperty(wsDisplay, event->xselection.requestor, | |
89 event->xselection.property, | |
90 0, 65536, True, atom_support, &ret_type, &ret_format, | |
91 &ret_items, &remain_byte, (unsigned char **)&delme); | |
92 | |
93 /*send finished*/ | |
94 memset (&xevent, 0, sizeof(xevent)); | |
95 xevent.xany.type = ClientMessage; | |
96 xevent.xany.display = wsDisplay; | |
97 xevent.xclient.window = selowner; | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
98 xevent.xclient.message_type = XA_XdndFinished; |
23077 | 99 xevent.xclient.format = 32; |
35631 | 100 XDND_FINISHED_TARGET_WIN(&xevent) = win->WindowID; |
23077 | 101 XSendEvent(wsDisplay, selowner, 0, 0, &xevent); |
102 | |
103 if (!delme){ | |
104 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_WS_DDNothing ); | |
105 return False; | |
106 } | |
107 | |
108 { | |
109 /* Handle dropped files */ | |
110 char * retain = delme; | |
111 char * files[MAX_DND_FILES]; | |
112 int num = 0; | |
113 | |
114 while(retain < delme + ret_items) { | |
115 if (!strncmp(retain,"file:",5)) { | |
116 /* add more 2 chars while removing 5 is harmless */ | |
117 retain+=5; | |
118 } | |
119 | |
120 /* add the "retain" to the list */ | |
121 files[num++]=retain; | |
122 | |
123 | |
124 /* now check for special characters */ | |
125 { | |
126 int newone = 0; | |
127 while(retain < (delme + ret_items)){ | |
128 if(*retain == '\r' || *retain == '\n'){ | |
129 *retain=0; | |
130 newone = 1; | |
131 } else { | |
132 if (newone) | |
133 break; | |
134 } | |
135 retain++; | |
136 } | |
137 } | |
138 | |
139 if (num >= MAX_DND_FILES) | |
140 break; | |
141 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
142 |
23077 | 143 /* Handle the files */ |
35759 | 144 if(win->DNDHandler){ |
145 win->DNDHandler(num,files); | |
23077 | 146 } |
147 } | |
148 | |
149 free(delme); | |
150 return True; | |
151 } | |
152 | |
153 Bool | |
34470
571201af959c
Remove unused parameter from wsXDNDProcessClientMessage().
ib
parents:
33758
diff
changeset
|
154 wsXDNDProcessClientMessage(XClientMessageEvent *event) |
23077 | 155 { |
156 /* test */ | |
157 /*{ | |
158 char * name = XGetAtomName(wsDisplay, event->message_type); | |
159 printf("Got %s\n",name); | |
160 XFree(name); | |
161 }*/ | |
162 | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
163 if (event->message_type == XA_XdndEnter) { |
23077 | 164 Atom ok = XInternAtom(wsDisplay, "text/uri-list", False); |
165 atom_support = None; | |
166 if ((event->data.l[1] & 1) == 0){ | |
167 int index; | |
168 for(index = 0; index <= 2 ; index++){ | |
33757 | 169 if ((Atom) event->data.l[2+index] == ok) { |
23077 | 170 atom_support = ok; |
171 } | |
172 } | |
173 if (atom_support == None) { | |
174 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_WS_NotAFile ); | |
175 } | |
176 } else { | |
177 /* need to check the whole list here */ | |
178 unsigned long ret_left = 1; | |
179 int offset = 0; | |
180 Atom* ret_buff; | |
181 Atom ret_type; | |
182 int ret_format; | |
183 unsigned long ret_items; | |
184 | |
185 /* while there is data left...*/ | |
186 while(ret_left && atom_support == None){ | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
187 XGetWindowProperty(wsDisplay,event->data.l[0],XA_XdndTypeList, |
23077 | 188 offset,256,False,XA_ATOM,&ret_type, |
189 &ret_format,&ret_items,&ret_left, | |
190 (unsigned char**)&ret_buff); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
191 |
23077 | 192 /* sanity checks...*/ |
193 if(ret_buff == NULL || ret_type != XA_ATOM || ret_format != 8*sizeof(Atom)){ | |
194 XFree(ret_buff); | |
195 break; | |
196 } | |
197 /* now chek what we've got */ | |
198 { | |
33758
fdf7cfbd2922
Use same data types for index variable and loop test variable.
ib
parents:
33757
diff
changeset
|
199 unsigned long i; |
23077 | 200 for(i=0; i<ret_items; i++){ |
201 if(ret_buff[i] == ok){ | |
202 atom_support = ok; | |
203 break; | |
204 } | |
205 } | |
206 } | |
207 /* maybe next time ... */ | |
208 XFree(ret_buff); | |
209 offset += 256; | |
210 } | |
211 } | |
212 return True; | |
213 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
214 |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
215 if (event->message_type == XA_XdndLeave) { |
23077 | 216 return True; |
217 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
218 |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
219 if (event->message_type == XA_XdndDrop) { |
33757 | 220 if ((Window) event->data.l[0] != XGetSelectionOwner(wsDisplay, XA_XdndSelection)){ |
23077 | 221 puts("Wierd selection owner... QT?"); |
222 } | |
223 if (atom_support != None) { | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
224 XConvertSelection(wsDisplay, XA_XdndSelection, atom_support, |
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
225 XA_XdndSelection, event->window, |
23077 | 226 CurrentTime); |
227 } | |
228 return True; | |
229 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
230 |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
231 if (event->message_type == XA_XdndPosition) { |
23077 | 232 Window srcwin = event->data.l[0]; |
233 if (atom_support == None){ | |
234 return True; | |
235 } | |
236 | |
237 /* send response */ | |
238 { | |
239 XEvent xevent; | |
240 memset (&xevent, 0, sizeof(xevent)); | |
241 xevent.xany.type = ClientMessage; | |
242 xevent.xany.display = wsDisplay; | |
243 xevent.xclient.window = srcwin; | |
25619
20f549053410
Fix illegal identifier, names starting with _ and uppercase are reserved.
diego
parents:
23077
diff
changeset
|
244 xevent.xclient.message_type = XA_XdndStatus; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
245 xevent.xclient.format = 32; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
246 |
23077 | 247 XDND_STATUS_TARGET_WIN (&xevent) = event->window; |
248 XDND_STATUS_WILL_ACCEPT_SET (&xevent, True); | |
249 XDND_STATUS_WANT_POSITION_SET(&xevent, True); | |
250 /* actually need smth real here */ | |
251 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
|
252 XDND_STATUS_ACTION(&xevent) = XA_XdndActionCopy; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
253 |
23077 | 254 XSendEvent(wsDisplay, srcwin, 0, 0, &xevent); |
255 } | |
256 return True; | |
257 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
258 |
23077 | 259 return False; |
260 } |