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);
46 _grip_left.setCursor(Openbox::instance->cursors().ll_angle);
47 _grip_right.setCursor(Openbox::instance->cursors().lr_angle);
49 _label.setText(_client->title());
54 otk::OtkWidget::unfocus(); // stuff starts out appearing focused in otk
56 _plate.show(); // the other stuff is shown based on decor settings
68 void OBFrame::setTitle(const std::string &text)
75 void OBFrame::setStyle(otk::Style *style)
79 otk::OtkWidget::setStyle(style);
81 // if a style was previously set, then 'replace' is true, cause we're
83 bool replace = (_style);
86 // XXX: do shit here whatever
91 setBorderColor(_style->getBorderColor());
93 // if !replace, then adjust() will get called after the client is grabbed!
95 // size/position everything
102 void OBFrame::focus()
104 otk::OtkWidget::focus();
109 void OBFrame::unfocus()
111 otk::OtkWidget::unfocus();
116 void OBFrame::adjust()
121 void OBFrame::adjustSize()
123 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
124 _decorations = _client->decorations();
125 _decorations = 0xffffffff;
127 int width; // the width of the client and its border
128 int bwidth; // width to make borders
129 int cbwidth; // width of the inner client border
131 if (_decorations & OBClient::Decor_Border) {
132 bwidth = _style->getBorderWidth();
133 cbwidth = _style->getFrameWidth();
135 bwidth = cbwidth = 0;
136 _innersize.left = _innersize.top = _innersize.bottom = _innersize.right =
138 width = _client->area().width() + cbwidth * 2;
140 _plate.setBorderWidth(cbwidth);
142 setBorderWidth(bwidth);
143 _titlebar.setBorderWidth(bwidth);
144 _grip_left.setBorderWidth(bwidth);
145 _grip_right.setBorderWidth(bwidth);
146 _handle.setBorderWidth(bwidth);
148 if (_decorations & OBClient::Decor_Titlebar) {
149 // set the titlebar size
150 _titlebar.setGeometry(-bwidth,
153 (_style->getFont()->height() +
154 _style->getBevelWidth() * 2));
155 _innersize.top += _titlebar.height() + bwidth;
157 // set the label size
158 _label.setGeometry(0, _style->getBevelWidth(),
159 width, _style->getFont()->height());
160 // set the buttons sizes
161 if (_decorations & OBClient::Decor_Iconify)
162 _button_iconify.setGeometry(0, _style->getBevelWidth() + 1,
164 _label.height() - 2);
165 if (_decorations & OBClient::Decor_Maximize)
166 _button_max.setGeometry(0, _style->getBevelWidth() + 1,
168 _label.height() - 2);
169 if (_decorations & OBClient::Decor_Sticky)
170 _button_stick.setGeometry(0, _style->getBevelWidth() + 1,
172 _label.height() - 2);
173 if (_decorations & OBClient::Decor_Close)
174 _button_close.setGeometry(0, _style->getBevelWidth() + 1,
176 _label.height() - 2);
178 // separation between titlebar elements
179 const int sep = _style->getBevelWidth() + 1;
181 std::string layout = "SLIMC"; // XXX: get this from somewhere
182 // XXX: it is REQUIRED that by this point, the string only has one of each
183 // possible letter, all of the letters are valid, and L exists somewhere in
186 // the size of the label. this ASSUMES the layout has only buttons other
187 // that the ONE LABEL!!
188 // adds an extra sep so that there's a space on either side of the
189 // titlebar.. note: x = sep, below.
190 int lwidth = width - sep * 2 -
191 (_button_iconify.width() + sep) * (layout.size() - 1);
192 // quick sanity check for really small windows. if this is needed, its
193 // obviously not going to be displayed right...
194 // XXX: maybe we should make this look better somehow? constraints?
195 if (lwidth <= 0) lwidth = 1;
196 _label.setWidth(lwidth);
199 for (int i = 0, len = layout.size(); i < len; ++i) {
202 _button_iconify.move(x, _button_iconify.rect().y());
203 x += _button_iconify.width();
206 _label.move(x, _label.rect().y());
210 _button_max.move(x, _button_max.rect().y());
211 x += _button_max.width();
214 _button_stick.move(x, _button_stick.rect().y());
215 x += _button_stick.width();
218 _button_close.move(x, _button_close.rect().y());
219 x += _button_close.width();
222 assert(false); // the layout string is invalid!
228 if (_decorations & OBClient::Decor_Handle) {
229 _handle.setGeometry(-bwidth,
230 _innersize.top + _client->area().height() + cbwidth,
231 width, _style->getHandleWidth());
232 _grip_left.setGeometry(-bwidth,
234 // XXX: get a Point class in otk and use that for
235 // the 'buttons size' since theyre all the same
236 _button_iconify.width() * 2,
238 _grip_right.setGeometry(((_handle.rect().right() + 1) -
239 _button_iconify.width() * 2),
241 // XXX: get a Point class in otk and use that for
242 // the 'buttons size' since theyre all the same
243 _button_iconify.width() * 2,
245 _innersize.bottom += _handle.height() + bwidth;
249 // position/size all the windows
251 resize(_innersize.left + _innersize.right + _client->area().width(),
252 _innersize.top + _innersize.bottom + _client->area().height());
254 _plate.setGeometry(_innersize.left - cbwidth, _innersize.top - cbwidth,
255 _client->area().width(), _client->area().height());
257 // map/unmap all the windows
258 if (_decorations & OBClient::Decor_Titlebar) {
260 if (_decorations & OBClient::Decor_Iconify)
261 _button_iconify.show();
263 _button_iconify.hide();
264 if (_decorations & OBClient::Decor_Maximize)
268 if (_decorations & OBClient::Decor_Sticky)
269 _button_stick.show();
271 _button_stick.hide();
272 if (_decorations & OBClient::Decor_Close)
273 _button_close.show();
275 _button_close.hide();
278 _titlebar.hide(true);
281 if (_decorations & OBClient::Decor_Handle)
286 // XXX: more is gunna have to happen here
288 _size.left = _innersize.left + bwidth;
289 _size.right = _innersize.right + bwidth;
290 _size.top = _innersize.top + bwidth;
291 _size.bottom = _innersize.bottom + bwidth;
299 void OBFrame::adjustPosition()
307 void OBFrame::adjustShape()
310 int bwidth = (_decorations & OBClient::Decor_Border) ?
311 _style->getBorderWidth() : 0;
313 if (!_client->shaped()) {
314 // clear the shape on the frame window
315 XShapeCombineMask(otk::OBDisplay::display, window(), ShapeBounding,
320 // make the frame's shape match the clients
321 XShapeCombineShape(otk::OBDisplay::display, window(), ShapeBounding,
324 _client->window(), ShapeBounding, ShapeSet);
329 if (_decorations & OBClient::Decor_Titlebar) {
330 xrect[0].x = _titlebar.rect().x();
331 xrect[0].y = _titlebar.rect().y();
332 xrect[0].width = _titlebar.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
333 xrect[0].height = _titlebar.height() + bwidth * 2;
337 if (_decorations & OBClient::Decor_Handle) {
338 xrect[1].x = _handle.rect().x();
339 xrect[1].y = _handle.rect().y();
340 xrect[1].width = _handle.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
341 xrect[1].height = _handle.height() + bwidth * 2;
345 XShapeCombineRectangles(otk::OBDisplay::display, window(),
346 ShapeBounding, 0, 0, xrect, num,
347 ShapeUnion, Unsorted);
353 void OBFrame::grabClient()
356 // reparent the client to the frame
357 XReparentWindow(otk::OBDisplay::display, _client->window(),
358 _plate.window(), 0, 0);
359 _client->ignore_unmaps++;
361 // select the event mask on the client's parent (to receive config req's)
362 XSelectInput(otk::OBDisplay::display, _plate.window(),
363 SubstructureRedirectMask);
365 // map the client so it maps when the frame does
366 XMapWindow(otk::OBDisplay::display, _client->window());
373 void OBFrame::releaseClient(bool remap)
375 // check if the app has already reparented its window to the root window
377 if (XCheckTypedWindowEvent(otk::OBDisplay::display, _client->window(),
378 ReparentNotify, &ev)) {
379 remap = true; // XXX: why do we remap the window if they already
380 // reparented to root?
382 // according to the ICCCM - if the client doesn't reparent to
383 // root, then we have to do it for them
384 XReparentWindow(otk::OBDisplay::display, _client->window(),
385 _screen->rootWindow(),
386 _client->area().x(), _client->area().y());
389 // if we want to remap the window, do so now
391 XMapWindow(otk::OBDisplay::display, _client->window());
395 void OBFrame::clientGravity(int &x, int &y)
397 x = _client->area().x();
398 y = _client->area().y();
401 switch (_client->gravity()) {
403 case NorthWestGravity:
404 case SouthWestGravity:
411 x -= (_size.left + _size.right) / 2;
414 case NorthEastGravity:
415 case SouthEastGravity:
417 x -= _size.left + _size.right;
427 switch (_client->gravity()) {
429 case NorthWestGravity:
430 case NorthEastGravity:
437 y -= (_size.top + _size.bottom) / 2;
440 case SouthWestGravity:
441 case SouthEastGravity:
443 y -= _size.top + _size.bottom;
454 void OBFrame::frameGravity(int &x, int &y)
460 switch (_client->gravity()) {
462 case NorthWestGravity:
464 case SouthWestGravity:
469 x += (_size.left + _size.right) / 2;
471 case NorthEastGravity:
473 case SouthEastGravity:
474 x += _size.left + _size.right;
483 switch (_client->gravity()) {
485 case NorthWestGravity:
487 case SouthWestGravity:
492 y += (_size.top + _size.bottom) / 2;
494 case NorthEastGravity:
496 case SouthEastGravity:
497 y += _size.top + _size.bottom;