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