]> Dogcows Code - chaz/openbox/blob - openbox/frame.c
a4843d6ff9f577f5407c57e1120f2cf18f07855b
[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->innerleft = createWindow(self->window, NULL, mask, &attrib);
128 self->innertop = createWindow(self->window, NULL, mask, &attrib);
129 self->innerright = createWindow(self->window, NULL, mask, &attrib);
130 self->innerbottom = createWindow(self->window, NULL, mask, &attrib);
131
132 self->title = createWindow(self->window, NULL, mask, &attrib);
133 self->titleleft = createWindow(self->window, NULL, mask, &attrib);
134 self->titletop = createWindow(self->window, NULL, mask, &attrib);
135 self->titletopleft = createWindow(self->window, NULL, mask, &attrib);
136 self->titletopright = createWindow(self->window, NULL, mask, &attrib);
137 self->titleright = createWindow(self->window, NULL, mask, &attrib);
138 self->titlebottom = createWindow(self->window, NULL, mask, &attrib);
139
140 self->topresize = createWindow(self->title, NULL, mask, &attrib);
141 self->tltresize = createWindow(self->title, NULL, mask, &attrib);
142 self->tllresize = createWindow(self->title, NULL, mask, &attrib);
143 self->trtresize = createWindow(self->title, NULL, mask, &attrib);
144 self->trrresize = createWindow(self->title, NULL, mask, &attrib);
145
146 self->left = createWindow(self->window, NULL, mask, &attrib);
147 self->right = 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;
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 ? ob_rr_theme->grip_width : 0);
433
434 XMoveResizeWindow(ob_display, self->titletop,
435 ob_rr_theme->grip_width + self->bwidth, 0,
436 /* width + bwidth*2 - bwidth*2 - grips*2 */
437 self->width - ob_rr_theme->grip_width * 2,
438 self->bwidth);
439 XMoveResizeWindow(ob_display, self->titletopleft,
440 0, 0,
441 ob_rr_theme->grip_width + self->bwidth,
442 self->bwidth);
443 XMoveResizeWindow(ob_display, self->titletopright,
444 self->client->area.width +
445 self->size.left + self->size.right -
446 ob_rr_theme->grip_width - self->bwidth,
447 0,
448 ob_rr_theme->grip_width + self->bwidth,
449 self->bwidth);
450
451 if (titlesides > 0) {
452 XMoveResizeWindow(ob_display, self->titleleft,
453 0, self->bwidth,
454 self->bwidth,
455 titlesides);
456 XMoveResizeWindow(ob_display, self->titleright,
457 self->client->area.width +
458 self->size.left + self->size.right -
459 self->bwidth,
460 self->bwidth,
461 self->bwidth,
462 titlesides);
463
464 XMapWindow(ob_display, self->titleleft);
465 XMapWindow(ob_display, self->titleright);
466 } else {
467 XUnmapWindow(ob_display, self->titleleft);
468 XUnmapWindow(ob_display, self->titleright);
469 }
470
471 XMapWindow(ob_display, self->titletop);
472 XMapWindow(ob_display, self->titletopleft);
473 XMapWindow(ob_display, self->titletopright);
474
475 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
476 XMoveResizeWindow(ob_display, self->titlebottom,
477 (self->max_horz ? 0 : self->bwidth),
478 ob_rr_theme->title_height + self->bwidth,
479 self->width,
480 self->bwidth);
481
482 XMapWindow(ob_display, self->titlebottom);
483 } else
484 XUnmapWindow(ob_display, self->titlebottom);
485 } else {
486 XUnmapWindow(ob_display, self->titlebottom);
487
488 XUnmapWindow(ob_display, self->titletop);
489 XUnmapWindow(ob_display, self->titletopleft);
490 XUnmapWindow(ob_display, self->titletopright);
491 XUnmapWindow(ob_display, self->titleleft);
492 XUnmapWindow(ob_display, self->titleright);
493 }
494
495 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
496 XMoveResizeWindow(ob_display, self->title,
497 (self->max_horz ? 0 : self->bwidth),
498 self->bwidth,
499 self->width, ob_rr_theme->title_height);
500
501 XMapWindow(ob_display, self->title);
502
503 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
504 XMoveResizeWindow(ob_display, self->topresize,
505 ob_rr_theme->grip_width,
506 0,
507 self->width - ob_rr_theme->grip_width *2,
508 ob_rr_theme->paddingy + 1);
509
510 XMoveWindow(ob_display, self->tltresize, 0, 0);
511 XMoveWindow(ob_display, self->tllresize, 0, 0);
512 XMoveWindow(ob_display, self->trtresize,
513 self->width - ob_rr_theme->grip_width, 0);
514 XMoveWindow(ob_display, self->trrresize,
515 self->width - ob_rr_theme->paddingx - 1, 0);
516
517 XMapWindow(ob_display, self->topresize);
518 XMapWindow(ob_display, self->tltresize);
519 XMapWindow(ob_display, self->tllresize);
520 XMapWindow(ob_display, self->trtresize);
521 XMapWindow(ob_display, self->trrresize);
522 } else {
523 XUnmapWindow(ob_display, self->topresize);
524 XUnmapWindow(ob_display, self->tltresize);
525 XUnmapWindow(ob_display, self->tllresize);
526 XUnmapWindow(ob_display, self->trtresize);
527 XUnmapWindow(ob_display, self->trrresize);
528 }
529 } else
530 XUnmapWindow(ob_display, self->title);
531 }
532
533 if ((self->decorations & OB_FRAME_DECOR_TITLEBAR))
534 /* layout the title bar elements */
535 layout_title(self);
536
537 if (!fake) {
538 gint sidebwidth = self->max_horz ? 0 : self->bwidth;
539
540 if (self->bwidth && self->size.bottom) {
541 XMoveResizeWindow(ob_display, self->handlebottom,
542 ob_rr_theme->grip_width +
543 self->bwidth + sidebwidth,
544 self->size.top + self->client->area.height +
545 self->size.bottom - self->bwidth,
546 self->width - (ob_rr_theme->grip_width +
547 sidebwidth) * 2,
548 self->bwidth);
549
550
551 if (sidebwidth) {
552 XMoveResizeWindow(ob_display, self->lgripleft,
553 0,
554 self->size.top +
555 self->client->area.height +
556 self->size.bottom -
557 (!self->max_horz ?
558 ob_rr_theme->grip_width :
559 self->size.bottom - self->cbwidth_b),
560 self->bwidth,
561 (!self->max_horz ?
562 ob_rr_theme->grip_width :
563 self->size.bottom - self->cbwidth_b));
564 XMoveResizeWindow(ob_display, self->rgripright,
565 self->size.left +
566 self->client->area.width +
567 self->size.right - self->bwidth,
568 self->size.top +
569 self->client->area.height +
570 self->size.bottom -
571 (!self->max_horz ?
572 ob_rr_theme->grip_width :
573 self->size.bottom - self->cbwidth_b),
574 self->bwidth,
575 (!self->max_horz ?
576 ob_rr_theme->grip_width :
577 self->size.bottom - self->cbwidth_b));
578
579 XMapWindow(ob_display, self->lgripleft);
580 XMapWindow(ob_display, self->rgripright);
581 } else {
582 XUnmapWindow(ob_display, self->lgripleft);
583 XUnmapWindow(ob_display, self->rgripright);
584 }
585
586 XMoveResizeWindow(ob_display, self->lgripbottom,
587 sidebwidth,
588 self->size.top + self->client->area.height +
589 self->size.bottom - self->bwidth,
590 ob_rr_theme->grip_width + self->bwidth,
591 self->bwidth);
592 XMoveResizeWindow(ob_display, self->rgripbottom,
593 self->size.left + self->client->area.width +
594 self->size.right - self->bwidth - sidebwidth -
595 ob_rr_theme->grip_width,
596 self->size.top + self->client->area.height +
597 self->size.bottom - self->bwidth,
598 ob_rr_theme->grip_width + self->bwidth,
599 self->bwidth);
600
601 XMapWindow(ob_display, self->handlebottom);
602 XMapWindow(ob_display, self->lgripbottom);
603 XMapWindow(ob_display, self->rgripbottom);
604
605 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
606 ob_rr_theme->handle_height > 0)
607 {
608 XMoveResizeWindow(ob_display, self->handletop,
609 ob_rr_theme->grip_width +
610 self->bwidth + sidebwidth,
611 FRAME_HANDLE_Y(self),
612 self->width - (ob_rr_theme->grip_width +
613 sidebwidth) * 2,
614 self->bwidth);
615 XMapWindow(ob_display, self->handletop);
616
617 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
618 XMoveResizeWindow(ob_display, self->handleleft,
619 ob_rr_theme->grip_width,
620 0,
621 self->bwidth,
622 ob_rr_theme->handle_height);
623 XMoveResizeWindow(ob_display, self->handleright,
624 self->width -
625 ob_rr_theme->grip_width -
626 self->bwidth,
627 0,
628 self->bwidth,
629 ob_rr_theme->handle_height);
630
631 XMoveResizeWindow(ob_display, self->lgriptop,
632 sidebwidth,
633 FRAME_HANDLE_Y(self),
634 ob_rr_theme->grip_width +
635 self->bwidth,
636 self->bwidth);
637 XMoveResizeWindow(ob_display, self->rgriptop,
638 self->size.left +
639 self->client->area.width +
640 self->size.right - self->bwidth -
641 sidebwidth - ob_rr_theme->grip_width,
642 FRAME_HANDLE_Y(self),
643 ob_rr_theme->grip_width +
644 self->bwidth,
645 self->bwidth);
646
647 XMapWindow(ob_display, self->handleleft);
648 XMapWindow(ob_display, self->handleright);
649 XMapWindow(ob_display, self->lgriptop);
650 XMapWindow(ob_display, self->rgriptop);
651 } else {
652 XUnmapWindow(ob_display, self->handleleft);
653 XUnmapWindow(ob_display, self->handleright);
654 XUnmapWindow(ob_display, self->lgriptop);
655 XUnmapWindow(ob_display, self->rgriptop);
656 }
657 } else {
658 XUnmapWindow(ob_display, self->handleleft);
659 XUnmapWindow(ob_display, self->handleright);
660 XUnmapWindow(ob_display, self->lgriptop);
661 XUnmapWindow(ob_display, self->rgriptop);
662
663 XUnmapWindow(ob_display, self->handletop);
664 }
665 } else {
666 XUnmapWindow(ob_display, self->handleleft);
667 XUnmapWindow(ob_display, self->handleright);
668 XUnmapWindow(ob_display, self->lgriptop);
669 XUnmapWindow(ob_display, self->rgriptop);
670
671 XUnmapWindow(ob_display, self->handletop);
672
673 XUnmapWindow(ob_display, self->handlebottom);
674 XUnmapWindow(ob_display, self->lgripleft);
675 XUnmapWindow(ob_display, self->rgripright);
676 XUnmapWindow(ob_display, self->lgripbottom);
677 XUnmapWindow(ob_display, self->rgripbottom);
678 }
679
680 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
681 ob_rr_theme->handle_height > 0)
682 {
683 XMoveResizeWindow(ob_display, self->handle,
684 sidebwidth,
685 FRAME_HANDLE_Y(self) + self->bwidth,
686 self->width, ob_rr_theme->handle_height);
687 XMapWindow(ob_display, self->handle);
688
689 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
690 XMoveResizeWindow(ob_display, self->lgrip,
691 0, 0,
692 ob_rr_theme->grip_width,
693 ob_rr_theme->handle_height);
694 XMoveResizeWindow(ob_display, self->rgrip,
695 self->width - ob_rr_theme->grip_width,
696 0,
697 ob_rr_theme->grip_width,
698 ob_rr_theme->handle_height);
699
700 XMapWindow(ob_display, self->lgrip);
701 XMapWindow(ob_display, self->rgrip);
702 } else {
703 XUnmapWindow(ob_display, self->lgrip);
704 XUnmapWindow(ob_display, self->rgrip);
705 }
706 } else {
707 XUnmapWindow(ob_display, self->lgrip);
708 XUnmapWindow(ob_display, self->rgrip);
709
710 XUnmapWindow(ob_display, self->handle);
711 }
712
713 if (self->bwidth && !self->max_horz) {
714 XMoveResizeWindow(ob_display, self->left,
715 0,
716 self->bwidth + ob_rr_theme->grip_width,
717 self->bwidth,
718 self->client->area.height +
719 self->size.top + self->size.bottom -
720 ob_rr_theme->grip_width * 2);
721
722 XMapWindow(ob_display, self->left);
723 } else
724 XUnmapWindow(ob_display, self->left);
725
726 if (self->bwidth && !self->max_horz) {
727 XMoveResizeWindow(ob_display, self->right,
728 self->client->area.width +
729 self->cbwidth_l + self->cbwidth_r + self->bwidth,
730 self->bwidth + ob_rr_theme->grip_width,
731 self->bwidth,
732 self->client->area.height +
733 self->size.top + self->size.bottom -
734 ob_rr_theme->grip_width * 2);
735
736 XMapWindow(ob_display, self->right);
737 } else
738 XUnmapWindow(ob_display, self->right);
739
740 XMoveResizeWindow(ob_display, self->backback,
741 self->size.left, self->size.top,
742 self->client->area.width,
743 self->client->area.height);
744 }
745 }
746
747 /* shading can change without being moved or resized */
748 RECT_SET_SIZE(self->area,
749 self->client->area.width +
750 self->size.left + self->size.right,
751 (self->client->shaded ?
752 ob_rr_theme->title_height + self->bwidth * 2:
753 self->client->area.height +
754 self->size.top + self->size.bottom));
755
756 if ((moved || resized) && !fake) {
757 /* find the new coordinates, done after setting the frame.size, for
758 frame_client_gravity. */
759 self->area.x = self->client->area.x;
760 self->area.y = self->client->area.y;
761 frame_client_gravity(self, &self->area.x, &self->area.y);
762 }
763
764 if (!fake) {
765 if (!frame_iconify_animating(self))
766 /* move and resize the top level frame.
767 shading can change without being moved or resized.
768
769 but don't do this during an iconify animation. it will be
770 reflected afterwards.
771 */
772 XMoveResizeWindow(ob_display, self->window,
773 self->area.x,
774 self->area.y,
775 self->area.width,
776 self->area.height);
777
778 /* when the client has StaticGravity, it likes to move around.
779 also this correctly positions the client when it maps.
780 this also needs to be run when the frame's decorations sizes change!
781 */
782 XMoveWindow(ob_display, self->client->window,
783 self->size.left, self->size.top);
784
785 if (resized) {
786 self->need_render = TRUE;
787 framerender_frame(self);
788 frame_adjust_shape(self);
789 }
790
791 if (!STRUT_EQUAL(self->size, oldsize)) {
792 gulong vals[4];
793 vals[0] = self->size.left;
794 vals[1] = self->size.right;
795 vals[2] = self->size.top;
796 vals[3] = self->size.bottom;
797 PROP_SETA32(self->client->window, net_frame_extents,
798 cardinal, vals, 4);
799 PROP_SETA32(self->client->window, kde_net_wm_frame_strut,
800 cardinal, vals, 4);
801 }
802
803 /* if this occurs while we are focus cycling, the indicator needs to
804 match the changes */
805 if (focus_cycle_target == self->client)
806 focus_cycle_draw_indicator(self->client);
807 }
808 if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR))
809 XResizeWindow(ob_display, self->label, self->label_width,
810 ob_rr_theme->label_height);
811
812 }
813
814 static void frame_adjust_cursors(ObFrame *self)
815 {
816 if ((self->functions & OB_CLIENT_FUNC_RESIZE) !=
817 (self->client->functions & OB_CLIENT_FUNC_RESIZE) ||
818 self->max_horz != self->client->max_horz ||
819 self->max_vert != self->client->max_vert ||
820 self->shaded != self->client->shaded)
821 {
822 gboolean r = (self->client->functions & OB_CLIENT_FUNC_RESIZE) &&
823 !(self->client->max_horz && self->client->max_vert);
824 gboolean topbot = !self->client->max_vert;
825 gboolean sh = self->client->shaded;
826 XSetWindowAttributes a;
827
828 /* these ones turn off when max vert, and some when shaded */
829 a.cursor = ob_cursor(r && topbot && !sh ?
830 OB_CURSOR_NORTH : OB_CURSOR_NONE);
831 XChangeWindowAttributes(ob_display, self->topresize, CWCursor, &a);
832 XChangeWindowAttributes(ob_display, self->titletop, CWCursor, &a);
833 a.cursor = ob_cursor(r && topbot ? OB_CURSOR_SOUTH : OB_CURSOR_NONE);
834 XChangeWindowAttributes(ob_display, self->handle, CWCursor, &a);
835 XChangeWindowAttributes(ob_display, self->handletop, CWCursor, &a);
836 XChangeWindowAttributes(ob_display, self->handlebottom, CWCursor, &a);
837 XChangeWindowAttributes(ob_display, self->innerbottom, CWCursor, &a);
838
839 /* these ones change when shaded */
840 a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_WEST : OB_CURSOR_NORTHWEST) :
841 OB_CURSOR_NONE);
842 XChangeWindowAttributes(ob_display, self->titleleft, CWCursor, &a);
843 XChangeWindowAttributes(ob_display, self->tltresize, CWCursor, &a);
844 XChangeWindowAttributes(ob_display, self->tllresize, CWCursor, &a);
845 XChangeWindowAttributes(ob_display, self->titletopleft, CWCursor, &a);
846 a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_EAST : OB_CURSOR_NORTHEAST) :
847 OB_CURSOR_NONE);
848 XChangeWindowAttributes(ob_display, self->titleright, CWCursor, &a);
849 XChangeWindowAttributes(ob_display, self->trtresize, CWCursor, &a);
850 XChangeWindowAttributes(ob_display, self->trrresize, CWCursor, &a);
851 XChangeWindowAttributes(ob_display, self->titletopright, CWCursor, &a);
852
853 /* these ones are pretty static */
854 a.cursor = ob_cursor(r ? OB_CURSOR_WEST : OB_CURSOR_NONE);
855 XChangeWindowAttributes(ob_display, self->left, CWCursor, &a);
856 XChangeWindowAttributes(ob_display, self->innerleft, CWCursor, &a);
857 a.cursor = ob_cursor(r ? OB_CURSOR_EAST : OB_CURSOR_NONE);
858 XChangeWindowAttributes(ob_display, self->right, CWCursor, &a);
859 XChangeWindowAttributes(ob_display, self->innerright, CWCursor, &a);
860 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHWEST : OB_CURSOR_NONE);
861 XChangeWindowAttributes(ob_display, self->lgrip, CWCursor, &a);
862 XChangeWindowAttributes(ob_display, self->handleleft, CWCursor, &a);
863 XChangeWindowAttributes(ob_display, self->lgripleft, CWCursor, &a);
864 XChangeWindowAttributes(ob_display, self->lgriptop, CWCursor, &a);
865 XChangeWindowAttributes(ob_display, self->lgripbottom, CWCursor, &a);
866 a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHEAST : OB_CURSOR_NONE);
867 XChangeWindowAttributes(ob_display, self->rgrip, CWCursor, &a);
868 XChangeWindowAttributes(ob_display, self->handleright, CWCursor, &a);
869 XChangeWindowAttributes(ob_display, self->rgripright, CWCursor, &a);
870 XChangeWindowAttributes(ob_display, self->rgriptop, CWCursor, &a);
871 XChangeWindowAttributes(ob_display, self->rgripbottom, CWCursor, &a);
872 }
873 }
874
875 void frame_adjust_client_area(ObFrame *self)
876 {
877 /* adjust the window which is there to prevent flashing on unmap */
878 XMoveResizeWindow(ob_display, self->backfront, 0, 0,
879 self->client->area.width,
880 self->client->area.height);
881 }
882
883 void frame_adjust_state(ObFrame *self)
884 {
885 self->need_render = TRUE;
886 framerender_frame(self);
887 }
888
889 void frame_adjust_focus(ObFrame *self, gboolean hilite)
890 {
891 self->focused = hilite;
892 self->need_render = TRUE;
893 framerender_frame(self);
894 XFlush(ob_display);
895 }
896
897 void frame_adjust_title(ObFrame *self)
898 {
899 self->need_render = TRUE;
900 framerender_frame(self);
901 }
902
903 void frame_adjust_icon(ObFrame *self)
904 {
905 self->need_render = TRUE;
906 framerender_frame(self);
907 }
908
909 void frame_grab_client(ObFrame *self)
910 {
911 /* DO NOT map the client window here. we used to do that, but it is bogus.
912 we need to set up the client's dimensions and everything before we
913 send a mapnotify or we create race conditions.
914 */
915
916 /* reparent the client to the frame */
917 XReparentWindow(ob_display, self->client->window, self->window, 0, 0);
918
919 /*
920 When reparenting the client window, it is usually not mapped yet, since
921 this occurs from a MapRequest. However, in the case where Openbox is
922 starting up, the window is already mapped, so we'll see an unmap event
923 for it.
924 */
925 if (ob_state() == OB_STATE_STARTING)
926 ++self->client->ignore_unmaps;
927
928 /* select the event mask on the client's parent (to receive config/map
929 req's) the ButtonPress is to catch clicks on the client border */
930 XSelectInput(ob_display, self->window, FRAME_EVENTMASK);
931
932 /* set all the windows for the frame in the window_map */
933 g_hash_table_insert(window_map, &self->window, self->client);
934 g_hash_table_insert(window_map, &self->backback, self->client);
935 g_hash_table_insert(window_map, &self->backfront, self->client);
936 g_hash_table_insert(window_map, &self->innerleft, self->client);
937 g_hash_table_insert(window_map, &self->innertop, self->client);
938 g_hash_table_insert(window_map, &self->innerright, self->client);
939 g_hash_table_insert(window_map, &self->innerbottom, self->client);
940 g_hash_table_insert(window_map, &self->title, self->client);
941 g_hash_table_insert(window_map, &self->label, self->client);
942 g_hash_table_insert(window_map, &self->max, self->client);
943 g_hash_table_insert(window_map, &self->close, self->client);
944 g_hash_table_insert(window_map, &self->desk, self->client);
945 g_hash_table_insert(window_map, &self->shade, self->client);
946 g_hash_table_insert(window_map, &self->icon, self->client);
947 g_hash_table_insert(window_map, &self->iconify, self->client);
948 g_hash_table_insert(window_map, &self->handle, self->client);
949 g_hash_table_insert(window_map, &self->lgrip, self->client);
950 g_hash_table_insert(window_map, &self->rgrip, self->client);
951 g_hash_table_insert(window_map, &self->topresize, self->client);
952 g_hash_table_insert(window_map, &self->tltresize, self->client);
953 g_hash_table_insert(window_map, &self->tllresize, self->client);
954 g_hash_table_insert(window_map, &self->trtresize, self->client);
955 g_hash_table_insert(window_map, &self->trrresize, self->client);
956 g_hash_table_insert(window_map, &self->left, self->client);
957 g_hash_table_insert(window_map, &self->right, self->client);
958 g_hash_table_insert(window_map, &self->titleleft, self->client);
959 g_hash_table_insert(window_map, &self->titletop, self->client);
960 g_hash_table_insert(window_map, &self->titletopleft, self->client);
961 g_hash_table_insert(window_map, &self->titletopright, self->client);
962 g_hash_table_insert(window_map, &self->titleright, self->client);
963 g_hash_table_insert(window_map, &self->titlebottom, self->client);
964 g_hash_table_insert(window_map, &self->handleleft, self->client);
965 g_hash_table_insert(window_map, &self->handletop, self->client);
966 g_hash_table_insert(window_map, &self->handleright, self->client);
967 g_hash_table_insert(window_map, &self->handlebottom, self->client);
968 g_hash_table_insert(window_map, &self->lgripleft, self->client);
969 g_hash_table_insert(window_map, &self->lgriptop, self->client);
970 g_hash_table_insert(window_map, &self->lgripbottom, self->client);
971 g_hash_table_insert(window_map, &self->rgripright, self->client);
972 g_hash_table_insert(window_map, &self->rgriptop, self->client);
973 g_hash_table_insert(window_map, &self->rgripbottom, self->client);
974 }
975
976 void frame_release_client(ObFrame *self)
977 {
978 XEvent ev;
979 gboolean reparent = TRUE;
980
981 /* if there was any animation going on, kill it */
982 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
983 self, FALSE);
984
985 /* check if the app has already reparented its window away */
986 while (XCheckTypedWindowEvent(ob_display, self->client->window,
987 ReparentNotify, &ev))
988 {
989 /* This check makes sure we don't catch our own reparent action to
990 our frame window. This doesn't count as the app reparenting itself
991 away of course.
992
993 Reparent events that are generated by us are just discarded here.
994 They are of no consequence to us anyhow.
995 */
996 if (ev.xreparent.parent != self->window) {
997 reparent = FALSE;
998 XPutBackEvent(ob_display, &ev);
999 break;
1000 }
1001 }
1002
1003 if (reparent) {
1004 /* according to the ICCCM - if the client doesn't reparent itself,
1005 then we will reparent the window to root for them */
1006 XReparentWindow(ob_display, self->client->window,
1007 RootWindow(ob_display, ob_screen),
1008 self->client->area.x,
1009 self->client->area.y);
1010 }
1011
1012 /* remove all the windows for the frame from the window_map */
1013 g_hash_table_remove(window_map, &self->window);
1014 g_hash_table_remove(window_map, &self->backback);
1015 g_hash_table_remove(window_map, &self->backfront);
1016 g_hash_table_remove(window_map, &self->innerleft);
1017 g_hash_table_remove(window_map, &self->innertop);
1018 g_hash_table_remove(window_map, &self->innerright);
1019 g_hash_table_remove(window_map, &self->innerbottom);
1020 g_hash_table_remove(window_map, &self->title);
1021 g_hash_table_remove(window_map, &self->label);
1022 g_hash_table_remove(window_map, &self->max);
1023 g_hash_table_remove(window_map, &self->close);
1024 g_hash_table_remove(window_map, &self->desk);
1025 g_hash_table_remove(window_map, &self->shade);
1026 g_hash_table_remove(window_map, &self->icon);
1027 g_hash_table_remove(window_map, &self->iconify);
1028 g_hash_table_remove(window_map, &self->handle);
1029 g_hash_table_remove(window_map, &self->lgrip);
1030 g_hash_table_remove(window_map, &self->rgrip);
1031 g_hash_table_remove(window_map, &self->topresize);
1032 g_hash_table_remove(window_map, &self->tltresize);
1033 g_hash_table_remove(window_map, &self->tllresize);
1034 g_hash_table_remove(window_map, &self->trtresize);
1035 g_hash_table_remove(window_map, &self->trrresize);
1036 g_hash_table_remove(window_map, &self->left);
1037 g_hash_table_remove(window_map, &self->right);
1038 g_hash_table_remove(window_map, &self->titleleft);
1039 g_hash_table_remove(window_map, &self->titletop);
1040 g_hash_table_remove(window_map, &self->titletopleft);
1041 g_hash_table_remove(window_map, &self->titletopright);
1042 g_hash_table_remove(window_map, &self->titleright);
1043 g_hash_table_remove(window_map, &self->titlebottom);
1044 g_hash_table_remove(window_map, &self->handleleft);
1045 g_hash_table_remove(window_map, &self->handletop);
1046 g_hash_table_remove(window_map, &self->handleright);
1047 g_hash_table_remove(window_map, &self->handlebottom);
1048 g_hash_table_remove(window_map, &self->lgripleft);
1049 g_hash_table_remove(window_map, &self->lgriptop);
1050 g_hash_table_remove(window_map, &self->lgripbottom);
1051 g_hash_table_remove(window_map, &self->rgripright);
1052 g_hash_table_remove(window_map, &self->rgriptop);
1053 g_hash_table_remove(window_map, &self->rgripbottom);
1054
1055 ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
1056 }
1057
1058 /* is there anything present between us and the label? */
1059 static gboolean is_button_present(ObFrame *self, const gchar *lc, gint dir) {
1060 for (; *lc != '\0' && lc >= config_title_layout; lc += dir) {
1061 if (*lc == ' ') continue; /* it was invalid */
1062 if (*lc == 'N' && self->decorations & OB_FRAME_DECOR_ICON)
1063 return TRUE;
1064 if (*lc == 'D' && self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
1065 return TRUE;
1066 if (*lc == 'S' && self->decorations & OB_FRAME_DECOR_SHADE)
1067 return TRUE;
1068 if (*lc == 'I' && self->decorations & OB_FRAME_DECOR_ICONIFY)
1069 return TRUE;
1070 if (*lc == 'M' && self->decorations & OB_FRAME_DECOR_MAXIMIZE)
1071 return TRUE;
1072 if (*lc == 'C' && self->decorations & OB_FRAME_DECOR_CLOSE)
1073 return TRUE;
1074 if (*lc == 'L') return FALSE;
1075 }
1076 return FALSE;
1077 }
1078
1079 static void layout_title(ObFrame *self)
1080 {
1081 gchar *lc;
1082 gint i;
1083
1084 const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
1085 /* position of the left most button */
1086 const gint left = ob_rr_theme->paddingx + 1;
1087 /* position of the right most button */
1088 const gint right = self->width;
1089
1090 /* turn them all off */
1091 self->icon_on = self->desk_on = self->shade_on = self->iconify_on =
1092 self->max_on = self->close_on = self->label_on = FALSE;
1093 self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
1094 self->leftmost = self->rightmost = OB_FRAME_CONTEXT_NONE;
1095
1096 /* figure out what's being show, find each element's position, and the
1097 width of the label
1098
1099 do the ones before the label, then after the label,
1100 i will be +1 the first time through when working to the left,
1101 and -1 the second time through when working to the right */
1102 for (i = 1; i >= -1; i-=2) {
1103 gint x;
1104 ObFrameContext *firstcon;
1105
1106 if (i > 0) {
1107 x = left;
1108 lc = config_title_layout;
1109 firstcon = &self->leftmost;
1110 } else {
1111 x = right;
1112 lc = config_title_layout + strlen(config_title_layout)-1;
1113 firstcon = &self->rightmost;
1114 }
1115
1116 /* stop at the end of the string (or the label, which calls break) */
1117 for (; *lc != '\0' && lc >= config_title_layout; lc+=i) {
1118 if (*lc == 'L') {
1119 if (i > 0) {
1120 self->label_on = TRUE;
1121 self->label_x = x;
1122 }
1123 break; /* break the for loop, do other side of label */
1124 } else if (*lc == 'N') {
1125 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICON;
1126 if ((self->icon_on = is_button_present(self, lc, i))) {
1127 /* icon is bigger than buttons */
1128 self->label_width -= bwidth + 2;
1129 if (i > 0) self->icon_x = x;
1130 x += i * (bwidth + 2);
1131 if (i < 0) self->icon_x = x;
1132 }
1133 } else if (*lc == 'D') {
1134 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
1135 if ((self->desk_on = is_button_present(self, lc, i))) {
1136 self->label_width -= bwidth;
1137 if (i > 0) self->desk_x = x;
1138 x += i * bwidth;
1139 if (i < 0) self->desk_x = x;
1140 }
1141 } else if (*lc == 'S') {
1142 if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
1143 if ((self->shade_on = is_button_present(self, lc, i))) {
1144 self->label_width -= bwidth;
1145 if (i > 0) self->shade_x = x;
1146 x += i * bwidth;
1147 if (i < 0) self->shade_x = x;
1148 }
1149 } else if (*lc == 'I') {
1150 if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
1151 if ((self->iconify_on = is_button_present(self, lc, i))) {
1152 self->label_width -= bwidth;
1153 if (i > 0) self->iconify_x = x;
1154 x += i * bwidth;
1155 if (i < 0) self->iconify_x = x;
1156 }
1157 } else if (*lc == 'M') {
1158 if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
1159 if ((self->max_on = is_button_present(self, lc, i))) {
1160 self->label_width -= bwidth;
1161 if (i > 0) self->max_x = x;
1162 x += i * bwidth;
1163 if (i < 0) self->max_x = x;
1164 }
1165 } else if (*lc == 'C') {
1166 if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
1167 if ((self->close_on = is_button_present(self, lc, i))) {
1168 self->label_width -= bwidth;
1169 if (i > 0) self->close_x = x;
1170 x += i * bwidth;
1171 if (i < 0) self->close_x = x;
1172 }
1173 } else
1174 continue; /* don't set firstcon */
1175 firstcon = NULL;
1176 }
1177 }
1178
1179 /* position and map the elements */
1180 if (self->icon_on) {
1181 XMapWindow(ob_display, self->icon);
1182 XMoveWindow(ob_display, self->icon, self->icon_x,
1183 ob_rr_theme->paddingy);
1184 } else
1185 XUnmapWindow(ob_display, self->icon);
1186
1187 if (self->desk_on) {
1188 XMapWindow(ob_display, self->desk);
1189 XMoveWindow(ob_display, self->desk, self->desk_x,
1190 ob_rr_theme->paddingy + 1);
1191 } else
1192 XUnmapWindow(ob_display, self->desk);
1193
1194 if (self->shade_on) {
1195 XMapWindow(ob_display, self->shade);
1196 XMoveWindow(ob_display, self->shade, self->shade_x,
1197 ob_rr_theme->paddingy + 1);
1198 } else
1199 XUnmapWindow(ob_display, self->shade);
1200
1201 if (self->iconify_on) {
1202 XMapWindow(ob_display, self->iconify);
1203 XMoveWindow(ob_display, self->iconify, self->iconify_x,
1204 ob_rr_theme->paddingy + 1);
1205 } else
1206 XUnmapWindow(ob_display, self->iconify);
1207
1208 if (self->max_on) {
1209 XMapWindow(ob_display, self->max);
1210 XMoveWindow(ob_display, self->max, self->max_x,
1211 ob_rr_theme->paddingy + 1);
1212 } else
1213 XUnmapWindow(ob_display, self->max);
1214
1215 if (self->close_on) {
1216 XMapWindow(ob_display, self->close);
1217 XMoveWindow(ob_display, self->close, self->close_x,
1218 ob_rr_theme->paddingy + 1);
1219 } else
1220 XUnmapWindow(ob_display, self->close);
1221
1222 if (self->label_on) {
1223 self->label_width = MAX(1, self->label_width); /* no lower than 1 */
1224 XMapWindow(ob_display, self->label);
1225 XMoveWindow(ob_display, self->label, self->label_x,
1226 ob_rr_theme->paddingy);
1227 } else
1228 XUnmapWindow(ob_display, self->label);
1229 }
1230
1231 ObFrameContext frame_context_from_string(const gchar *name)
1232 {
1233 if (!g_ascii_strcasecmp("Desktop", name))
1234 return OB_FRAME_CONTEXT_DESKTOP;
1235 else if (!g_ascii_strcasecmp("Root", name))
1236 return OB_FRAME_CONTEXT_ROOT;
1237 else if (!g_ascii_strcasecmp("Client", name))
1238 return OB_FRAME_CONTEXT_CLIENT;
1239 else if (!g_ascii_strcasecmp("Titlebar", name))
1240 return OB_FRAME_CONTEXT_TITLEBAR;
1241 else if (!g_ascii_strcasecmp("Frame", name))
1242 return OB_FRAME_CONTEXT_FRAME;
1243 else if (!g_ascii_strcasecmp("TLCorner", name))
1244 return OB_FRAME_CONTEXT_TLCORNER;
1245 else if (!g_ascii_strcasecmp("TRCorner", name))
1246 return OB_FRAME_CONTEXT_TRCORNER;
1247 else if (!g_ascii_strcasecmp("BLCorner", name))
1248 return OB_FRAME_CONTEXT_BLCORNER;
1249 else if (!g_ascii_strcasecmp("BRCorner", name))
1250 return OB_FRAME_CONTEXT_BRCORNER;
1251 else if (!g_ascii_strcasecmp("Top", name))
1252 return OB_FRAME_CONTEXT_TOP;
1253 else if (!g_ascii_strcasecmp("Bottom", name))
1254 return OB_FRAME_CONTEXT_BOTTOM;
1255 else if (!g_ascii_strcasecmp("Left", name))
1256 return OB_FRAME_CONTEXT_LEFT;
1257 else if (!g_ascii_strcasecmp("Right", name))
1258 return OB_FRAME_CONTEXT_RIGHT;
1259 else if (!g_ascii_strcasecmp("Maximize", name))
1260 return OB_FRAME_CONTEXT_MAXIMIZE;
1261 else if (!g_ascii_strcasecmp("AllDesktops", name))
1262 return OB_FRAME_CONTEXT_ALLDESKTOPS;
1263 else if (!g_ascii_strcasecmp("Shade", name))
1264 return OB_FRAME_CONTEXT_SHADE;
1265 else if (!g_ascii_strcasecmp("Iconify", name))
1266 return OB_FRAME_CONTEXT_ICONIFY;
1267 else if (!g_ascii_strcasecmp("Icon", name))
1268 return OB_FRAME_CONTEXT_ICON;
1269 else if (!g_ascii_strcasecmp("Close", name))
1270 return OB_FRAME_CONTEXT_CLOSE;
1271 else if (!g_ascii_strcasecmp("MoveResize", name))
1272 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1273 return OB_FRAME_CONTEXT_NONE;
1274 }
1275
1276 ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
1277 {
1278 ObFrame *self;
1279
1280 if (moveresize_in_progress)
1281 return OB_FRAME_CONTEXT_MOVE_RESIZE;
1282
1283 if (win == RootWindow(ob_display, ob_screen))
1284 return OB_FRAME_CONTEXT_ROOT ;
1285 if (client == NULL) return OB_FRAME_CONTEXT_NONE;
1286 if (win == client->window) {
1287 /* conceptually, this is the desktop, as far as users are
1288 concerned */
1289 if (client->type == OB_CLIENT_TYPE_DESKTOP)
1290 return OB_FRAME_CONTEXT_DESKTOP;
1291 return OB_FRAME_CONTEXT_CLIENT;
1292 }
1293
1294 self = client->frame;
1295
1296 /* when the user clicks in the corners of the titlebar and the client
1297 is fully maximized, then treat it like they clicked in the
1298 button that is there */
1299 if (self->max_horz && self->max_vert &&
1300 (win == self->title || win == self->titletop ||
1301 win == self->titleleft || win == self->titletopleft ||
1302 win == self->titleright || win == self->titletopright))
1303 {
1304 /* get the mouse coords in reference to the whole frame */
1305 gint fx = x;
1306 gint fy = y;
1307
1308 /* these windows are down a border width from the top of the frame */
1309 if (win == self->title ||
1310 win == self->titleleft || win == self->titleright)
1311 fy += self->bwidth;
1312
1313 /* title is a border width in from the edge */
1314 if (win == self->title)
1315 fx += self->bwidth;
1316 /* titletop is a bit to the right */
1317 else if (win == self->titletop)
1318 fx += ob_rr_theme->grip_width + self->bwidth;
1319 /* titletopright is way to the right edge */
1320 else if (win == self->titletopright)
1321 fx += self->area.width - (ob_rr_theme->grip_width + self->bwidth);
1322 /* titleright is even more way to the right edge */
1323 else if (win == self->titleright)
1324 fx += self->area.width - self->bwidth;
1325
1326 /* figure out if we're over the area that should be considered a
1327 button */
1328 if (fy < self->bwidth + ob_rr_theme->paddingy + 1 +
1329 ob_rr_theme->button_size)
1330 {
1331 if (fx < (self->bwidth + ob_rr_theme->paddingx + 1 +
1332 ob_rr_theme->button_size))
1333 {
1334 if (self->leftmost != OB_FRAME_CONTEXT_NONE)
1335 return self->leftmost;
1336 }
1337 else if (fx >= (self->area.width -
1338 (self->bwidth + ob_rr_theme->paddingx + 1 +
1339 ob_rr_theme->button_size)))
1340 {
1341 if (self->rightmost != OB_FRAME_CONTEXT_NONE)
1342 return self->rightmost;
1343 }
1344 }
1345
1346 /* there is no resizing maximized windows so make them the titlebar
1347 context */
1348 return OB_FRAME_CONTEXT_TITLEBAR;
1349 }
1350 else if (self->max_vert &&
1351 (win == self->titletop || win == self->topresize))
1352 /* can't resize vertically when max vert */
1353 return OB_FRAME_CONTEXT_TITLEBAR;
1354 else if (self->shaded &&
1355 (win == self->titletop || win == self->topresize))
1356 /* can't resize vertically when shaded */
1357 return OB_FRAME_CONTEXT_TITLEBAR;
1358
1359 if (win == self->window) return OB_FRAME_CONTEXT_FRAME;
1360 if (win == self->label) return OB_FRAME_CONTEXT_TITLEBAR;
1361 if (win == self->handle) return OB_FRAME_CONTEXT_BOTTOM;
1362 if (win == self->handletop) return OB_FRAME_CONTEXT_BOTTOM;
1363 if (win == self->handlebottom) return OB_FRAME_CONTEXT_BOTTOM;
1364 if (win == self->handleleft) return OB_FRAME_CONTEXT_BLCORNER;
1365 if (win == self->lgrip) return OB_FRAME_CONTEXT_BLCORNER;
1366 if (win == self->lgripleft) return OB_FRAME_CONTEXT_BLCORNER;
1367 if (win == self->lgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1368 if (win == self->lgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1369 if (win == self->handleright) return OB_FRAME_CONTEXT_BRCORNER;
1370 if (win == self->rgrip) return OB_FRAME_CONTEXT_BRCORNER;
1371 if (win == self->rgripright) return OB_FRAME_CONTEXT_BLCORNER;
1372 if (win == self->rgriptop) return OB_FRAME_CONTEXT_BLCORNER;
1373 if (win == self->rgripbottom) return OB_FRAME_CONTEXT_BLCORNER;
1374 if (win == self->title) return OB_FRAME_CONTEXT_TITLEBAR;
1375 if (win == self->titlebottom) return OB_FRAME_CONTEXT_TITLEBAR;
1376 if (win == self->titleleft) return OB_FRAME_CONTEXT_TLCORNER;
1377 if (win == self->titletopleft) return OB_FRAME_CONTEXT_TLCORNER;
1378 if (win == self->titleright) return OB_FRAME_CONTEXT_TRCORNER;
1379 if (win == self->titletopright) return OB_FRAME_CONTEXT_TRCORNER;
1380 if (win == self->titletop) return OB_FRAME_CONTEXT_TOP;
1381 if (win == self->topresize) return OB_FRAME_CONTEXT_TOP;
1382 if (win == self->tltresize) return OB_FRAME_CONTEXT_TLCORNER;
1383 if (win == self->tllresize) return OB_FRAME_CONTEXT_TLCORNER;
1384 if (win == self->trtresize) return OB_FRAME_CONTEXT_TRCORNER;
1385 if (win == self->trrresize) return OB_FRAME_CONTEXT_TRCORNER;
1386 if (win == self->left) return OB_FRAME_CONTEXT_LEFT;
1387 if (win == self->right) return OB_FRAME_CONTEXT_RIGHT;
1388 if (win == self->innertop) return OB_FRAME_CONTEXT_TITLEBAR;
1389 if (win == self->innerleft) return OB_FRAME_CONTEXT_LEFT;
1390 if (win == self->innerbottom) return OB_FRAME_CONTEXT_BOTTOM;
1391 if (win == self->innerright) return OB_FRAME_CONTEXT_RIGHT;
1392 if (win == self->max) return OB_FRAME_CONTEXT_MAXIMIZE;
1393 if (win == self->iconify) return OB_FRAME_CONTEXT_ICONIFY;
1394 if (win == self->close) return OB_FRAME_CONTEXT_CLOSE;
1395 if (win == self->icon) return OB_FRAME_CONTEXT_ICON;
1396 if (win == self->desk) return OB_FRAME_CONTEXT_ALLDESKTOPS;
1397 if (win == self->shade) return OB_FRAME_CONTEXT_SHADE;
1398
1399 return OB_FRAME_CONTEXT_NONE;
1400 }
1401
1402 void frame_client_gravity(ObFrame *self, gint *x, gint *y)
1403 {
1404 /* horizontal */
1405 switch (self->client->gravity) {
1406 default:
1407 case NorthWestGravity:
1408 case SouthWestGravity:
1409 case WestGravity:
1410 break;
1411
1412 case NorthGravity:
1413 case SouthGravity:
1414 case CenterGravity:
1415 /* the middle of the client will be the middle of the frame */
1416 *x -= (self->size.right - self->size.left) / 2;
1417 break;
1418
1419 case NorthEastGravity:
1420 case SouthEastGravity:
1421 case EastGravity:
1422 /* the right side of the client will be the right side of the frame */
1423 *x -= self->size.right + self->size.left -
1424 self->client->border_width * 2;
1425 break;
1426
1427 case ForgetGravity:
1428 case StaticGravity:
1429 /* the client's position won't move */
1430 *x -= self->size.left - self->client->border_width;
1431 break;
1432 }
1433
1434 /* vertical */
1435 switch (self->client->gravity) {
1436 default:
1437 case NorthWestGravity:
1438 case NorthEastGravity:
1439 case NorthGravity:
1440 break;
1441
1442 case CenterGravity:
1443 case EastGravity:
1444 case WestGravity:
1445 /* the middle of the client will be the middle of the frame */
1446 *y -= (self->size.bottom - self->size.top) / 2;
1447 break;
1448
1449 case SouthWestGravity:
1450 case SouthEastGravity:
1451 case SouthGravity:
1452 /* the bottom of the client will be the bottom of the frame */
1453 *y -= self->size.bottom + self->size.top -
1454 self->client->border_width * 2;
1455 break;
1456
1457 case ForgetGravity:
1458 case StaticGravity:
1459 /* the client's position won't move */
1460 *y -= self->size.top - self->client->border_width;
1461 break;
1462 }
1463 }
1464
1465 void frame_frame_gravity(ObFrame *self, gint *x, gint *y)
1466 {
1467 /* horizontal */
1468 switch (self->client->gravity) {
1469 default:
1470 case NorthWestGravity:
1471 case WestGravity:
1472 case SouthWestGravity:
1473 break;
1474 case NorthGravity:
1475 case CenterGravity:
1476 case SouthGravity:
1477 /* the middle of the client will be the middle of the frame */
1478 *x += (self->size.right - self->size.left) / 2;
1479 break;
1480 case NorthEastGravity:
1481 case EastGravity:
1482 case SouthEastGravity:
1483 /* the right side of the client will be the right side of the frame */
1484 *x += self->size.right + self->size.left -
1485 self->client->border_width * 2;
1486 break;
1487 case StaticGravity:
1488 case ForgetGravity:
1489 /* the client's position won't move */
1490 *x += self->size.left - self->client->border_width;
1491 break;
1492 }
1493
1494 /* vertical */
1495 switch (self->client->gravity) {
1496 default:
1497 case NorthWestGravity:
1498 case NorthGravity:
1499 case NorthEastGravity:
1500 break;
1501 case WestGravity:
1502 case CenterGravity:
1503 case EastGravity:
1504 /* the middle of the client will be the middle of the frame */
1505 *y += (self->size.bottom - self->size.top) / 2;
1506 break;
1507 case SouthWestGravity:
1508 case SouthGravity:
1509 case SouthEastGravity:
1510 /* the bottom of the client will be the bottom of the frame */
1511 *y += self->size.bottom + self->size.top -
1512 self->client->border_width * 2;
1513 break;
1514 case StaticGravity:
1515 case ForgetGravity:
1516 /* the client's position won't move */
1517 *y += self->size.top - self->client->border_width;
1518 break;
1519 }
1520 }
1521
1522 void frame_rect_to_frame(ObFrame *self, Rect *r)
1523 {
1524 r->width += self->size.left + self->size.right;
1525 r->height += self->size.top + self->size.bottom;
1526 frame_client_gravity(self, &r->x, &r->y);
1527 }
1528
1529 static void flash_done(gpointer data)
1530 {
1531 ObFrame *self = data;
1532
1533 if (self->focused != self->flash_on)
1534 frame_adjust_focus(self, self->focused);
1535 }
1536
1537 static gboolean flash_timeout(gpointer data)
1538 {
1539 ObFrame *self = data;
1540 GTimeVal now;
1541
1542 g_get_current_time(&now);
1543 if (now.tv_sec > self->flash_end.tv_sec ||
1544 (now.tv_sec == self->flash_end.tv_sec &&
1545 now.tv_usec >= self->flash_end.tv_usec))
1546 self->flashing = FALSE;
1547
1548 if (!self->flashing)
1549 return FALSE; /* we are done */
1550
1551 self->flash_on = !self->flash_on;
1552 if (!self->focused) {
1553 frame_adjust_focus(self, self->flash_on);
1554 self->focused = FALSE;
1555 }
1556
1557 return TRUE; /* go again */
1558 }
1559
1560 void frame_flash_start(ObFrame *self)
1561 {
1562 self->flash_on = self->focused;
1563
1564 if (!self->flashing)
1565 ob_main_loop_timeout_add(ob_main_loop,
1566 G_USEC_PER_SEC * 0.6,
1567 flash_timeout,
1568 self,
1569 g_direct_equal,
1570 flash_done);
1571 g_get_current_time(&self->flash_end);
1572 g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5);
1573
1574 self->flashing = TRUE;
1575 }
1576
1577 void frame_flash_stop(ObFrame *self)
1578 {
1579 self->flashing = FALSE;
1580 }
1581
1582 static gulong frame_animate_iconify_time_left(ObFrame *self,
1583 const GTimeVal *now)
1584 {
1585 glong sec, usec;
1586 sec = self->iconify_animation_end.tv_sec - now->tv_sec;
1587 usec = self->iconify_animation_end.tv_usec - now->tv_usec;
1588 if (usec < 0) {
1589 usec += G_USEC_PER_SEC;
1590 sec--;
1591 }
1592 /* no negative values */
1593 return MAX(sec * G_USEC_PER_SEC + usec, 0);
1594 }
1595
1596 static gboolean frame_animate_iconify(gpointer p)
1597 {
1598 ObFrame *self = p;
1599 gint x, y, w, h;
1600 gint iconx, icony, iconw;
1601 GTimeVal now;
1602 gulong time;
1603 gboolean iconifying;
1604
1605 if (self->client->icon_geometry.width == 0) {
1606 /* there is no icon geometry set so just go straight down */
1607 Rect *a = screen_physical_area_monitor
1608 (screen_find_monitor(&self->area));
1609 iconx = self->area.x + self->area.width / 2 + 32;
1610 icony = a->y + a->width;
1611 iconw = 64;
1612 g_free(a);
1613 } else {
1614 iconx = self->client->icon_geometry.x;
1615 icony = self->client->icon_geometry.y;
1616 iconw = self->client->icon_geometry.width;
1617 }
1618
1619 iconifying = self->iconify_animation_going > 0;
1620
1621 /* how far do we have left to go ? */
1622 g_get_current_time(&now);
1623 time = frame_animate_iconify_time_left(self, &now);
1624
1625 if (time == 0 || iconifying) {
1626 /* start where the frame is supposed to be */
1627 x = self->area.x;
1628 y = self->area.y;
1629 w = self->area.width;
1630 h = self->area.height;
1631 } else {
1632 /* start at the icon */
1633 x = iconx;
1634 y = icony;
1635 w = iconw;
1636 h = self->size.top; /* just the titlebar */
1637 }
1638
1639 if (time > 0) {
1640 glong dx, dy, dw;
1641 glong elapsed;
1642
1643 dx = self->area.x - iconx;
1644 dy = self->area.y - icony;
1645 dw = self->area.width - self->bwidth * 2 - iconw;
1646 /* if restoring, we move in the opposite direction */
1647 if (!iconifying) { dx = -dx; dy = -dy; dw = -dw; }
1648
1649 elapsed = FRAME_ANIMATE_ICONIFY_TIME - time;
1650 x = x - (dx * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1651 y = y - (dy * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1652 w = w - (dw * elapsed) / FRAME_ANIMATE_ICONIFY_TIME;
1653 h = self->size.top; /* just the titlebar */
1654 }
1655
1656 if (time == 0)
1657 frame_end_iconify_animation(self);
1658 else {
1659 XMoveResizeWindow(ob_display, self->window, x, y, w, h);
1660 XFlush(ob_display);
1661 }
1662
1663 return time > 0; /* repeat until we're out of time */
1664 }
1665
1666 void frame_end_iconify_animation(ObFrame *self)
1667 {
1668 /* see if there is an animation going */
1669 if (self->iconify_animation_going == 0) return;
1670
1671 if (!self->visible)
1672 XUnmapWindow(ob_display, self->window);
1673 else {
1674 /* Send a ConfigureNotify when the animation is done, this fixes
1675 KDE's pager showing the window in the wrong place. since the
1676 window is mapped at a different location and is then moved, we
1677 need to send the synthetic configurenotify, since apps may have
1678 read the position when the client mapped, apparently. */
1679 client_reconfigure(self->client, TRUE);
1680 }
1681
1682 /* we're not animating any more ! */
1683 self->iconify_animation_going = 0;
1684
1685 XMoveResizeWindow(ob_display, self->window,
1686 self->area.x, self->area.y,
1687 self->area.width, self->area.height);
1688 /* we delay re-rendering until after we're done animating */
1689 framerender_frame(self);
1690 XFlush(ob_display);
1691 }
1692
1693 void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying)
1694 {
1695 gulong time;
1696 gboolean new_anim = FALSE;
1697 gboolean set_end = TRUE;
1698 GTimeVal now;
1699
1700 /* if there is no titlebar, just don't animate for now
1701 XXX it would be nice tho.. */
1702 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1703 return;
1704
1705 /* get the current time */
1706 g_get_current_time(&now);
1707
1708 /* get how long until the end */
1709 time = FRAME_ANIMATE_ICONIFY_TIME;
1710 if (self->iconify_animation_going) {
1711 if (!!iconifying != (self->iconify_animation_going > 0)) {
1712 /* animation was already going on in the opposite direction */
1713 time = time - frame_animate_iconify_time_left(self, &now);
1714 } else
1715 /* animation was already going in the same direction */
1716 set_end = FALSE;
1717 } else
1718 new_anim = TRUE;
1719 self->iconify_animation_going = iconifying ? 1 : -1;
1720
1721 /* set the ending time */
1722 if (set_end) {
1723 self->iconify_animation_end.tv_sec = now.tv_sec;
1724 self->iconify_animation_end.tv_usec = now.tv_usec;
1725 g_time_val_add(&self->iconify_animation_end, time);
1726 }
1727
1728 if (new_anim) {
1729 ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify,
1730 self, FALSE);
1731 ob_main_loop_timeout_add(ob_main_loop,
1732 FRAME_ANIMATE_ICONIFY_STEP_TIME,
1733 frame_animate_iconify, self,
1734 g_direct_equal, NULL);
1735
1736 /* do the first step */
1737 frame_animate_iconify(self);
1738
1739 /* show it during the animation even if it is not "visible" */
1740 if (!self->visible)
1741 XMapWindow(ob_display, self->window);
1742 }
1743 }
This page took 0.120547 seconds and 3 git commands to generate.