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"
22 const long OBFrame::event_mask;
24 OBFrame::OBFrame(OBClient *client, otk::Style *style)
25 : otk::OtkWidget(Openbox::instance, style),
28 _screen(otk::OBDisplay::screenInfo(client->screen())),
29 _plate(this, OBWidget::Type_Plate),
30 _titlebar(this, OBWidget::Type_Titlebar),
31 _button_close(&_titlebar, OBWidget::Type_CloseButton),
32 _button_iconify(&_titlebar, OBWidget::Type_IconifyButton),
33 _button_max(&_titlebar, OBWidget::Type_MaximizeButton),
34 _button_stick(&_titlebar, OBWidget::Type_StickyButton),
35 _label(&_titlebar, OBWidget::Type_Label),
36 _handle(this, OBWidget::Type_Handle),
37 _grip_left(&_handle, OBWidget::Type_LeftGrip),
38 _grip_right(&_handle, OBWidget::Type_RightGrip),
39 _decorations(client->decorations())
44 XSelectInput(otk::OBDisplay::display, window(), OBFrame::event_mask);
47 _titlebar.unmanaged();
48 _button_close.unmanaged();
49 _button_iconify.unmanaged();
50 _button_max.unmanaged();
51 _button_stick.unmanaged();
54 _grip_left.unmanaged();
55 _grip_right.unmanaged();
58 _grip_left.setCursor(Openbox::instance->cursors().ll_angle);
59 _grip_right.setCursor(Openbox::instance->cursors().lr_angle);
61 _button_close.setText("X");
62 _button_iconify.setText("I");
63 _button_max.setText("M");
64 _button_stick.setText("S");
65 _label.setText(_client->title());
70 //XXX: uncomment me unfocus(); // stuff starts out focused in otk
72 _plate.show(); // the other stuff is shown based on decor settings
84 void OBFrame::setStyle(otk::Style *style)
88 otk::OtkWidget::setStyle(style);
90 // if a style was previously set, then 'replace' is true, cause we're
92 bool replace = (_style);
95 // XXX: do shit here whatever
100 // XXX: change when focus changes!
101 XSetWindowBorder(otk::OBDisplay::display, window(),
102 _style->getBorderColor()->pixel());
104 // if !replace, then adjust() will get called after the client is grabbed!
106 // size/position everything
113 void OBFrame::adjustSize()
115 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
116 _decorations = _client->decorations();
117 _decorations = 0xffffffff;
119 int width; // the width of the client and its border
120 int bwidth; // width to make borders
121 int cbwidth; // width of the inner client border
123 if (_decorations & OBClient::Decor_Border) {
124 bwidth = _style->getBorderWidth();
125 cbwidth = _style->getFrameWidth();
127 bwidth = cbwidth = 0;
128 _innersize.left = _innersize.top = _innersize.bottom = _innersize.right =
130 width = _client->area().width() + cbwidth * 2;
132 _plate.setBorderWidth(cbwidth);
134 setBorderWidth(bwidth);
135 _titlebar.setBorderWidth(bwidth);
136 _grip_left.setBorderWidth(bwidth);
137 _grip_right.setBorderWidth(bwidth);
138 _handle.setBorderWidth(bwidth);
140 if (_decorations & OBClient::Decor_Titlebar) {
141 // set the titlebar size
142 _titlebar.setGeometry(-bwidth,
145 (_style->getFont().height() +
146 _style->getBevelWidth() * 2));
147 _innersize.top += _titlebar.height() + bwidth;
149 // set the label size
150 _label.setGeometry(0, _style->getBevelWidth(),
151 width, _style->getFont().height());
152 // set the buttons sizes
153 if (_decorations & OBClient::Decor_Iconify)
154 _button_iconify.setGeometry(0, _style->getBevelWidth() + 1,
156 _label.height() - 2);
157 if (_decorations & OBClient::Decor_Maximize)
158 _button_max.setGeometry(0, _style->getBevelWidth() + 1,
160 _label.height() - 2);
161 if (_decorations & OBClient::Decor_Sticky)
162 _button_stick.setGeometry(0, _style->getBevelWidth() + 1,
164 _label.height() - 2);
165 if (_decorations & OBClient::Decor_Close)
166 _button_close.setGeometry(0, _style->getBevelWidth() + 1,
168 _label.height() - 2);
170 // separation between titlebar elements
171 const int sep = _style->getBevelWidth() + 1;
173 std::string layout = "SLIMC"; // XXX: get this from somewhere
174 // XXX: it is REQUIRED that by this point, the string only has one of each
175 // possible letter, all of the letters are valid, and L exists somewhere in
178 // the size of the label. this ASSUMES the layout has only buttons other
179 // that the ONE LABEL!!
180 // adds an extra sep so that there's a space on either side of the
181 // titlebar.. note: x = sep, below.
182 int lwidth = width - sep * 2 -
183 (_button_iconify.width() + sep) * (layout.size() - 1);
184 // quick sanity check for really small windows. if this is needed, its
185 // obviously not going to be displayed right...
186 // XXX: maybe we should make this look better somehow? constraints?
187 if (lwidth <= 0) lwidth = 1;
188 _label.setWidth(lwidth);
191 for (int i = 0, len = layout.size(); i < len; ++i) {
194 _button_iconify.move(x, _button_iconify.rect().y());
195 x += _button_iconify.width();
198 _label.move(x, _label.rect().y());
202 _button_max.move(x, _button_max.rect().y());
203 x += _button_max.width();
206 _button_stick.move(x, _button_stick.rect().y());
207 x += _button_stick.width();
210 _button_close.move(x, _button_close.rect().y());
211 x += _button_close.width();
214 assert(false); // the layout string is invalid!
220 if (_decorations & OBClient::Decor_Handle) {
221 _handle.setGeometry(-bwidth,
222 _innersize.top + _client->area().height() + cbwidth,
223 width, _style->getHandleWidth());
224 _grip_left.setGeometry(-bwidth,
226 // XXX: get a Point class in otk and use that for
227 // the 'buttons size' since theyre all the same
228 _button_iconify.width() * 2,
230 _grip_right.setGeometry(((_handle.rect().right() + 1) -
231 _button_iconify.width() * 2),
233 // XXX: get a Point class in otk and use that for
234 // the 'buttons size' since theyre all the same
235 _button_iconify.width() * 2,
237 _innersize.bottom += _handle.height() + bwidth;
241 // position/size all the windows
243 resize(_innersize.left + _innersize.right + _client->area().width(),
244 _innersize.top + _innersize.bottom + _client->area().height());
246 _plate.setGeometry(_innersize.left - cbwidth, _innersize.top - cbwidth,
247 _client->area().width(), _client->area().height());
249 // map/unmap all the windows
250 if (_decorations & OBClient::Decor_Titlebar) {
252 if (_decorations & OBClient::Decor_Iconify)
253 _button_iconify.show();
255 _button_iconify.hide();
256 if (_decorations & OBClient::Decor_Maximize)
260 if (_decorations & OBClient::Decor_Sticky)
261 _button_stick.show();
263 _button_stick.hide();
264 if (_decorations & OBClient::Decor_Close)
265 _button_close.show();
267 _button_close.hide();
270 _titlebar.hide(true);
273 if (_decorations & OBClient::Decor_Handle)
278 // XXX: more is gunna have to happen here
280 _size.left = _innersize.left + bwidth;
281 _size.right = _innersize.right + bwidth;
282 _size.top = _innersize.top + bwidth;
283 _size.bottom = _innersize.bottom + bwidth;
291 void OBFrame::adjustPosition()
299 void OBFrame::adjustShape()
302 int bwidth = (_decorations & OBClient::Decor_Border) ?
303 _style->getBorderWidth() : 0;
305 if (!_client->shaped()) {
306 // clear the shape on the frame window
307 XShapeCombineMask(otk::OBDisplay::display, window(), ShapeBounding,
312 // make the frame's shape match the clients
313 XShapeCombineShape(otk::OBDisplay::display, window(), ShapeBounding,
316 _client->window(), ShapeBounding, ShapeSet);
321 if (_decorations & OBClient::Decor_Titlebar) {
322 xrect[0].x = _titlebar.rect().x();
323 xrect[0].y = _titlebar.rect().y();
324 xrect[0].width = _titlebar.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
325 xrect[0].height = _titlebar.height() + bwidth * 2;
329 if (_decorations & OBClient::Decor_Handle) {
330 xrect[1].x = _handle.rect().x();
331 xrect[1].y = _handle.rect().y();
332 xrect[1].width = _handle.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
333 xrect[1].height = _handle.height() + bwidth * 2;
337 XShapeCombineRectangles(otk::OBDisplay::display, window(),
338 ShapeBounding, 0, 0, xrect, num,
339 ShapeUnion, Unsorted);
345 void OBFrame::grabClient()
348 // reparent the client to the frame
349 XReparentWindow(otk::OBDisplay::display, _client->window(),
350 _plate.window(), 0, 0);
351 _client->ignore_unmaps++;
353 // select the event mask on the client's parent (to receive config req's)
354 XSelectInput(otk::OBDisplay::display, _plate.window(),
355 SubstructureRedirectMask);
357 // map the client so it maps when the frame does
358 XMapWindow(otk::OBDisplay::display, _client->window());
365 void OBFrame::releaseClient(bool remap)
367 // check if the app has already reparented its window to the root window
369 if (XCheckTypedWindowEvent(otk::OBDisplay::display, _client->window(),
370 ReparentNotify, &ev)) {
371 remap = true; // XXX: why do we remap the window if they already
372 // reparented to root?
374 // according to the ICCCM - if the client doesn't reparent to
375 // root, then we have to do it for them
376 XReparentWindow(otk::OBDisplay::display, _client->window(),
377 _screen->rootWindow(),
378 _client->area().x(), _client->area().y());
381 // if we want to remap the window, do so now
383 XMapWindow(otk::OBDisplay::display, _client->window());
387 void OBFrame::clientGravity(int &x, int &y)
389 x = _client->area().x();
390 y = _client->area().y();
393 switch (_client->gravity()) {
395 case NorthWestGravity:
396 case SouthWestGravity:
403 x -= (_size.left + _size.right) / 2;
406 case NorthEastGravity:
407 case SouthEastGravity:
409 x -= _size.left + _size.right;
419 switch (_client->gravity()) {
421 case NorthWestGravity:
422 case NorthEastGravity:
429 y -= (_size.top + _size.bottom) / 2;
432 case SouthWestGravity:
433 case SouthEastGravity:
435 y -= _size.top + _size.bottom;
446 void OBFrame::frameGravity(int &x, int &y)
452 switch (_client->gravity()) {
454 case NorthWestGravity:
456 case SouthWestGravity:
461 x += (_size.left + _size.right) / 2;
463 case NorthEastGravity:
465 case SouthEastGravity:
466 x += _size.left + _size.right;
475 switch (_client->gravity()) {
477 case NorthWestGravity:
479 case SouthWestGravity:
484 y += (_size.top + _size.bottom) / 2;
486 case NorthEastGravity:
488 case SouthEastGravity:
489 y += _size.top + _size.bottom;