]> Dogcows Code - chaz/openbox/blob - openbox/frame.c
no un-needed rendering
[chaz/openbox] / openbox / frame.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 frame.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
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 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "frame.h"
21 #include "client.h"
22 #include "openbox.h"
23 #include "extensions.h"
24 #include "prop.h"
25 #include "config.h"
26 #include "framerender.h"
27 #include "mainloop.h"
28 #include "focus_cycle.h"
29 #include "focus_cycle_indicator.h"
30 #include "moveresize.h"
31 #include "screen.h"
32 #include "render/theme.h"
33
34 #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
35 ButtonPressMask | ButtonReleaseMask | \
36 SubstructureRedirectMask | FocusChangeMask)
37 #define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \
38 ButtonMotionMask | PointerMotionMask | \
39 EnterWindowMask | LeaveWindowMask)
40
41 #define FRAME_ANIMATE_ICONIFY_TIME 150000 /* .15 seconds */
42 #define FRAME_ANIMATE_ICONIFY_STEP_TIME (G_USEC_PER_SEC / 60) /* 60 Hz */
43
44 #define FRAME_HANDLE_Y(f) (f->size.top + f->client->area.height + f->cbwidth_b)
45
46 static void flash_done(gpointer data);
47 static gboolean flash_timeout(gpointer data);
48
49 static void layout_title(ObFrame *self);
50 static void set_theme_statics(ObFrame *self);
51 static void free_theme_statics(ObFrame *self);
52 static gboolean frame_animate_iconify(gpointer self);
53 static void frame_adjust_cursors(ObFrame *self);
54
55 static Window createWindow(Window parent, Visual *visual,
56 gulong mask, XSetWindowAttributes *attrib)
57 {
58 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
59 (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput,
60 (visual ? visual : RrVisual(ob_rr_inst)),
61 mask, attrib);
62
63 }
64
65 static Visual *check_32bit_client(ObClient *c)
66 {
67 XWindowAttributes wattrib;
68 Status ret;
69
70 /* we're already running at 32 bit depth, yay. we don't need to use their
71 visual */
72 if (RrDepth(ob_rr_inst) == 32)
73 return NULL;
74
75 ret = XGetWindowAttributes(ob_display, c->window, &wattrib);
76 g_assert(ret != BadDrawable);
77 g_assert(ret != BadWindow);
78
79 if (wattrib.depth == 32)
80 return wattrib.visual;
81 return NULL;
82 }
83
84 ObFrame *frame_new(ObClient *client)
85 {
86 XSetWindowAttributes attrib;
87 gulong mask;
88 ObFrame *self;
89 Visual *visual;
90
91 self = g_new0(ObFrame, 1);
92 self->client = client;
93
94 visual = check_32bit_client(client);
95
96 /* create the non-visible decor windows */
97
98 mask = 0;
99 if (visual) {
100 /* client has a 32-bit visual */
101 mask |= CWColormap | CWBackPixel | CWBorderPixel;
102 /* create a colormap with the visual */
103 self->colormap = attrib.colormap =
104 XCreateColormap(ob_display,
105 RootWindow(ob_display, ob_screen),
106 visual, AllocNone);
107 attrib.background_pixel = BlackPixel(ob_display, ob_screen);
108 attrib.border_pixel = BlackPixel(ob_display, ob_screen);
109 }
110 self->window = createWindow(RootWindow(ob_display, ob_screen), visual,
111 mask, &attrib);
112
113 /* create the visible decor windows */
114
115 mask = 0;
116 if (visual) {
117 /* client has a 32-bit visual */
118 mask |= CWColormap | CWBackPixel | CWBorderPixel;
119 attrib.colormap = RrColormap(ob_rr_inst);
120 }
121
122 self->backback = createWindow(self->window, NULL, mask, &attrib);
123 self->backfront = createWindow(self->backback, NULL, mask, &attrib);
124
125 mask |= CWEventMask;
126 attrib.event_mask = ELEMENT_EVENTMASK;
127 self->title = createWindow(self->window, NULL, mask, &attrib);
128 self->titleleft = createWindow(self->window, NULL, mask, &attrib);
129 self->titletop = createWindow(self->window, NULL, mask, &attrib);
130 self->titletopleft = createWindow(self->window, NULL, mask, &attrib);
131 self->titletopright = createWindow(self->window, NULL, mask, &attrib);
132 self->titleright = createWindow(self->window, NULL, mask, &attrib);
133 self->titlebottom = createWindow(self->window, NULL, mask, &attrib);
134
135 self->topresize = createWindow(self->title, NULL, mask, &attrib);
136 self->tltresize = createWindow(self->title, NULL, mask, &attrib);
137 self->tllresize = createWindow(self->title, NULL, mask, &attrib);
138 self->trtresize = createWindow(self->title, NULL, mask, &attrib);
139 self->trrresize = createWindow(self->title, NULL, mask, &attrib);
140
141 self->left = createWindow(self->window, NULL, mask, &attrib);
142 self->right = createWindow(self->window, NULL, mask, &attrib);
143
144 self->innerleft = createWindow(self->window, NULL, mask, &attrib);
145 self->innertop = createWindow(self->window, NULL, mask, &attrib);
146 self->innerright = createWindow(self->window, NULL, mask, &attrib);
147 self->innerbottom = createWindow(self->window, NULL, mask, &attrib);
148
149 self->label = createWindow(self->title, NULL, mask, &attrib);
150 self->max = createWindow(self->title, NULL, mask, &attrib);
151 self->close = createWindow(self->title, NULL, mask, &attrib);
152 self->desk = createWindow(self->title, NULL, mask, &attrib);
153 self->shade = createWindow(self->title, NULL, mask, &attrib);
154 self->icon = createWindow(self->title, NULL, mask, &attrib);
155 self->iconify = createWindow(self->title, NULL, mask, &attrib);
156
157 self->handle = createWindow(self->window, NULL, mask, &attrib);
158 self->lgrip = createWindow(self->handle, NULL, mask, &attrib);
159 self->rgrip = createWindow(self->handle, NULL, mask, &attrib);
160
161 self->handleleft = createWindow(self->handle, NULL, mask, &attrib);
162 self->handleright = createWindow(self->handle, NULL, mask, &attrib);
163
164 self->handletop = createWindow(self->window, NULL, mask, &attrib);
165 self->handlebottom = createWindow(self->window, NULL, mask, &attrib);
166 self->lgripleft = createWindow(self->window, NULL, mask, &attrib);
167 self->lgriptop = createWindow(self->window, NULL, mask, &attrib);
168 self->lgripbottom = createWindow(self->window, NULL, mask, &attrib);
169 self->rgripright = createWindow(self->window, NULL, mask, &attrib);
170 self->rgriptop = createWindow(self->window, NULL, mask, &attrib);
171 self->rgripbottom = createWindow(self->window, NULL, mask, &attrib);
172
173 self->focused = FALSE;
174
175 /* the other stuff is shown based on decor settings */
176 XMapWindow(ob_display, self->label);
177 XMapWindow(ob_display, self->backback);
178 XMapWindow(ob_display, self->backfront);
179
180 self->max_press = self->close_press = self->desk_press =
181 self->iconify_press = self->shade_press = FALSE;
182 self->max_hover = self->close_hover = self->desk_hover =
183 self->iconify_hover = self->shade_hover = FALSE;
184
185 set_theme_statics(self);
186
187 return (ObFrame*)self;
188 }
189
190 static void set_theme_statics(ObFrame *self)
191 {
192 /* set colors/appearance/sizes for stuff that doesn't change */
193 XResizeWindow(ob_display, self->max,
194 ob_rr_theme->button_size, ob_rr_theme->button_size);
195 XResizeWindow(ob_display, self->iconify,
196 ob_rr_theme->button_size, ob_rr_theme->button_size);
197 XResizeWindow(ob_display, self->icon,
198 ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
199 XResizeWindow(ob_display, self->close,
200 ob_rr_theme->button_size, ob_rr_theme->button_size);
201 XResizeWindow(ob_display, self->desk,
202 ob_rr_theme->button_size, ob_rr_theme->button_size);
203 XResizeWindow(ob_display, self->shade,
204 ob_rr_theme->button_size, ob_rr_theme->button_size);
205 XResizeWindow(ob_display, self->tltresize,
206 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
207 XResizeWindow(ob_display, self->trtresize,
208 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
209 XResizeWindow(ob_display, self->tllresize,
210 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
211 XResizeWindow(ob_display, self->trrresize,
212 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
213
214 /* set up the dynamic appearances */
215 self->a_unfocused_title = RrAppearanceCopy(ob_rr_theme->a_unfocused_title);
216 self->a_focused_title = RrAppearanceCopy(ob_rr_theme->a_focused_title);
217 self->a_unfocused_label = RrAppearanceCopy(ob_rr_theme->a_unfocused_label);
218 self->a_focused_label = RrAppearanceCopy(ob_rr_theme->a_focused_label);
219 self->a_unfocused_handle =
220 RrAppearanceCopy(ob_rr_theme->a_unfocused_handle);
221 self->a_focused_handle = RrAppearanceCopy(ob_rr_theme->a_focused_handle);
222 self->a_icon = RrAppearanceCopy(ob_rr_theme->a_icon);
223 }
224
225 static void free_theme_statics(ObFrame *self)
226 {
227 RrAppearanceFree(self->a_unfocused_title);
228 RrAppearanceFree(self->a_focused_title);
229 RrAppearanceFree(self->a_unfocused_label);
230 RrAppearanceFree(self->a_focused_label);
231 RrAppearanceFree(self->a_unfocused_handle);
232 RrAppearanceFree(self->a_focused_handle);
233 RrAppearanceFree(self->a_icon);
234 }
235
236 void frame_free(ObFrame *self)
237 {
238 free_theme_statics(self);
239
240 XDestroyWindow(ob_display, self->window);
241 if (self->colormap)
242 XFreeColormap(ob_display, self->colormap);
243
244 g_free(self);
245 }
246
247 void frame_show(ObFrame *self)
248 {
249 if (!self->visible) {
250 self->visible = TRUE;
251 framerender_frame(self);
252 XMapWindow(ob_display, self->client->window);
253 XMapWindow(ob_display, self->window);
254 }
255 }
256
257 void frame_hide(ObFrame *self)
258 {
259 if (self->visible) {
260 self->visible = FALSE;
261 if (!frame_iconify_animating(self))
262 XUnmapWindow(ob_display, self->window);
263 /* we unmap the client itself so that we can get MapRequest
264 events, and because the ICCCM tells us to! */
265 XUnmapWindow(ob_display, self->client->window);
266 self->client->ignore_unmaps += 1;
267 }
268 }
269
270 void frame_adjust_theme(ObFrame *self)
271 {
272 free_theme_statics(self);
273 set_theme_statics(self);
274 }
275
276 void frame_adjust_shape(ObFrame *self)
277 {
278 #ifdef SHAPE
279 gint num;
280 XRectangle xrect[2];
281
282 if (!self->client->shaped) {
283 /* clear the shape on the frame window */
284 XShapeCombineMask(ob_display, self->window, ShapeBounding,
285 self->size.left,
286 self->size.top,
287 None, ShapeSet);
288 } else {
289 /* make the frame's shape match the clients */
290 XShapeCombineShape(ob_display, self->window, ShapeBounding,
291 self->size.left,
292 self->size.top,
293 self->client->window,
294 ShapeBounding, ShapeSet);
295
296 num = 0;
297 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
298 xrect[0].x = 0;
299 xrect[0].y = 0;
300 xrect[0].width = self->area.width;
301 xrect[0].height = self->size.top;
302 ++num;
303 }
304
305 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
306 ob_rr_theme->handle_height > 0)
307 {
308 xrect[1].x = 0;
309 xrect[1].y = FRAME_HANDLE_Y(self);
310 xrect[1].width = self->area.width;
311 xrect[1].height = ob_rr_theme->handle_height +
312 self->bwidth * 2;
313 ++num;
314 }
315
316 XShapeCombineRectangles(ob_display, self->window,
317 ShapeBounding, 0, 0, xrect, num,
318 ShapeUnion, Unsorted);
319 }
320 #endif
321 }
322
323 void frame_adjust_area(ObFrame *self, gboolean moved,
324 gboolean resized, gboolean fake)
325 {
326 Strut oldsize;
327
328 oldsize = self->size;
329
330 if (resized) {
331 /* do this before changing the frame's status like max_horz max_vert */
332 frame_adjust_cursors(self);
333
334 self->functions = self->client->functions;
335 self->decorations = self->client->decorations;
336 self->max_horz = self->client->max_horz;
337 self->max_vert = self->client->max_vert;
338 self->shaded = self->client->shaded;
339
340 if (self->decorations & OB_FRAME_DECOR_BORDER ||
341 (self->client->undecorated && config_theme_keepborder))
342 self->bwidth = ob_rr_theme->fbwidth;
343 else
344 self->bwidth = 0;
345
346 if (self->decorations & OB_FRAME_DECOR_BORDER) {
347 self->cbwidth_l = self->cbwidth_r = ob_rr_theme->cbwidthx;
348 self->cbwidth_t = self->cbwidth_b = ob_rr_theme->cbwidthy;
349 } else
350 self->cbwidth_l = self->cbwidth_t =
351 self->cbwidth_r = self->cbwidth_b = 0;
352
353 if (self->max_horz) {
354 self->cbwidth_l = self->cbwidth_r = 0;
355 self->width = self->client->area.width - self->bwidth * 2;
356 if (self->max_vert)
357 self->cbwidth_b = 0;
358 } else
359 self->width = self->client->area.width +
360 self->cbwidth_l + self->cbwidth_r;
361
362 /* some elements are sized based of the width, so don't let them have
363 negative values */
364 self->width = MAX(self->width,
365 (ob_rr_theme->grip_width + self->bwidth) * 2 + 1);
366
367 STRUT_SET(self->size,
368 self->cbwidth_l + (!self->max_horz ? self->bwidth : 0),
369 self->cbwidth_t + self->bwidth,
370 self->cbwidth_r + (!self->max_horz ? self->bwidth : 0),
371 self->cbwidth_b + (!self->max_horz || !self->max_vert ? self->bwidth : 0));
372
373 if (self->decorations & OB_FRAME_DECOR_TITLEBAR)
374 self->size.top += ob_rr_theme->title_height + self->bwidth;
375 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
376 ob_rr_theme->handle_height > 0)
377 {
378 self->size.bottom += ob_rr_theme->handle_height + self->bwidth;
379 }
380
381 /* position/size and map/unmap all the windows */
382
383 if (!fake) {
384 if (self->cbwidth_l) {
385 XMoveResizeWindow(ob_display, self->innerleft,
386 self->size.left - self->cbwidth_l,
387 self->size.top,
388 self->cbwidth_l, self->client->area.height);
389
390 XMapWindow(ob_display, self->innerleft);
391 } else
392 XUnmapWindow(ob_display, self->innerleft);
393
394 if (self->cbwidth_r) {
395 XMoveResizeWindow(ob_display, self->innerright,
396 self->size.left + self->client->area.width,
397 self->size.top,
398 self->cbwidth_r, self->client->area.height);
399
400 XMapWindow(ob_display, self->innerright);
401 } else
402 XUnmapWindow(ob_display, self->innerright);
403
404 if (self->cbwidth_t) {
405 XMoveResizeWindow(ob_display, self->innertop,
406 self->size.left - self->cbwidth_l,
407 self->size.top - self->cbwidth_t,
408 self->client->area.width +
409 self->cbwidth_l + self->cbwidth_r,
410 self->cbwidth_t);
411
412 XMapWindow(ob_display, self->innertop);
413 } else
414 XUnmapWindow(ob_display, self->innertop);
415
416 if (self->cbwidth_b) {
417 XMoveResizeWindow(ob_display, self->innerbottom,
418 self->size.left - self->cbwidth_l,
419 self->size.top + self->client->area.height,
420 self->client->area.width +
421 self->cbwidth_l + self->cbwidth_r,
422 self->cbwidth_b);
423
424 XMapWindow(ob_display, self->innerbottom);
425 } else
426 XUnmapWindow(ob_display, self->innerbottom);
427
428 if (self->bwidth) {
429 gint titlesides;
430
431 /* height of titleleft and titleright */
432 titlesides = (!self->max_horz ?
433 ob_rr_theme->grip_width :
434 self->size.top - self->bwidth);
435
436 XMoveResizeWindow(ob_display, self->titletop,
437 ob_rr_theme->grip_width + self->bwidth, 0,
438 /* width + bwidth*2 - bwidth*2 - grips*2 */
439 self->width - ob_rr_theme->grip_width * 2,
440 self->bwidth);
441 XMoveResizeWindow(ob_display, self->titletopleft,
442 0, 0,
443 ob_rr_theme->grip_width + self->bwidth,
444 self->bwidth);
445 XMoveResizeWindow(ob_display, self->titletopright,
446 self->client->area.width +
447 self->size.left + self->size.right -
448 ob_rr_theme->grip_width - self->bwidth,
449 0,
450 ob_rr_theme->grip_width + self->bwidth,
451 self->bwidth);
452
453 if (titlesides > 0) {
454 XMoveResizeWindow(ob_display, self->titleleft,
455 0, self->bwidth,
456 self->bwidth,
457 titlesides);
458 XMoveResizeWindow(ob_display, self->titleright,
459 self->client->area.width +
460 self->size.left + self->size.right -
461 self->bwidth,
462 self->bwidth,
463 self->bwidth,
464 titlesides);
465
466 XMapWindow(ob_display, self->titleleft);
467 XMapWindow(ob_display, self->titleright);
468 } else {
469 XUnmapWindow(ob_display, self->titleleft);
470 XUnmapWindow(ob_display, self->titleright);
471 }
472
473 XMapWindow(ob_display, self->titletop);
474 XMapWindow(ob_display, self->titletopleft);
475 XMapWindow(ob_display, self->titletopright);
476
477 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
478 XMoveResizeWindow(ob_display, self->titlebottom,
479 self->bwidth,
480 ob_rr_theme->title_height + self->bwidth,
481 self->width,
482 self->bwidth);
483
484 XMapWindow(ob_display, self->titlebottom);
485 } else
486 XUnmapWindow(ob_display, self->titlebottom);
487 } else {
488 XUnmapWindow(ob_display, self->titlebottom);
489
490 XUnmapWindow(ob_display, self->titletop);
491 XUnmapWindow(ob_display, self->titletopleft);
492 XUnmapWindow(ob_display, self->titletopright);
493 XUnmapWindow(ob_display, self->titleleft);
494 XUnmapWindow(ob_display, self->titleright);
495 }
496
497 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
498 XMoveResizeWindow(ob_display, self->title,
499 self->bwidth, self->bwidth,
500 self->width, ob_rr_theme->title_height);
501
502 XMapWindow(ob_display, self->title);
503
504 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
505 XMoveResizeWindow(ob_display, self->topresize,
506 ob_rr_theme->grip_width,
507 0,
508 self->width - ob_rr_theme->grip_width *2,
509 ob_rr_theme->paddingy + 1);
510
511 XMoveWindow(ob_display, self->tltresize, 0, 0);
512 XMoveWindow(ob_display, self->tllresize, 0, 0);
513 XMoveWindow(ob_display, self->trtresize,
514 self->width - ob_rr_theme->grip_width, 0);
515 XMoveWindow(ob_display, self->trrresize,
516 self->width - ob_rr_theme->paddingx - 1, 0);
517
518 XMapWindow(ob_display, self->topresize);
519 XMapWindow(ob_display, self->tltresize);
520 XMapWindow(ob_display, self->tllresize);
521 XMapWindow(ob_display, self->trtresize);
522 XMapWindow(ob_display, self->trrresize);
523 } else {
524 XUnmapWindow(ob_display, self->topresize);
525 XUnmapWindow(ob_display, self->tltresize);
526 XUnmapWindow(ob_display, self->tllresize);
527 XUnmapWindow(ob_display, self->trtresize);
528 XUnmapWindow(ob_display, self->trrresize);
529 }
530 } else
531 XUnmapWindow(ob_display, self->title);
532 }
533
534 if ((self->decorations & OB_FRAME_DECOR_TITLEBAR))
535 /* layout the title bar elements */
536 layout_title(self);
537
538 if (!fake) {
539 if (self->bwidth && self->size.bottom) {
540 XMoveResizeWindow(ob_display, self->handlebottom,
541 ob_rr_theme->grip_width +
542 self->bwidth * 2,
543 self->size.top + self->client->area.height +
544 self->size.bottom - self->bwidth,
545 self->width - (ob_rr_theme->grip_width +
546 self->bwidth) * 2,
547 self->bwidth);
548
549 XMoveResizeWindow(ob_display, self->lgripleft,
550 0,
551 self->size.top + self->client->area.height +
552 self->size.bottom -
553 (!self->max_horz ?
554 ob_rr_theme->grip_width :
555 self->size.bottom - self->cbwidth_b),
556 self->bwidth,
557 (!self->max_horz ?
558 ob_rr_theme->grip_width :
559 self->size.bottom - self->cbwidth_b));
560 XMoveResizeWindow(ob_display, self->rgripright,
561 self->size.left + self->client->area.width +
562 self->size.right - self->bwidth,
563 self->size.top + self->client->area.height +
564 self->size.bottom -
565 (!self->max_horz ?
566 ob_rr_theme->grip_width :
567 self->size.bottom - self->cbwidth_b),
568 self->bwidth,
569 (!self->max_horz ?
570 ob_rr_theme->grip_width :
571 self->size.bottom - self->cbwidth_b));
572
573 XMoveResizeWindow(ob_display, self->lgripbottom,
574 self->bwidth,
575 self->size.top + self->client->area.height +
576 self->size.bottom - self->bwidth,
577 ob_rr_theme->grip_width + self->bwidth,
578 self->bwidth);
579 XMoveResizeWindow(ob_display, self->rgripbottom,
580 self->size.left + self->client->area.width +
581 self->size.right - self->bwidth * 2 -
582 ob_rr_theme->grip_width,
583 self->size.top + self->client->area.height +
584 self->size.bottom - self->bwidth,
585 ob_rr_theme->grip_width + self->bwidth,
586 self->bwidth);
587
588 XMapWindow(ob_display, self->handlebottom);
589 XMapWindow(ob_display, self->lgripleft);
590 XMapWindow(ob_display, self->rgripright);
591 XMapWindow(ob_display, self->lgripbottom);
592 XMapWindow(ob_display, self->rgripbottom);
593
594 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
595 ob_rr_theme->handle_height > 0)
596 {
597 XMoveResizeWindow(ob_display, self->handletop,
598 ob_rr_theme->grip_width +
599 self->bwidth * 2,
600 FRAME_HANDLE_Y(self),
601 self->width - (ob_rr_theme->grip_width +
602 self->bwidth) * 2,
603 self->bwidth);
604 XMapWindow(ob_display, self->handletop);
605
606 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
607 XMoveResizeWindow(ob_display, self->handleleft,
608 ob_rr_theme->grip_width,
609 0,
610 self->bwidth,
611 ob_rr_theme->handle_height);
612 XMoveResizeWindow(ob_display, self->handleright,
613 self->width -
614 ob_rr_theme->grip_width -
615 self->bwidth,
616 0,
617 self->bwidth,
618 ob_rr_theme->handle_height);
619
620 XMoveResizeWindow(ob_display, self->lgriptop,
621 self->bwidth,
622 FRAME_HANDLE_Y(self),
623 ob_rr_theme->grip_width +
624 self->bwidth,
625 self->bwidth);
626 XMoveResizeWindow(ob_display, self->rgriptop,
627 self->size.left +
628 self->client->area.width +
629 self->size.right - self->bwidth * 2 -
630 ob_rr_theme->grip_width,
631 FRAME_HANDLE_Y(self),
632 ob_rr_theme->grip_width +
633 self->bwidth,
634 self->bwidth);
635
636 XMapWindow(ob_display, self->handleleft);
637 XMapWindow(ob_display, self->handleright);
638 XMapWindow(ob_display, self->lgriptop);
639 XMapWindow(ob_display, self->rgriptop);
640 } else {
641 XUnmapWindow(ob_display, self->handleleft);
642 XUnmapWindow(ob_display, self->handleright);
643 XUnmapWindow(ob_display, self->lgriptop);
644 XUnmapWindow(ob_display, self->rgriptop);
645 }
646 } else {
647 XUnmapWindow(ob_display, self->handleleft);
648 XUnmapWindow(ob_display, self->handleright);
649 XUnmapWindow(ob_display, self->lgriptop);
650 XUnmapWindow(ob_display, self->rgriptop);
651
652 XUnmapWindow(ob_display, self->handletop);
653 }
654 } else {
655 XUnmapWindow(ob_display, self->handleleft);
656 XUnmapWindow(ob_display, self->handleright);
657 XUnmapWindow(ob_display, self->lgriptop);
658 XUnmapWindow(ob_display, self->rgriptop);
659
660 XUnmapWindow(ob_display, self->handletop);
661
662 XUnmapWindow(ob_display, self->handlebottom);
663 XUnmapWindow(ob_display, self->lgripleft);
664 XUnmapWindow(ob_display, self->rgripright);
665 XUnmapWindow(ob_display, self->lgripbottom);
666 XUnmapWindow(ob_display, self->rgripbottom);
667 }
668
669 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
670 ob_rr_theme->handle_height > 0)
671 {
672 XMoveResizeWindow(ob_display, self->handle,
673 self->bwidth,
674 FRAME_HANDLE_Y(self) + self->bwidth,
675 self->width, ob_rr_theme->handle_height);
676 XMapWindow(ob_display, self->handle);
677
678 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
679 XMoveResizeWindow(ob_display, self->lgrip,
680 0, 0,
681 ob_rr_theme->grip_width,
682 ob_rr_theme->handle_height);
683 XMoveResizeWindow(ob_display, self->rgrip,
684 self->width - ob_rr_theme->grip_width,
685 0,
686 ob_rr_theme->grip_width,
687 ob_rr_theme->handle_height);
688
689 XMapWindow(ob_display, self->lgrip);
690 XMapWindow(ob_display, self->rgrip);
691 } else {
692 XUnmapWindow(ob_display, self->lgrip);
693 XUnmapWindow(ob_display, self->rgrip);
694 }
695 } else {
696 XUnmapWindow(ob_display, self->lgrip);
697 XUnmapWindow(ob_display, self->rgrip);
698
699 XUnmapWindow(ob_display, self->handle);
700 }
701
702 if (self->bwidth && !self->max_horz) {
703 XMoveResizeWindow(ob_display, self->left,
704 0,
705 self->bwidth + ob_rr_theme->grip_width,
706 self->bwidth,
707 self->client->area.height +
708 self->size.top + self->size.bottom -
709 ob_rr_theme->grip_width * 2);
710
711 XMapWindow(ob_display, self->left);
712 } else
713 XUnmapWindow(ob_display, self->left);
714
715 if (self->bwidth && !self->max_horz) {
716 XMoveResizeWindow(ob_display, self->right,
717 self->client->area.width +
718 self->cbwidth_l + self->cbwidth_r + self->bwidth,
719 self->bwidth + ob_rr_theme->grip_width,
720 self->bwidth,
721 self->client->area.height +
722 self->size.top + self->size.bottom -
723 ob_rr_theme->grip_width * 2);
724
725 XMapWindow(ob_display, self->right);
726 } else
727 XUnmapWindow(ob_display, self->right);
728
729 XMoveResizeWindow(ob_display, self->backback,
730 self->size.left, self->size.top,
731 self->client->area.width,
732 self->client->area.height);
733 }
734 }
735
736 /* shading can change without being moved or resized */
737 RECT_SET_SIZE(self->area,
738 self->client->area.width +
739 self->size.left + self->size.right,
740 (self->client->shaded ?
741 ob_rr_theme->title_height + self->bwidth * 2:
742 self->client->area.height +
743 self->size.top + self->size.bottom));
744
745 if ((moved || resized) && !fake) {
746 /* find the new coordinates, done after setting the frame.size, for
747 frame_client_gravity. */
748 self->area.x = self->client->area.x;
749 self->area.y = self->client->area.y;
750 frame_client_gravity(self, &self->area.x, &self->area.y,
751 self->client->area.width,
752 self->client->area.height);
753 }
754
755 if (!fake) {
756 if (!frame_iconify_animating(self))
757 /* move and resize the top level frame.
758 shading can change without being moved or resized.
759
760 but don't do this during an iconify animation. it will be
761 reflected afterwards.
762 */
763 XMoveResizeWindow(ob_display, self->window,
764 self->area.x,
765 self->area.y,
766 self->area.width,
767 self->area.height);
768
769 /* when the client has StaticGravity, it likes to move around.
770 also this correctly positions the client when it maps.
771 this also needs to be run when the frame's decorations sizes change!
772 */
773 XMoveWindow(ob_display, self->client->window,
774 self->size.left, self->size.top);
775
776 if (resized) {
777 self->need_render = TRUE;
778 framerender_frame(self);
779 frame_adjust_shape(self);
780 }
781
782 if (!STRUT_EQUAL(self->size, oldsize)) {
783 gulong vals[4];
784 vals[0] = self->size.left;
785 vals[1] = self->size.right;
786 vals[2] = self->size.top;
787 vals[3] = self->size.bottom;
788 PROP_SETA32(self->client->window, net_frame_extents,
789 cardinal, vals, 4);
790 PROP_SETA32(self->client->window, kde_net_wm_frame_strut,
791 cardinal, vals, 4);
792 }
793
794 /* if this occurs while we are focus cycling, the indicator needs to
795 match the changes */
796 if (focus_cycle_target == self->client)
797 focus_cycle_draw_indicator(self->client);
798 }
799 if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR))
800 XResizeWindow(ob_display, self->label, self->label_width,
801 ob_rr_theme->label_height);
802
803 }
804
805 static void frame_adjust_cursors(ObFrame *self)
806 {
807 if ((self->functions & OB_CLIENT_FUNC_RESIZE) !=
808 (self->client->functions & OB_CLIENT_FUNC_RESIZE) ||
809 self->max_horz != self->client->max_horz ||
810 self->max_vert != self->client->max_vert ||
811 self->shaded != self->client->shaded)
812 {
813 gboolean r = (self->client->functions & OB_CLIENT_FUNC_RESIZE) &&
814 !(self->client->max_horz && self->client->max_vert);
815 gboolean topbot = !self->client->max_vert;
816 gboolean sh = self->client->shaded;
817 XSetWindowAttributes a;
818
819 /* these ones turn off when max vert, and some when shaded */
820 a.cursor = ob_cursor(r && topbot && !sh ?
821 OB_CURSOR_NORTH : OB_CURSOR_NONE);
822 XChangeWindowAttributes(ob_display, self->topresize, CWCursor, &a);
823 XChangeWindowAttributes(ob_display, self->titletop, CWCursor, &a);
824 a.cursor = ob_cursor(r && topbot ? OB_CURSOR_SOUTH : OB_CURSOR_NONE);
825 XChangeWindowAttributes(ob_display, self->handle, CWCursor, &a);
826 XChangeWindowAttributes(ob_display, self->handletop, CWCursor, &a);
827 XChangeWindowAttributes(ob_display, self->handlebottom, CWCursor, &a);
828 XChangeWindowAttributes(ob_display, self->innerbottom, CWCursor, &a);
829
830 /* these ones change when shaded */
831 a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_WEST : OB_CURSOR_NORTHWEST) :
832 OB_CURSOR_NONE);
833 XChangeWindowAttributes(ob_display, self->titleleft, CWCursor, &a);
834 XChangeWindowAttributes(ob_display, self->tltresize, CWCursor, &a);
835 XChangeWindowAttributes(ob_display, self->tllresize, CWCursor, &a);
836 XChangeWindowAttributes(ob_display, self->titletopleft, CWCursor, &a);
837 a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_EAST : OB_CURSOR_NORTHEAST) :
838 OB_CURSOR_NONE);
839 XChangeWindowAttributes(ob_display, self->titleright, CWCursor, &a);
840 XChangeWindowAttributes(ob_display, self->trtresize, CWCursor, &a);
841 XChangeWindowAttributes(ob_display, self->trrresize, CWCursor, &a);
842 XChangeWindowAttributes(ob_display, self->titletopright, CWCursor, &a);
843
844 /* these ones are pretty static */
845 a.cursor = ob_cursor(r ? OB_CURSOR_WEST : OB_CURSOR_NONE);
846 XChangeWindowAttributes(ob_display, self->left, CWCursor, &a);
847 XChangeWindowAttributes(ob_display, self->innerleft, CWCursor, &a);
848 a.cursor = ob_cursor(r ? OB_CURSOR_EAST : OB_CURSOR_NONE);
849 XChangeWindowAttributes(ob_display, self->right, CWCursor, &a);
850 XChangeWindowAttributes(ob_display, self->innerright, CWCursor, &a);
851 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHWEST : OB_CURSOR_NONE);
852 XChangeWindowAttributes(ob_display, self->lgrip, CWCursor, &a);
853 XChangeWindowAttributes(ob_display, self->handleleft, CWCursor, &a);
854 XChangeWindowAttributes(ob_display, self->lgripleft, CWCursor, &a);
855 XChangeWindowAttributes(ob_display, self->lgriptop, CWCursor, &a);
856 XChangeWindowAttributes(ob_display, self->lgripbottom, CWCursor, &a);
857 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHEAST : OB_CURSOR_NONE);
858 XChangeWindowAttributes(ob_display, self->rgrip, CWCursor, &a);
859 XChangeWindowAttributes(ob_display, self->handleright, CWCursor, &a);
860 XChangeWindowAttributes(ob_display, self->rgripright, CWCursor, &a);
861 XChangeWindowAttributes(ob_display, self->rgriptop, CWCursor, &a);
862 XChangeWindowAttributes(ob_display, self->rgripbottom, CWCursor, &a);
863 }
864 }
865
866 void frame_adjust_client_area(ObFrame *self)
867 {
868 /* adjust the window which is there to prevent flashing on unmap */
869 XMoveResizeWindow(ob_display, self->backfront, 0, 0,
870 self->client->area.width,
871 self->client->area.height);
872 }
873
874 void frame_adjust_state(ObFrame *self)
875 {
876 self->need_render = TRUE;
877 framerender_frame(self);
878 }
879
880 void frame_adjust_focus(ObFrame *self, gboolean hilite)
881 {
882 self->focused = hilite;
883 self->need_render = TRUE;
884 framerender_frame(self);
885 XFlush(ob_display);
886 }
887
888 void frame_adjust_title(ObFrame *self)
889 {
890 self->need_render = TRUE;
891 framerender_frame(self);
892 }
893
894 void frame_adjust_icon(ObFrame *self)
895 {
896 self->need_render = TRUE;
897 framerender_frame(self);
898 }
899
900 void frame_grab_client(ObFrame *self)
901 {
902 /* DO NOT map the client window here. we used to do that, but it is bogus.
903 we need to set up the client's dimensions and everything before we
904 send a mapnotify or we create race conditions.
905 */
906
907 /* reparent the client to the frame */
908 XReparentWindow(ob_display, self->client->window, self->window, 0, 0);
909
910 /*
911 When reparenting the client window, it is usually not mapped yet, since
912 this occurs from a MapRequest. However, in the case where Openbox is
913 starting up, the window is already mapped, so we'll see an unmap event
914 for it.
915 */
916 if (ob_state() == OB_STATE_STARTING)
917 ++self->client->ignore_unmaps;
918
919 /* select the event mask on the client's parent (to receive config/map
920 req's) the ButtonPress is to catch clicks on the client border */
921 XSelectInput(ob_display, self->window, FRAME_EVENTMASK);
922
923 /* set all the windows for the frame in the window_map */
924 g_hash_table_insert(window_map, &self->window, self->client);
925 g_hash_table_insert(window_map, &self->backback, self->client);
926 g_hash_table_insert(window_map, &self->backfront, self->client);
927 g_hash_table_insert(window_map, &self->innerleft, self->client);
928 g_hash_table_insert(window_map, &self->innertop, self->client);
929 g_hash_table_insert(window_map, &self->innerright, self->client);
930 g_hash_table_insert(window_map, &self->innerbottom, self->client);
931 g_hash_table_insert(window_map, &self->title, self->client);
932 g_hash_table_insert(window_map, &self->label, self->client);
933 g_hash_table_insert(window_map, &self->max, self->client);
934 g_hash_table_insert(window_map, &self->close, self->client);
935 g_hash_table_insert(window_map, &self->desk, self->client);
936 g_hash_table_insert(window_map, &self->shade, self->client);
937 g_hash_table_insert(window_map, &self->icon, self->client);
938 g_hash_table_insert(window_map, &self->iconify, self->client);
939 g_hash_table_insert(window_map, &self->handle, self->client);
940 g_hash_table_insert(window_map, &self->lgrip, self->client);
941 g_hash_table_insert(window_map, &self->rgrip, self->client);
942 g_hash_table_insert(window_map, &self->topresize, self->client);
943 g_hash_table_insert(window_map, &self->tltresize, self->client);
944 g_hash_table_insert(window_map, &self->tllresize, self->client);
945 g_hash_table_insert(window_map, &self->trtresize, self->client);
946 g_hash_table_insert(window_map, &self->trrresize, self->client);
947 g_hash_table_insert(window_map, &self->left, self->client);
948 g_hash_table_insert(window_map, &self->right, self->client);
949 g_hash_table_insert(window_map, &self->titleleft, self->client);
950 g_hash_table_insert(window_map, &self->titletop, self->client);
951 g_hash_table_insert(window_map, &self->titletopleft, self->client);
952 g_hash_table_insert(window_map, &self->titletopright, self->client);
953 g_hash_table_insert(window_map, &self->titleright, self->client);
954 g_hash_table_insert(window_map, &self->titlebottom, self->client);
955 g_hash_table_insert(window_map, &self->handleleft, self->client);
956 g_hash_table_insert(window_map, &self->handletop, self->client);
957 g_hash_table_insert(window_map, &self->handleright, self->client);
958 g_hash_table_insert(window_map, &self->handlebottom, self->client);
959 g_hash_table_insert(window_map, &self->lgripleft, self->client);
960 g_hash_table_insert(window_map, &self->lgriptop, self->client);
961 g_hash_table_insert(window_map, &self->lgripbottom, self->client);
962 g_hash_table_insert(window_map, &self->rgripright, self->client);
963 g_hash_table_insert(window_map, &self->rgriptop, self->client);
964 g_hash_table_insert(window_map, &self->rgripbottom, self->client);
965 }
966
967 void frame_release_client(ObFrame *self)
968 {
969 XEvent ev;
970 gboolean reparent = TRUE;
971
972 /* if there was any animation going on, kill it */
973 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
974 self, FALSE);
975
976 /* check if the app has already reparented its window away */
977 while (XCheckTypedWindowEvent(ob_display, self->client->window,
978 ReparentNotify, &ev))
979 {
980 /* This check makes sure we don't catch our own reparent action to
981 our frame window. This doesn't count as the app reparenting itself
982 away of course.
983
984 Reparent events that are generated by us are just discarded here.
985 They are of no consequence to us anyhow.
986 */
987 if (ev.xreparent.parent != self->window) {
988 reparent = FALSE;
989 XPutBackEvent(ob_display, &ev);
990 break;
991 }
992 }
993
994 if (reparent) {
995 /* according to the ICCCM - if the client doesn't reparent itself,
996 then we will reparent the window to root for them */
997 XReparentWindow(ob_display, self->client->window,
998 RootWindow(ob_display, ob_screen),
999 self->client->area.x,
1000 self->client->area.y);
1001 }
1002
1003 /* remove all the windows for the frame from the window_map */
1004 g_hash_table_remove(window_map, &self->window);
1005 g_hash_table_remove(window_map, &self->backback);
1006 g_hash_table_remove(window_map, &self->backfront);
1007 g_hash_table_remove(window_map, &self->innerleft);
1008 g_hash_table_remove(window_map, &self->innertop);
1009 g_hash_table_remove(window_map, &self->innerright);
1010 g_hash_table_remove(window_map, &self->innerbottom);
1011 g_hash_table_remove(window_map, &self->title);
1012 g_hash_table_remove(window_map, &self->label);
1013 g_hash_table_remove(window_map, &self->max);
1014 g_hash_table_remove(window_map, &self->close);
1015 g_hash_table_remove(window_map, &self->desk);
1016 g_hash_table_remove(window_map, &self->shade);
1017 g_hash_table_remove(window_map, &self->icon);
1018 g_hash_table_remove(window_map, &self->iconify);
1019 g_hash_table_remove(window_map, &self->handle);
1020 g_hash_table_remove(window_map, &self->lgrip);
1021 g_hash_table_remove(window_map, &self->rgrip);
1022 g_hash_table_remove(window_map, &self->topresize);
1023 g_hash_table_remove(window_map, &self->tltresize);
1024 g_hash_table_remove(window_map, &self->tllresize);
1025 g_hash_table_remove(window_map, &self->trtresize);
1026 g_hash_table_remove(window_map, &self->trrresize);
1027 g_hash_table_remove(window_map, &self->left);
1028 g_hash_table_remove(window_map, &self->right);
1029 g_hash_table_remove(window_map, &self->titleleft);
1030 g_hash_table_remove(window_map, &self->titletop);
1031 g_hash_table_remove(window_map, &self->titletopleft);
1032 g_hash_table_remove(window_map, &self->titletopright);
1033 g_hash_table_remove(window_map, &self->titleright);
1034 g_hash_table_remove(window_map, &self->titlebottom);
1035 g_hash_table_remove(window_map, &self->handleleft);
1036 g_hash_table_remove(window_map, &self->handletop);
1037 g_hash_table_remove(window_map, &self->handleright);
1038 g_hash_table_remove(window_map, &self->handlebottom);
1039 g_hash_table_remove(window_map, &self->lgripleft);
1040 g_hash_table_remove(window_map, &self->lgriptop);
1041 g_hash_table_remove(window_map, &self->lgripbottom);
1042 g_hash_table_remove(window_map, &self->rgripright);
1043 g_hash_table_remove(window_map, &self->rgriptop);
1044 g_hash_table_remove(window_map, &self->rgripbottom);
1045
1046 ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
1047 }
1048
1049 /* is there anything present between us and the label? */
1050 static gboolean is_button_present(ObFrame *self, const gchar *lc, gint dir) {
1051 for (; *lc != '\0' && lc >= config_title_layout; lc += dir) {
1052 if (*lc == ' ') continue; /* it was invalid */
1053 if (*lc == 'N' && self->decorations & OB_FRAME_DECOR_ICON)
1054 return TRUE;
1055 if (*lc == 'D' && self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
1056 return TRUE;
1057 if (*lc == 'S' && self->decorations & OB_FRAME_DECOR_SHADE)
1058 return TRUE;
1059 if (*lc == 'I' && self->decorations & OB_FRAME_DECOR_ICONIFY)
1060 return TRUE;
1061 if (*lc == 'M' && self->decorations & OB_FRAME_DECOR_MAXIMIZE)
1062 return TRUE;
1063 if (*lc == 'C' && self->decorations & OB_FRAME_DECOR_CLOSE)
1064 return TRUE;
1065 if (*lc == 'L') return FALSE;
1066 }
1067 return FALSE;
1068 }
1069
1070 static void layout_title(ObFrame *self)
1071 {
1072 gchar *lc;
1073 gint i;
1074
1075 const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
1076 /* position of the left most button */
1077 const gint left = ob_rr_theme->paddingx + 1;
1078 /* position of the right most button */
1079 const gint right = self->width;
1080
1081 /* turn them all off */
1082 self->icon_on = self->desk_on = self->shade_on = self->iconify_on =
1083 self->max_on = self->close_on = self->label_on = FALSE;
1084 self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
1085 self->leftmost = self->rightmost = OB_FRAME_CONTEXT_NONE;
1086
1087 /* figure out what's being show, find each element's position, and the
1088 width of the label
1089
1090 do the ones before the label, then after the label,
1091 i will be +1 the first time through when working to the left,
1092 and -1 the second time through when working to the right */
1093 for (i = 1; i >= -1; i-=2) {
1094 gint x;
1095 ObFrameContext *firstcon;
1096
1097 if (i > 0) {
1098 x = left;
1099 lc = config_title_layout;
1100 firstcon = &self->leftmost;
1101 } else {
1102 x = right;
1103 lc = config_title_layout + strlen(config_title_layout)-1;
1104 firstcon = &self->rightmost;
1105 }
1106
1107 /* stop at the end of the string (or the label, which calls break) */
1108 for (; *lc != '\0' && lc >= config_title_layout; lc+=i) {
1109 if (*lc == 'L') {
1110 if (i > 0) {
1111 self->label_on = TRUE;
1112 self->label_x = x;
1113 }
1114 break; /* break the for loop, do other side of label */
1115 } else if (*lc == 'N') {
1116 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICON;
1117 if ((self->icon_on = is_button_present(self, lc, i))) {
1118 /* icon is bigger than buttons */
1119 self->label_width -= bwidth + 2;
1120 if (i > 0) self->icon_x = x;
1121 x += i * (bwidth + 2);
1122 if (i < 0) self->icon_x = x;
1123 }
1124 } else if (*lc == 'D') {
1125 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
1126 if ((self->desk_on = is_button_present(self, lc, i))) {
1127 self->label_width -= bwidth;
1128 if (i > 0) self->desk_x = x;
1129 x += i * bwidth;
1130 if (i < 0) self->desk_x = x;
1131 }
1132 } else if (*lc == 'S') {
1133 if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
1134 if ((self->shade_on = is_button_present(self, lc, i))) {
1135 self->label_width -= bwidth;
1136 if (i > 0) self->shade_x = x;
1137 x += i * bwidth;
1138 if (i < 0) self->shade_x = x;
1139 }
1140 } else if (*lc == 'I') {
1141 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
1142 if ((self->iconify_on = is_button_present(self, lc, i))) {
1143 self->label_width -= bwidth;
1144 if (i > 0) self->iconify_x = x;
1145 x += i * bwidth;
1146 if (i < 0) self->iconify_x = x;
1147 }
1148 } else if (*lc == 'M') {
1149 if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
1150 if ((self->max_on = is_button_present(self, lc, i))) {
1151 self->label_width -= bwidth;
1152 if (i > 0) self->max_x = x;
1153 x += i * bwidth;
1154 if (i < 0) self->max_x = x;
1155 }
1156 } else if (*lc == 'C') {
1157 if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
1158 if ((self->close_on = is_button_present(self, lc, i))) {
1159 self->label_width -= bwidth;
1160 if (i > 0) self->close_x = x;
1161 x += i * bwidth;
1162 if (i < 0) self->close_x = x;
1163 }
1164 } else
1165 continue; /* don't set firstcon */
1166 firstcon = NULL;
1167 }
1168 }
1169
1170 /* position and map the elements */
1171 if (self->icon_on) {
1172 XMapWindow(ob_display, self->icon);
1173 XMoveWindow(ob_display, self->icon, self->icon_x,
1174 ob_rr_theme->paddingy);
1175 } else
1176 XUnmapWindow(ob_display, self->icon);
1177
1178 if (self->desk_on) {
1179 XMapWindow(ob_display, self->desk);
1180 XMoveWindow(ob_display, self->desk, self->desk_x,
1181 ob_rr_theme->paddingy + 1);
1182 } else
1183 XUnmapWindow(ob_display, self->desk);
1184
1185 if (self->shade_on) {
1186 XMapWindow(ob_display, self->shade);
1187 XMoveWindow(ob_display, self->shade, self->shade_x,
1188 ob_rr_theme->paddingy + 1);
1189 } else
1190 XUnmapWindow(ob_display, self->shade);
1191
1192 if (self->iconify_on) {
1193 XMapWindow(ob_display, self->iconify);
1194 XMoveWindow(ob_display, self->iconify, self->iconify_x,
1195 ob_rr_theme->paddingy + 1);
1196 } else
1197 XUnmapWindow(ob_display, self->iconify);
1198
1199 if (self->max_on) {
1200 XMapWindow(ob_display, self->max);
1201 XMoveWindow(ob_display, self->max, self->max_x,
1202 ob_rr_theme->paddingy + 1);
1203 } else
1204 XUnmapWindow(ob_display, self->max);
1205
1206 if (self->close_on) {
1207 XMapWindow(ob_display, self->close);
1208 XMoveWindow(ob_display, self->close, self->close_x,
1209 ob_rr_theme->paddingy + 1);
1210 } else
1211 XUnmapWindow(ob_display, self->close);
1212
1213 if (self->label_on) {
1214 self->label_width = MAX(1, self->label_width); /* no lower than 1 */
1215 XMapWindow(ob_display, self->label);
1216 XMoveWindow(ob_display, self->label, self->label_x,
1217 ob_rr_theme->paddingy);
1218 } else
1219 XUnmapWindow(ob_display, self->label);
1220 }
1221
1222 ObFrameContext frame_context_from_string(const gchar *name)
1223 {
1224 if (!g_ascii_strcasecmp("Desktop", name))
1225 return OB_FRAME_CONTEXT_DESKTOP;
1226 else if (!g_ascii_strcasecmp("Root", name))
1227 return OB_FRAME_CONTEXT_ROOT;
1228 else if (!g_ascii_strcasecmp("Client", name))
1229 return OB_FRAME_CONTEXT_CLIENT;
1230 else if (!g_ascii_strcasecmp("Titlebar", name))
1231 return OB_FRAME_CONTEXT_TITLEBAR;
1232 else if (!g_ascii_strcasecmp("Frame", name))
1233 return OB_FRAME_CONTEXT_FRAME;
1234 else if (!g_ascii_strcasecmp("TLCorner", name))
1235 return OB_FRAME_CONTEXT_TLCORNER;
1236 else if (!g_ascii_strcasecmp("TRCorner", name))
1237 return OB_FRAME_CONTEXT_TRCORNER;
1238 else if (!g_ascii_strcasecmp("BLCorner", name))
1239 return OB_FRAME_CONTEXT_BLCORNER;
1240 else if (!g_ascii_strcasecmp("BRCorner", name))
1241 return OB_FRAME_CONTEXT_BRCORNER;
1242 else if (!g_ascii_strcasecmp("Top", name))
1243 return OB_FRAME_CONTEXT_TOP;
1244 else if (!g_ascii_strcasecmp("Bottom", name))
1245 return OB_FRAME_CONTEXT_BOTTOM;
1246 else if (!g_ascii_strcasecmp("Left", name))
1247 return OB_FRAME_CONTEXT_LEFT;
1248 else if (!g_ascii_strcasecmp("Right", name))
1249 return OB_FRAME_CONTEXT_RIGHT;
1250 else if (!g_ascii_strcasecmp("Maximize", name))
1251 return OB_FRAME_CONTEXT_MAXIMIZE;
1252 else if (!g_ascii_strcasecmp("AllDesktops", name))
1253 return OB_FRAME_CONTEXT_ALLDESKTOPS;
1254 else if (!g_ascii_strcasecmp("Shade", name))
1255 return OB_FRAME_CONTEXT_SHADE;
1256 else if (!g_ascii_strcasecmp("Iconify", name))
1257 return OB_FRAME_CONTEXT_ICONIFY;
1258 else if (!g_ascii_strcasecmp("Icon", name))
1259 return OB_FRAME_CONTEXT_ICON;
1260 else if (!g_ascii_strcasecmp("Close", name))
1261 return OB_FRAME_CONTEXT_CLOSE;
1262 else if (!g_ascii_strcasecmp("MoveResize", name))
1263 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1264 return OB_FRAME_CONTEXT_NONE;
1265 }
1266
1267 ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
1268 {
1269 ObFrame *self;
1270
1271 if (moveresize_in_progress)
1272 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1273
1274 if (win == RootWindow(ob_display, ob_screen))
1275 return OB_FRAME_CONTEXT_ROOT ;
1276 if (client == NULL) return OB_FRAME_CONTEXT_NONE;
1277 if (win == client->window) {
1278 /* conceptually, this is the desktop, as far as users are
1279 concerned */
1280 if (client->type == OB_CLIENT_TYPE_DESKTOP)
1281 return OB_FRAME_CONTEXT_DESKTOP;
1282 return OB_FRAME_CONTEXT_CLIENT;
1283 }
1284
1285 self = client->frame;
1286
1287 /* when the user clicks in the corners of the titlebar and the client
1288 is fully maximized, then treat it like they clicked in the
1289 button that is there */
1290 if (self->max_horz && self->max_vert &&
1291 (win == self->title || win == self->titletop ||
1292 win == self->titleleft || win == self->titletopleft ||
1293 win == self->titleright || win == self->titletopright))
1294 {
1295 /* get the mouse coords in reference to the whole frame */
1296 gint fx = x;
1297 gint fy = y;
1298
1299 /* these windows are down a border width from the top of the frame */
1300 if (win == self->title ||
1301 win == self->titleleft || win == self->titleright)
1302 fy += self->bwidth;
1303
1304 /* title is a border width in from the edge */
1305 if (win == self->title)
1306 fx += self->bwidth;
1307 /* titletop is a bit to the right */
1308 else if (win == self->titletop)
1309 fx += ob_rr_theme->grip_width + self->bwidth;
1310 /* titletopright is way to the right edge */
1311 else if (win == self->titletopright)
1312 fx += self->area.width - (ob_rr_theme->grip_width + self->bwidth);
1313 /* titleright is even more way to the right edge */
1314 else if (win == self->titleright)
1315 fx += self->area.width - self->bwidth;
1316
1317 /* figure out if we're over the area that should be considered a
1318 button */
1319 if (fy < self->bwidth + ob_rr_theme->paddingy + 1 +
1320 ob_rr_theme->button_size)
1321 {
1322 if (fx < (self->bwidth + ob_rr_theme->paddingx + 1 +
1323 ob_rr_theme->button_size))
1324 {
1325 if (self->leftmost != OB_FRAME_CONTEXT_NONE)
1326 return self->leftmost;
1327 }
1328 else if (fx >= (self->area.width -
1329 (self->bwidth + ob_rr_theme->paddingx + 1 +
1330 ob_rr_theme->button_size)))
1331 {
1332 if (self->rightmost != OB_FRAME_CONTEXT_NONE)
1333 return self->rightmost;
1334 }
1335 }
1336
1337 /* there is no resizing maximized windows so make them the titlebar
1338 context */
1339 return OB_FRAME_CONTEXT_TITLEBAR;
1340 }
1341 else if (self->max_vert &&
1342 (win == self->titletop || win == self->topresize))
1343 /* can't resize vertically when max vert */
1344 return OB_FRAME_CONTEXT_TITLEBAR;
1345 else if (self->shaded &&
1346 (win == self->titletop || win == self->topresize))
1347 /* can't resize vertically when shaded */
1348 return OB_FRAME_CONTEXT_TITLEBAR;
1349
1350 if (win == self->window) return OB_FRAME_CONTEXT_FRAME;
1351 if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR;
1352 if (win == self->handle) return OB_FRAME_CONTEXT_BOTTOM;
1353 if (win == self->handletop) return OB_FRAME_CONTEXT_BOTTOM;
1354 if (win == self->handlebottom) return OB_FRAME_CONTEXT_BOTTOM;
1355 if (win == self->handleleft) return OB_FRAME_CONTEXT_BLCORNER;
1356 if (win == self->lgrip) return OB_FRAME_CONTEXT_BLCORNER;
1357 if (win == self->lgripleft) return OB_FRAME_CONTEXT_BLCORNER;
1358 if (win == self->lgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1359 if (win == self->lgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1360 if (win == self->handleright) return OB_FRAME_CONTEXT_BRCORNER;
1361 if (win == self->rgrip) return OB_FRAME_CONTEXT_BRCORNER;
1362 if (win == self->rgripright) return OB_FRAME_CONTEXT_BLCORNER;
1363 if (win == self->rgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1364 if (win == self->rgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1365 if (win == self->title) return OB_FRAME_CONTEXT_TITLEBAR;
1366 if (win == self->titlebottom) return OB_FRAME_CONTEXT_TITLEBAR;
1367 if (win == self->titleleft) return OB_FRAME_CONTEXT_TLCORNER;
1368 if (win == self->titletopleft) return OB_FRAME_CONTEXT_TLCORNER;
1369 if (win == self->titleright) return OB_FRAME_CONTEXT_TRCORNER;
1370 if (win == self->titletopright) return OB_FRAME_CONTEXT_TRCORNER;
1371 if (win == self->titletop) return OB_FRAME_CONTEXT_TOP;
1372 if (win == self->topresize) return OB_FRAME_CONTEXT_TOP;
1373 if (win == self->tltresize) return OB_FRAME_CONTEXT_TLCORNER;
1374 if (win == self->tllresize) return OB_FRAME_CONTEXT_TLCORNER;
1375 if (win == self->trtresize) return OB_FRAME_CONTEXT_TRCORNER;
1376 if (win == self->trrresize) return OB_FRAME_CONTEXT_TRCORNER;
1377 if (win == self->left) return OB_FRAME_CONTEXT_LEFT;
1378 if (win == self->right) return OB_FRAME_CONTEXT_RIGHT;
1379 if (win == self->innertop) return OB_FRAME_CONTEXT_TITLEBAR;
1380 if (win == self->innerleft) return OB_FRAME_CONTEXT_LEFT;
1381 if (win == self->innerbottom) return OB_FRAME_CONTEXT_BOTTOM;
1382 if (win == self->innerright) return OB_FRAME_CONTEXT_RIGHT;
1383 if (win == self->max) return OB_FRAME_CONTEXT_MAXIMIZE;
1384 if (win == self->iconify) return OB_FRAME_CONTEXT_ICONIFY;
1385 if (win == self->close) return OB_FRAME_CONTEXT_CLOSE;
1386 if (win == self->icon) return OB_FRAME_CONTEXT_ICON;
1387 if (win == self->desk) return OB_FRAME_CONTEXT_ALLDESKTOPS;
1388 if (win == self->shade) return OB_FRAME_CONTEXT_SHADE;
1389
1390 return OB_FRAME_CONTEXT_NONE;
1391 }
1392
1393 void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h)
1394 {
1395 /* horizontal */
1396 switch (self->client->gravity) {
1397 default:
1398 case NorthWestGravity:
1399 case SouthWestGravity:
1400 case WestGravity:
1401 break;
1402
1403 case NorthGravity:
1404 case SouthGravity:
1405 case CenterGravity:
1406 /* the middle of the client will be the middle of the frame */
1407 *x -= (self->size.right - self->size.left) / 2;
1408 break;
1409
1410 case NorthEastGravity:
1411 case SouthEastGravity:
1412 case EastGravity:
1413 /* the right side of the client will be the right side of the frame */
1414 *x -= self->size.right + self->size.left -
1415 self->client->border_width * 2;
1416 break;
1417
1418 case ForgetGravity:
1419 case StaticGravity:
1420 /* the client's position won't move */
1421 *x -= self->size.left - self->client->border_width;
1422 break;
1423 }
1424
1425 /* vertical */
1426 switch (self->client->gravity) {
1427 default:
1428 case NorthWestGravity:
1429 case NorthEastGravity:
1430 case NorthGravity:
1431 break;
1432
1433 case CenterGravity:
1434 case EastGravity:
1435 case WestGravity:
1436 /* the middle of the client will be the middle of the frame */
1437 *y -= (self->size.bottom - self->size.top) / 2;
1438 break;
1439
1440 case SouthWestGravity:
1441 case SouthEastGravity:
1442 case SouthGravity:
1443 /* the bottom of the client will be the bottom of the frame */
1444 *y -= self->size.bottom + self->size.top -
1445 self->client->border_width * 2;
1446 break;
1447
1448 case ForgetGravity:
1449 case StaticGravity:
1450 /* the client's position won't move */
1451 *y -= self->size.top - self->client->border_width;
1452 break;
1453 }
1454 }
1455
1456 void frame_frame_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h)
1457 {
1458 /* horizontal */
1459 switch (self->client->gravity) {
1460 default:
1461 case NorthWestGravity:
1462 case WestGravity:
1463 case SouthWestGravity:
1464 break;
1465 case NorthGravity:
1466 case CenterGravity:
1467 case SouthGravity:
1468 /* the middle of the client will be the middle of the frame */
1469 *x += (self->size.right - self->size.left) / 2;
1470 break;
1471 case NorthEastGravity:
1472 case EastGravity:
1473 case SouthEastGravity:
1474 /* the right side of the client will be the right side of the frame */
1475 *x += self->size.right + self->size.left -
1476 self->client->border_width * 2;
1477 break;
1478 case StaticGravity:
1479 case ForgetGravity:
1480 /* the client's position won't move */
1481 *x += self->size.left - self->client->border_width;
1482 break;
1483 }
1484
1485 /* vertical */
1486 switch (self->client->gravity) {
1487 default:
1488 case NorthWestGravity:
1489 case NorthGravity:
1490 case NorthEastGravity:
1491 break;
1492 case WestGravity:
1493 case CenterGravity:
1494 case EastGravity:
1495 /* the middle of the client will be the middle of the frame */
1496 *y += (self->size.bottom - self->size.top) / 2;
1497 break;
1498 case SouthWestGravity:
1499 case SouthGravity:
1500 case SouthEastGravity:
1501 /* the bottom of the client will be the bottom of the frame */
1502 *y += self->size.bottom + self->size.top -
1503 self->client->border_width * 2;
1504 break;
1505 case StaticGravity:
1506 case ForgetGravity:
1507 /* the client's position won't move */
1508 *y += self->size.top - self->client->border_width;
1509 break;
1510 }
1511 }
1512
1513 void frame_rect_to_frame(ObFrame *self, Rect *r)
1514 {
1515 r->width += self->size.left + self->size.right;
1516 r->height += self->size.top + self->size.bottom;
1517 frame_client_gravity(self, &r->x, &r->y, r->width, r->height);
1518 }
1519
1520 static void flash_done(gpointer data)
1521 {
1522 ObFrame *self = data;
1523
1524 if (self->focused != self->flash_on)
1525 frame_adjust_focus(self, self->focused);
1526 }
1527
1528 static gboolean flash_timeout(gpointer data)
1529 {
1530 ObFrame *self = data;
1531 GTimeVal now;
1532
1533 g_get_current_time(&now);
1534 if (now.tv_sec > self->flash_end.tv_sec ||
1535 (now.tv_sec == self->flash_end.tv_sec &&
1536 now.tv_usec >= self->flash_end.tv_usec))
1537 self->flashing = FALSE;
1538
1539 if (!self->flashing)
1540 return FALSE; /* we are done */
1541
1542 self->flash_on = !self->flash_on;
1543 if (!self->focused) {
1544 frame_adjust_focus(self, self->flash_on);
1545 self->focused = FALSE;
1546 }
1547
1548 return TRUE; /* go again */
1549 }
1550
1551 void frame_flash_start(ObFrame *self)
1552 {
1553 self->flash_on = self->focused;
1554
1555 if (!self->flashing)
1556 ob_main_loop_timeout_add(ob_main_loop,
1557 G_USEC_PER_SEC * 0.6,
1558 flash_timeout,
1559 self,
1560 g_direct_equal,
1561 flash_done);
1562 g_get_current_time(&self->flash_end);
1563 g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
1564
1565 self->flashing = TRUE;
1566 }
1567
1568 void frame_flash_stop(ObFrame *self)
1569 {
1570 self->flashing = FALSE;
1571 }
1572
1573 static gulong frame_animate_iconify_time_left(ObFrame *self,
1574 const GTimeVal *now)
1575 {
1576 glong sec, usec;
1577 sec = self->iconify_animation_end.tv_sec - now->tv_sec;
1578 usec = self->iconify_animation_end.tv_usec - now->tv_usec;
1579 if (usec < 0) {
1580 usec += G_USEC_PER_SEC;
1581 sec--;
1582 }
1583 /* no negative values */
1584 return MAX(sec * G_USEC_PER_SEC + usec, 0);
1585 }
1586
1587 static gboolean frame_animate_iconify(gpointer p)
1588 {
1589 ObFrame *self = p;
1590 gint x, y, w, h;
1591 gint iconx, icony, iconw;
1592 GTimeVal now;
1593 gulong time;
1594 gboolean iconifying;
1595
1596 if (self->client->icon_geometry.width == 0) {
1597 /* there is no icon geometry set so just go straight down */
1598 Rect *a = screen_physical_area_monitor
1599 (screen_find_monitor(&self->area));
1600 iconx = self->area.x + self->area.width / 2 + 32;
1601 icony = a->y + a->width;
1602 iconw = 64;
1603 g_free(a);
1604 } else {
1605 iconx = self->client->icon_geometry.x;
1606 icony = self->client->icon_geometry.y;
1607 iconw = self->client->icon_geometry.width;
1608 }
1609
1610 iconifying = self->iconify_animation_going > 0;
1611
1612 /* how far do we have left to go ? */
1613 g_get_current_time(&now);
1614 time = frame_animate_iconify_time_left(self, &now);
1615
1616 if (time == 0 || iconifying) {
1617 /* start where the frame is supposed to be */
1618 x = self->area.x;
1619 y = self->area.y;
1620 w = self->area.width;
1621 h = self->area.height;
1622 } else {
1623 /* start at the icon */
1624 x = iconx;
1625 y = icony;
1626 w = iconw;
1627 h = self->size.top; /* just the titlebar */
1628 }
1629
1630 if (time > 0) {
1631 glong dx, dy, dw;
1632 glong elapsed;
1633
1634 dx = self->area.x - iconx;
1635 dy = self->area.y - icony;
1636 dw = self->area.width - self->bwidth * 2 - iconw;
1637 /* if restoring, we move in the opposite direction */
1638 if (!iconifying) { dx = -dx; dy = -dy; dw = -dw; }
1639
1640 elapsed = FRAME_ANIMATE_ICONIFY_TIME - time;
1641 x = x - (dx * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1642 y = y - (dy * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1643 w = w - (dw * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1644 h = self->size.top; /* just the titlebar */
1645 }
1646
1647 if (time == 0)
1648 frame_end_iconify_animation(self);
1649 else {
1650 XMoveResizeWindow(ob_display, self->window, x, y, w, h);
1651 XFlush(ob_display);
1652 }
1653
1654 return time > 0; /* repeat until we're out of time */
1655 }
1656
1657 void frame_end_iconify_animation(ObFrame *self)
1658 {
1659 /* see if there is an animation going */
1660 if (self->iconify_animation_going == 0) return;
1661
1662 if (!self->visible)
1663 XUnmapWindow(ob_display, self->window);
1664 else {
1665 /* Send a ConfigureNotify when the animation is done, this fixes
1666 KDE's pager showing the window in the wrong place. */
1667 client_reconfigure(self->client);
1668 }
1669
1670 /* we're not animating any more ! */
1671 self->iconify_animation_going = 0;
1672
1673 XMoveResizeWindow(ob_display, self->window,
1674 self->area.x, self->area.y,
1675 self->area.width, self->area.height);
1676 /* we delay re-rendering until after we're done animating */
1677 framerender_frame(self);
1678 XFlush(ob_display);
1679 }
1680
1681 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying)
1682 {
1683 gulong time;
1684 gboolean new_anim = FALSE;
1685 gboolean set_end = TRUE;
1686 GTimeVal now;
1687
1688 /* if there is no titlebar, just don't animate for now
1689 XXX it would be nice tho.. */
1690 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1691 return;
1692
1693 /* get the current time */
1694 g_get_current_time(&now);
1695
1696 /* get how long until the end */
1697 time = FRAME_ANIMATE_ICONIFY_TIME;
1698 if (self->iconify_animation_going) {
1699 if (!!iconifying != (self->iconify_animation_going > 0)) {
1700 /* animation was already going on in the opposite direction */
1701 time = time - frame_animate_iconify_time_left(self, &now);
1702 } else
1703 /* animation was already going in the same direction */
1704 set_end = FALSE;
1705 } else
1706 new_anim = TRUE;
1707 self->iconify_animation_going = iconifying ? 1 : -1;
1708
1709 /* set the ending time */
1710 if (set_end) {
1711 self->iconify_animation_end.tv_sec = now.tv_sec;
1712 self->iconify_animation_end.tv_usec = now.tv_usec;
1713 g_time_val_add(&self->iconify_animation_end, time);
1714 }
1715
1716 if (new_anim) {
1717 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1718 self, FALSE);
1719 ob_main_loop_timeout_add(ob_main_loop,
1720 FRAME_ANIMATE_ICONIFY_STEP_TIME,
1721 frame_animate_iconify, self,
1722 g_direct_equal, NULL);
1723
1724 /* do the first step */
1725 frame_animate_iconify(self);
1726
1727 /* show it during the animation even if it is not "visible" */
1728 if (!self->visible)
1729 XMapWindow(ob_display, self->window);
1730 }
1731 }
This page took 0.112615 seconds and 5 git commands to generate.