1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
9 #include <X11/extensions/shape.h>
16 #include "otk/display.hh"
19 #include <iostream> // TEMP
23 OBFrame::OBFrame(OBClient *client, otk::Style *style)
24 : otk::OtkWidget(Openbox::instance, style),
26 _screen(otk::OBDisplay::screenInfo(client->screen())),
29 _button_close(&_titlebar),
30 _button_iconify(&_titlebar),
31 _button_max(&_titlebar),
32 _button_stick(&_titlebar),
36 _grip_right(&_handle),
37 _decorations(client->decorations())
43 _titlebar.unmanaged();
44 _button_close.unmanaged();
45 _button_iconify.unmanaged();
46 _button_max.unmanaged();
47 _button_stick.unmanaged();
50 _grip_left.unmanaged();
51 _grip_right.unmanaged();
56 _button_close.setText("X");
57 _button_iconify.setText("I");
58 _button_max.setText("M");
59 _button_stick.setText("S");
60 _label.setText(_client->title());
75 void OBFrame::setStyle(otk::Style *style)
79 otk::OtkWidget::setStyle(style);
80 // set the grips' textures
81 _grip_left.setTexture(style->getGripFocus());
82 _grip_left.setUnfocusTexture(style->getGripUnfocus());
83 _grip_left.setPressedFocusTexture(style->getGripFocus());
84 _grip_left.setPressedUnfocusTexture(style->getGripUnfocus());
85 _grip_right.setTexture(style->getGripFocus());
86 _grip_right.setUnfocusTexture(style->getGripUnfocus());
87 _grip_right.setPressedFocusTexture(style->getGripFocus());
88 _grip_right.setPressedUnfocusTexture(style->getGripUnfocus());
90 _titlebar.setTexture(style->getTitleFocus());
91 _titlebar.setUnfocusTexture(style->getTitleUnfocus());
92 _handle.setTexture(style->getHandleFocus());
93 _handle.setUnfocusTexture(style->getHandleUnfocus());
95 // if a style was previously set, then 'replace' is true, cause we're
97 bool replace = (_style);
100 // XXX: do shit here whatever
101 // XXX: save the position based on gravity
106 // XXX: change when focus changes!
107 XSetWindowBorder(otk::OBDisplay::display, _plate.getWindow(),
108 _style->getFrameFocus()->color().pixel());
110 XSetWindowBorder(otk::OBDisplay::display, getWindow(),
111 _style->getBorderColor()->pixel());
112 XSetWindowBorder(otk::OBDisplay::display, _titlebar.getWindow(),
113 _style->getBorderColor()->pixel());
114 XSetWindowBorder(otk::OBDisplay::display, _grip_left.getWindow(),
115 _style->getBorderColor()->pixel());
116 XSetWindowBorder(otk::OBDisplay::display, _grip_right.getWindow(),
117 _style->getBorderColor()->pixel());
118 XSetWindowBorder(otk::OBDisplay::display, _handle.getWindow(),
119 _style->getBorderColor()->pixel());
121 // if !replace, then adjust() will get called after the client is grabbed!
123 adjust(); // size/position everything
127 void OBFrame::adjust()
129 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
130 _decorations = _client->decorations();
131 _decorations = 0xffffffff;
133 int width; // the width of the client and its border
134 int bwidth; // width to make borders
135 int cbwidth; // width of the inner client border
137 if (_decorations & OBClient::Decor_Border) {
138 bwidth = _style->getBorderWidth();
139 cbwidth = _style->getFrameWidth();
141 bwidth = cbwidth = 0;
142 // inside this function _size is the size EXCLUDING the outer border
143 // at the end of this function it becomes the size INCLUDING the outer border
144 _size.left = _size.top = _size.bottom = _size.right = cbwidth;
145 width = _client->area().width() + cbwidth * 2;
147 XSetWindowBorderWidth(otk::OBDisplay::display, _plate.getWindow(), cbwidth);
149 XSetWindowBorderWidth(otk::OBDisplay::display, getWindow(), bwidth);
150 XSetWindowBorderWidth(otk::OBDisplay::display, _titlebar.getWindow(),
152 XSetWindowBorderWidth(otk::OBDisplay::display, _grip_left.getWindow(),
154 XSetWindowBorderWidth(otk::OBDisplay::display, _grip_right.getWindow(),
156 XSetWindowBorderWidth(otk::OBDisplay::display, _handle.getWindow(), bwidth);
158 if (_decorations & OBClient::Decor_Titlebar) {
159 // set the titlebar size
160 _titlebar.setGeometry(-bwidth,
163 (_style->getFont().height() +
164 _style->getBevelWidth() * 2));
165 _size.top += _titlebar.height() + bwidth;
167 // set the label size
168 _label.setGeometry(0, _style->getBevelWidth(),
169 width, _style->getFont().height());
170 // set the buttons sizes
171 if (_decorations & OBClient::Decor_Iconify)
172 _button_iconify.setGeometry(0, _style->getBevelWidth() + 1,
174 _label.height() - 2);
175 if (_decorations & OBClient::Decor_Maximize)
176 _button_max.setGeometry(0, _style->getBevelWidth() + 1,
178 _label.height() - 2);
179 if (_decorations & OBClient::Decor_Sticky)
180 _button_stick.setGeometry(0, _style->getBevelWidth() + 1,
182 _label.height() - 2);
183 if (_decorations & OBClient::Decor_Close)
184 _button_close.setGeometry(0, _style->getBevelWidth() + 1,
186 _label.height() - 2);
188 // separation between titlebar elements
189 const int sep = _style->getBevelWidth() + 1;
191 std::string layout = "SLIMC"; // XXX: get this from somewhere
192 // XXX: it is REQUIRED that by this point, the string only has one of each
193 // possible letter, all of the letters are valid, and L exists somewhere in
196 // the size of the label. this ASSUMES the layout has only buttons other
197 // that the ONE LABEL!!
198 // adds an extra sep so that there's a space on either side of the
199 // titlebar.. note: x = sep, below.
200 _label.setWidth(width - sep * 2 -
201 (_button_iconify.width() + sep) * (layout.size() - 1));
204 for (int i = 0, len = layout.size(); i < len; ++i) {
207 _button_iconify.move(x, _button_iconify.getRect().y());
208 x += _button_iconify.width();
211 _label.move(x, _label.getRect().y());
215 _button_max.move(x, _button_max.getRect().y());
216 x += _button_max.width();
219 _button_stick.move(x, _button_stick.getRect().y());
220 x += _button_stick.width();
223 _button_close.move(x, _button_close.getRect().y());
224 x += _button_close.width();
227 assert(false); // the layout string is invalid!
233 if (_decorations & OBClient::Decor_Handle) {
234 _handle.setGeometry(-bwidth,
235 _size.top + _client->area().height() + cbwidth,
236 width, _style->getHandleWidth());
237 _grip_left.setGeometry(-bwidth,
239 // XXX: get a Point class in otk and use that for
240 // the 'buttons size' since theyre all the same
241 _button_iconify.width() * 2,
243 _grip_right.setGeometry(((_handle.getRect().right() + 1) -
244 _button_iconify.width() * 2),
246 // XXX: get a Point class in otk and use that for
247 // the 'buttons size' since theyre all the same
248 _button_iconify.width() * 2,
250 _size.bottom += _handle.height() + bwidth;
254 // position/size all the windows
256 resize(_size.left + _size.right + _client->area().width(),
257 _size.top + _size.bottom + _client->area().height());
259 _plate.setGeometry(_size.left - cbwidth, _size.top - cbwidth,
260 _client->area().width(), _client->area().height());
262 // map/unmap all the windows
263 if (_decorations & OBClient::Decor_Titlebar) {
265 if (_decorations & OBClient::Decor_Iconify)
266 _button_iconify.show();
268 _button_iconify.hide();
269 if (_decorations & OBClient::Decor_Maximize)
273 if (_decorations & OBClient::Decor_Sticky)
274 _button_stick.show();
276 _button_stick.hide();
277 if (_decorations & OBClient::Decor_Close)
278 _button_close.show();
280 _button_close.hide();
283 _titlebar.hide(true);
286 if (_decorations & OBClient::Decor_Handle)
291 // inside this function _size is the size EXCLUDING the outer border
292 // at the end of this function it becomes the size INCLUDING the outer border
293 _size.left += bwidth;
294 _size.right += bwidth;
296 _size.bottom += bwidth;
298 // XXX: more is gunna have to happen here
306 void OBFrame::adjustShape()
309 if (!_client->shaped()) {
310 // clear the shape on the frame window
311 XShapeCombineMask(otk::OBDisplay::display, getWindow(), ShapeBounding,
316 // make the frame's shape match the clients
317 XShapeCombineShape(otk::OBDisplay::display, getWindow(), ShapeBounding,
320 _client->window(), ShapeBounding, ShapeSet);
326 if (decorations & Decor_Titlebar) {
327 xrect[0].x = xrect[0].y = -frame.border_w;
328 xrect[0].width = frame.rect.width();
329 xrect[0].height = frame.title_h + (frame.border_w * 2);
333 if (decorations & Decor_Handle) {
334 xrect[1].x = -frame.border_w;
335 xrect[1].y = frame.rect.height() - frame.margin.bottom +
336 frame.mwm_border_w - frame.border_w;
337 xrect[1].width = frame.rect.width();
338 xrect[1].height = frame.handle_h + (frame.border_w * 2);
342 XShapeCombineRectangles(otk::OBDisplay::display, getWindow(),
343 ShapeBounding, 0, 0, xrect, num,
344 ShapeUnion, Unsorted);
350 void OBFrame::grabClient()
353 // select the event mask on the frame
354 //XSelectInput(otk::OBDisplay::display, _window, SubstructureRedirectMask);
356 // reparent the client to the frame
357 XReparentWindow(otk::OBDisplay::display, _client->window(),
358 _plate.getWindow(), 0, 0);
359 _client->ignore_unmaps++;
361 // raise the client above the frame
362 //XRaiseWindow(otk::OBDisplay::display, _client->window());
363 // map the client so it maps when the frame does
364 XMapWindow(otk::OBDisplay::display, _client->window());
371 void OBFrame::releaseClient(bool remap)
373 // check if the app has already reparented its window to the root window
375 if (XCheckTypedWindowEvent(otk::OBDisplay::display, _client->window(),
376 ReparentNotify, &ev)) {
377 remap = true; // XXX: why do we remap the window if they already
378 // reparented to root?
380 // according to the ICCCM - if the client doesn't reparent to
381 // root, then we have to do it for them
382 XReparentWindow(otk::OBDisplay::display, _client->window(),
383 _screen->getRootWindow(),
384 _client->area().x(), _client->area().y());
387 // if we want to remap the window, do so now
389 XMapWindow(otk::OBDisplay::display, _client->window());
393 void OBFrame::applyGravity()
396 // apply horizontal window gravity
397 switch (_client->gravity()) {
399 case NorthWestGravity:
400 case SouthWestGravity:
402 x = _client->area().x();
408 x = _client->area().x() - (_size.left + _size.right) / 2;
411 case NorthEastGravity:
412 case SouthEastGravity:
414 x = _client->area().x() - _size.left - _size.right + 2;
419 x = _client->area().x() - _size.left;
423 // apply vertical window gravity
424 switch (_client->gravity()) {
426 case NorthWestGravity:
427 case NorthEastGravity:
429 y = _client->area().y();
435 y = _client->area().y() - (_size.top + _size.bottom) / 2;
438 case SouthWestGravity:
439 case SouthEastGravity:
441 y = _client->area().y() - _size.top - _size.bottom + 2;
446 y = _client->area().y() - _size.top;