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