Mercurial > audlegacy
annotate src/audacious/dock.c @ 4412:180996fcf12a
bmp_config_* -> aud_config_*
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 31 Mar 2008 06:36:41 +0300 |
parents | 6c97378391b8 |
children | 6e412073cf28 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2313
diff
changeset
|
12 * the Free Software Foundation; under version 3 of the License. |
2313 | 13 * |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2313
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
21 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * Audacious or using our public API to be a derived work. |
2313 | 24 */ |
25 | |
26 #include "dock.h" | |
27 | |
28 #include <gdk/gdk.h> | |
29 #include <stdlib.h> | |
30 #include "main.h" | |
31 | |
32 #include "platform/smartinclude.h" | |
33 | |
34 struct _DockedWindow { | |
35 GtkWindow *w; | |
36 gint offset_x, offset_y; | |
37 }; | |
38 | |
39 typedef struct _DockedWindow DockedWindow; | |
40 | |
41 | |
42 static gint | |
43 docked_list_compare(DockedWindow * a, DockedWindow * b) | |
44 { | |
45 if (a->w == b->w) | |
46 return 0; | |
47 return 1; | |
48 } | |
49 | |
50 static void | |
51 snap_edge(gint * x, gint * y, gint w, gint h, gint bx, gint by, | |
52 gint bw, gint bh) | |
53 { | |
54 gint sd = cfg.snap_distance; | |
55 | |
56 if ((*x + w > bx - sd) && (*x + w < bx + sd) && | |
57 (*y > by - h - sd) && (*y < by + bh + sd)) { | |
58 *x = bx - w; | |
59 if ((*y > by - sd) && (*y < by + sd)) | |
60 *y = by; | |
61 if ((*y + h > by + bh - sd) && (*y + h < by + bh + sd)) | |
62 *y = by + bh - h; | |
63 } | |
64 if ((*x > bx + bw - sd) && (*x < bx + bw + sd) && | |
65 (*y > by - h - sd) && (*y < by + bh + sd)) { | |
66 *x = bx + bw; | |
67 if ((*y > by - sd) && (*y < by + sd)) | |
68 *y = by; | |
69 if ((*y + h > by + bh - sd) && (*y + h < by + bh + sd)) | |
70 *y = by + bh - h; | |
71 } | |
72 } | |
73 | |
74 static void | |
75 snap(gint * x, gint * y, gint w, gint h, gint bx, gint by, gint bw, gint bh) | |
76 { | |
77 snap_edge(x, y, w, h, bx, by, bw, bh); | |
78 snap_edge(y, x, h, w, by, bx, bh, bw); | |
79 } | |
80 | |
81 static void | |
82 calc_snap_offset(GList * dlist, GList * wlist, gint x, gint y, | |
83 gint * off_x, gint * off_y) | |
84 { | |
85 gint nx, ny, nw, nh, sx, sy, sw, sh; | |
86 GtkWindow *w; | |
87 GList *dnode, *wnode; | |
88 DockedWindow temp, *dw; | |
89 | |
90 | |
91 *off_x = 0; | |
92 *off_y = 0; | |
93 | |
94 if (!cfg.snap_windows) | |
95 return; | |
96 | |
97 /* | |
98 * FIXME: Why not break out of the loop when we find someting | |
99 * to snap to? | |
100 */ | |
101 for (dnode = dlist; dnode; dnode = g_list_next(dnode)) { | |
102 dw = dnode->data; | |
103 gtk_window_get_size(dw->w, &nw, &nh); | |
104 | |
105 nx = dw->offset_x + *off_x + x; | |
106 ny = dw->offset_y + *off_y + y; | |
107 | |
108 /* Snap to screen edges */ | |
109 if (abs(nx) < cfg.snap_distance) | |
110 *off_x -= nx; | |
111 if (abs(ny) < cfg.snap_distance) | |
112 *off_y -= ny; | |
113 if (abs(nx + nw - gdk_screen_width()) < cfg.snap_distance) | |
114 *off_x -= nx + nw - gdk_screen_width(); | |
115 if (abs(ny + nh - gdk_screen_height()) < cfg.snap_distance) | |
116 *off_y -= ny + nh - gdk_screen_height(); | |
117 | |
118 /* Snap to other windows */ | |
119 for (wnode = wlist; wnode; wnode = g_list_next(wnode)) { | |
120 temp.w = wnode->data; | |
121 if (g_list_find_custom | |
122 (dlist, &temp, (GCompareFunc) docked_list_compare)) | |
123 /* These windows are already docked */ | |
124 continue; | |
125 | |
126 w = GTK_WINDOW(wnode->data); | |
127 gtk_window_get_position(w, &sx, &sy); | |
128 gtk_window_get_size(w, &sw, &sh); | |
129 | |
130 nx = dw->offset_x + *off_x + x; | |
131 ny = dw->offset_y + *off_y + y; | |
132 | |
133 snap(&nx, &ny, nw, nh, sx, sy, sw, sh); | |
134 | |
135 *off_x += nx - (dw->offset_x + *off_x + x); | |
136 *off_y += ny - (dw->offset_y + *off_y + y); | |
137 } | |
138 } | |
139 } | |
140 | |
141 | |
142 static gboolean | |
143 is_docked(gint a_x, gint a_y, gint a_w, gint a_h, | |
144 gint b_x, gint b_y, gint b_w, gint b_h) | |
145 { | |
146 if (((a_x == b_x + b_w) || (a_x + a_w == b_x)) && | |
147 (b_y + b_h >= a_y) && (b_y <= a_y + a_h)) | |
148 return TRUE; | |
149 | |
150 if (((a_y == b_y + b_h) || (a_y + a_h == b_y)) && | |
151 (b_x >= a_x - b_w) && (b_x <= a_x + a_w)) | |
152 return TRUE; | |
153 | |
154 return FALSE; | |
155 } | |
156 | |
157 /* | |
158 * Builds a list of all windows that are docked to the window "w". | |
159 * Recursively adds all windows that are docked to the windows that are | |
160 * docked to "w" and so on... | |
161 * FIXME: init_off_? ? | |
162 */ | |
163 | |
164 static GList * | |
165 get_docked_list(GList * dlist, GList * wlist, GtkWindow * w, | |
166 gint init_off_x, gint init_off_y) | |
167 { | |
168 GList *node; | |
169 DockedWindow *dwin, temp; | |
170 gint w_x, w_y, w_width, w_height; | |
171 gint t_x, t_y, t_width, t_height; | |
172 | |
173 | |
174 gtk_window_get_position(w, &w_x, &w_y); | |
175 gtk_window_get_size(w, &w_width, &w_height); | |
176 if (!dlist) { | |
177 dwin = g_new0(DockedWindow, 1); | |
178 dwin->w = w; | |
179 dlist = g_list_append(dlist, dwin); | |
180 } | |
181 | |
182 for (node = wlist; node; node = g_list_next(node)) { | |
183 temp.w = node->data; | |
184 if (g_list_find_custom | |
185 (dlist, &temp, (GCompareFunc) docked_list_compare)) | |
186 continue; | |
187 | |
188 gtk_window_get_position(GTK_WINDOW(node->data), &t_x, &t_y); | |
189 gtk_window_get_size(GTK_WINDOW(node->data), &t_width, &t_height); | |
190 if (is_docked | |
191 (w_x, w_y, w_width, w_height, t_x, t_y, t_width, t_height)) { | |
192 dwin = g_new0(DockedWindow, 1); | |
193 dwin->w = node->data; | |
194 | |
195 dwin->offset_x = t_x - w_x + init_off_x; | |
196 dwin->offset_y = t_y - w_y + init_off_y; | |
197 | |
198 dlist = g_list_append(dlist, dwin); | |
199 | |
200 dlist = | |
201 get_docked_list(dlist, wlist, dwin->w, dwin->offset_x, | |
202 dwin->offset_y); | |
203 } | |
204 } | |
205 return dlist; | |
206 } | |
207 | |
208 static void | |
209 free_docked_list(GList * dlist) | |
210 { | |
211 GList *node; | |
212 | |
213 for (node = dlist; node; node = g_list_next(node)) | |
214 g_free(node->data); | |
215 g_list_free(dlist); | |
216 } | |
217 | |
218 static void | |
219 docked_list_move(GList * list, gint x, gint y) | |
220 { | |
221 GList *node; | |
222 DockedWindow *dw; | |
223 | |
224 for (node = list; node; node = g_list_next(node)) { | |
225 dw = node->data; | |
226 gtk_window_move(dw->w, x + dw->offset_x, y + dw->offset_y); | |
227 } | |
228 } | |
229 | |
230 static GList * | |
231 shade_move_list(GList * list, GtkWindow * widget, gint offset) | |
232 { | |
233 gint x, y, w, h; | |
234 GList *node; | |
235 DockedWindow *dw; | |
236 | |
237 gtk_window_get_position(widget, &x, &y); | |
238 gtk_window_get_size(widget, &w, &h); | |
239 | |
240 | |
241 for (node = list; node;) { | |
242 gint dx, dy, dwidth, dheight; | |
243 | |
244 dw = node->data; | |
245 gtk_window_get_position(dw->w, &dx, &dy); | |
246 gtk_window_get_size(dw->w, &dwidth, &dheight); | |
247 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight) && | |
248 ((dx + dwidth) > x && dx < (x + w))) { | |
249 list = g_list_remove_link(list, node); | |
250 g_list_free_1(node); | |
251 | |
252 node = list = shade_move_list(list, dw->w, offset); | |
253 } | |
254 else | |
255 node = g_list_next(node); | |
256 } | |
257 gtk_window_move(widget, x, y + offset); | |
258 return list; | |
259 } | |
260 | |
261 /* | |
262 * Builds a list of the windows in the list of DockedWindows "winlist" | |
263 * that are docked to the top or bottom of the window, and recursively | |
264 * adds all windows that are docked to the top or bottom of that window, | |
265 * and so on... | |
266 * Note: The data in "winlist" is not copied. | |
267 */ | |
268 static GList * | |
269 find_shade_list(GtkWindow * widget, GList * winlist, GList * shade_list) | |
270 { | |
271 gint x, y, w, h; | |
272 gint dx, dy, dwidth, dheight; | |
273 GList *node; | |
274 | |
275 gtk_window_get_position(widget, &x, &y); | |
276 gtk_window_get_size(widget, &w, &h); | |
277 for (node = winlist; node; node = g_list_next(node)) { | |
278 DockedWindow *dw = node->data; | |
279 if (g_list_find_custom | |
280 (shade_list, dw, (GCompareFunc) docked_list_compare)) | |
281 continue; | |
282 gtk_window_get_position(dw->w, &dx, &dy); | |
283 gtk_window_get_size(dw->w, &dwidth, &dheight); | |
284 | |
285 /* FIXME. Is the is_docked() necessary? */ | |
286 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight) && | |
287 ((dx + dwidth) > x && dx < (x + w))) { | |
288 shade_list = g_list_append(shade_list, dw); | |
289 shade_list = find_shade_list(dw->w, winlist, shade_list); | |
290 } | |
291 } | |
292 return shade_list; | |
293 } | |
294 | |
295 void | |
296 dock_window_resize(GtkWindow * widget, gint new_w, gint new_h, gint w, gint h) | |
297 { | |
298 gdk_window_set_hints(GTK_WIDGET(widget)->window, 0, 0, MIN(w, new_w), | |
299 MIN(h, new_h), MAX(w, new_w), MAX(h, new_h), | |
300 GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); | |
301 gdk_window_resize(GTK_WIDGET(widget)->window, new_w, new_h); | |
302 gdk_window_set_hints(GTK_WIDGET(widget)->window, 0, 0, new_w, new_h, | |
303 new_w, new_h, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); | |
304 } | |
305 | |
306 void | |
307 dock_shade(GList * window_list, GtkWindow * widget, gint new_h) | |
308 { | |
309 gint x, y, w, h, off_y, orig_off_y; | |
310 GList *node, *docked_list, *slist; | |
311 DockedWindow *dw; | |
312 | |
313 gtk_window_get_position(widget, &x, &y); | |
314 gtk_window_get_size(widget, &w, &h); | |
315 | |
316 if (cfg.show_wm_decorations) { | |
317 dock_window_resize(widget, w, new_h, w, h); | |
318 return; | |
319 } | |
320 | |
321 docked_list = get_docked_list(NULL, window_list, widget, 0, 0); | |
322 slist = find_shade_list(widget, docked_list, NULL); | |
323 | |
324 off_y = new_h - h; | |
325 do { | |
326 orig_off_y = off_y; | |
327 for (node = slist; node; node = g_list_next(node)) { | |
328 gint dx, dy, dwidth, dheight; | |
329 | |
330 dw = node->data; | |
331 if (dw->w == widget) | |
332 continue; | |
333 gtk_window_get_position(dw->w, &dx, &dy); | |
334 gtk_window_get_size(dw->w, &dwidth, &dheight); | |
335 if ((dy >= y) && ((dy + off_y + dheight) > gdk_screen_height())) | |
336 off_y -= (dy + off_y + dheight) - gdk_screen_height(); | |
337 else if ((dy >= y) && ((dy + dheight) == gdk_screen_height())) | |
338 off_y = 0; | |
339 | |
340 if (((dy >= y) && ((dy + off_y) < 0))) | |
341 off_y -= dy + off_y; | |
342 if ((dy < y) && ((dy + (off_y - (new_h - h))) < 0)) | |
343 off_y -= dy + (off_y - (new_h - h)); | |
344 } | |
345 } while (orig_off_y != off_y); | |
346 if (slist) { | |
347 GList *mlist = g_list_copy(slist); | |
348 | |
349 /* Remove this widget from the list */ | |
350 for (node = mlist; node; node = g_list_next(node)) { | |
351 dw = node->data; | |
352 if (dw->w == widget) { | |
353 mlist = g_list_remove_link(mlist, node); | |
354 g_list_free_1(node); | |
355 break; | |
356 } | |
357 } | |
358 for (node = mlist; node;) { | |
359 GList *temp; | |
360 gint dx, dy, dwidth, dheight; | |
361 | |
362 dw = node->data; | |
363 | |
364 gtk_window_get_position(dw->w, &dx, &dy); | |
365 gtk_window_get_size(dw->w, &dwidth, &dheight); | |
366 /* | |
367 * Find windows that are directly docked to this window, | |
368 * move it, and any windows docked to that window again | |
369 */ | |
370 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight) && | |
371 ((dx + dwidth) > x && dx < (x + w))) { | |
372 mlist = g_list_remove_link(mlist, node); | |
373 g_list_free_1(node); | |
374 if (dy > y) | |
375 temp = shade_move_list(mlist, dw->w, off_y); | |
376 else if (off_y - (new_h - h) != 0) | |
377 temp = shade_move_list(mlist, dw->w, off_y - (new_h - h)); | |
378 else | |
379 temp = mlist; | |
380 node = mlist = temp; | |
381 } | |
382 else | |
383 node = g_list_next(node); | |
384 } | |
385 g_list_free(mlist); | |
386 } | |
387 g_list_free(slist); | |
388 free_docked_list(docked_list); | |
389 gtk_window_move(widget, x, y + off_y - (new_h - h)); | |
390 dock_window_resize(widget, w, new_h, w, h); | |
391 } | |
392 | |
393 void | |
394 dock_move_press(GList * window_list, GtkWindow * w, | |
395 GdkEventButton * event, gboolean move_list) | |
396 { | |
397 gint mx, my; | |
398 DockedWindow *dwin; | |
399 | |
400 if (cfg.show_wm_decorations) | |
401 return; | |
402 | |
403 gtk_window_present(w); | |
3465
0dd74d0da472
the less gdk calls, the better
Tomasz Mon <desowin@gmail.com>
parents:
3123
diff
changeset
|
404 mx = event->x; |
0dd74d0da472
the less gdk calls, the better
Tomasz Mon <desowin@gmail.com>
parents:
3123
diff
changeset
|
405 my = event->y; |
2313 | 406 gtk_object_set_data(GTK_OBJECT(w), "move_offset_x", GINT_TO_POINTER(mx)); |
407 gtk_object_set_data(GTK_OBJECT(w), "move_offset_y", GINT_TO_POINTER(my)); | |
408 if (move_list) | |
409 gtk_object_set_data(GTK_OBJECT(w), "docked_list", | |
410 get_docked_list(NULL, window_list, w, 0, 0)); | |
411 else { | |
412 dwin = g_new0(DockedWindow, 1); | |
413 dwin->w = w; | |
414 gtk_object_set_data(GTK_OBJECT(w), "docked_list", | |
415 g_list_append(NULL, dwin)); | |
416 } | |
417 gtk_object_set_data(GTK_OBJECT(w), "window_list", window_list); | |
418 gtk_object_set_data(GTK_OBJECT(w), "is_moving", GINT_TO_POINTER(1)); | |
419 } | |
420 | |
421 void | |
422 dock_move_motion(GtkWindow * w, GdkEventMotion * event) | |
423 { | |
3465
0dd74d0da472
the less gdk calls, the better
Tomasz Mon <desowin@gmail.com>
parents:
3123
diff
changeset
|
424 gint offset_x, offset_y, win_x, win_y, x, y; |
2313 | 425 GList *dlist; |
426 GList *window_list; | |
427 | |
428 if (!gtk_object_get_data(GTK_OBJECT(w), "is_moving")) | |
429 return; | |
430 | |
431 offset_x = | |
432 GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(w), "move_offset_x")); | |
433 offset_y = | |
434 GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(w), "move_offset_y")); | |
435 dlist = gtk_object_get_data(GTK_OBJECT(w), "docked_list"); | |
436 window_list = gtk_object_get_data(GTK_OBJECT(w), "window_list"); | |
437 | |
438 gtk_window_get_position(w, &win_x, &win_y); | |
439 | |
3465
0dd74d0da472
the less gdk calls, the better
Tomasz Mon <desowin@gmail.com>
parents:
3123
diff
changeset
|
440 x = event->x_root - offset_x; |
0dd74d0da472
the less gdk calls, the better
Tomasz Mon <desowin@gmail.com>
parents:
3123
diff
changeset
|
441 y = event->y_root - offset_y; |
2313 | 442 |
443 calc_snap_offset(dlist, window_list, x, y, &offset_x, &offset_y); | |
444 x += offset_x; | |
445 y += offset_y; | |
446 | |
447 docked_list_move(dlist, x, y); | |
448 } | |
449 | |
450 void | |
451 dock_move_release(GtkWindow * w) | |
452 { | |
453 GList *dlist; | |
454 gtk_object_remove_data(GTK_OBJECT(w), "is_moving"); | |
455 gtk_object_remove_data(GTK_OBJECT(w), "move_offset_x"); | |
456 gtk_object_remove_data(GTK_OBJECT(w), "move_offset_y"); | |
457 if ((dlist = gtk_object_get_data(GTK_OBJECT(w), "docked_list")) != NULL) | |
458 free_docked_list(dlist); | |
459 gtk_object_remove_data(GTK_OBJECT(w), "docked_list"); | |
460 gtk_object_remove_data(GTK_OBJECT(w), "window_list"); | |
461 } | |
462 | |
463 gboolean | |
464 dock_is_moving(GtkWindow * w) | |
465 { | |
466 if (gtk_object_get_data(GTK_OBJECT(w), "is_moving")) | |
467 return TRUE; | |
468 return FALSE; | |
469 } | |
470 | |
471 GList * | |
472 dock_add_window(GList * list, GtkWindow * window) | |
473 { | |
474 return g_list_append(list, window); | |
475 } | |
476 | |
477 GList * | |
478 dock_remove_window(GList * list, GtkWindow * window) | |
479 { | |
480 return g_list_remove(list, window); | |
481 } | |
482 | |
483 GList * | |
484 dock_window_set_decorated(GList * list, GtkWindow * window, | |
485 gboolean decorated) | |
486 { | |
487 if (gtk_window_get_decorated(window) == decorated) | |
488 return list; | |
489 | |
490 if (decorated) | |
491 list = dock_remove_window(list, window); | |
492 else | |
493 list = dock_add_window(list, window); | |
494 | |
495 gtk_window_set_decorated(window, decorated); | |
496 | |
497 return list; | |
498 } | |
3768
bf6b1c5091d5
Export dock functions
Christian Birchinger <joker@netswarm.net>
parents:
3465
diff
changeset
|
499 |
bf6b1c5091d5
Export dock functions
Christian Birchinger <joker@netswarm.net>
parents:
3465
diff
changeset
|
500 GList * |
bf6b1c5091d5
Export dock functions
Christian Birchinger <joker@netswarm.net>
parents:
3465
diff
changeset
|
501 get_dock_window_list() { |
bf6b1c5091d5
Export dock functions
Christian Birchinger <joker@netswarm.net>
parents:
3465
diff
changeset
|
502 return dock_window_list; |
bf6b1c5091d5
Export dock functions
Christian Birchinger <joker@netswarm.net>
parents:
3465
diff
changeset
|
503 } |