1064
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
3 *
|
|
4 * Based on XMMS:
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
1459
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1064
|
20 */
|
|
21
|
|
22 #include "dock.h"
|
|
23
|
|
24 #include <gdk/gdk.h>
|
|
25 #include <stdlib.h>
|
|
26 #include "main.h"
|
|
27
|
1640
|
28 #include "platform/smartinclude.h"
|
1064
|
29
|
|
30 struct _DockedWindow {
|
|
31 GtkWindow *w;
|
|
32 gint offset_x, offset_y;
|
|
33 };
|
|
34
|
|
35 typedef struct _DockedWindow DockedWindow;
|
|
36
|
|
37
|
|
38 static gint
|
|
39 docked_list_compare(DockedWindow * a, DockedWindow * b)
|
|
40 {
|
|
41 if (a->w == b->w)
|
|
42 return 0;
|
|
43 return 1;
|
|
44 }
|
|
45
|
|
46 static void
|
|
47 snap_edge(gint * x, gint * y, gint w, gint h, gint bx, gint by,
|
|
48 gint bw, gint bh)
|
|
49 {
|
|
50 gint sd = cfg.snap_distance;
|
|
51
|
|
52 if ((*x + w > bx - sd) && (*x + w < bx + sd) &&
|
|
53 (*y > by - h - sd) && (*y < by + bh + sd)) {
|
|
54 *x = bx - w;
|
|
55 if ((*y > by - sd) && (*y < by + sd))
|
|
56 *y = by;
|
|
57 if ((*y + h > by + bh - sd) && (*y + h < by + bh + sd))
|
|
58 *y = by + bh - h;
|
|
59 }
|
|
60 if ((*x > bx + bw - sd) && (*x < bx + bw + sd) &&
|
|
61 (*y > by - h - sd) && (*y < by + bh + sd)) {
|
|
62 *x = bx + bw;
|
|
63 if ((*y > by - sd) && (*y < by + sd))
|
|
64 *y = by;
|
|
65 if ((*y + h > by + bh - sd) && (*y + h < by + bh + sd))
|
|
66 *y = by + bh - h;
|
|
67 }
|
|
68 }
|
|
69
|
|
70 static void
|
|
71 snap(gint * x, gint * y, gint w, gint h, gint bx, gint by, gint bw, gint bh)
|
|
72 {
|
|
73 snap_edge(x, y, w, h, bx, by, bw, bh);
|
|
74 snap_edge(y, x, h, w, by, bx, bh, bw);
|
|
75 }
|
|
76
|
|
77 static void
|
|
78 calc_snap_offset(GList * dlist, GList * wlist, gint x, gint y,
|
|
79 gint * off_x, gint * off_y)
|
|
80 {
|
|
81 gint nx, ny, nw, nh, sx, sy, sw, sh;
|
|
82 GtkWindow *w;
|
|
83 GList *dnode, *wnode;
|
|
84 DockedWindow temp, *dw;
|
|
85
|
|
86
|
|
87 *off_x = 0;
|
|
88 *off_y = 0;
|
|
89
|
|
90 if (!cfg.snap_windows)
|
|
91 return;
|
|
92
|
|
93 /*
|
|
94 * FIXME: Why not break out of the loop when we find someting
|
|
95 * to snap to?
|
|
96 */
|
|
97 for (dnode = dlist; dnode; dnode = g_list_next(dnode)) {
|
|
98 dw = dnode->data;
|
|
99 gtk_window_get_size(dw->w, &nw, &nh);
|
|
100
|
|
101 nx = dw->offset_x + *off_x + x;
|
|
102 ny = dw->offset_y + *off_y + y;
|
|
103
|
|
104 /* Snap to screen edges */
|
|
105 if (abs(nx) < cfg.snap_distance)
|
|
106 *off_x -= nx;
|
|
107 if (abs(ny) < cfg.snap_distance)
|
|
108 *off_y -= ny;
|
|
109 if (abs(nx + nw - gdk_screen_width()) < cfg.snap_distance)
|
|
110 *off_x -= nx + nw - gdk_screen_width();
|
|
111 if (abs(ny + nh - gdk_screen_height()) < cfg.snap_distance)
|
|
112 *off_y -= ny + nh - gdk_screen_height();
|
|
113
|
|
114 /* Snap to other windows */
|
|
115 for (wnode = wlist; wnode; wnode = g_list_next(wnode)) {
|
|
116 temp.w = wnode->data;
|
|
117 if (g_list_find_custom
|
|
118 (dlist, &temp, (GCompareFunc) docked_list_compare))
|
|
119 /* These windows are already docked */
|
|
120 continue;
|
|
121
|
|
122 w = GTK_WINDOW(wnode->data);
|
|
123 gtk_window_get_position(w, &sx, &sy);
|
|
124 gtk_window_get_size(w, &sw, &sh);
|
|
125
|
|
126 nx = dw->offset_x + *off_x + x;
|
|
127 ny = dw->offset_y + *off_y + y;
|
|
128
|
|
129 snap(&nx, &ny, nw, nh, sx, sy, sw, sh);
|
|
130
|
|
131 *off_x += nx - (dw->offset_x + *off_x + x);
|
|
132 *off_y += ny - (dw->offset_y + *off_y + y);
|
|
133 }
|
|
134 }
|
|
135 }
|
|
136
|
|
137
|
|
138 static gboolean
|
|
139 is_docked(gint a_x, gint a_y, gint a_w, gint a_h,
|
|
140 gint b_x, gint b_y, gint b_w, gint b_h)
|
|
141 {
|
|
142 if (((a_x == b_x + b_w) || (a_x + a_w == b_x)) &&
|
|
143 (b_y + b_h >= a_y) && (b_y <= a_y + a_h))
|
|
144 return TRUE;
|
|
145
|
|
146 if (((a_y == b_y + b_h) || (a_y + a_h == b_y)) &&
|
|
147 (b_x >= a_x - b_w) && (b_x <= a_x + a_w))
|
|
148 return TRUE;
|
|
149
|
|
150 return FALSE;
|
|
151 }
|
|
152
|
|
153 /*
|
|
154 * Builds a list of all windows that are docked to the window "w".
|
|
155 * Recursively adds all windows that are docked to the windows that are
|
|
156 * docked to "w" and so on...
|
|
157 * FIXME: init_off_? ?
|
|
158 */
|
|
159
|
|
160 static GList *
|
|
161 get_docked_list(GList * dlist, GList * wlist, GtkWindow * w,
|
|
162 gint init_off_x, gint init_off_y)
|
|
163 {
|
|
164 GList *node;
|
|
165 DockedWindow *dwin, temp;
|
|
166 gint w_x, w_y, w_width, w_height;
|
|
167 gint t_x, t_y, t_width, t_height;
|
|
168
|
|
169
|
|
170 gtk_window_get_position(w, &w_x, &w_y);
|
|
171 gtk_window_get_size(w, &w_width, &w_height);
|
|
172 if (!dlist) {
|
|
173 dwin = g_new0(DockedWindow, 1);
|
|
174 dwin->w = w;
|
|
175 dlist = g_list_append(dlist, dwin);
|
|
176 }
|
|
177
|
|
178 for (node = wlist; node; node = g_list_next(node)) {
|
|
179 temp.w = node->data;
|
|
180 if (g_list_find_custom
|
|
181 (dlist, &temp, (GCompareFunc) docked_list_compare))
|
|
182 continue;
|
|
183
|
|
184 gtk_window_get_position(GTK_WINDOW(node->data), &t_x, &t_y);
|
|
185 gtk_window_get_size(GTK_WINDOW(node->data), &t_width, &t_height);
|
|
186 if (is_docked
|
|
187 (w_x, w_y, w_width, w_height, t_x, t_y, t_width, t_height)) {
|
|
188 dwin = g_new0(DockedWindow, 1);
|
|
189 dwin->w = node->data;
|
|
190
|
|
191 dwin->offset_x = t_x - w_x + init_off_x;
|
|
192 dwin->offset_y = t_y - w_y + init_off_y;
|
|
193
|
|
194 dlist = g_list_append(dlist, dwin);
|
|
195
|
|
196 dlist =
|
|
197 get_docked_list(dlist, wlist, dwin->w, dwin->offset_x,
|
|
198 dwin->offset_y);
|
|
199 }
|
|
200 }
|
|
201 return dlist;
|
|
202 }
|
|
203
|
|
204 static void
|
|
205 free_docked_list(GList * dlist)
|
|
206 {
|
|
207 GList *node;
|
|
208
|
|
209 for (node = dlist; node; node = g_list_next(node))
|
|
210 g_free(node->data);
|
|
211 g_list_free(dlist);
|
|
212 }
|
|
213
|
|
214 static void
|
|
215 docked_list_move(GList * list, gint x, gint y)
|
|
216 {
|
|
217 GList *node;
|
|
218 DockedWindow *dw;
|
|
219
|
|
220 for (node = list; node; node = g_list_next(node)) {
|
|
221 dw = node->data;
|
|
222 gtk_window_move(dw->w, x + dw->offset_x, y + dw->offset_y);
|
|
223 gdk_flush();
|
|
224 }
|
|
225 }
|
|
226
|
|
227 static GList *
|
|
228 shade_move_list(GList * list, GtkWindow * widget, gint offset)
|
|
229 {
|
|
230 gint x, y, w, h;
|
|
231 GList *node;
|
|
232 DockedWindow *dw;
|
|
233
|
|
234 gtk_window_get_position(widget, &x, &y);
|
|
235 gtk_window_get_size(widget, &w, &h);
|
|
236
|
|
237
|
|
238 for (node = list; node;) {
|
|
239 gint dx, dy, dwidth, dheight;
|
|
240
|
|
241 dw = node->data;
|
|
242 gtk_window_get_position(dw->w, &dx, &dy);
|
|
243 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
244 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight) &&
|
|
245 ((dx + dwidth) > x && dx < (x + w))) {
|
|
246 list = g_list_remove_link(list, node);
|
|
247 g_list_free_1(node);
|
|
248
|
|
249 node = list = shade_move_list(list, dw->w, offset);
|
|
250 }
|
|
251 else
|
|
252 node = g_list_next(node);
|
|
253 }
|
|
254 gtk_window_move(widget, x, y + offset);
|
|
255 return list;
|
|
256 }
|
|
257
|
|
258 /*
|
|
259 * Builds a list of the windows in the list of DockedWindows "winlist"
|
|
260 * that are docked to the top or bottom of the window, and recursively
|
|
261 * adds all windows that are docked to the top or bottom of that window,
|
|
262 * and so on...
|
|
263 * Note: The data in "winlist" is not copied.
|
|
264 */
|
|
265 static GList *
|
|
266 find_shade_list(GtkWindow * widget, GList * winlist, GList * shade_list)
|
|
267 {
|
|
268 gint x, y, w, h;
|
|
269 gint dx, dy, dwidth, dheight;
|
|
270 GList *node;
|
|
271
|
|
272 gtk_window_get_position(widget, &x, &y);
|
|
273 gtk_window_get_size(widget, &w, &h);
|
|
274 for (node = winlist; node; node = g_list_next(node)) {
|
|
275 DockedWindow *dw = node->data;
|
|
276 if (g_list_find_custom
|
|
277 (shade_list, dw, (GCompareFunc) docked_list_compare))
|
|
278 continue;
|
|
279 gtk_window_get_position(dw->w, &dx, &dy);
|
|
280 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
281
|
|
282 /* FIXME. Is the is_docked() necessary? */
|
|
283 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight) &&
|
|
284 ((dx + dwidth) > x && dx < (x + w))) {
|
|
285 shade_list = g_list_append(shade_list, dw);
|
|
286 shade_list = find_shade_list(dw->w, winlist, shade_list);
|
|
287 }
|
|
288 }
|
|
289 return shade_list;
|
|
290 }
|
|
291
|
|
292 static void
|
|
293 dock_window_resize(GtkWindow * widget, gint new_w, gint new_h, gint w, gint h)
|
|
294 {
|
|
295 gdk_window_set_hints(GTK_WIDGET(widget)->window, 0, 0, MIN(w, new_w),
|
|
296 MIN(h, new_h), MAX(w, new_w), MAX(h, new_h),
|
|
297 GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE);
|
|
298 gdk_window_resize(GTK_WIDGET(widget)->window, new_w, new_h);
|
|
299 gdk_window_set_hints(GTK_WIDGET(widget)->window, 0, 0, new_w, new_h,
|
|
300 new_w, new_h, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE);
|
|
301 }
|
|
302
|
|
303 void
|
|
304 dock_shade(GList * window_list, GtkWindow * widget, gint new_h)
|
|
305 {
|
|
306 gint x, y, w, h, off_y, orig_off_y;
|
|
307 GList *node, *docked_list, *slist;
|
|
308 DockedWindow *dw;
|
|
309
|
|
310 gtk_window_get_position(widget, &x, &y);
|
|
311 gtk_window_get_size(widget, &w, &h);
|
|
312
|
|
313 if (cfg.show_wm_decorations) {
|
|
314 dock_window_resize(widget, w, new_h, w, h);
|
|
315 return;
|
|
316 }
|
|
317
|
|
318 docked_list = get_docked_list(NULL, window_list, widget, 0, 0);
|
|
319 slist = find_shade_list(widget, docked_list, NULL);
|
|
320
|
|
321 off_y = new_h - h;
|
|
322 do {
|
|
323 orig_off_y = off_y;
|
|
324 for (node = slist; node; node = g_list_next(node)) {
|
|
325 gint dx, dy, dwidth, dheight;
|
|
326
|
|
327 dw = node->data;
|
|
328 if (dw->w == widget)
|
|
329 continue;
|
|
330 gtk_window_get_position(dw->w, &dx, &dy);
|
|
331 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
332 if ((dy >= y) && ((dy + off_y + dheight) > gdk_screen_height()))
|
|
333 off_y -= (dy + off_y + dheight) - gdk_screen_height();
|
|
334 else if ((dy >= y) && ((dy + dheight) == gdk_screen_height()))
|
|
335 off_y = 0;
|
|
336
|
|
337 if (((dy >= y) && ((dy + off_y) < 0)))
|
|
338 off_y -= dy + off_y;
|
|
339 if ((dy < y) && ((dy + (off_y - (new_h - h))) < 0))
|
|
340 off_y -= dy + (off_y - (new_h - h));
|
|
341 }
|
|
342 } while (orig_off_y != off_y);
|
|
343 if (slist) {
|
|
344 GList *mlist = g_list_copy(slist);
|
|
345
|
|
346 /* Remove this widget from the list */
|
|
347 for (node = mlist; node; node = g_list_next(node)) {
|
|
348 dw = node->data;
|
|
349 if (dw->w == widget) {
|
|
350 mlist = g_list_remove_link(mlist, node);
|
|
351 g_list_free_1(node);
|
|
352 break;
|
|
353 }
|
|
354 }
|
|
355 for (node = mlist; node;) {
|
|
356 GList *temp;
|
|
357 gint dx, dy, dwidth, dheight;
|
|
358
|
|
359 dw = node->data;
|
|
360
|
|
361 gtk_window_get_position(dw->w, &dx, &dy);
|
|
362 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
363 /*
|
|
364 * Find windows that are directly docked to this window,
|
|
365 * move it, and any windows docked to that window again
|
|
366 */
|
|
367 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight) &&
|
|
368 ((dx + dwidth) > x && dx < (x + w))) {
|
|
369 mlist = g_list_remove_link(mlist, node);
|
|
370 g_list_free_1(node);
|
|
371 if (dy > y)
|
|
372 temp = shade_move_list(mlist, dw->w, off_y);
|
|
373 else if (off_y - (new_h - h) != 0)
|
|
374 temp = shade_move_list(mlist, dw->w, off_y - (new_h - h));
|
|
375 else
|
|
376 temp = mlist;
|
|
377 node = mlist = temp;
|
|
378 }
|
|
379 else
|
|
380 node = g_list_next(node);
|
|
381 }
|
|
382 g_list_free(mlist);
|
|
383 }
|
|
384 g_list_free(slist);
|
|
385 free_docked_list(docked_list);
|
|
386 gtk_window_move(widget, x, y + off_y - (new_h - h));
|
|
387 dock_window_resize(widget, w, new_h, w, h);
|
|
388 }
|
|
389
|
|
390 static GList *
|
|
391 resize_move_list(GList * list, GtkWindow * widget,
|
|
392 gint offset_x, gint offset_y)
|
|
393 {
|
|
394 gint x, y, w, h;
|
|
395 GList *node;
|
|
396 DockedWindow *dw;
|
|
397
|
|
398 gtk_window_get_position(widget, &x, &y);
|
|
399 gtk_window_get_size(widget, &w, &h);
|
|
400
|
|
401
|
|
402 for (node = list; node;) {
|
|
403 gint dx, dy, dwidth, dheight;
|
|
404 dw = node->data;
|
|
405 gtk_window_get_position(dw->w, &dx, &dy);
|
|
406 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
407 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight)) {
|
|
408
|
|
409 list = g_list_remove_link(list, node);
|
|
410 g_list_free_1(node);
|
|
411 node = list = resize_move_list(list, dw->w, offset_x, offset_y);
|
|
412 }
|
|
413 else
|
|
414 node = g_list_next(node);
|
|
415 }
|
|
416 gtk_window_move(widget, x + offset_x, y + offset_y);
|
|
417 return list;
|
|
418 }
|
|
419
|
|
420 static GList *
|
|
421 resize_calc_offset(GList * list, GtkWindow * widget,
|
|
422 gint offset_x, gint offset_y,
|
|
423 gint * goffset_x, gint * goffset_y)
|
|
424 {
|
|
425 gint x, y, w, h;
|
|
426 GList *node;
|
|
427 DockedWindow *dw;
|
|
428
|
|
429 gtk_window_get_position(widget, &x, &y);
|
|
430 gtk_window_get_size(widget, &w, &h);
|
|
431
|
|
432
|
|
433 for (node = list; node;) {
|
|
434 gint dx, dy, dwidth, dheight;
|
|
435 dw = node->data;
|
|
436 gtk_window_get_position(dw->w, &dx, &dy);
|
|
437 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
438 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight)) {
|
|
439 if (dx + offset_x + dwidth > gdk_screen_width()) {
|
|
440 offset_x -= dx + offset_x + dwidth - gdk_screen_width();
|
|
441 (*goffset_x) -= dx + offset_x + dwidth - gdk_screen_width();
|
|
442 }
|
|
443 if (dy + offset_y + dheight > gdk_screen_height()) {
|
|
444 offset_y -= dy + offset_y + dheight - gdk_screen_height();
|
|
445 (*goffset_y) -= dy + offset_y + dheight - gdk_screen_height();
|
|
446 }
|
|
447 list = g_list_remove_link(list, node);
|
|
448 g_list_free_1(node);
|
|
449 node = list =
|
|
450 resize_calc_offset(list, dw->w, offset_x, offset_y,
|
|
451 goffset_x, goffset_y);
|
|
452 }
|
|
453 else
|
|
454 node = g_list_next(node);
|
|
455 }
|
|
456 return list;
|
|
457 }
|
|
458
|
|
459 void
|
|
460 dock_resize(GList * window_list, GtkWindow * widget, gint new_w, gint new_h)
|
|
461 {
|
|
462 gint x, y, w, h;
|
|
463 gint dx, dy, dwidth, dheight;
|
|
464 gint off_x, off_y;
|
|
465 GList *list, *dlist = NULL, *tlist = NULL, *mlist = NULL, *node;
|
|
466 DockedWindow *dw;
|
|
467
|
|
468 gtk_window_get_position(widget, &x, &y);
|
|
469 gtk_window_get_size(widget, &w, &h);
|
|
470 if (cfg.show_wm_decorations) {
|
|
471 dock_window_resize(widget, new_w, new_h, w, h);
|
|
472 return;
|
|
473 }
|
|
474
|
|
475 list = get_docked_list(NULL, window_list, widget, 0, 0);
|
|
476
|
|
477 off_x = 0;
|
|
478 off_y = 0;
|
|
479
|
|
480 for (node = list; node; node = g_list_next(node)) {
|
|
481 dw = node->data;
|
|
482 if (dw->w != widget) {
|
|
483 gtk_window_get_position(dw->w, &dx, &dy);
|
|
484 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
485 if (is_docked(x, y, w, h, dx, dy, dwidth, dheight))
|
|
486 dlist = g_list_append(dlist, dw);
|
|
487 else
|
|
488 mlist = g_list_append(mlist, dw);
|
|
489 }
|
|
490 }
|
|
491 tlist = g_list_copy(mlist);
|
|
492 for (node = dlist; node; node = g_list_next(node)) {
|
|
493 gint doff_x, doff_y;
|
|
494 dw = node->data;
|
|
495 gtk_window_get_position(dw->w, &dx, &dy);
|
|
496 gtk_window_get_size(dw->w, &dwidth, &dheight);
|
|
497 if (dx - x - w == 0)
|
|
498 doff_x = (x + off_x + new_w) - dx;
|
|
499 else
|
|
500 doff_x = (x + off_x + (dx - x)) - dx;
|
|
501
|
|
502 if (dy - y - h == 0)
|
|
503 doff_y = (y + off_y + new_h) - dy;
|
|
504 else
|
|
505 doff_y = (y + off_y + (dy - y)) - dy;
|
|
506
|
|
507 if (dx + doff_x + dwidth > gdk_screen_width()) {
|
|
508 off_x -= dx + doff_x + dwidth - gdk_screen_width();
|
|
509 doff_x -= dx + doff_x + dwidth - gdk_screen_width();
|
|
510 }
|
|
511 if (dy + doff_y + dheight > gdk_screen_height()) {
|
|
512 off_y -= dy + doff_y + dheight - gdk_screen_height();
|
|
513 doff_y -= dy + doff_y + dheight - gdk_screen_height();
|
|
514 }
|
|
515 tlist =
|
|
516 resize_calc_offset(tlist, dw->w, doff_x, doff_y, &off_x, &off_y);
|
|
517 }
|
|
518 if ((x + off_x + new_w) > gdk_screen_width())
|
|
519 off_x -= x + off_x + new_w - gdk_screen_width();
|
|
520 if ((y + off_y + new_h) > gdk_screen_height())
|
|
521 off_y -= y + off_y + new_h - gdk_screen_height();
|
|
522
|
|
523 g_list_free(tlist);
|
|
524 for (node = dlist; node; node = g_list_next(node)) {
|
|
525 gint doff_x, doff_y;
|
|
526 dw = node->data;
|
|
527 gtk_window_get_position(dw->w, &dx, &dy);
|
|
528 if (dx - x - w == 0)
|
|
529 doff_x = (x + off_x + new_w) - dx;
|
|
530 else
|
|
531 doff_x = (x + off_x + (dx - x)) - dx;
|
|
532
|
|
533 if (dy - y - h == 0)
|
|
534 doff_y = (y + off_y + new_h) - dy;
|
|
535 else
|
|
536 doff_y = (y + off_y + (dy - y)) - dy;
|
|
537 mlist = resize_move_list(mlist, dw->w, doff_x, doff_y);
|
|
538 gtk_window_move(GTK_WINDOW(dw->w), dx + doff_x, dy + doff_y);
|
|
539 }
|
|
540
|
|
541
|
|
542 gtk_window_move(widget, x + off_x, y + off_y);
|
|
543 dock_window_resize(widget, new_w, new_h, w, h);
|
|
544 }
|
|
545
|
|
546 void
|
|
547 dock_move_press(GList * window_list, GtkWindow * w,
|
|
548 GdkEventButton * event, gboolean move_list)
|
|
549 {
|
|
550 gint mx, my;
|
|
551 DockedWindow *dwin;
|
|
552
|
|
553 if (cfg.show_wm_decorations)
|
|
554 return;
|
|
555
|
|
556 gtk_window_present(w);
|
|
557 gdk_window_get_pointer(GTK_WIDGET(w)->window, &mx, &my, NULL);
|
|
558 gtk_object_set_data(GTK_OBJECT(w), "move_offset_x", GINT_TO_POINTER(mx));
|
|
559 gtk_object_set_data(GTK_OBJECT(w), "move_offset_y", GINT_TO_POINTER(my));
|
|
560 if (move_list)
|
|
561 gtk_object_set_data(GTK_OBJECT(w), "docked_list",
|
|
562 get_docked_list(NULL, window_list, w, 0, 0));
|
|
563 else {
|
|
564 dwin = g_new0(DockedWindow, 1);
|
|
565 dwin->w = w;
|
|
566 gtk_object_set_data(GTK_OBJECT(w), "docked_list",
|
|
567 g_list_append(NULL, dwin));
|
|
568 }
|
|
569 gtk_object_set_data(GTK_OBJECT(w), "window_list", window_list);
|
|
570 gtk_object_set_data(GTK_OBJECT(w), "is_moving", GINT_TO_POINTER(1));
|
|
571 }
|
|
572
|
|
573 void
|
|
574 dock_move_motion(GtkWindow * w, GdkEventMotion * event)
|
|
575 {
|
|
576 gint offset_x, offset_y, win_x, win_y, x, y, mx, my;
|
|
577 GList *dlist;
|
|
578 GList *window_list;
|
|
579
|
|
580 gdk_flush();
|
|
581
|
|
582 if (!gtk_object_get_data(GTK_OBJECT(w), "is_moving"))
|
|
583 return;
|
|
584
|
|
585 offset_x =
|
|
586 GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(w), "move_offset_x"));
|
|
587 offset_y =
|
|
588 GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(w), "move_offset_y"));
|
|
589 dlist = gtk_object_get_data(GTK_OBJECT(w), "docked_list");
|
|
590 window_list = gtk_object_get_data(GTK_OBJECT(w), "window_list");
|
|
591
|
|
592 gtk_window_get_position(w, &win_x, &win_y);
|
|
593
|
|
594 gdk_window_get_pointer(NULL, &mx, &my, NULL);
|
|
595
|
|
596 x = mx - offset_x;
|
|
597 y = my - offset_y;
|
|
598
|
|
599 calc_snap_offset(dlist, window_list, x, y, &offset_x, &offset_y);
|
|
600 x += offset_x;
|
|
601 y += offset_y;
|
|
602
|
|
603 docked_list_move(dlist, x, y);
|
|
604 }
|
|
605
|
|
606 void
|
|
607 dock_move_release(GtkWindow * w)
|
|
608 {
|
|
609 GList *dlist;
|
|
610 gtk_object_remove_data(GTK_OBJECT(w), "is_moving");
|
|
611 gtk_object_remove_data(GTK_OBJECT(w), "move_offset_x");
|
|
612 gtk_object_remove_data(GTK_OBJECT(w), "move_offset_y");
|
|
613 if ((dlist = gtk_object_get_data(GTK_OBJECT(w), "docked_list")) != NULL)
|
|
614 free_docked_list(dlist);
|
|
615 gtk_object_remove_data(GTK_OBJECT(w), "docked_list");
|
|
616 gtk_object_remove_data(GTK_OBJECT(w), "window_list");
|
|
617 }
|
|
618
|
|
619 gboolean
|
|
620 dock_is_moving(GtkWindow * w)
|
|
621 {
|
|
622 if (gtk_object_get_data(GTK_OBJECT(w), "is_moving"))
|
|
623 return TRUE;
|
|
624 return FALSE;
|
|
625 }
|
|
626
|
|
627 GList *
|
|
628 dock_add_window(GList * list, GtkWindow * window)
|
|
629 {
|
|
630 return g_list_append(list, window);
|
|
631 }
|
|
632
|
|
633 GList *
|
|
634 dock_remove_window(GList * list, GtkWindow * window)
|
|
635 {
|
|
636 return g_list_remove(list, window);
|
|
637 }
|
|
638
|
|
639 GList *
|
|
640 dock_window_set_decorated(GList * list, GtkWindow * window,
|
|
641 gboolean decorated)
|
|
642 {
|
|
643 if (gtk_window_get_decorated(window) == decorated)
|
|
644 return list;
|
|
645
|
|
646 if (decorated)
|
|
647 list = dock_remove_window(list, window);
|
|
648 else
|
|
649 list = dock_add_window(list, window);
|
|
650
|
|
651 gtk_window_set_decorated(window, decorated);
|
|
652
|
|
653 return list;
|
|
654 }
|