]> icculus.org git repositories - mikachu/openbox.git/blob - src/Window.cc
posible fix for maximizing when slit is auto-hidden
[mikachu/openbox.git] / src / Window.cc
1 // Window.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef   _GNU_SOURCE
26 #define   _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef    HAVE_CONFIG_H
30 #  include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include <X11/Xatom.h>
34 #include <X11/keysym.h>
35
36 #ifdef    HAVE_STRING_H
37 #  include <string.h>
38 #endif // HAVE_STRING_H
39
40 #ifdef    DEBUG
41 #  ifdef    HAVE_STDIO_H
42 #    include <stdio.h>
43 #  endif // HAVE_STDIO_H
44 #endif // DEBUG
45
46 #include "i18n.h"
47 #include "openbox.h"
48 #include "Iconmenu.h"
49 #include "Screen.h"
50 #include "Toolbar.h"
51 #include "Window.h"
52 #include "Windowmenu.h"
53 #include "Workspace.h"
54 #ifdef    SLIT
55 #  include "Slit.h"
56 #endif // SLIT
57 #include "Util.h"
58
59 /*
60  * Initializes the class with default values/the window's set initial values.
61  */
62 OpenboxWindow::OpenboxWindow(Openbox &o, Window w, BScreen *s) : openbox(o) {
63 #ifdef    DEBUG
64   fprintf(stderr, i18n->getMessage(WindowSet, WindowCreating,
65                      "OpenboxWindow::OpenboxWindow(): creating 0x%lx\n"),
66           w);
67 #endif // DEBUG
68
69   client.window = w;
70   display = openbox.getXDisplay();
71
72   openbox.grab();
73   if (! validateClient()) return;
74
75   // fetch client size and placement
76   XWindowAttributes wattrib;
77   if ((! XGetWindowAttributes(display, client.window, &wattrib)) ||
78       (! wattrib.screen) || wattrib.override_redirect) {
79 #ifdef    DEBUG
80     fprintf(stderr,
81             i18n->getMessage(WindowSet, WindowXGetWindowAttributesFail,
82                "OpenboxWindow::OpenboxWindow(): XGetWindowAttributes "
83                "failed\n"));
84 #endif // DEBUG
85
86     openbox.ungrab();
87     return;
88   }
89
90   if (s) {
91     screen = s;
92   } else {
93     screen = openbox.searchScreen(RootWindowOfScreen(wattrib.screen));
94     if (! screen) {
95 #ifdef    DEBUG
96       fprintf(stderr, i18n->getMessage(WindowSet, WindowCannotFindScreen,
97                       "OpenboxWindow::OpenboxWindow(): can't find screen\n"
98                       "\tfor root window 0x%lx\n"),
99                       RootWindowOfScreen(wattrib.screen));
100 #endif // DEBUG
101
102       openbox.ungrab();
103       return;
104     }
105   }
106
107   flags.moving = flags.resizing = flags.shaded = flags.visible =
108     flags.iconic = flags.transient = flags.focused =
109     flags.stuck = flags.modal =  flags.send_focus_message =
110     flags.shaped = flags.managed = False;
111   flags.maximized = 0;
112
113   openbox_attrib.workspace = workspace_number = window_number = -1;
114
115   openbox_attrib.flags = openbox_attrib.attrib = openbox_attrib.stack
116     = openbox_attrib.decoration = 0l;
117   openbox_attrib.premax_x = openbox_attrib.premax_y = 0;
118   openbox_attrib.premax_w = openbox_attrib.premax_h = 0;
119
120   frame.window = frame.plate = frame.title = frame.handle = None;
121   frame.close_button = frame.iconify_button = frame.maximize_button = None;
122   frame.right_grip = frame.left_grip = None;
123
124   frame.utitle = frame.ftitle = frame.uhandle = frame.fhandle = None;
125   frame.ulabel = frame.flabel = frame.ubutton = frame.fbutton = None;
126   frame.pbutton = frame.ugrip = frame.fgrip = None;
127
128   decorations.titlebar = decorations.border = decorations.handle = True;
129   decorations.iconify = decorations.maximize = decorations.menu = True;
130   functions.resize = functions.move = functions.iconify =
131     functions.maximize = True;
132   functions.close = decorations.close = False;
133
134   client.wm_hint_flags = client.normal_hint_flags = 0;
135   client.transient_for = client.transient = 0;
136   client.title = 0;
137   client.title_len = 0;
138   client.icon_title = 0;
139   client.mwm_hint = (MwmHints *) 0;
140   client.openbox_hint = (OpenboxHints *) 0;
141
142   // get the initial size and location of client window (relative to the
143   // _root window_). This position is the reference point used with the
144   // window's gravity to find the window's initial position.
145   client.x = wattrib.x;
146   client.y = wattrib.y;
147   client.width = wattrib.width;
148   client.height = wattrib.height;
149   client.old_bw = wattrib.border_width;
150
151   windowmenu = 0;
152   lastButtonPressTime = 0;
153   image_ctrl = screen->getImageControl();
154
155   timer = new BTimer(openbox, *this);
156   timer->setTimeout(openbox.getAutoRaiseDelay());
157   timer->fireOnce(True);
158
159   getOpenboxHints();
160   if (! client.openbox_hint)
161     getMWMHints();
162
163   // get size, aspect, minimum/maximum size and other hints set by the
164   // client
165   getWMProtocols();
166   getWMHints();
167   getWMNormalHints();
168
169 #ifdef    SLIT
170   if (client.initial_state == WithdrawnState) {
171     screen->getSlit()->addClient(client.window);
172     openbox.ungrab();
173     delete this;
174     return;
175   }
176 #endif // SLIT
177
178   flags.managed = True;
179   openbox.saveWindowSearch(client.window, this);
180
181   // determine if this is a transient window
182   Window win;
183   if (XGetTransientForHint(display, client.window, &win)) {
184     if (win && (win != client.window)) {
185       OpenboxWindow *tr;
186       if ((tr = openbox.searchWindow(win))) {
187         while (tr->client.transient) tr = tr->client.transient;
188         client.transient_for = tr;
189         tr->client.transient = this;
190         flags.stuck = client.transient_for->flags.stuck;
191         flags.transient = True;
192       } else if (win == client.window_group) {
193         if ((tr = openbox.searchGroup(win, this))) {
194           while (tr->client.transient) tr = tr->client.transient;
195           client.transient_for = tr;
196           tr->client.transient = this;
197           flags.stuck = client.transient_for->flags.stuck;
198           flags.transient = True;
199         }
200       }
201     }
202
203     if (win == screen->getRootWindow()) flags.modal = True;
204   }
205
206   // adjust the window decorations based on transience and window sizes
207   if (flags.transient)
208     decorations.maximize = decorations.handle = functions.maximize = False;
209
210   if ((client.normal_hint_flags & PMinSize) &&
211       (client.normal_hint_flags & PMaxSize) &&
212        client.max_width <= client.min_width &&
213       client.max_height <= client.min_height) {
214     decorations.maximize = decorations.handle =
215       functions.resize = functions.maximize = False;
216   }
217   upsize();
218
219   Bool place_window = True;
220   if (openbox.isStartup() || flags.transient ||
221       client.normal_hint_flags & (PPosition|USPosition)) {
222     setGravityOffsets();
223
224     if ((openbox.isStartup()) ||
225         (frame.x >= 0 &&
226          (signed) (frame.y + frame.y_border) >= 0 &&
227          frame.x <= (signed) screen->size().w() &&
228          frame.y <= (signed) screen->size().h()))
229       place_window = False;
230   }
231
232   frame.window = createToplevelWindow(frame.x, frame.y, frame.width,
233                                       frame.height,
234                                       frame.border_w);
235   openbox.saveWindowSearch(frame.window, this);
236
237   frame.plate = createChildWindow(frame.window);
238   openbox.saveWindowSearch(frame.plate, this);
239
240   if (decorations.titlebar) {
241     frame.title = createChildWindow(frame.window);
242     frame.label = createChildWindow(frame.title);
243     openbox.saveWindowSearch(frame.title, this);
244     openbox.saveWindowSearch(frame.label, this);
245   }
246
247   if (decorations.handle) {
248     frame.handle = createChildWindow(frame.window);
249     openbox.saveWindowSearch(frame.handle, this);
250
251     frame.left_grip =
252       createChildWindow(frame.handle, openbox.getLowerLeftAngleCursor());
253     openbox.saveWindowSearch(frame.left_grip, this);
254
255     frame.right_grip =
256       createChildWindow(frame.handle, openbox.getLowerRightAngleCursor());
257     openbox.saveWindowSearch(frame.right_grip, this);
258   }
259
260   associateClientWindow();
261
262   if (! screen->sloppyFocus())
263     openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask,
264         GrabModeSync, GrabModeSync, None, None);
265
266   openbox.grabButton(Button1, Mod1Mask, frame.window, True,
267       ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
268       GrabModeAsync, None, openbox.getMoveCursor());
269   openbox.grabButton(Button2, Mod1Mask, frame.window, True,
270       ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None);
271   openbox.grabButton(Button3, Mod1Mask, frame.window, True,
272       ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
273       GrabModeAsync, None, None);
274
275   positionWindows();
276   XRaiseWindow(display, frame.plate);
277   XMapSubwindows(display, frame.plate);
278   if (decorations.titlebar) XMapSubwindows(display, frame.title);
279   XMapSubwindows(display, frame.window);
280
281   if (decorations.menu)
282     windowmenu = new Windowmenu(*this);
283
284   decorate();
285
286   if (workspace_number < 0 || workspace_number >= screen->getWorkspaceCount())
287     screen->getCurrentWorkspace()->addWindow(this, place_window);
288   else
289     screen->getWorkspace(workspace_number)->addWindow(this, place_window);
290
291   configure(frame.x, frame.y, frame.width, frame.height);
292
293   if (flags.shaded) {
294     flags.shaded = False;
295     shade();
296   }
297
298   if (flags.maximized && functions.maximize) {
299     unsigned int button = flags.maximized;
300     flags.maximized = 0;
301     maximize(button);
302   }
303
304   setFocusFlag(False);
305
306   openbox.ungrab();
307 }
308
309
310 OpenboxWindow::~OpenboxWindow(void) {
311   if (flags.moving || flags.resizing) {
312     screen->hideGeometry();
313     XUngrabPointer(display, CurrentTime);
314   }
315
316   if (workspace_number != -1 && window_number != -1)
317     screen->getWorkspace(workspace_number)->removeWindow(this);
318   else if (flags.iconic)
319     screen->removeIcon(this);
320
321   if (timer) {
322     if (timer->isTiming()) timer->stop();
323     delete timer;
324   }
325
326   if (windowmenu) delete windowmenu;
327
328   if (client.title)
329     delete [] client.title;
330
331   if (client.icon_title)
332     delete [] client.icon_title;
333
334   if (client.mwm_hint)
335     XFree(client.mwm_hint);
336
337   if (client.openbox_hint)
338     XFree(client.openbox_hint);
339
340   if (client.window_group)
341     openbox.removeGroupSearch(client.window_group);
342
343   if (flags.transient && client.transient_for)
344     client.transient_for->client.transient = client.transient;
345   if (client.transient)
346     client.transient->client.transient_for = client.transient_for;
347
348   if (frame.close_button) {
349     openbox.removeWindowSearch(frame.close_button);
350     XDestroyWindow(display, frame.close_button);
351   }
352
353   if (frame.iconify_button) {
354     openbox.removeWindowSearch(frame.iconify_button);
355     XDestroyWindow(display, frame.iconify_button);
356   }
357
358   if (frame.maximize_button) {
359     openbox.removeWindowSearch(frame.maximize_button);
360     XDestroyWindow(display, frame.maximize_button);
361   }
362
363   if (frame.title) {
364     if (frame.ftitle)
365       image_ctrl->removeImage(frame.ftitle);
366
367     if (frame.utitle)
368       image_ctrl->removeImage(frame.utitle);
369
370     if (frame.flabel)
371       image_ctrl->removeImage(frame.flabel);
372
373     if( frame.ulabel)
374       image_ctrl->removeImage(frame.ulabel);
375
376     openbox.removeWindowSearch(frame.label);
377     openbox.removeWindowSearch(frame.title);
378     XDestroyWindow(display, frame.label);
379     XDestroyWindow(display, frame.title);
380   }
381
382   if (frame.handle) {
383     if (frame.fhandle)
384       image_ctrl->removeImage(frame.fhandle);
385
386     if (frame.uhandle)
387       image_ctrl->removeImage(frame.uhandle);
388
389     if (frame.fgrip)
390       image_ctrl->removeImage(frame.fgrip);
391
392     if (frame.ugrip)
393       image_ctrl->removeImage(frame.ugrip);
394
395     openbox.removeWindowSearch(frame.handle);
396     openbox.removeWindowSearch(frame.right_grip);
397     openbox.removeWindowSearch(frame.left_grip);
398     XDestroyWindow(display, frame.right_grip);
399     XDestroyWindow(display, frame.left_grip);
400     XDestroyWindow(display, frame.handle);
401   }
402
403   if (frame.fbutton)
404     image_ctrl->removeImage(frame.fbutton);
405
406   if (frame.ubutton)
407     image_ctrl->removeImage(frame.ubutton);
408
409   if (frame.pbutton)
410     image_ctrl->removeImage(frame.pbutton);
411
412   if (frame.plate) {
413     openbox.removeWindowSearch(frame.plate);
414     XDestroyWindow(display, frame.plate);
415   }
416
417   if (frame.window) {
418     openbox.removeWindowSearch(frame.window);
419     XDestroyWindow(display, frame.window);
420   }
421
422   if (flags.managed) {
423     openbox.removeWindowSearch(client.window);
424     screen->removeNetizen(client.window);
425   }
426 }
427
428
429 /*
430  * Creates a new top level window, with a given location, size, and border
431  * width.
432  * Returns: the newly created window
433  */
434 Window OpenboxWindow::createToplevelWindow(int x, int y, unsigned int width,
435                                             unsigned int height,
436                                             unsigned int borderwidth)
437 {
438   XSetWindowAttributes attrib_create;
439   unsigned long create_mask = CWBackPixmap | CWBorderPixel | CWColormap |
440                               CWOverrideRedirect | CWEventMask;
441
442   attrib_create.background_pixmap = None;
443   attrib_create.colormap = screen->getColormap();
444   attrib_create.override_redirect = True;
445   attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask |
446                              ButtonMotionMask | EnterWindowMask;
447
448   return XCreateWindow(display, screen->getRootWindow(), x, y, width, height,
449                         borderwidth, screen->getDepth(), InputOutput,
450                         screen->getVisual(), create_mask,
451                         &attrib_create);
452 }
453
454
455 /*
456  * Creates a child window, and optionally associates a given cursor with
457  * the new window.
458  */
459 Window OpenboxWindow::createChildWindow(Window parent, Cursor cursor) {
460   XSetWindowAttributes attrib_create;
461   unsigned long create_mask = CWBackPixmap | CWBorderPixel |
462                               CWEventMask;
463
464   attrib_create.background_pixmap = None;
465   attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask |
466                              ButtonMotionMask | ExposureMask |
467                              EnterWindowMask | LeaveWindowMask;
468
469   if (cursor) {
470     create_mask |= CWCursor;
471     attrib_create.cursor = cursor;
472   }
473
474   return XCreateWindow(display, parent, 0, 0, 1, 1, 0, screen->getDepth(),
475                        InputOutput, screen->getVisual(), create_mask,
476                        &attrib_create);
477 }
478
479
480 void OpenboxWindow::associateClientWindow(void) {
481   XSetWindowBorderWidth(display, client.window, 0);
482   getWMName();
483   getWMIconName();
484
485   XChangeSaveSet(display, client.window, SetModeInsert);
486   XSetWindowAttributes attrib_set;
487
488   XSelectInput(display, frame.plate, NoEventMask);
489   XReparentWindow(display, client.window, frame.plate, 0, 0);
490   XSelectInput(display, frame.plate, SubstructureRedirectMask);
491
492   XFlush(display);
493
494   attrib_set.event_mask = PropertyChangeMask | StructureNotifyMask |
495                           FocusChangeMask;
496   attrib_set.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask |
497                                      ButtonMotionMask;
498
499   XChangeWindowAttributes(display, client.window, CWEventMask|CWDontPropagate,
500                           &attrib_set);
501
502 #ifdef    SHAPE
503   if (openbox.hasShapeExtensions()) {
504     XShapeSelectInput(display, client.window, ShapeNotifyMask);
505
506     int foo;
507     unsigned int ufoo;
508
509     XShapeQueryExtents(display, client.window, &flags.shaped, &foo, &foo,
510                        &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
511
512     if (flags.shaped) {
513       XShapeCombineShape(display, frame.window, ShapeBounding,
514                          frame.mwm_border_w, frame.y_border +
515                          frame.mwm_border_w, client.window,
516                          ShapeBounding, ShapeSet);
517
518       int num = 1;
519       XRectangle xrect[2];
520       xrect[0].x = xrect[0].y = 0;
521       xrect[0].width = frame.width;
522       xrect[0].height = frame.y_border;
523
524       if (decorations.handle) {
525         xrect[1].x = 0;
526         xrect[1].y = frame.y_handle;
527         xrect[1].width = frame.width;
528         xrect[1].height = frame.handle_h + frame.border_w;
529         num++;
530       }
531
532       XShapeCombineRectangles(display, frame.window, ShapeBounding, 0, 0,
533                               xrect, num, ShapeUnion, Unsorted);
534     }
535   }
536 #endif // SHAPE
537
538   if (decorations.iconify) createIconifyButton();
539   if (decorations.maximize) createMaximizeButton();
540   if (decorations.close) createCloseButton();
541
542   if (frame.ubutton) {
543     if (frame.close_button)
544       XSetWindowBackgroundPixmap(display, frame.close_button, frame.ubutton);
545     if (frame.maximize_button)
546       XSetWindowBackgroundPixmap(display, frame.maximize_button,
547                                  frame.ubutton);
548     if (frame.iconify_button)
549       XSetWindowBackgroundPixmap(display, frame.iconify_button, frame.ubutton);
550   } else {
551     if (frame.close_button)
552       XSetWindowBackground(display, frame.close_button, frame.ubutton_pixel);
553     if (frame.maximize_button)
554       XSetWindowBackground(display, frame.maximize_button,
555                            frame.ubutton_pixel);
556     if (frame.iconify_button)
557       XSetWindowBackground(display, frame.iconify_button, frame.ubutton_pixel);
558   }
559 }
560
561
562 void OpenboxWindow::decorate(void) {
563   Pixmap tmp = frame.fbutton;
564   BTexture *texture = &(screen->getWindowStyle()->b_focus);
565   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
566     frame.fbutton = None;
567     frame.fbutton_pixel = texture->getColor()->getPixel();
568   } else {
569     frame.fbutton =
570       image_ctrl->renderImage(frame.button_w, frame.button_h, texture);
571   }
572   if (tmp) image_ctrl->removeImage(tmp);
573
574   tmp = frame.ubutton;
575   texture = &(screen->getWindowStyle()->b_unfocus);
576   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
577     frame.ubutton = None;
578     frame.ubutton_pixel = texture->getColor()->getPixel();
579   } else {
580     frame.ubutton =
581       image_ctrl->renderImage(frame.button_w, frame.button_h, texture);
582   }
583   if (tmp) image_ctrl->removeImage(tmp);
584
585   tmp = frame.pbutton;
586   texture = &(screen->getWindowStyle()->b_pressed);
587   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
588     frame.pbutton = None;
589     frame.pbutton_pixel = texture->getColor()->getPixel();
590   } else {
591     frame.pbutton =
592       image_ctrl->renderImage(frame.button_w, frame.button_h, texture);
593   }
594   if (tmp) image_ctrl->removeImage(tmp);
595
596   if (decorations.titlebar) {
597     tmp = frame.ftitle;
598     texture = &(screen->getWindowStyle()->t_focus);
599     if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
600       frame.ftitle = None;
601       frame.ftitle_pixel = texture->getColor()->getPixel();
602     } else {
603       frame.ftitle =
604         image_ctrl->renderImage(frame.width, frame.title_h, texture);
605     }
606     if (tmp) image_ctrl->removeImage(tmp);
607
608     tmp = frame.utitle;
609     texture = &(screen->getWindowStyle()->t_unfocus);
610     if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
611       frame.utitle = None;
612       frame.utitle_pixel = texture->getColor()->getPixel();
613     } else {
614       frame.utitle =
615         image_ctrl->renderImage(frame.width, frame.title_h, texture);
616     }
617     if (tmp) image_ctrl->removeImage(tmp);
618
619     XSetWindowBorder(display, frame.title,
620                      screen->getBorderColor()->getPixel());
621
622     decorateLabel();
623   }
624
625   if (decorations.border) {
626     frame.fborder_pixel = screen->getWindowStyle()->f_focus.getPixel();
627     frame.uborder_pixel = screen->getWindowStyle()->f_unfocus.getPixel();
628     openbox_attrib.flags |= AttribDecoration;
629     openbox_attrib.decoration = DecorNormal;
630   } else {
631     openbox_attrib.flags |= AttribDecoration;
632     openbox_attrib.decoration = DecorNone;
633   }
634
635   if (decorations.handle) {
636     tmp = frame.fhandle;
637     texture = &(screen->getWindowStyle()->h_focus);
638     if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
639       frame.fhandle = None;
640       frame.fhandle_pixel = texture->getColor()->getPixel();
641     } else {
642       frame.fhandle =
643         image_ctrl->renderImage(frame.width, frame.handle_h, texture);
644     }
645     if (tmp) image_ctrl->removeImage(tmp);
646
647     tmp = frame.uhandle;
648     texture = &(screen->getWindowStyle()->h_unfocus);
649     if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
650       frame.uhandle = None;
651       frame.uhandle_pixel = texture->getColor()->getPixel();
652     } else {
653       frame.uhandle =
654         image_ctrl->renderImage(frame.width, frame.handle_h, texture);
655     }
656     if (tmp) image_ctrl->removeImage(tmp);
657
658     tmp = frame.fgrip;
659     texture = &(screen->getWindowStyle()->g_focus);
660     if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
661       frame.fgrip = None;
662       frame.fgrip_pixel = texture->getColor()->getPixel();
663     } else {
664       frame.fgrip =
665         image_ctrl->renderImage(frame.grip_w, frame.grip_h, texture);
666     }
667     if (tmp) image_ctrl->removeImage(tmp);
668
669     tmp = frame.ugrip;
670     texture = &(screen->getWindowStyle()->g_unfocus);
671     if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
672       frame.ugrip = None;
673       frame.ugrip_pixel = texture->getColor()->getPixel();
674     } else {
675       frame.ugrip =
676         image_ctrl->renderImage(frame.grip_w, frame.grip_h, texture);
677     }
678     if (tmp) image_ctrl->removeImage(tmp);
679
680     XSetWindowBorder(display, frame.handle,
681                      screen->getBorderColor()->getPixel());
682     XSetWindowBorder(display, frame.left_grip,
683                      screen->getBorderColor()->getPixel());
684     XSetWindowBorder(display, frame.right_grip,
685                      screen->getBorderColor()->getPixel());
686   }
687
688   XSetWindowBorder(display, frame.window,
689                    screen->getBorderColor()->getPixel());
690 }
691
692
693 void OpenboxWindow::decorateLabel(void) {
694   Pixmap tmp = frame.flabel;
695   BTexture *texture = &(screen->getWindowStyle()->l_focus);
696   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
697     frame.flabel = None;
698     frame.flabel_pixel = texture->getColor()->getPixel();
699   } else {
700     frame.flabel =
701       image_ctrl->renderImage(frame.label_w, frame.label_h, texture);
702   }
703   if (tmp) image_ctrl->removeImage(tmp);
704
705   tmp = frame.ulabel;
706   texture = &(screen->getWindowStyle()->l_unfocus);
707   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
708     frame.ulabel = None;
709     frame.ulabel_pixel = texture->getColor()->getPixel();
710   } else {
711     frame.ulabel =
712       image_ctrl->renderImage(frame.label_w, frame.label_h, texture);
713   }
714   if (tmp) image_ctrl->removeImage(tmp);
715 }
716
717
718 void OpenboxWindow::createCloseButton(void) {
719   if (decorations.close && frame.title != None) {
720     frame.close_button = createChildWindow(frame.title);
721     openbox.saveWindowSearch(frame.close_button, this);
722   }
723 }
724
725
726 void OpenboxWindow::createIconifyButton(void) {
727   if (decorations.iconify && frame.title != None) {
728     frame.iconify_button = createChildWindow(frame.title);
729     openbox.saveWindowSearch(frame.iconify_button, this);
730   }
731 }
732
733
734 void OpenboxWindow::createMaximizeButton(void) {
735   if (decorations.maximize && frame.title != None) {
736     frame.maximize_button = createChildWindow(frame.title);
737     openbox.saveWindowSearch(frame.maximize_button, this);
738   }
739 }
740
741
742 void OpenboxWindow::positionButtons(Bool redecorate_label) {
743   const char *format = openbox.getTitleBarLayout();
744   const unsigned int bw = frame.bevel_w + 1;
745   const unsigned int by = frame.bevel_w + 1;
746   unsigned int bx = frame.bevel_w + 1;
747   unsigned int bcount = strlen(format) - 1;
748
749   if (!decorations.close)
750     bcount--;
751   if (!decorations.maximize)
752     bcount--;
753   if (!decorations.iconify)
754     bcount--;
755   frame.label_w = frame.width - bx * 2 - (frame.button_w + bw) * bcount;
756   
757   bool hasclose, hasiconify, hasmaximize;
758   hasclose = hasiconify = hasmaximize = false;
759  
760   for (int i = 0; format[i] != '\0' && i < 4; i++) {
761     switch(format[i]) {
762     case 'C':
763       if (decorations.close && frame.close_button != None) {
764         XMoveResizeWindow(display, frame.close_button, bx, by,
765                           frame.button_w, frame.button_h);
766         XMapWindow(display, frame.close_button);
767         XClearWindow(display, frame.close_button);
768         bx += frame.button_w + bw;
769         hasclose = true;
770       } else if (frame.close_button)
771         XUnmapWindow(display, frame.close_button);
772       break;
773     case 'I':
774       if (decorations.iconify && frame.iconify_button != None) {
775         XMoveResizeWindow(display, frame.iconify_button, bx, by,
776                           frame.button_w, frame.button_h);
777         XMapWindow(display, frame.iconify_button);
778         XClearWindow(display, frame.iconify_button);
779         bx += frame.button_w + bw;
780         hasiconify = true;
781       } else if (frame.close_button)
782         XUnmapWindow(display, frame.close_button);
783       break;
784     case 'M':
785       if (decorations.maximize && frame.maximize_button != None) {
786         XMoveResizeWindow(display, frame.maximize_button, bx, by,
787                           frame.button_w, frame.button_h);
788         XMapWindow(display, frame.maximize_button);
789         XClearWindow(display, frame.maximize_button);
790         bx += frame.button_w + bw;
791         hasmaximize = true;
792       } else if (frame.close_button)
793         XUnmapWindow(display, frame.close_button);
794       break;
795     case 'L':
796       XMoveResizeWindow(display, frame.label, bx, by - 1,
797                         frame.label_w, frame.label_h);
798       bx += frame.label_w + bw;
799       break;
800     }
801   }
802
803   if (!hasclose) {
804       openbox.removeWindowSearch(frame.close_button);
805       XDestroyWindow(display, frame.close_button);     
806   }
807   if (!hasiconify) {
808       openbox.removeWindowSearch(frame.iconify_button);
809       XDestroyWindow(display, frame.iconify_button);
810   }
811   if (!hasmaximize) {
812       openbox.removeWindowSearch(frame.maximize_button);
813       XDestroyWindow(display, frame.maximize_button);                 
814   }
815   if (redecorate_label)
816     decorateLabel();
817   redrawLabel();
818   redrawAllButtons();
819 }
820
821
822 void OpenboxWindow::reconfigure(void) {
823   upsize();
824
825   client.x = frame.x + frame.mwm_border_w + frame.border_w;
826   client.y = frame.y + frame.y_border + frame.mwm_border_w +
827              frame.border_w;
828
829   if (client.title) {
830     if (i18n->multibyte()) {
831       XRectangle ink, logical;
832       XmbTextExtents(screen->getWindowStyle()->fontset,
833                      client.title, client.title_len, &ink, &logical);
834       client.title_text_w = logical.width;
835     } else {
836       client.title_text_w = XTextWidth(screen->getWindowStyle()->font,
837                                        client.title, client.title_len);
838     }
839     client.title_text_w += (frame.bevel_w * 4);
840   }
841
842   positionWindows();
843   decorate();
844
845   XClearWindow(display, frame.window);
846   setFocusFlag(flags.focused);
847
848   configure(frame.x, frame.y, frame.width, frame.height);
849
850   if (! screen->sloppyFocus())
851     openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask,
852         GrabModeSync, GrabModeSync, None, None);
853   else
854     openbox.ungrabButton(Button1, 0, frame.plate);
855
856   if (windowmenu) {
857     windowmenu->move(windowmenu->getX(), frame.y + frame.title_h);
858     windowmenu->reconfigure();
859   }
860 }
861
862
863 void OpenboxWindow::positionWindows(void) {
864   XResizeWindow(display, frame.window, frame.width,
865                 ((flags.shaded) ? frame.title_h : frame.height));
866   XSetWindowBorderWidth(display, frame.window, frame.border_w);
867   XSetWindowBorderWidth(display, frame.plate, frame.mwm_border_w);
868   XMoveResizeWindow(display, frame.plate, 0, frame.y_border,
869                     client.width, client.height);
870   XMoveResizeWindow(display, client.window, 0, 0, client.width, client.height);
871
872   if (decorations.titlebar) {
873     XSetWindowBorderWidth(display, frame.title, frame.border_w);
874     XMoveResizeWindow(display, frame.title, -frame.border_w,
875                       -frame.border_w, frame.width, frame.title_h);
876
877     positionButtons();
878   } else if (frame.title) {
879     XUnmapWindow(display, frame.title);
880   }
881   if (decorations.handle) {
882     XSetWindowBorderWidth(display, frame.handle, frame.border_w);
883     XSetWindowBorderWidth(display, frame.left_grip, frame.border_w);
884     XSetWindowBorderWidth(display, frame.right_grip, frame.border_w);
885
886     XMoveResizeWindow(display, frame.handle, -frame.border_w,
887                       frame.y_handle - frame.border_w,
888                       frame.width, frame.handle_h);
889     XMoveResizeWindow(display, frame.left_grip, -frame.border_w,
890                       -frame.border_w, frame.grip_w, frame.grip_h);
891     XMoveResizeWindow(display, frame.right_grip,
892                       frame.width - frame.grip_w - frame.border_w,
893                       -frame.border_w, frame.grip_w, frame.grip_h);
894     XMapSubwindows(display, frame.handle);
895   } else if (frame.handle) {
896     XUnmapWindow(display, frame.handle);
897   }
898 }
899
900
901 void OpenboxWindow::getWMName(void) {
902   if (client.title) {
903     delete [] client.title;
904     client.title = (char *) 0;
905   }
906
907   XTextProperty text_prop;
908   char **list;
909   int num;
910
911   if (XGetWMName(display, client.window, &text_prop)) {
912     if (text_prop.value && text_prop.nitems > 0) {
913       if (text_prop.encoding != XA_STRING) {
914         text_prop.nitems = strlen((char *) text_prop.value);
915
916         if ((XmbTextPropertyToTextList(display, &text_prop,
917                                        &list, &num) == Success) &&
918             (num > 0) && *list) {
919           client.title = bstrdup(*list);
920           XFreeStringList(list);
921         } else {
922           client.title = bstrdup((char *) text_prop.value);
923         }
924       } else {
925         client.title = bstrdup((char *) text_prop.value);
926       }
927       XFree((char *) text_prop.value);
928     } else {
929       client.title = bstrdup(i18n->getMessage(WindowSet, WindowUnnamed,
930                                               "Unnamed"));
931     }
932   } else {
933     client.title = bstrdup(i18n->getMessage(WindowSet, WindowUnnamed,
934                                             "Unnamed"));
935   }
936   client.title_len = strlen(client.title);
937
938   if (i18n->multibyte()) {
939     XRectangle ink, logical;
940     XmbTextExtents(screen->getWindowStyle()->fontset,
941                    client.title, client.title_len, &ink, &logical);
942     client.title_text_w = logical.width;
943   } else {
944     client.title_len = strlen(client.title);
945     client.title_text_w = XTextWidth(screen->getWindowStyle()->font,
946                                      client.title, client.title_len);
947   }
948
949   client.title_text_w += (frame.bevel_w * 4);
950 }
951
952
953 void OpenboxWindow::getWMIconName(void) {
954   if (client.icon_title) {
955     delete [] client.icon_title;
956     client.icon_title = (char *) 0;
957   }
958
959   XTextProperty text_prop;
960   char **list;
961   int num;
962
963   if (XGetWMIconName(display, client.window, &text_prop)) {
964     if (text_prop.value && text_prop.nitems > 0) {
965       if (text_prop.encoding != XA_STRING) {
966         text_prop.nitems = strlen((char *) text_prop.value);
967
968         if ((XmbTextPropertyToTextList(display, &text_prop,
969                                        &list, &num) == Success) &&
970             (num > 0) && *list) {
971           client.icon_title = bstrdup(*list);
972           XFreeStringList(list);
973         } else {
974           client.icon_title = bstrdup((char *) text_prop.value);
975         }
976       } else {
977         client.icon_title = bstrdup((char *) text_prop.value);
978       }
979       XFree((char *) text_prop.value);
980     } else {
981       client.icon_title = bstrdup(client.title);
982     }
983   } else {
984     client.icon_title = bstrdup(client.title);
985   }
986 }
987
988
989 /*
990  * Retrieve which WM Protocols are supported by the client window.
991  * If the WM_DELETE_WINDOW protocol is supported, add the close button to the
992  * window's decorations and allow the close behavior.
993  * If the WM_TAKE_FOCUS protocol is supported, save a value that indicates
994  * this.
995  */
996 void OpenboxWindow::getWMProtocols(void) {
997   Atom *proto;
998   int num_return = 0;
999
1000   if (XGetWMProtocols(display, client.window, &proto, &num_return)) {
1001     for (int i = 0; i < num_return; ++i) {
1002       if (proto[i] == openbox.getWMDeleteAtom())
1003         functions.close = decorations.close = True;
1004       else if (proto[i] == openbox.getWMTakeFocusAtom())
1005         flags.send_focus_message = True;
1006       else if (proto[i] == openbox.getOpenboxStructureMessagesAtom())
1007         screen->addNetizen(new Netizen(*screen, client.window));
1008     }
1009
1010     XFree(proto);
1011   }
1012 }
1013
1014
1015 /*
1016  * Gets the value of the WM_HINTS property.
1017  * If the property is not set, then use a set of default values.
1018  */
1019 void OpenboxWindow::getWMHints(void) {
1020   XWMHints *wmhint = XGetWMHints(display, client.window);
1021   if (! wmhint) {
1022     flags.visible = True;
1023     flags.iconic = False;
1024     focus_mode = F_Passive;
1025     client.window_group = None;
1026     client.initial_state = NormalState;
1027     return;
1028   }
1029   client.wm_hint_flags = wmhint->flags;
1030   if (wmhint->flags & InputHint) {
1031     if (wmhint->input == True) {
1032       if (flags.send_focus_message)
1033         focus_mode = F_LocallyActive;
1034       else
1035         focus_mode = F_Passive;
1036     } else {
1037       if (flags.send_focus_message)
1038         focus_mode = F_GloballyActive;
1039       else
1040         focus_mode = F_NoInput;
1041     }
1042   } else {
1043     focus_mode = F_Passive;
1044   }
1045
1046   if (wmhint->flags & StateHint)
1047     client.initial_state = wmhint->initial_state;
1048   else
1049     client.initial_state = NormalState;
1050
1051   if (wmhint->flags & WindowGroupHint) {
1052     if (! client.window_group) {
1053       client.window_group = wmhint->window_group;
1054       openbox.saveGroupSearch(client.window_group, this);
1055     }
1056   } else {
1057     client.window_group = None;
1058   }
1059   XFree(wmhint);
1060 }
1061
1062
1063 /*
1064  * Gets the value of the WM_NORMAL_HINTS property.
1065  * If the property is not set, then use a set of default values.
1066  */
1067 void OpenboxWindow::getWMNormalHints(void) {
1068   long icccm_mask;
1069   XSizeHints sizehint;
1070
1071   client.min_width = client.min_height =
1072     client.base_width = client.base_height =
1073     client.width_inc = client.height_inc = 1;
1074   client.max_width = screen->size().w();
1075   client.max_height = screen->size().h();
1076   client.min_aspect_x = client.min_aspect_y =
1077     client.max_aspect_x = client.max_aspect_y = 1;
1078   client.win_gravity = NorthWestGravity;
1079
1080   if (! XGetWMNormalHints(display, client.window, &sizehint, &icccm_mask))
1081     return;
1082
1083   client.normal_hint_flags = sizehint.flags;
1084
1085   if (sizehint.flags & PMinSize) {
1086     client.min_width = sizehint.min_width;
1087     client.min_height = sizehint.min_height;
1088   }
1089
1090   if (sizehint.flags & PMaxSize) {
1091     client.max_width = sizehint.max_width;
1092     client.max_height = sizehint.max_height;
1093   }
1094
1095   if (sizehint.flags & PResizeInc) {
1096     client.width_inc = sizehint.width_inc;
1097     client.height_inc = sizehint.height_inc;
1098   }
1099
1100   if (sizehint.flags & PAspect) {
1101     client.min_aspect_x = sizehint.min_aspect.x;
1102     client.min_aspect_y = sizehint.min_aspect.y;
1103     client.max_aspect_x = sizehint.max_aspect.x;
1104     client.max_aspect_y = sizehint.max_aspect.y;
1105   }
1106
1107   if (sizehint.flags & PBaseSize) {
1108     client.base_width = sizehint.base_width;
1109     client.base_height = sizehint.base_height;
1110   }
1111
1112   if (sizehint.flags & PWinGravity)
1113     client.win_gravity = sizehint.win_gravity;
1114 }
1115
1116
1117 /*
1118  * Gets the MWM hints for the class' contained window.
1119  * This is used while initializing the window to its first state, and not
1120  * thereafter.
1121  * Returns: true if the MWM hints are successfully retreived and applied; false
1122  * if they are not.
1123  */
1124 void OpenboxWindow::getMWMHints(void) {
1125   int format;
1126   Atom atom_return;
1127   unsigned long num, len;
1128
1129   int ret = XGetWindowProperty(display, client.window,
1130                                openbox.getMotifWMHintsAtom(), 0,
1131                                PropMwmHintsElements, False,
1132                                openbox.getMotifWMHintsAtom(), &atom_return,
1133                                &format, &num, &len,
1134                                (unsigned char **) &client.mwm_hint);
1135
1136   if (ret != Success || !client.mwm_hint || num != PropMwmHintsElements)
1137     return;
1138
1139   if (client.mwm_hint->flags & MwmHintsDecorations) {
1140     if (client.mwm_hint->decorations & MwmDecorAll) {
1141       decorations.titlebar = decorations.handle = decorations.border =
1142         decorations.iconify = decorations.maximize =
1143         decorations.close = decorations.menu = True;
1144     } else {
1145       decorations.titlebar = decorations.handle = decorations.border =
1146         decorations.iconify = decorations.maximize =
1147         decorations.close = decorations.menu = False;
1148
1149       if (client.mwm_hint->decorations & MwmDecorBorder)
1150         decorations.border = True;
1151       if (client.mwm_hint->decorations & MwmDecorHandle)
1152         decorations.handle = True;
1153       if (client.mwm_hint->decorations & MwmDecorTitle)
1154         decorations.titlebar = True;
1155       if (client.mwm_hint->decorations & MwmDecorMenu)
1156         decorations.menu = True;
1157       if (client.mwm_hint->decorations & MwmDecorIconify)
1158         decorations.iconify = True;
1159       if (client.mwm_hint->decorations & MwmDecorMaximize)
1160         decorations.maximize = True;
1161     }
1162   }
1163
1164   if (client.mwm_hint->flags & MwmHintsFunctions) {
1165     if (client.mwm_hint->functions & MwmFuncAll) {
1166       functions.resize = functions.move = functions.iconify =
1167         functions.maximize = functions.close = True;
1168     } else {
1169       functions.resize = functions.move = functions.iconify =
1170         functions.maximize = functions.close = False;
1171
1172       if (client.mwm_hint->functions & MwmFuncResize)
1173         functions.resize = True;
1174       if (client.mwm_hint->functions & MwmFuncMove)
1175         functions.move = True;
1176       if (client.mwm_hint->functions & MwmFuncIconify)
1177         functions.iconify = True;
1178       if (client.mwm_hint->functions & MwmFuncMaximize)
1179         functions.maximize = True;
1180       if (client.mwm_hint->functions & MwmFuncClose)
1181         functions.close = True;
1182     }
1183   }
1184 }
1185
1186
1187 /*
1188  * Gets the openbox hints from the class' contained window.
1189  * This is used while initializing the window to its first state, and not
1190  * thereafter.
1191  * Returns: true if the hints are successfully retreived and applied; false if
1192  * they are not.
1193  */
1194 void OpenboxWindow::getOpenboxHints(void) {
1195   int format;
1196   Atom atom_return;
1197   unsigned long num, len;
1198
1199   int ret = XGetWindowProperty(display, client.window,
1200                                openbox.getOpenboxHintsAtom(), 0,
1201                                PropOpenboxHintsElements, False,
1202                                openbox.getOpenboxHintsAtom(), &atom_return,
1203                                &format, &num, &len,
1204                                (unsigned char **) &client.openbox_hint);
1205   if (ret != Success || !client.openbox_hint ||
1206       num != PropOpenboxHintsElements)
1207     return;
1208
1209   if (client.openbox_hint->flags & AttribShaded)
1210     flags.shaded = (client.openbox_hint->attrib & AttribShaded);
1211
1212   if ((client.openbox_hint->flags & AttribMaxHoriz) &&
1213       (client.openbox_hint->flags & AttribMaxVert))
1214     flags.maximized = (client.openbox_hint->attrib &
1215                        (AttribMaxHoriz | AttribMaxVert)) ? 1 : 0;
1216   else if (client.openbox_hint->flags & AttribMaxVert)
1217     flags.maximized = (client.openbox_hint->attrib & AttribMaxVert) ? 2 : 0;
1218   else if (client.openbox_hint->flags & AttribMaxHoriz)
1219     flags.maximized = (client.openbox_hint->attrib & AttribMaxHoriz) ? 3 : 0;
1220
1221   if (client.openbox_hint->flags & AttribOmnipresent)
1222     flags.stuck = (client.openbox_hint->attrib & AttribOmnipresent);
1223
1224   if (client.openbox_hint->flags & AttribWorkspace)
1225     workspace_number = client.openbox_hint->workspace;
1226
1227   // if (client.openbox_hint->flags & AttribStack)
1228   //   don't yet have always on top/bottom for openbox yet... working
1229   //   on that
1230
1231   if (client.openbox_hint->flags & AttribDecoration) {
1232     switch (client.openbox_hint->decoration) {
1233     case DecorNone:
1234       decorations.titlebar = decorations.border = decorations.handle =
1235         decorations.iconify = decorations.maximize =
1236         decorations.menu = False;
1237       functions.resize = functions.move = functions.iconify =
1238         functions.maximize = False;
1239
1240       break;
1241
1242     case DecorTiny:
1243       decorations.titlebar = decorations.iconify = decorations.menu =
1244         functions.move = functions.iconify = True;
1245       decorations.border = decorations.handle = decorations.maximize =
1246         functions.resize = functions.maximize = False;
1247
1248       break;
1249
1250     case DecorTool:
1251       decorations.titlebar = decorations.menu = functions.move = True;
1252       decorations.iconify = decorations.border = decorations.handle =
1253         decorations.maximize = functions.resize = functions.maximize =
1254         functions.iconify = False;
1255
1256       break;
1257
1258     case DecorNormal:
1259     default:
1260       decorations.titlebar = decorations.border = decorations.handle =
1261         decorations.iconify = decorations.maximize =
1262         decorations.menu = True;
1263       functions.resize = functions.move = functions.iconify =
1264         functions.maximize = True;
1265
1266       break;
1267     }
1268
1269     reconfigure();
1270   }
1271 }
1272
1273
1274 void OpenboxWindow::configure(int dx, int dy,
1275                                unsigned int dw, unsigned int dh) {
1276   Bool send_event = (frame.x != dx || frame.y != dy);
1277
1278   if ((dw != frame.width) || (dh != frame.height)) {
1279     if ((((signed) frame.width) + dx) < 0) dx = 0;
1280     if ((((signed) frame.height) + dy) < 0) dy = 0;
1281
1282     frame.x = dx;
1283     frame.y = dy;
1284     frame.width = dw;
1285     frame.height = dh;
1286
1287     downsize();
1288
1289 #ifdef    SHAPE
1290     if (openbox.hasShapeExtensions() && flags.shaped) {
1291       XShapeCombineShape(display, frame.window, ShapeBounding,
1292                          frame.mwm_border_w, frame.y_border +
1293                          frame.mwm_border_w, client.window,
1294                          ShapeBounding, ShapeSet);
1295
1296       int num = 1;
1297       XRectangle xrect[2];
1298       xrect[0].x = xrect[0].y = 0;
1299       xrect[0].width = frame.width;
1300       xrect[0].height = frame.y_border;
1301
1302       if (decorations.handle) {
1303         xrect[1].x = 0;
1304         xrect[1].y = frame.y_handle;
1305         xrect[1].width = frame.width;
1306         xrect[1].height = frame.handle_h + frame.border_w;
1307         num++;
1308       }
1309
1310       XShapeCombineRectangles(display, frame.window, ShapeBounding, 0, 0,
1311                               xrect, num, ShapeUnion, Unsorted);
1312     }
1313 #endif // SHAPE
1314
1315     XMoveWindow(display, frame.window, frame.x, frame.y);
1316
1317     positionWindows();
1318     decorate();
1319     setFocusFlag(flags.focused);
1320     redrawAllButtons();
1321   } else {
1322     frame.x = dx;
1323     frame.y = dy;
1324
1325     XMoveWindow(display, frame.window, frame.x, frame.y);
1326
1327     if (! flags.moving) send_event = True;
1328   }
1329
1330   if (send_event && ! flags.moving) {
1331     client.x = dx + frame.mwm_border_w + frame.border_w;
1332     client.y = dy + frame.y_border + frame.mwm_border_w +
1333                frame.border_w;
1334
1335     XEvent event;
1336     event.type = ConfigureNotify;
1337
1338     event.xconfigure.display = display;
1339     event.xconfigure.event = client.window;
1340     event.xconfigure.window = client.window;
1341     event.xconfigure.x = client.x;
1342     event.xconfigure.y = client.y;
1343     event.xconfigure.width = client.width;
1344     event.xconfigure.height = client.height;
1345     event.xconfigure.border_width = client.old_bw;
1346     event.xconfigure.above = frame.window;
1347     event.xconfigure.override_redirect = False;
1348
1349     XSendEvent(display, client.window, True, NoEventMask, &event);
1350
1351     screen->updateNetizenConfigNotify(&event);
1352   }
1353 }
1354
1355
1356 Bool OpenboxWindow::setInputFocus(void) {
1357   if (((signed) (frame.x + frame.width)) < 0) {
1358     if (((signed) (frame.y + frame.y_border)) < 0)
1359       configure(frame.border_w, frame.border_w, frame.width, frame.height);
1360     else if (frame.y > (signed) screen->size().h())
1361       configure(frame.border_w, screen->size().h() - frame.height,
1362                 frame.width, frame.height);
1363     else
1364       configure(frame.border_w, frame.y + frame.border_w,
1365                 frame.width, frame.height);
1366   } else if (frame.x > (signed) screen->size().w()) {
1367     if (((signed) (frame.y + frame.y_border)) < 0)
1368       configure(screen->size().w() - frame.width, frame.border_w,
1369                 frame.width, frame.height);
1370     else if (frame.y > (signed) screen->size().h())
1371       configure(screen->size().w() - frame.width,
1372                 screen->size().h() - frame.height, frame.width, frame.height);
1373     else
1374       configure(screen->size().w() - frame.width,
1375                 frame.y + frame.border_w, frame.width, frame.height);
1376   }
1377
1378   openbox.grab();
1379   if (! validateClient()) return False;
1380
1381   Bool ret = False;
1382
1383   if (client.transient && flags.modal) {
1384     ret = client.transient->setInputFocus();
1385   } else if (! flags.focused) {
1386     if (focus_mode == F_LocallyActive || focus_mode == F_Passive)
1387       XSetInputFocus(display, client.window,
1388                      RevertToPointerRoot, CurrentTime);
1389     else
1390       XSetInputFocus(display, screen->getRootWindow(),
1391                      RevertToNone, CurrentTime);
1392
1393     openbox.setFocusedWindow(this);
1394
1395     if (flags.send_focus_message) {
1396       XEvent ce;
1397       ce.xclient.type = ClientMessage;
1398       ce.xclient.message_type = openbox.getWMProtocolsAtom();
1399       ce.xclient.display = display;
1400       ce.xclient.window = client.window;
1401       ce.xclient.format = 32;
1402       ce.xclient.data.l[0] = openbox.getWMTakeFocusAtom();
1403       ce.xclient.data.l[1] = openbox.getLastTime();
1404       ce.xclient.data.l[2] = 0l;
1405       ce.xclient.data.l[3] = 0l;
1406       ce.xclient.data.l[4] = 0l;
1407       XSendEvent(display, client.window, False, NoEventMask, &ce);
1408     }
1409
1410     if (screen->sloppyFocus() && screen->autoRaise())
1411       timer->start();
1412
1413     ret = True;
1414   }
1415
1416   openbox.ungrab();
1417
1418   return ret;
1419 }
1420
1421
1422 void OpenboxWindow::iconify(void) {
1423   if (flags.iconic) return;
1424
1425   if (windowmenu) windowmenu->hide();
1426
1427   setState(IconicState);
1428
1429   XSelectInput(display, client.window, NoEventMask);
1430   XUnmapWindow(display, client.window);
1431   XSelectInput(display, client.window,
1432                PropertyChangeMask | StructureNotifyMask | FocusChangeMask);
1433
1434   XUnmapWindow(display, frame.window);
1435   flags.visible = False;
1436   flags.iconic = True;
1437
1438   screen->getWorkspace(workspace_number)->removeWindow(this);
1439
1440   if (flags.transient && client.transient_for &&
1441       !client.transient_for->flags.iconic) {
1442     client.transient_for->iconify();
1443   }
1444   screen->addIcon(this);
1445
1446   if (client.transient && !client.transient->flags.iconic) {
1447     client.transient->iconify();
1448   }
1449 }
1450
1451
1452 void OpenboxWindow::deiconify(Bool reassoc, Bool raise) {
1453   if (flags.iconic || reassoc)
1454     screen->reassociateWindow(this, -1, False);
1455   else if (workspace_number != screen->getCurrentWorkspace()->getWorkspaceID())
1456     return;
1457
1458   setState(NormalState);
1459
1460   XSelectInput(display, client.window, NoEventMask);
1461   XMapWindow(display, client.window);
1462   XSelectInput(display, client.window,
1463                PropertyChangeMask | StructureNotifyMask | FocusChangeMask);
1464
1465   XMapSubwindows(display, frame.window);
1466   XMapWindow(display, frame.window);
1467
1468   if (flags.iconic && screen->focusNew()) setInputFocus();
1469
1470   flags.visible = True;
1471   flags.iconic = False;
1472
1473   if (reassoc && client.transient) client.transient->deiconify(True, False);
1474
1475   if (raise)
1476     screen->getWorkspace(workspace_number)->raiseWindow(this);
1477 }
1478
1479
1480 void OpenboxWindow::close(void) {
1481   XEvent ce;
1482   ce.xclient.type = ClientMessage;
1483   ce.xclient.message_type = openbox.getWMProtocolsAtom();
1484   ce.xclient.display = display;
1485   ce.xclient.window = client.window;
1486   ce.xclient.format = 32;
1487   ce.xclient.data.l[0] = openbox.getWMDeleteAtom();
1488   ce.xclient.data.l[1] = CurrentTime;
1489   ce.xclient.data.l[2] = 0l;
1490   ce.xclient.data.l[3] = 0l;
1491   ce.xclient.data.l[4] = 0l;
1492   XSendEvent(display, client.window, False, NoEventMask, &ce);
1493 }
1494
1495
1496 void OpenboxWindow::withdraw(void) {
1497   flags.visible = False;
1498   flags.iconic = False;
1499
1500   XUnmapWindow(display, frame.window);
1501
1502   XSelectInput(display, client.window, NoEventMask);
1503   XUnmapWindow(display, client.window);
1504   XSelectInput(display, client.window,
1505                PropertyChangeMask | StructureNotifyMask | FocusChangeMask);
1506
1507   if (windowmenu) windowmenu->hide();
1508 }
1509
1510
1511 void OpenboxWindow::maximize(unsigned int button) {
1512   // handle case where menu is open then the max button is used instead
1513   if (windowmenu && windowmenu->isVisible()) windowmenu->hide();
1514
1515   if (flags.maximized) {
1516     flags.maximized = 0;
1517
1518     openbox_attrib.flags &= ! (AttribMaxHoriz | AttribMaxVert);
1519     openbox_attrib.attrib &= ! (AttribMaxHoriz | AttribMaxVert);
1520
1521     // when a resize is begun, maximize(0) is called to clear any maximization
1522     // flags currently set.  Otherwise it still thinks it is maximized.
1523     // so we do not need to call configure() because resizing will handle it
1524     if (!flags.resizing)
1525       configure(openbox_attrib.premax_x, openbox_attrib.premax_y,
1526                 openbox_attrib.premax_w, openbox_attrib.premax_h);
1527
1528     openbox_attrib.premax_x = openbox_attrib.premax_y = 0;
1529     openbox_attrib.premax_w = openbox_attrib.premax_h = 0;
1530
1531     redrawAllButtons();
1532     setState(current_state);
1533     return;
1534   }
1535
1536   // the following code is temporary and will be taken care of by Screen in the
1537   // future (with the NETWM 'strut')
1538   Rect space(0, 0, screen->size().w(), screen->size().h());
1539   if (! screen->fullMax()) {
1540 #ifdef    SLIT
1541     Slit *slit = screen->getSlit();
1542     int slit_x = slit->autoHide() ? slit->hiddenOrigin().x() : slit->area().x(),
1543         slit_y = slit->autoHide() ? slit->hiddenOrigin().y() : slit->area().y();
1544     Toolbar *toolbar = screen->getToolbar();
1545     int tbarh = screen->hideToolbar() ? 0 :
1546       toolbar->getExposedHeight() + screen->getBorderWidth() * 2;
1547     bool tbartop;
1548     switch (toolbar->placement()) {
1549     case Toolbar::TopLeft:
1550     case Toolbar::TopCenter:
1551     case Toolbar::TopRight:
1552       tbartop = true;
1553       break;
1554     case Toolbar::BottomLeft:
1555     case Toolbar::BottomCenter:
1556     case Toolbar::BottomRight:
1557       tbartop = false;
1558       break;
1559     default:
1560       ASSERT(false);      // unhandled placement
1561     }
1562     if ((slit->direction() == Slit::Horizontal &&
1563          (slit->placement() == Slit::TopLeft ||
1564           slit->placement() == Slit::TopRight)) ||
1565         slit->placement() == Slit::TopCenter) {
1566       // exclude top
1567       if (tbartop)
1568         space.setH(space.h() - slit_y);
1569       else
1570         space.setH(space.h() - tbarh);
1571       space.setY(space.y() + slit_y + slit->area().h() +
1572                  screen->getBorderWidth() * 2);
1573       space.setH(space.h() - (slit_y + slit->area().h() +
1574                               screen->getBorderWidth() * 2));
1575     } else if ((slit->direction() == Slit::Vertical &&
1576               (slit->placement() == Slit::TopRight ||
1577                slit->placement() == Slit::BottomRight)) ||
1578              slit->placement() == Slit::CenterRight) {
1579       // exclude right
1580       space.setW(space.w() - (screen->size().w() - slit_x +
1581                               screen->getBorderWidth() * 2));
1582       if (tbartop)
1583         space.setY(space.y() + tbarh);
1584       space.setH(space.h() - tbarh);
1585     } else if ((slit->direction() == Slit::Horizontal &&
1586               (slit->placement() == Slit::BottomLeft ||
1587                slit->placement() == Slit::BottomRight)) ||
1588              slit->placement() == Slit::BottomCenter) {
1589       // exclude bottom
1590       space.setH(space.h() - (screen->size().h() - slit_y));
1591     } else {// if ((slit->direction() == Slit::Vertical &&
1592       //      (slit->placement() == Slit::TopLeft ||
1593       //       slit->placement() == Slit::BottomLeft)) ||
1594       //     slit->placement() == Slit::CenterLeft)
1595       // exclude left
1596       space.setX(slit_x + slit->area().w() +
1597                  screen->getBorderWidth() * 2);
1598       space.setW(space.w() - (slit_x + slit->area().w() +
1599                               screen->getBorderWidth() * 2));
1600       if (tbartop)
1601         space.setY(space.y() + tbarh);
1602       space.setH(space.h() - tbarh);
1603     }
1604 #else // !SLIT
1605     Toolbar *toolbar = screen->getToolbar();
1606     int tbarh = screen->hideToolbar() ? 0 :
1607       toolbar->getExposedHeight() + screen->getBorderWidth() * 2;
1608     switch (toolbar->placement()) {
1609     case Toolbar::TopLeft:
1610     case Toolbar::TopCenter:
1611     case Toolbar::TopRight:
1612       space.setY(toolbar->getExposedHeight());
1613       space.setH(space.h() - toolbar->getExposedHeight());
1614       break;
1615     case Toolbar::BottomLeft:
1616     case Toolbar::BottomCenter:
1617     case Toolbar::BottomRight:
1618       space.setH(space.h() - tbarh);
1619       break;
1620     default:
1621       ASSERT(false);      // unhandled placement
1622     }
1623 #endif // SLIT
1624   }
1625
1626   openbox_attrib.premax_x = frame.x;
1627   openbox_attrib.premax_y = frame.y;
1628   openbox_attrib.premax_w = frame.width;
1629   openbox_attrib.premax_h = frame.height;
1630
1631   unsigned int dw = space.w(),
1632                dh = space.h();
1633   dw -= frame.border_w * 2;
1634   dw -= frame.mwm_border_w * 2;
1635   dw -= client.base_width;
1636
1637   dh -= frame.border_w * 2;
1638   dh -= frame.mwm_border_w * 2;
1639   dh -= ((frame.handle_h + frame.border_w) * decorations.handle);
1640   dh -= client.base_height;
1641   dh -= frame.y_border;
1642
1643   if (dw < client.min_width) dw = client.min_width;
1644   if (dh < client.min_height) dh = client.min_height;
1645   if (dw > client.max_width) dw = client.max_width;
1646   if (dh > client.max_height) dh = client.max_height;
1647
1648   dw -= (dw % client.width_inc);
1649   dw += client.base_width;
1650   dw += frame.mwm_border_w * 2;
1651
1652   dh -= (dh % client.height_inc);
1653   dh += client.base_height;
1654   dh += frame.y_border;
1655   dh += ((frame.handle_h + frame.border_w) * decorations.handle);
1656   dh += frame.mwm_border_w * 2;
1657
1658   int dx = space.x() + ((space.w() - dw) / 2) - frame.border_w,
1659       dy = space.y() + ((space.h() - dh) / 2) - frame.border_w;
1660
1661   switch(button) {
1662   case 1:
1663     openbox_attrib.flags |= AttribMaxHoriz | AttribMaxVert;
1664     openbox_attrib.attrib |= AttribMaxHoriz | AttribMaxVert;
1665     break;
1666
1667   case 2:
1668     openbox_attrib.flags |= AttribMaxVert;
1669     openbox_attrib.attrib |= AttribMaxVert;
1670
1671     dw = frame.width;
1672     dx = frame.x;
1673     break;
1674
1675   case 3:
1676     openbox_attrib.flags |= AttribMaxHoriz;
1677     openbox_attrib.attrib |= AttribMaxHoriz;
1678
1679     dh = frame.height;
1680     dy = frame.y;
1681     break;
1682   }
1683
1684   if (flags.shaded) {
1685     openbox_attrib.flags ^= AttribShaded;
1686     openbox_attrib.attrib ^= AttribShaded;
1687     flags.shaded = False;
1688   }
1689
1690   flags.maximized = button;
1691
1692   configure(dx, dy, dw, dh);
1693   screen->getWorkspace(workspace_number)->raiseWindow(this);
1694   redrawAllButtons();
1695   setState(current_state);
1696 }
1697
1698
1699 void OpenboxWindow::setWorkspace(int n) {
1700   workspace_number = n;
1701
1702   openbox_attrib.flags |= AttribWorkspace;
1703   openbox_attrib.workspace = workspace_number;
1704 }
1705
1706
1707 void OpenboxWindow::shade(void) {
1708   if (!decorations.titlebar)
1709     return;
1710
1711   if (flags.shaded) {
1712     XResizeWindow(display, frame.window, frame.width, frame.height);
1713     flags.shaded = False;
1714     openbox_attrib.flags ^= AttribShaded;
1715     openbox_attrib.attrib ^= AttribShaded;
1716
1717     setState(NormalState);
1718   } else {
1719     XResizeWindow(display, frame.window, frame.width, frame.title_h);
1720     flags.shaded = True;
1721     openbox_attrib.flags |= AttribShaded;
1722     openbox_attrib.attrib |= AttribShaded;
1723
1724     setState(IconicState);
1725   }
1726 }
1727
1728
1729 void OpenboxWindow::stick(void) {
1730   if (flags.stuck) {
1731     openbox_attrib.flags ^= AttribOmnipresent;
1732     openbox_attrib.attrib ^= AttribOmnipresent;
1733
1734     flags.stuck = False;
1735
1736     if (! flags.iconic)
1737       screen->reassociateWindow(this, -1, True);
1738
1739     setState(current_state);
1740   } else {
1741     flags.stuck = True;
1742
1743     openbox_attrib.flags |= AttribOmnipresent;
1744     openbox_attrib.attrib |= AttribOmnipresent;
1745
1746     setState(current_state);
1747   }
1748 }
1749
1750
1751 void OpenboxWindow::setFocusFlag(Bool focus) {
1752   flags.focused = focus;
1753
1754   if (decorations.titlebar) {
1755     if (flags.focused) {
1756       if (frame.ftitle)
1757         XSetWindowBackgroundPixmap(display, frame.title, frame.ftitle);
1758       else
1759         XSetWindowBackground(display, frame.title, frame.ftitle_pixel);
1760     } else {
1761       if (frame.utitle)
1762         XSetWindowBackgroundPixmap(display, frame.title, frame.utitle);
1763       else
1764         XSetWindowBackground(display, frame.title, frame.utitle_pixel);
1765     }
1766     XClearWindow(display, frame.title);
1767
1768     redrawLabel();
1769     redrawAllButtons();
1770   }
1771
1772   if (decorations.handle) {
1773     if (flags.focused) {
1774       if (frame.fhandle)
1775         XSetWindowBackgroundPixmap(display, frame.handle, frame.fhandle);
1776       else
1777         XSetWindowBackground(display, frame.handle, frame.fhandle_pixel);
1778
1779       if (frame.fgrip) {
1780         XSetWindowBackgroundPixmap(display, frame.right_grip, frame.fgrip);
1781         XSetWindowBackgroundPixmap(display, frame.left_grip, frame.fgrip);
1782       } else {
1783         XSetWindowBackground(display, frame.right_grip, frame.fgrip_pixel);
1784         XSetWindowBackground(display, frame.left_grip, frame.fgrip_pixel);
1785       }
1786     } else {
1787       if (frame.uhandle)
1788         XSetWindowBackgroundPixmap(display, frame.handle, frame.uhandle);
1789       else
1790         XSetWindowBackground(display, frame.handle, frame.uhandle_pixel);
1791
1792       if (frame.ugrip) {
1793         XSetWindowBackgroundPixmap(display, frame.right_grip, frame.ugrip);
1794         XSetWindowBackgroundPixmap(display, frame.left_grip, frame.ugrip);
1795       } else {
1796         XSetWindowBackground(display, frame.right_grip, frame.ugrip_pixel);
1797         XSetWindowBackground(display, frame.left_grip, frame.ugrip_pixel);
1798       }
1799     }
1800     XClearWindow(display, frame.handle);
1801     XClearWindow(display, frame.right_grip);
1802     XClearWindow(display, frame.left_grip);
1803   }
1804
1805   if (decorations.border) {
1806     if (flags.focused)
1807       XSetWindowBorder(display, frame.plate, frame.fborder_pixel);
1808     else
1809       XSetWindowBorder(display, frame.plate, frame.uborder_pixel);
1810   }
1811
1812   if (screen->sloppyFocus() && screen->autoRaise() && timer->isTiming())
1813     timer->stop();
1814 }
1815
1816
1817 void OpenboxWindow::installColormap(Bool install) {
1818   openbox.grab();
1819   if (! validateClient()) return;
1820
1821   int i = 0, ncmap = 0;
1822   Colormap *cmaps = XListInstalledColormaps(display, client.window, &ncmap);
1823   XWindowAttributes wattrib;
1824   if (cmaps) {
1825     if (XGetWindowAttributes(display, client.window, &wattrib)) {
1826       if (install) {
1827         // install the window's colormap
1828         for (i = 0; i < ncmap; i++) {
1829           if (*(cmaps + i) == wattrib.colormap)
1830             // this window is using an installed color map... do not install
1831             install = False;
1832         }
1833         // otherwise, install the window's colormap
1834         if (install)
1835           XInstallColormap(display, wattrib.colormap);
1836       } else {
1837         // uninstall the window's colormap
1838         for (i = 0; i < ncmap; i++) {
1839           if (*(cmaps + i) == wattrib.colormap)
1840             // we found the colormap to uninstall
1841             XUninstallColormap(display, wattrib.colormap);
1842         }
1843       }
1844     }
1845
1846     XFree(cmaps);
1847   }
1848
1849   openbox.ungrab();
1850 }
1851
1852
1853 void OpenboxWindow::setState(unsigned long new_state) {
1854   current_state = new_state;
1855
1856   unsigned long state[2];
1857   state[0] = (unsigned long) current_state;
1858   state[1] = (unsigned long) None;
1859   XChangeProperty(display, client.window, openbox.getWMStateAtom(),
1860                   openbox.getWMStateAtom(), 32, PropModeReplace,
1861                   (unsigned char *) state, 2);
1862
1863   XChangeProperty(display, client.window,
1864                   openbox.getOpenboxAttributesAtom(),
1865                   openbox.getOpenboxAttributesAtom(), 32, PropModeReplace,
1866                   (unsigned char *) &openbox_attrib,
1867                   PropOpenboxAttributesElements);
1868 }
1869
1870
1871 Bool OpenboxWindow::getState(void) {
1872   current_state = 0;
1873
1874   Atom atom_return;
1875   Bool ret = False;
1876   int foo;
1877   unsigned long *state, ulfoo, nitems;
1878
1879   if ((XGetWindowProperty(display, client.window, openbox.getWMStateAtom(),
1880                           0l, 2l, False, openbox.getWMStateAtom(),
1881                           &atom_return, &foo, &nitems, &ulfoo,
1882                           (unsigned char **) &state) != Success) ||
1883       (! state)) {
1884     openbox.ungrab();
1885     return False;
1886   }
1887
1888   if (nitems >= 1) {
1889     current_state = (unsigned long) state[0];
1890
1891     ret = True;
1892   }
1893
1894   XFree((void *) state);
1895
1896   return ret;
1897 }
1898
1899
1900 void OpenboxWindow::setGravityOffsets(void) {
1901   // x coordinates for each gravity type
1902   const int x_west = client.x;
1903   const int x_east = client.x + client.width - frame.width;
1904   const int x_center = client.x + client.width - frame.width/2;
1905   // y coordinates for each gravity type
1906   const int y_north = client.y;
1907   const int y_south = client.y + client.height - frame.height;
1908   const int y_center = client.y + client.height - frame.height/2;
1909
1910   switch (client.win_gravity) {
1911   case NorthWestGravity:
1912   default:
1913     frame.x = x_west;
1914     frame.y = y_north;
1915     break;
1916   case NorthGravity:
1917     frame.x = x_center;
1918     frame.y = y_north;
1919     break;
1920   case NorthEastGravity:
1921     frame.x = x_east;
1922     frame.y = y_north;
1923     break;
1924   case SouthWestGravity:
1925     frame.x = x_west;
1926     frame.y = y_south;
1927     break;
1928   case SouthGravity:
1929     frame.x = x_center;
1930     frame.y = y_south;
1931     break;
1932   case SouthEastGravity:
1933     frame.x = x_east;
1934     frame.y = y_south;
1935     break;
1936   case WestGravity:
1937     frame.x = x_west;
1938     frame.y = y_center;
1939     break;
1940   case EastGravity:
1941     frame.x = x_east;
1942     frame.y = y_center;
1943     break;
1944   case CenterGravity:
1945     frame.x = x_center;
1946     frame.y = y_center;
1947     break;
1948   case ForgetGravity:
1949   case StaticGravity:
1950     frame.x = client.x - frame.mwm_border_w + frame.border_w;
1951     frame.y = client.y - frame.y_border - frame.mwm_border_w - frame.border_w;
1952     break;
1953   }
1954 }
1955
1956
1957 void OpenboxWindow::restoreAttributes(void) {
1958   if (! getState()) current_state = NormalState;
1959
1960   Atom atom_return;
1961   int foo;
1962   unsigned long ulfoo, nitems;
1963
1964   OpenboxAttributes *net;
1965   int ret = XGetWindowProperty(display, client.window,
1966                                openbox.getOpenboxAttributesAtom(), 0l,
1967                                PropOpenboxAttributesElements, False,
1968                                openbox.getOpenboxAttributesAtom(),
1969                                &atom_return, &foo, &nitems, &ulfoo,
1970                                (unsigned char **) &net);
1971   if (ret != Success || !net || nitems != PropOpenboxAttributesElements)
1972     return;
1973
1974   openbox_attrib.flags = net->flags;
1975   openbox_attrib.attrib = net->attrib;
1976   openbox_attrib.decoration = net->decoration;
1977   openbox_attrib.workspace = net->workspace;
1978   openbox_attrib.stack = net->stack;
1979   openbox_attrib.premax_x = net->premax_x;
1980   openbox_attrib.premax_y = net->premax_y;
1981   openbox_attrib.premax_w = net->premax_w;
1982   openbox_attrib.premax_h = net->premax_h;
1983
1984   XFree((void *) net);
1985
1986   if (openbox_attrib.flags & AttribShaded &&
1987       openbox_attrib.attrib & AttribShaded) {
1988     int save_state =
1989       ((current_state == IconicState) ? NormalState : current_state);
1990
1991     flags.shaded = False;
1992     shade();
1993
1994     current_state = save_state;
1995   }
1996
1997   if (((int) openbox_attrib.workspace != screen->getCurrentWorkspaceID()) &&
1998       ((int) openbox_attrib.workspace < screen->getWorkspaceCount())) {
1999     screen->reassociateWindow(this, openbox_attrib.workspace, True);
2000
2001     if (current_state == NormalState) current_state = WithdrawnState;
2002   } else if (current_state == WithdrawnState) {
2003     current_state = NormalState;
2004   }
2005
2006   if (openbox_attrib.flags & AttribOmnipresent &&
2007       openbox_attrib.attrib & AttribOmnipresent) {
2008     flags.stuck = False;
2009     stick();
2010
2011     current_state = NormalState;
2012   }
2013
2014   if ((openbox_attrib.flags & AttribMaxHoriz) ||
2015       (openbox_attrib.flags & AttribMaxVert)) {
2016     int x = openbox_attrib.premax_x, y = openbox_attrib.premax_y;
2017     unsigned int w = openbox_attrib.premax_w, h = openbox_attrib.premax_h;
2018     flags.maximized = 0;
2019
2020     unsigned int m = False;
2021     if ((openbox_attrib.flags & AttribMaxHoriz) &&
2022         (openbox_attrib.flags & AttribMaxVert))
2023       m = (openbox_attrib.attrib & (AttribMaxHoriz | AttribMaxVert)) ? 1 : 0;
2024     else if (openbox_attrib.flags & AttribMaxVert)
2025       m = (openbox_attrib.attrib & AttribMaxVert) ? 2 : 0;
2026     else if (openbox_attrib.flags & AttribMaxHoriz)
2027       m = (openbox_attrib.attrib & AttribMaxHoriz) ? 3 : 0;
2028
2029     if (m) maximize(m);
2030
2031     openbox_attrib.premax_x = x;
2032     openbox_attrib.premax_y = y;
2033     openbox_attrib.premax_w = w;
2034     openbox_attrib.premax_h = h;
2035   }
2036
2037   setState(current_state);
2038 }
2039
2040
2041 /*
2042  * The reverse of the setGravityOffsets function. Uses the frame window's
2043  * position to find the window's reference point.
2044  */
2045 void OpenboxWindow::restoreGravity(void) {
2046   // x coordinates for each gravity type
2047   const int x_west = frame.x;
2048   const int x_east = frame.x + frame.width - client.width;
2049   const int x_center = frame.x + (frame.width/2) - client.width;
2050   // y coordinates for each gravity type
2051   const int y_north = frame.y;
2052   const int y_south = frame.y + frame.height - client.height;
2053   const int y_center = frame.y + (frame.height/2) - client.height;
2054
2055   switch(client.win_gravity) {
2056   default:
2057   case NorthWestGravity:
2058     client.x = x_west;
2059     client.y = y_north;
2060     break;
2061   case NorthGravity:
2062     client.x = x_center;
2063     client.y = y_north;
2064     break;
2065   case NorthEastGravity:
2066     client.x = x_east;
2067     client.y = y_north;
2068     break;
2069   case SouthWestGravity:
2070     client.x = x_west;
2071     client.y = y_south;
2072     break;
2073   case SouthGravity:
2074     client.x = x_center;
2075     client.y = y_south;
2076     break;
2077   case SouthEastGravity:
2078     client.x = x_east;
2079     client.y = y_south;
2080     break;
2081   case WestGravity:
2082     client.x = x_west;
2083     client.y = y_center;
2084     break;
2085   case EastGravity:
2086     client.x = x_east;
2087     client.y = y_center;
2088     break;
2089   case CenterGravity:
2090     client.x = x_center;
2091     client.y = y_center;
2092     break;
2093   case ForgetGravity:
2094   case StaticGravity:
2095     client.x = frame.x + frame.mwm_border_w + frame.border_w;
2096     client.y = frame.y + frame.y_border + frame.mwm_border_w +
2097       frame.border_w;
2098     break;
2099   }
2100 }
2101
2102
2103 void OpenboxWindow::redrawLabel(void) {
2104   int dx = frame.bevel_w * 2, dlen = client.title_len;
2105   unsigned int l = client.title_text_w;
2106
2107   if (flags.focused) {
2108     if (frame.flabel)
2109       XSetWindowBackgroundPixmap(display, frame.label, frame.flabel);
2110     else
2111       XSetWindowBackground(display, frame.label, frame.flabel_pixel);
2112   } else {
2113     if (frame.ulabel)
2114       XSetWindowBackgroundPixmap(display, frame.label, frame.ulabel);
2115     else
2116       XSetWindowBackground(display, frame.label, frame.ulabel_pixel);
2117   }
2118   XClearWindow(display, frame.label);
2119
2120   if (client.title_text_w > frame.label_w) {
2121     for (; dlen >= 0; dlen--) {
2122       if (i18n->multibyte()) {
2123         XRectangle ink, logical;
2124         XmbTextExtents(screen->getWindowStyle()->fontset, client.title, dlen,
2125                        &ink, &logical);
2126         l = logical.width;
2127       } else {
2128         l = XTextWidth(screen->getWindowStyle()->font, client.title, dlen);
2129       }
2130       l += (frame.bevel_w * 4);
2131
2132       if (l < frame.label_w)
2133         break;
2134     }
2135   }
2136
2137   switch (screen->getWindowStyle()->justify) {
2138   case BScreen::RightJustify:
2139     dx += frame.label_w - l;
2140     break;
2141
2142   case BScreen::CenterJustify:
2143     dx += (frame.label_w - l) / 2;
2144     break;
2145   }
2146
2147   WindowStyle *style = screen->getWindowStyle();
2148   GC text_gc = (flags.focused) ? style->l_text_focus_gc :
2149     style->l_text_unfocus_gc;
2150   if (i18n->multibyte())
2151     XmbDrawString(display, frame.label, style->fontset, text_gc, dx,
2152                   (1 - style->fontset_extents->max_ink_extent.y),
2153                   client.title, dlen);
2154   else
2155     XDrawString(display, frame.label, text_gc, dx,
2156                 (style->font->ascent + 1), client.title, dlen);
2157 }
2158
2159
2160 void OpenboxWindow::redrawAllButtons(void) {
2161   if (frame.iconify_button) redrawIconifyButton(False);
2162   if (frame.maximize_button) redrawMaximizeButton(flags.maximized);
2163   if (frame.close_button) redrawCloseButton(False);
2164 }
2165
2166
2167 void OpenboxWindow::redrawIconifyButton(Bool pressed) {
2168   if (! pressed) {
2169     if (flags.focused) {
2170       if (frame.fbutton)
2171         XSetWindowBackgroundPixmap(display, frame.iconify_button,
2172                                    frame.fbutton);
2173       else
2174         XSetWindowBackground(display, frame.iconify_button,
2175                              frame.fbutton_pixel);
2176     } else {
2177       if (frame.ubutton)
2178         XSetWindowBackgroundPixmap(display, frame.iconify_button,
2179                                    frame.ubutton);
2180       else
2181         XSetWindowBackground(display, frame.iconify_button,
2182                              frame.ubutton_pixel);
2183     }
2184   } else {
2185     if (frame.pbutton)
2186       XSetWindowBackgroundPixmap(display, frame.iconify_button, frame.pbutton);
2187     else
2188       XSetWindowBackground(display, frame.iconify_button, frame.pbutton_pixel);
2189   }
2190   XClearWindow(display, frame.iconify_button);
2191
2192   XDrawRectangle(display, frame.iconify_button,
2193                  ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc :
2194                   screen->getWindowStyle()->b_pic_unfocus_gc),
2195                  2, (frame.button_h - 5), (frame.button_w - 5), 2);
2196 }
2197
2198
2199 void OpenboxWindow::redrawMaximizeButton(Bool pressed) {
2200   if (! pressed) {
2201     if (flags.focused) {
2202       if (frame.fbutton)
2203         XSetWindowBackgroundPixmap(display, frame.maximize_button,
2204                                    frame.fbutton);
2205       else
2206         XSetWindowBackground(display, frame.maximize_button,
2207                              frame.fbutton_pixel);
2208     } else {
2209       if (frame.ubutton)
2210         XSetWindowBackgroundPixmap(display, frame.maximize_button,
2211                                    frame.ubutton);
2212       else
2213         XSetWindowBackground(display, frame.maximize_button,
2214                              frame.ubutton_pixel);
2215     }
2216   } else {
2217     if (frame.pbutton)
2218       XSetWindowBackgroundPixmap(display, frame.maximize_button,
2219                                  frame.pbutton);
2220     else
2221       XSetWindowBackground(display, frame.maximize_button,
2222                            frame.pbutton_pixel);
2223   }
2224   XClearWindow(display, frame.maximize_button);
2225
2226   XDrawRectangle(display, frame.maximize_button,
2227                  ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc :
2228                   screen->getWindowStyle()->b_pic_unfocus_gc),
2229                  2, 2, (frame.button_w - 5), (frame.button_h - 5));
2230   XDrawLine(display, frame.maximize_button,
2231             ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc :
2232              screen->getWindowStyle()->b_pic_unfocus_gc),
2233             2, 3, (frame.button_w - 3), 3);
2234 }
2235
2236
2237 void OpenboxWindow::redrawCloseButton(Bool pressed) {
2238   if (! pressed) {
2239     if (flags.focused) {
2240       if (frame.fbutton)
2241         XSetWindowBackgroundPixmap(display, frame.close_button,
2242                                    frame.fbutton);
2243       else
2244         XSetWindowBackground(display, frame.close_button,
2245                              frame.fbutton_pixel);
2246     } else {
2247       if (frame.ubutton)
2248         XSetWindowBackgroundPixmap(display, frame.close_button,
2249                                    frame.ubutton);
2250       else
2251         XSetWindowBackground(display, frame.close_button,
2252                              frame.ubutton_pixel);
2253     }
2254   } else {
2255     if (frame.pbutton)
2256       XSetWindowBackgroundPixmap(display, frame.close_button, frame.pbutton);
2257     else
2258       XSetWindowBackground(display, frame.close_button, frame.pbutton_pixel);
2259   }
2260   XClearWindow(display, frame.close_button);
2261
2262   XDrawLine(display, frame.close_button,
2263             ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc :
2264              screen->getWindowStyle()->b_pic_unfocus_gc), 2, 2,
2265             (frame.button_w - 3), (frame.button_h - 3));
2266   XDrawLine(display, frame.close_button,
2267             ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc :
2268              screen->getWindowStyle()->b_pic_unfocus_gc), 2,
2269             (frame.button_h - 3),
2270             (frame.button_w - 3), 2);
2271 }
2272
2273
2274 void OpenboxWindow::mapRequestEvent(XMapRequestEvent *re) {
2275   if (re->window == client.window) {
2276 #ifdef    DEBUG
2277     fprintf(stderr, i18n->getMessage(WindowSet, WindowMapRequest,
2278                              "OpenboxWindow::mapRequestEvent() for 0x%lx\n"),
2279             client.window);
2280 #endif // DEBUG
2281
2282     openbox.grab();
2283     if (! validateClient()) return;
2284
2285     Bool get_state_ret = getState();
2286     if (! (get_state_ret && openbox.isStartup())) {
2287       if ((client.wm_hint_flags & StateHint) &&
2288           (! (current_state == NormalState || current_state == IconicState)))
2289         current_state = client.initial_state;
2290       else
2291         current_state = NormalState;
2292     } else if (flags.iconic) {
2293       current_state = NormalState;
2294     }
2295
2296     switch (current_state) {
2297     case IconicState:
2298       iconify();
2299       break;
2300
2301     case WithdrawnState:
2302       withdraw();
2303       break;
2304
2305     case NormalState:
2306     case InactiveState:
2307     case ZoomState:
2308     default:
2309       deiconify(False);
2310       break;
2311     }
2312
2313     openbox.ungrab();
2314   }
2315 }
2316
2317
2318 void OpenboxWindow::mapNotifyEvent(XMapEvent *ne) {
2319   if ((ne->window == client.window) && (! ne->override_redirect)
2320       && (flags.visible)) {
2321     openbox.grab();
2322     if (! validateClient()) return;
2323
2324     if (decorations.titlebar) positionButtons();
2325
2326     setState(NormalState);
2327
2328     redrawAllButtons();
2329
2330     if (flags.transient || screen->focusNew())
2331       setInputFocus();
2332     else
2333       setFocusFlag(False);
2334
2335     flags.visible = True;
2336     flags.iconic = False;
2337
2338     openbox.ungrab();
2339   }
2340 }
2341
2342
2343 void OpenboxWindow::unmapNotifyEvent(XUnmapEvent *ue) {
2344   if (ue->window == client.window) {
2345 #ifdef    DEBUG
2346     fprintf(stderr, i18n->getMessage(WindowSet, WindowUnmapNotify,
2347                              "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"),
2348             client.window);
2349 #endif // DEBUG
2350
2351     openbox.grab();
2352     if (! validateClient()) return;
2353
2354     XChangeSaveSet(display, client.window, SetModeDelete);
2355     XSelectInput(display, client.window, NoEventMask);
2356
2357     XDeleteProperty(display, client.window, openbox.getWMStateAtom());
2358     XDeleteProperty(display, client.window,
2359                     openbox.getOpenboxAttributesAtom());
2360
2361     XUnmapWindow(display, frame.window);
2362     XUnmapWindow(display, client.window);
2363
2364     XEvent dummy;
2365     if (! XCheckTypedWindowEvent(display, client.window, ReparentNotify,
2366                                  &dummy)) {
2367 #ifdef    DEBUG
2368       fprintf(stderr, i18n->getMessage(WindowSet, WindowUnmapNotifyReparent,
2369                        "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to "
2370                        "root.\n"), client.window);
2371 #endif // DEBUG
2372
2373       restoreGravity();
2374       XReparentWindow(display, client.window, screen->getRootWindow(),
2375                       client.x, client.y);
2376     }
2377
2378     XFlush(display);
2379
2380     openbox.ungrab();
2381
2382     delete this;
2383   }
2384 }
2385
2386
2387 void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent *de) {
2388   if (de->window == client.window) {
2389     XUnmapWindow(display, frame.window);
2390
2391     delete this;
2392   }
2393 }
2394
2395
2396 void OpenboxWindow::propertyNotifyEvent(Atom atom) {
2397   openbox.grab();
2398   if (! validateClient()) return;
2399
2400   switch(atom) {
2401   case XA_WM_CLASS:
2402   case XA_WM_CLIENT_MACHINE:
2403   case XA_WM_COMMAND:
2404     break;
2405
2406   case XA_WM_TRANSIENT_FOR:
2407     // determine if this is a transient window
2408     Window win;
2409     if (XGetTransientForHint(display, client.window, &win)) {
2410       if (win && (win != client.window)) {
2411         if ((client.transient_for = openbox.searchWindow(win))) {
2412           client.transient_for->client.transient = this;
2413           flags.stuck = client.transient_for->flags.stuck;
2414           flags.transient = True;
2415         } else if (win == client.window_group) {
2416           //jr This doesn't look quite right...
2417           if ((client.transient_for = openbox.searchGroup(win, this))) {
2418             client.transient_for->client.transient = this;
2419             flags.stuck = client.transient_for->flags.stuck;
2420             flags.transient = True;
2421           }
2422         }
2423       }
2424
2425       if (win == screen->getRootWindow()) flags.modal = True;
2426     }
2427
2428     // adjust the window decorations based on transience
2429     if (flags.transient)
2430       decorations.maximize = decorations.handle = functions.maximize = False;
2431
2432     reconfigure();
2433
2434     break;
2435
2436   case XA_WM_HINTS:
2437     getWMHints();
2438     break;
2439
2440   case XA_WM_ICON_NAME:
2441     getWMIconName();
2442     if (flags.iconic) screen->iconUpdate();
2443     break;
2444
2445   case XA_WM_NAME:
2446     getWMName();
2447
2448     if (decorations.titlebar)
2449       redrawLabel();
2450
2451     if (! flags.iconic)
2452       screen->getWorkspace(workspace_number)->update();
2453
2454     break;
2455
2456   case XA_WM_NORMAL_HINTS: {
2457     getWMNormalHints();
2458
2459     if ((client.normal_hint_flags & PMinSize) &&
2460         (client.normal_hint_flags & PMaxSize)) {
2461       if (client.max_width <= client.min_width &&
2462           client.max_height <= client.min_height)
2463         decorations.maximize = decorations.handle =
2464             functions.resize = functions.maximize = False;
2465       else
2466         decorations.maximize = decorations.handle =
2467             functions.resize = functions.maximize = True;
2468     }
2469
2470     int x = frame.x, y = frame.y;
2471     unsigned int w = frame.width, h = frame.height;
2472
2473     upsize();
2474
2475     if ((x != frame.x) || (y != frame.y) ||
2476         (w != frame.width) || (h != frame.height))
2477       reconfigure();
2478
2479     break;
2480   }
2481
2482   default:
2483     if (atom == openbox.getWMProtocolsAtom()) {
2484       getWMProtocols();
2485
2486       if (decorations.close && (! frame.close_button)) {
2487         createCloseButton();
2488         if (decorations.titlebar) positionButtons(True);
2489         if (windowmenu) windowmenu->reconfigure();
2490       }
2491     }
2492
2493     break;
2494   }
2495
2496   openbox.ungrab();
2497 }
2498
2499
2500 void OpenboxWindow::exposeEvent(XExposeEvent *ee) {
2501   if (frame.label == ee->window && decorations.titlebar)
2502     redrawLabel();
2503   else if (frame.close_button == ee->window)
2504     redrawCloseButton(False);
2505   else if (frame.maximize_button == ee->window)
2506     redrawMaximizeButton(flags.maximized);
2507   else if (frame.iconify_button == ee->window)
2508     redrawIconifyButton(False);
2509 }
2510
2511
2512 void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent *cr) {
2513   if (cr->window == client.window) {
2514     openbox.grab();
2515     if (! validateClient()) return;
2516
2517     int cx = frame.x, cy = frame.y;
2518     unsigned int cw = frame.width, ch = frame.height;
2519
2520     if (cr->value_mask & CWBorderWidth)
2521       client.old_bw = cr->border_width;
2522
2523     if (cr->value_mask & CWX)
2524       cx = cr->x - frame.mwm_border_w - frame.border_w;
2525
2526     if (cr->value_mask & CWY)
2527       cy = cr->y - frame.y_border - frame.mwm_border_w -
2528         frame.border_w;
2529
2530     if (cr->value_mask & CWWidth)
2531       cw = cr->width + (frame.mwm_border_w * 2);
2532
2533     if (cr->value_mask & CWHeight)
2534       ch = cr->height + frame.y_border + (frame.mwm_border_w * 2) +
2535         (frame.border_w * decorations.handle) + frame.handle_h;
2536
2537     if (frame.x != cx || frame.y != cy ||
2538         frame.width != cw || frame.height != ch)
2539       configure(cx, cy, cw, ch);
2540
2541     if (cr->value_mask & CWStackMode) {
2542       switch (cr->detail) {
2543       case Above:
2544       case TopIf:
2545       default:
2546         if (flags.iconic) deiconify();
2547         screen->getWorkspace(workspace_number)->raiseWindow(this);
2548         break;
2549
2550       case Below:
2551       case BottomIf:
2552         if (flags.iconic) deiconify();
2553         screen->getWorkspace(workspace_number)->lowerWindow(this);
2554         break;
2555       }
2556     }
2557
2558     openbox.ungrab();
2559   }
2560 }
2561
2562
2563 void OpenboxWindow::buttonPressEvent(XButtonEvent *be) {
2564   openbox.grab();
2565   if (! validateClient())
2566     return;
2567
2568   int stack_change = 1; // < 0 means to lower the window
2569                         // > 0 means to raise the window
2570                         // 0 means to leave it where it is
2571   
2572   // alt + left/right click begins interactively moving/resizing the window
2573   // when the mouse is moved
2574   if (be->state == Mod1Mask && (be->button == 1 || be->button == 3)) {
2575     frame.grab_x = be->x_root - frame.x - frame.border_w;
2576     frame.grab_y = be->y_root - frame.y - frame.border_w;
2577     if (be->button == 3) {
2578       if (screen->getWindowZones() == 4 &&
2579           be->y < (signed) frame.height / 2) {
2580         resize_zone = ZoneTop;
2581       } else {
2582         resize_zone = ZoneBottom;
2583       }
2584       if (screen->getWindowZones() >= 2 &&
2585           be->x < (signed) frame.width / 2) {
2586         resize_zone |= ZoneLeft;
2587       } else {
2588         resize_zone |= ZoneRight;
2589       }
2590     }
2591   // control + left click on the titlebar shades the window
2592   } else if (be->state == ControlMask && be->button == 1) {
2593     if (be->window == frame.title ||
2594         be->window == frame.label)
2595       shade();
2596   // left click
2597   } else if (be->state == 0 && be->button == 1) {
2598     if (windowmenu && windowmenu->isVisible())
2599         windowmenu->hide();
2600
2601     if (be->window == frame.maximize_button) {
2602       redrawMaximizeButton(True);
2603     } else if (be->window == frame.iconify_button) {
2604       redrawIconifyButton(True);
2605     } else if (be->window == frame.close_button) {
2606       redrawCloseButton(True);
2607     } else if (be->window == frame.plate) {
2608       XAllowEvents(display, ReplayPointer, be->time);
2609     } else if (be->window == frame.title ||
2610                be->window == frame.label) {
2611       // shade the window when the titlebar is double clicked
2612       if ( (be->time - lastButtonPressTime) <=
2613             openbox.getDoubleClickInterval()) {
2614         lastButtonPressTime = 0;
2615         shade();
2616       } else {
2617         lastButtonPressTime = be->time;
2618       }
2619       // clicking and dragging on the titlebar moves the window, so on a click
2620       // we need to save the coords of the click in case the user drags
2621       frame.grab_x = be->x_root - frame.x - frame.border_w;
2622       frame.grab_y = be->y_root - frame.y - frame.border_w;
2623     } else if (be->window == frame.handle ||
2624                be->window == frame.left_grip ||
2625                be->window == frame.right_grip ||
2626                be->window == frame.window) {
2627       // clicking and dragging on the window's frame moves the window, so on a
2628       // click we need to save the coords of the click in case the user drags
2629       frame.grab_x = be->x_root - frame.x - frame.border_w;
2630       frame.grab_y = be->y_root - frame.y - frame.border_w;
2631       if (be->window == frame.left_grip)
2632         resize_zone = ZoneBottom | ZoneLeft;
2633       else if (be->window == frame.right_grip)
2634         resize_zone = ZoneBottom | ZoneRight;
2635     }
2636   // middle click
2637   } else if (be->state == 0 && be->button == 2) {
2638     if (be->window == frame.maximize_button) {
2639       redrawMaximizeButton(True);
2640     // a middle click anywhere on the window's frame except for on the buttons
2641     // will lower the window
2642     } else if (! (be->window == frame.iconify_button ||
2643                   be->window == frame.close_button) ) {
2644       stack_change = -1;
2645     }
2646   // right click
2647   } else if (be->state == 0 && be->button == 3) {
2648     if (be->window == frame.maximize_button) {
2649       redrawMaximizeButton(True);
2650     // a right click on the window's frame will show or hide the window's
2651     // windowmenu
2652     } else if (be->window == frame.title ||
2653                be->window == frame.label ||
2654                be->window == frame.handle ||
2655                be->window == frame.window) {
2656       int mx, my;
2657       if (windowmenu) {
2658         if (windowmenu->isVisible()) {
2659           windowmenu->hide();
2660         } else {
2661           // get the coords for the menu
2662           mx = be->x_root - windowmenu->getWidth() / 2;
2663           if (be->window == frame.title || be->window == frame.label) {
2664             my = frame.y + frame.title_h;
2665           } else if (be->window = frame.handle) {
2666             my = frame.y + frame.y_handle - windowmenu->getHeight();
2667           } else { // (be->window == frame.window)
2668             if (be->y <= (signed) frame.bevel_w) {
2669               my = frame.y + frame.y_border;
2670             } else {
2671               my = be->y_root - (windowmenu->getHeight() / 2);
2672             }
2673           }
2674
2675           if (mx > (signed) (frame.x + frame.width -
2676               windowmenu->getWidth())) {
2677             mx = frame.x + frame.width - windowmenu->getWidth();
2678           } else if (mx < frame.x) {
2679             mx = frame.x;
2680           }
2681
2682           if (my > (signed) (frame.y + frame.y_handle -
2683                 windowmenu->getHeight())) {
2684             my = frame.y + frame.y_handle - windowmenu->getHeight();
2685           } else if (my < (signed) (frame.y +
2686               ((decorations.titlebar) ? frame.title_h : frame.y_border))) {
2687             my = frame.y +
2688               ((decorations.titlebar) ? frame.title_h : frame.y_border);
2689           }
2690
2691           windowmenu->move(mx, my);
2692           windowmenu->show();
2693           XRaiseWindow(display, windowmenu->getWindowID());
2694           XRaiseWindow(display, windowmenu->getSendToMenu()->getWindowID());
2695           stack_change = 0;  // dont raise the window overtop of the menu
2696         }
2697       }
2698     }
2699   // mouse wheel up
2700   } else if (be->state == 0 && be->button == 4) {
2701     if ((be->window == frame.label ||
2702         be->window == frame.title) &&
2703         !flags.shaded)
2704       shade();
2705   // mouse wheel down
2706   } else if (be->state == 0 && be->button == 5) {
2707     if ((be->window == frame.label ||
2708         be->window == frame.title) &&
2709         flags.shaded)
2710       shade();
2711   }
2712
2713   if (! (flags.focused || screen->sloppyFocus()) ) {
2714     setInputFocus();  // any click focus' the window in 'click to focus'
2715   }
2716   if (stack_change < 0) {
2717     screen->getWorkspace(workspace_number)->lowerWindow(this);
2718   } else if (stack_change > 0) {
2719     screen->getWorkspace(workspace_number)->raiseWindow(this);
2720   }
2721  
2722   openbox.ungrab();
2723 }
2724
2725
2726 void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) {
2727   openbox.grab();
2728   if (! validateClient())
2729     return;
2730
2731   // alt + middle button released
2732   if (re->state == (Mod1Mask & Button2Mask) && re->button == 2) {
2733     if (re->window == frame.window) {
2734       XUngrabPointer(display, CurrentTime); // why? i dont know
2735     }
2736   // left button released
2737   } else if (re->button == 1) {
2738     if (re->window == frame.maximize_button) {
2739       if (re->state == Button1Mask && // only the left button was depressed
2740           (re->x >= 0) && ((unsigned) re->x <= frame.button_w) &&
2741           (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) {
2742         maximize(re->button);
2743       } else {
2744         redrawMaximizeButton(False);
2745       }
2746     } else if (re->window == frame.iconify_button) {
2747       if (re->state == Button1Mask && // only the left button was depressed
2748           (re->x >= 0) && ((unsigned) re->x <= frame.button_w) &&
2749           (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) {
2750         iconify();
2751       } else {
2752         redrawIconifyButton(False);
2753       }
2754     } else if (re->window == frame.close_button) {
2755       if (re->state == Button1Mask && // only the left button was depressed
2756           (re->x >= 0) && ((unsigned) re->x <= frame.button_w) &&
2757           (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) {
2758           close();
2759       }
2760       //we should always redraw the close button. some applications
2761       //eg. acroread don't honour the close.
2762       redrawCloseButton(False);
2763     }
2764   // middle button released
2765   } else if (re->button == 2) {
2766     if (re->window == frame.maximize_button) {
2767       if (re->state == Button2Mask && // only the middle button was depressed
2768           (re->x >= 0) && ((unsigned) re->x <= frame.button_w) &&
2769           (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) {
2770         maximize(re->button);
2771       } else {
2772         redrawMaximizeButton(False);
2773       }
2774     }
2775   // right button released
2776   } else if (re->button == 3) {
2777     if (re->window == frame.maximize_button) {
2778       if (re->state == Button3Mask && // only the right button was depressed
2779           (re->x >= 0) && ((unsigned) re->x <= frame.button_w) &&
2780           (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) {
2781         maximize(re->button);
2782       } else {
2783         redrawMaximizeButton(False);
2784       }
2785     }
2786   }
2787   
2788   // when the window is being interactively moved, a button release stops the
2789   // move where it is
2790   if (flags.moving) {
2791     flags.moving = False;
2792
2793     openbox.maskWindowEvents(0, (OpenboxWindow *) 0);
2794     if (!screen->opaqueMove()) {
2795       XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2796                      frame.move_x, frame.move_y, frame.resize_w - 1,
2797                      frame.resize_h - 1);
2798
2799       configure(frame.move_x, frame.move_y, frame.width, frame.height);
2800       openbox.ungrab();
2801     } else {
2802       configure(frame.x, frame.y, frame.width, frame.height);
2803     }
2804     screen->hideGeometry();
2805     XUngrabPointer(display, CurrentTime);
2806   // when the window is being interactively resized, a button release stops the
2807   // resizing
2808   } else if (flags.resizing) {
2809     flags.resizing = False;
2810     XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2811                    frame.resize_x, frame.resize_y,
2812                    frame.resize_w - 1, frame.resize_h - 1);
2813     screen->hideGeometry();
2814     if (resize_zone & ZoneLeft) {
2815       left_fixsize();
2816     } else {  // when resizing with "Alt+Button3", the resize is the same as if
2817               // done with the right grip (the right side of the window is what
2818               // moves)
2819       right_fixsize();
2820     }
2821     // unset maximized state when resized after fully maximized
2822     if (flags.maximized == 1) {
2823         maximize(0);
2824     }
2825     configure(frame.resize_x, frame.resize_y,
2826               frame.resize_w - (frame.border_w * 2),
2827               frame.resize_h - (frame.border_w * 2));
2828     openbox.ungrab();
2829     XUngrabPointer(display, CurrentTime);
2830     resize_zone = 0;
2831   }
2832
2833   openbox.ungrab();
2834 }
2835
2836
2837 void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) {
2838   if (!flags.resizing && (me->state & Button1Mask) && functions.move &&
2839       (frame.title == me->window || frame.label == me->window ||
2840        frame.handle == me->window || frame.window == me->window)) {
2841     if (! flags.moving) {
2842       XGrabPointer(display, me->window, False, Button1MotionMask |
2843                    ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
2844                    None, openbox.getMoveCursor(), CurrentTime);
2845
2846       if (windowmenu && windowmenu->isVisible())
2847         windowmenu->hide();
2848
2849       flags.moving = True;
2850
2851       openbox.maskWindowEvents(client.window, this);
2852
2853       if (! screen->opaqueMove()) {
2854         openbox.grab();
2855
2856         frame.move_x = frame.x;
2857         frame.move_y = frame.y;
2858         frame.resize_w = frame.width + (frame.border_w * 2);
2859         frame.resize_h = ((flags.shaded) ? frame.title_h : frame.height) +
2860           (frame.border_w * 2);
2861
2862         screen->showPosition(frame.x, frame.y);
2863
2864         XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2865                        frame.move_x, frame.move_y,
2866                        frame.resize_w - 1, frame.resize_h - 1);
2867       }
2868     } else {
2869       int dx = me->x_root - frame.grab_x, dy = me->y_root - frame.grab_y;
2870
2871       dx -= frame.border_w;
2872       dy -= frame.border_w;
2873
2874       int snap_distance = screen->edgeSnapThreshold();
2875       // width/height of the snapping window
2876       unsigned int snap_w = frame.width + (frame.border_w * 2);
2877       unsigned int snap_h = area().h() + (frame.border_w * 2);
2878       if (snap_distance) {
2879         int drx = screen->size().w() - (dx + snap_w);
2880
2881         if (dx < drx && (dx > 0 && dx < snap_distance) ||
2882                         (dx < 0 && dx > -snap_distance) )
2883           dx = 0;
2884         else if ( (drx > 0 && drx < snap_distance) ||
2885                   (drx < 0 && drx > -snap_distance) )
2886           dx = screen->size().w() - snap_w;
2887
2888         int dtty, dbby, dty, dby;
2889         switch (screen->getToolbar()->placement()) {
2890         case Toolbar::TopLeft:
2891         case Toolbar::TopCenter:
2892         case Toolbar::TopRight:
2893           dtty = screen->getToolbar()->getExposedHeight() +
2894                  frame.border_w;
2895           dbby = screen->size().h();
2896           break;
2897
2898         default:
2899           dtty = 0;
2900           dbby = screen->getToolbar()->area().y();
2901           break;
2902         }
2903
2904         dty = dy - dtty;
2905         dby = dbby - (dy + snap_h);
2906
2907         if ( (dy > 0 && dty < snap_distance) ||
2908             (dy < 0 && dty > -snap_distance) )
2909           dy = dtty;
2910         else if ( (dby > 0 && dby < snap_distance) ||
2911                  (dby < 0 && dby > -snap_distance) )
2912           dy = dbby - snap_h;
2913       }
2914
2915       if (screen->opaqueMove()) {
2916         configure(dx, dy, frame.width, frame.height);
2917       } else {
2918         XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2919                        frame.move_x, frame.move_y, frame.resize_w - 1,
2920                        frame.resize_h - 1);
2921
2922         frame.move_x = dx;
2923         frame.move_y = dy;
2924
2925         XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2926                        frame.move_x, frame.move_y, frame.resize_w - 1,
2927                        frame.resize_h - 1);
2928       }
2929
2930       screen->showPosition(dx, dy);
2931     }
2932   } else if (functions.resize &&
2933              (((me->state & Button1Mask) && (me->window == frame.right_grip ||
2934                                              me->window == frame.left_grip)) ||
2935               (me->state & (Mod1Mask | Button3Mask) &&
2936                                              me->window == frame.window))) {
2937     Bool left = resize_zone & ZoneLeft;
2938
2939     if (! flags.resizing) {
2940       Cursor cursor;
2941       if (resize_zone & ZoneTop)
2942         cursor = (resize_zone & ZoneLeft) ?
2943           openbox.getUpperLeftAngleCursor() :
2944           openbox.getUpperRightAngleCursor();
2945       else
2946         cursor = (resize_zone & ZoneLeft) ?
2947           openbox.getLowerLeftAngleCursor() :
2948           openbox.getLowerRightAngleCursor();
2949       XGrabPointer(display, me->window, False, ButtonMotionMask |
2950                    ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None,
2951                    cursor, CurrentTime);
2952
2953       flags.resizing = True;
2954
2955       openbox.grab();
2956
2957       int gx, gy;
2958       if (resize_zone & ZoneRight)
2959         frame.grab_x = me->x - screen->getBorderWidth();
2960       else
2961         frame.grab_x = me->x + screen->getBorderWidth();
2962       if (resize_zone & ZoneTop)
2963         frame.grab_y = me->y + screen->getBorderWidth() * 2;
2964       else
2965         frame.grab_y = me->y - screen->getBorderWidth() * 2;
2966       frame.resize_x = frame.x;
2967       frame.resize_y = frame.y;
2968       frame.resize_w = frame.width + (frame.border_w * 2);
2969       frame.resize_h = frame.height + (frame.border_w * 2);
2970
2971       if (left)
2972         left_fixsize(&gx, &gy);
2973       else
2974         right_fixsize(&gx, &gy);
2975
2976       screen->showGeometry(gx, gy);
2977
2978       XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2979                      frame.resize_x, frame.resize_y,
2980                      frame.resize_w - 1, frame.resize_h - 1);
2981     } else {
2982       XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
2983                      frame.resize_x, frame.resize_y,
2984                      frame.resize_w - 1, frame.resize_h - 1);
2985
2986       int gx, gy;
2987
2988       if (resize_zone & ZoneTop)
2989         frame.resize_h = frame.height - (me->y - frame.grab_y);
2990       else
2991         frame.resize_h = frame.height + (me->y - frame.grab_y);
2992       if (frame.resize_h < 1) frame.resize_h = 1;
2993
2994       if (left) {
2995         frame.resize_x = me->x_root - frame.grab_x;
2996         if (frame.resize_x > (signed) (frame.x + frame.width))
2997           frame.resize_x = frame.resize_x + frame.width - 1;
2998
2999         left_fixsize(&gx, &gy);
3000       } else {
3001         frame.resize_w = frame.width + (me->x - frame.grab_x);
3002         if (frame.resize_w < 1) frame.resize_w = 1;
3003
3004         right_fixsize(&gx, &gy);
3005       }
3006
3007       XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(),
3008                      frame.resize_x, frame.resize_y,
3009                      frame.resize_w - 1, frame.resize_h - 1);
3010
3011       screen->showGeometry(gx, gy);
3012     }
3013   }
3014 }
3015
3016
3017 #ifdef    SHAPE
3018 void OpenboxWindow::shapeEvent(XShapeEvent *) {
3019   if (openbox.hasShapeExtensions()) {
3020     if (flags.shaped) {
3021       openbox.grab();
3022       if (! validateClient()) return;
3023       XShapeCombineShape(display, frame.window, ShapeBounding,
3024                          frame.mwm_border_w, frame.y_border +
3025                          frame.mwm_border_w, client.window,
3026                          ShapeBounding, ShapeSet);
3027
3028       int num = 1;
3029       XRectangle xrect[2];
3030       xrect[0].x = xrect[0].y = 0;
3031       xrect[0].width = frame.width;
3032       xrect[0].height = frame.y_border;
3033
3034       if (decorations.handle) {
3035         xrect[1].x = 0;
3036         xrect[1].y = frame.y_handle;
3037         xrect[1].width = frame.width;
3038         xrect[1].height = frame.handle_h + frame.border_w;
3039         num++;
3040       }
3041
3042       XShapeCombineRectangles(display, frame.window, ShapeBounding, 0, 0,
3043                               xrect, num, ShapeUnion, Unsorted);
3044       openbox.ungrab();
3045     }
3046   }
3047 }
3048 #endif // SHAPE
3049
3050
3051 Bool OpenboxWindow::validateClient(void) {
3052   XSync(display, False);
3053
3054   XEvent e;
3055   if (XCheckTypedWindowEvent(display, client.window, DestroyNotify, &e) ||
3056       XCheckTypedWindowEvent(display, client.window, UnmapNotify, &e)) {
3057     XPutBackEvent(display, &e);
3058     openbox.ungrab();
3059
3060     return False;
3061   }
3062
3063   return True;
3064 }
3065
3066
3067 void OpenboxWindow::restore(void) {
3068   XChangeSaveSet(display, client.window, SetModeDelete);
3069   XSelectInput(display, client.window, NoEventMask);
3070
3071   restoreGravity();
3072
3073   XUnmapWindow(display, frame.window);
3074   XUnmapWindow(display, client.window);
3075
3076   XSetWindowBorderWidth(display, client.window, client.old_bw);
3077   XReparentWindow(display, client.window, screen->getRootWindow(),
3078                   client.x, client.y);
3079   XMapWindow(display, client.window);
3080
3081   XFlush(display);
3082 }
3083
3084
3085 void OpenboxWindow::timeout(void) {
3086   screen->getWorkspace(workspace_number)->raiseWindow(this);
3087 }
3088
3089
3090 void OpenboxWindow::changeOpenboxHints(OpenboxHints *net) {
3091   if ((net->flags & AttribShaded) &&
3092       ((openbox_attrib.attrib & AttribShaded) !=
3093        (net->attrib & AttribShaded)))
3094     shade();
3095
3096   if (flags.visible && // watch out for requests when we can not be seen
3097       (net->flags & (AttribMaxVert | AttribMaxHoriz)) &&
3098       ((openbox_attrib.attrib & (AttribMaxVert | AttribMaxHoriz)) !=
3099        (net->attrib & (AttribMaxVert | AttribMaxHoriz)))) {
3100     if (flags.maximized) {
3101       maximize(0);
3102     } else {
3103       int button = 0;
3104
3105       if ((net->flags & AttribMaxHoriz) && (net->flags & AttribMaxVert))
3106         button = ((net->attrib & (AttribMaxHoriz | AttribMaxVert)) ?  1 : 0);
3107       else if (net->flags & AttribMaxVert)
3108         button = ((net->attrib & AttribMaxVert) ? 2 : 0);
3109       else if (net->flags & AttribMaxHoriz)
3110         button = ((net->attrib & AttribMaxHoriz) ? 3 : 0);
3111
3112       maximize(button);
3113     }
3114   }
3115
3116   if ((net->flags & AttribOmnipresent) &&
3117       ((openbox_attrib.attrib & AttribOmnipresent) !=
3118        (net->attrib & AttribOmnipresent)))
3119     stick();
3120
3121   if ((net->flags & AttribWorkspace) &&
3122       (workspace_number != (signed) net->workspace)) {
3123     screen->reassociateWindow(this, net->workspace, True);
3124
3125     if (screen->getCurrentWorkspaceID() != (signed) net->workspace) withdraw();
3126     else deiconify();
3127   }
3128
3129   if (net->flags & AttribDecoration) {
3130     switch (net->decoration) {
3131     case DecorNone:
3132       decorations.titlebar = decorations.border = decorations.handle =
3133        decorations.iconify = decorations.maximize = decorations.menu = False;
3134
3135       break;
3136
3137     default:
3138     case DecorNormal:
3139       decorations.titlebar = decorations.border = decorations.handle =
3140        decorations.iconify = decorations.maximize = decorations.menu = True;
3141
3142       break;
3143
3144     case DecorTiny:
3145       decorations.titlebar = decorations.iconify = decorations.menu = True;
3146       decorations.border = decorations.handle = decorations.maximize = False;
3147  
3148       break;
3149
3150     case DecorTool:
3151       decorations.titlebar = decorations.menu = functions.move = True;
3152       decorations.iconify = decorations.border = decorations.handle =
3153         decorations.maximize = False;
3154
3155       break;
3156     }
3157     if (frame.window) {
3158       XMapSubwindows(display, frame.window);
3159       XMapWindow(display, frame.window);
3160     }
3161
3162     reconfigure();
3163     setState(current_state);
3164   }
3165 }
3166
3167
3168 /*
3169  * Set the sizes of all components of the window frame
3170  * (the window decorations).
3171  * These values are based upon the current style settings and the client
3172  * window's dimentions.
3173  */
3174 void OpenboxWindow::upsize(void) {
3175   frame.bevel_w = screen->getBevelWidth();
3176
3177   if (decorations.border) {
3178     frame.border_w = screen->getBorderWidth();
3179     if (!flags.transient)
3180       frame.mwm_border_w = screen->getFrameWidth();
3181     else
3182       frame.mwm_border_w = 0;
3183   } else {
3184     frame.mwm_border_w = frame.border_w = 0;
3185   }
3186
3187   if (decorations.titlebar) {
3188     // the height of the titlebar is based upon the height of the font being
3189     // used to display the window's title
3190     WindowStyle *style = screen->getWindowStyle();
3191     if (i18n->multibyte())
3192       frame.title_h = (style->fontset_extents->max_ink_extent.height +
3193                        (frame.bevel_w * 2) + 2);
3194     else
3195       frame.title_h = (style->font->ascent + style->font->descent +
3196                        (frame.bevel_w * 2) + 2);
3197
3198     frame.label_h = frame.title_h - (frame.bevel_w * 2);
3199     frame.button_w = frame.button_h = (frame.label_h - 2);
3200     frame.y_border = frame.title_h + frame.border_w;
3201   } else {
3202     frame.title_h = 0;
3203     frame.label_h = 0;
3204     frame.button_w = frame.button_h = 0;
3205     frame.y_border = 0;
3206   }
3207
3208   frame.border_h = client.height + frame.mwm_border_w * 2;
3209
3210   if (decorations.handle) {
3211     frame.y_handle = frame.y_border + frame.border_h + frame.border_w;
3212     frame.grip_w = frame.button_w * 2;
3213     frame.grip_h = frame.handle_h = screen->getHandleWidth();
3214   } else {
3215     frame.y_handle = frame.y_border + frame.border_h;
3216     frame.handle_h = 0;
3217     frame.grip_w = frame.grip_h = 0;
3218   }
3219   
3220   frame.width = client.width + (frame.mwm_border_w * 2);
3221   frame.height = frame.y_handle + frame.handle_h;
3222 }
3223
3224
3225 /*
3226  * Set the size and position of the client window.
3227  * These values are based upon the current style settings and the frame
3228  * window's dimensions.
3229  */
3230 void OpenboxWindow::downsize(void) {
3231   frame.y_handle = frame.height - frame.handle_h;
3232   frame.border_h = frame.y_handle - frame.y_border -
3233     (decorations.handle ? frame.border_w : 0);
3234
3235   client.x = frame.x + frame.mwm_border_w + frame.border_w;
3236   client.y = frame.y + frame.y_border + frame.mwm_border_w + frame.border_w;
3237
3238   client.width = frame.width - (frame.mwm_border_w * 2);
3239   client.height = frame.height - frame.y_border - (frame.mwm_border_w * 2)
3240     - frame.handle_h - (decorations.handle ? frame.border_w : 0);
3241
3242   frame.y_handle = frame.border_h + frame.y_border + frame.border_w;
3243 }
3244
3245
3246 void OpenboxWindow::right_fixsize(int *gx, int *gy) {
3247   // calculate the size of the client window and conform it to the
3248   // size specified by the size hints of the client window...
3249   int dx = frame.resize_w - client.base_width - (frame.mwm_border_w * 2) -
3250     (frame.border_w * 2) + (client.width_inc / 2);
3251   int dy = frame.resize_h - frame.y_border - client.base_height -
3252     frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2)
3253     + (client.height_inc / 2);
3254
3255   if (dx < (signed) client.min_width) dx = client.min_width;
3256   if (dy < (signed) client.min_height) dy = client.min_height;
3257   if ((unsigned) dx > client.max_width) dx = client.max_width;
3258   if ((unsigned) dy > client.max_height) dy = client.max_height;
3259
3260   dx /= client.width_inc;
3261   dy /= client.height_inc;
3262
3263   if (gx) *gx = dx;
3264   if (gy) *gy = dy;
3265
3266   dx = (dx * client.width_inc) + client.base_width;
3267   dy = (dy * client.height_inc) + client.base_height;
3268
3269   frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2);
3270   frame.resize_h = dy + frame.y_border + frame.handle_h +
3271                    (frame.mwm_border_w * 2) +  (frame.border_w * 3);
3272   if (resize_zone & ZoneTop)
3273     frame.resize_y = frame.y + frame.height - frame.resize_h +
3274       screen->getBorderWidth() * 2;
3275 }
3276
3277
3278 void OpenboxWindow::left_fixsize(int *gx, int *gy) {
3279   // calculate the size of the client window and conform it to the
3280   // size specified by the size hints of the client window...
3281   int dx = frame.x + frame.width - frame.resize_x - client.base_width -
3282     (frame.mwm_border_w * 2) + (client.width_inc / 2);
3283   int dy = frame.resize_h - frame.y_border - client.base_height -
3284     frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2)
3285     + (client.height_inc / 2);
3286
3287   if (dx < (signed) client.min_width) dx = client.min_width;
3288   if (dy < (signed) client.min_height) dy = client.min_height;
3289   if ((unsigned) dx > client.max_width) dx = client.max_width;
3290   if ((unsigned) dy > client.max_height) dy = client.max_height;
3291
3292   dx /= client.width_inc;
3293   dy /= client.height_inc;
3294
3295   if (gx) *gx = dx;
3296   if (gy) *gy = dy;
3297
3298   dx = (dx * client.width_inc) + client.base_width;
3299   dy = (dy * client.height_inc) + client.base_height;
3300
3301   frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2);
3302   frame.resize_x = frame.x + frame.width - frame.resize_w +
3303                    (frame.border_w * 2);
3304   frame.resize_h = dy + frame.y_border + frame.handle_h +
3305                    (frame.mwm_border_w * 2) + (frame.border_w * 3);
3306   if (resize_zone & ZoneTop)
3307     frame.resize_y = frame.y + frame.height - frame.resize_h +
3308       screen->getBorderWidth() * 2;
3309   
3310 }