+void Frame::adjustTitle()
+{
+ // XXX optimizations later...
+ adjustSize();
+}
+
+static void render(int screen, const otk::Size &size, Window win,
+ otk::Surface **surface,
+ const otk::RenderTexture &texture)
+{
+ otk::Surface *s = new otk::Surface(screen, size);
+ otk::display->renderControl(screen)->drawBackground(*s, texture);
+ XSetWindowBackgroundPixmap(**otk::display, win, s->pixmap());
+ XClearWindow(**otk::display, win);
+ if (*surface) delete *surface;
+ s->freePixelData();
+ *surface = s;
+}
+
+void Frame::adjustSize()
+{
+ Client::DecorationFlags decorations = _client->decorations();
+ const otk::RenderStyle *style = otk::RenderStyle::style(_client->screen());
+
+ if (decorations & Client::Decor_Border) {
+ geom.bwidth = style->frameBorderWidth();
+ geom.cbwidth = style->clientBorderWidth();
+ } else {
+ geom.bwidth = geom.cbwidth = 0;
+ }
+ _innersize.left = _innersize.top = _innersize.bottom = _innersize.right =
+ geom.cbwidth;
+ geom.width = _client->area().width() + geom.cbwidth * 2;
+ assert(geom.width > 0);
+
+ // set border widths
+ XSetWindowBorderWidth(**otk::display, _plate, geom.cbwidth);
+ XSetWindowBorderWidth(**otk::display, _frame, geom.bwidth);
+ XSetWindowBorderWidth(**otk::display, _title, geom.bwidth);
+ XSetWindowBorderWidth(**otk::display, _handle, geom.bwidth);
+ XSetWindowBorderWidth(**otk::display, _lgrip, geom.bwidth);
+ XSetWindowBorderWidth(**otk::display, _rgrip, geom.bwidth);
+
+ // position/size and map/unmap all the windows
+
+ if (decorations & Client::Decor_Titlebar) {
+ XMoveResizeWindow(**otk::display, _title, -geom.bwidth, -geom.bwidth,
+ geom.width, geom.title_height());
+ _innersize.top += geom.title_height() + geom.bwidth;
+ XMapWindow(**otk::display, _title);
+
+ // layout the title bar elements
+ layoutTitle();
+ } else
+ XUnmapWindow(**otk::display, _title);
+
+ if (decorations & Client::Decor_Handle) {
+ geom.handle_y = _innersize.top + _client->area().height() + geom.cbwidth;
+ XMoveResizeWindow(**otk::display, _handle, -geom.bwidth, geom.handle_y,
+ geom.width, geom.handle_height);
+ XMoveWindow(**otk::display, _lgrip, -geom.bwidth, -geom.bwidth);
+ XMoveWindow(**otk::display, _rgrip,
+ -geom.bwidth + geom.width - geom.grip_width(),
+ -geom.bwidth);
+ _innersize.bottom += geom.handle_height + geom.bwidth;
+ XMapWindow(**otk::display, _handle);
+ } else
+ XUnmapWindow(**otk::display, _handle);
+
+ XResizeWindow(**otk::display, _frame, geom.width,
+ (_client->shaded() ? geom.title_height() :
+ _innersize.top + _innersize.bottom +
+ _client->area().height()));
+
+ // do this in two steps because clients whose gravity is set to
+ // 'Static' don't end up getting moved at all with an XMoveResizeWindow
+ XMoveWindow(**otk::display, _plate, _innersize.left - geom.cbwidth,
+ _innersize.top - geom.cbwidth);
+ XResizeWindow(**otk::display, _plate, _client->area().width(),
+ _client->area().height());
+
+ _size.left = _innersize.left + geom.bwidth;
+ _size.right = _innersize.right + geom.bwidth;
+ _size.top = _innersize.top + geom.bwidth;
+ _size.bottom = _innersize.bottom + geom.bwidth;
+
+ _area = otk::Rect(_area.position(), otk::Size(_client->area().width() +
+ _size.left + _size.right,
+ _client->area().height() +
+ _size.top + _size.bottom));
+
+ // render all the elements
+ int screen = _client->screen();
+ bool focus = _client->focused();
+ if (decorations & Client::Decor_Titlebar) {
+ render(screen, otk::Size(geom.width, geom.title_height()), _title,
+ &_title_sur, *(focus ? style->titlebarFocusBackground() :
+ style->titlebarUnfocusBackground()));