1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
9 #include <X11/extensions/shape.h>
17 #include "bindings.hh"
18 #include "otk/display.hh"
24 const long OBFrame::event_mask;
26 OBFrame::OBFrame(OBClient *client, otk::Style *style)
27 : otk::OtkWidget(Openbox::instance, style),
30 _screen(otk::OBDisplay::screenInfo(client->screen())),
31 _plate(this, OBWidget::Type_Plate),
32 _titlebar(this, OBWidget::Type_Titlebar),
33 _button_close(&_titlebar, OBWidget::Type_CloseButton),
34 _button_iconify(&_titlebar, OBWidget::Type_IconifyButton),
35 _button_max(&_titlebar, OBWidget::Type_MaximizeButton),
36 _button_stick(&_titlebar, OBWidget::Type_StickyButton),
37 _label(&_titlebar, OBWidget::Type_Label),
38 _handle(this, OBWidget::Type_Handle),
39 _grip_left(&_handle, OBWidget::Type_LeftGrip),
40 _grip_right(&_handle, OBWidget::Type_RightGrip),
41 _decorations(client->decorations())
46 XSelectInput(otk::OBDisplay::display, window(), OBFrame::event_mask);
48 _grip_left.setCursor(Openbox::instance->cursors().ll_angle);
49 _grip_right.setCursor(Openbox::instance->cursors().lr_angle);
51 _label.setText(_client->title());
56 otk::OtkWidget::unfocus(); // stuff starts out appearing focused in otk
58 _plate.show(); // the other stuff is shown based on decor settings
73 void OBFrame::grabButtons(bool grab)
75 _plate.grabButtons(grab);
77 // grab any requested buttons on the entire frame
78 std::vector<std::string> grabs;
79 if (python_get_stringlist("client_buttons", &grabs)) {
80 std::vector<std::string>::iterator grab_it, grab_end = grabs.end();
81 for (grab_it = grabs.begin(); grab_it != grab_end; ++grab_it) {
83 if (!Openbox::instance->bindings()->translate(*grab_it, b, false))
85 printf("grabbing %d %d\n", b.key, b.modifiers);
87 otk::OBDisplay::grabButton(b.key, b.modifiers, _window, true,
88 ButtonPressMask | ButtonMotionMask |
89 ButtonReleaseMask, GrabModeAsync,
90 GrabModeAsync, _window, None, false);
92 otk::OBDisplay::ungrabButton(b.key, b.modifiers, _window);
99 void OBFrame::setTitle(const std::string &text)
101 _label.setText(text);
106 void OBFrame::setStyle(otk::Style *style)
110 otk::OtkWidget::setStyle(style);
112 // if a style was previously set, then 'replace' is true, cause we're
114 bool replace = (_style);
117 // XXX: do shit here whatever
122 setBorderColor(_style->getBorderColor());
124 // if !replace, then adjust() will get called after the client is grabbed!
126 // size/position everything
133 void OBFrame::focus()
135 otk::OtkWidget::focus();
141 void OBFrame::unfocus()
143 otk::OtkWidget::unfocus();
148 void OBFrame::adjust()
150 // the party all happens in adjustSize
154 void OBFrame::adjustSize()
156 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
157 _decorations = _client->decorations();
158 _decorations = 0xffffffff;
160 int width; // the width of the client and its border
161 int bwidth; // width to make borders
162 int cbwidth; // width of the inner client border
163 const int bevel = _style->getBevelWidth();
165 if (_decorations & OBClient::Decor_Border) {
166 bwidth = _style->getBorderWidth();
167 cbwidth = _style->getFrameWidth();
169 bwidth = cbwidth = 0;
170 _innersize.left = _innersize.top = _innersize.bottom = _innersize.right =
172 width = _client->area().width() + cbwidth * 2;
174 _plate.setBorderWidth(cbwidth);
176 setBorderWidth(bwidth);
177 _titlebar.setBorderWidth(bwidth);
178 _grip_left.setBorderWidth(bwidth);
179 _grip_right.setBorderWidth(bwidth);
180 _handle.setBorderWidth(bwidth);
182 if (_decorations & OBClient::Decor_Titlebar) {
183 // set the titlebar size
184 _titlebar.setGeometry(-bwidth,
187 _style->getFont()->height() + bevel * 2);
188 _innersize.top += _titlebar.height() + bwidth;
190 // set the label size
191 _label.setGeometry(0, bevel, width, _style->getFont()->height());
192 // set the buttons sizes
193 if (_decorations & OBClient::Decor_Iconify)
194 _button_iconify.setGeometry(0, bevel + 1,
196 _label.height() - 2);
197 if (_decorations & OBClient::Decor_Maximize)
198 _button_max.setGeometry(0, bevel + 1,
200 _label.height() - 2);
201 if (_decorations & OBClient::Decor_Sticky)
202 _button_stick.setGeometry(0, bevel + 1,
204 _label.height() - 2);
205 if (_decorations & OBClient::Decor_Close)
206 _button_close.setGeometry(0, bevel + 1,
208 _label.height() - 2);
210 // separation between titlebar elements
211 const int sep = bevel + 1;
213 std::string layout = "SLIMC"; // XXX: get this from somewhere
214 // XXX: it is REQUIRED that by this point, the string only has one of each
215 // possible letter, all of the letters are valid, and L exists somewhere in
218 // the size of the label. this ASSUMES the layout has only buttons other
219 // that the ONE LABEL!!
220 // adds an extra sep so that there's a space on either side of the
221 // titlebar.. note: x = sep, below.
222 int lwidth = width - sep * 2 -
223 (_button_iconify.width() + sep) * (layout.size() - 1);
224 // quick sanity check for really small windows. if this is needed, its
225 // obviously not going to be displayed right...
226 // XXX: maybe we should make this look better somehow? constraints?
227 if (lwidth <= 0) lwidth = 1;
228 _label.setWidth(lwidth);
231 for (int i = 0, len = layout.size(); i < len; ++i) {
234 _button_iconify.move(x, _button_iconify.rect().y());
235 x += _button_iconify.width();
238 _label.move(x, _label.rect().y());
242 _button_max.move(x, _button_max.rect().y());
243 x += _button_max.width();
246 _button_stick.move(x, _button_stick.rect().y());
247 x += _button_stick.width();
250 _button_close.move(x, _button_close.rect().y());
251 x += _button_close.width();
254 assert(false); // the layout string is invalid!
260 if (_decorations & OBClient::Decor_Handle) {
261 _handle.setGeometry(-bwidth,
262 _innersize.top + _client->area().height() + cbwidth,
263 width, _style->getHandleWidth());
264 _grip_left.setGeometry(-bwidth,
266 // XXX: get a Point class in otk and use that for
267 // the 'buttons size' since theyre all the same
268 _button_iconify.width() * 2,
270 _grip_right.setGeometry(((_handle.rect().right() + 1) -
271 _button_iconify.width() * 2),
273 // XXX: get a Point class in otk and use that for
274 // the 'buttons size' since theyre all the same
275 _button_iconify.width() * 2,
277 _innersize.bottom += _handle.height() + bwidth;
281 // position/size all the windows
283 resize(_innersize.left + _innersize.right + _client->area().width(),
284 _innersize.top + _innersize.bottom + _client->area().height());
286 _plate.setGeometry(_innersize.left - cbwidth, _innersize.top - cbwidth,
287 _client->area().width(), _client->area().height());
289 // map/unmap all the windows
290 if (_decorations & OBClient::Decor_Titlebar) {
292 if (_decorations & OBClient::Decor_Iconify)
293 _button_iconify.show();
295 _button_iconify.hide();
296 if (_decorations & OBClient::Decor_Maximize)
300 if (_decorations & OBClient::Decor_Sticky)
301 _button_stick.show();
303 _button_stick.hide();
304 if (_decorations & OBClient::Decor_Close)
305 _button_close.show();
307 _button_close.hide();
310 _titlebar.hide(true);
313 if (_decorations & OBClient::Decor_Handle)
318 _size.left = _innersize.left + bwidth;
319 _size.right = _innersize.right + bwidth;
320 _size.top = _innersize.top + bwidth;
321 _size.bottom = _innersize.bottom + bwidth;
329 void OBFrame::adjustPosition()
337 void OBFrame::adjustShape()
340 int bwidth = (_decorations & OBClient::Decor_Border) ?
341 _style->getBorderWidth() : 0;
343 if (!_client->shaped()) {
344 // clear the shape on the frame window
345 XShapeCombineMask(otk::OBDisplay::display, window(), ShapeBounding,
350 // make the frame's shape match the clients
351 XShapeCombineShape(otk::OBDisplay::display, window(), ShapeBounding,
354 _client->window(), ShapeBounding, ShapeSet);
359 if (_decorations & OBClient::Decor_Titlebar) {
360 xrect[0].x = _titlebar.rect().x();
361 xrect[0].y = _titlebar.rect().y();
362 xrect[0].width = _titlebar.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
363 xrect[0].height = _titlebar.height() + bwidth * 2;
367 if (_decorations & OBClient::Decor_Handle) {
368 xrect[1].x = _handle.rect().x();
369 xrect[1].y = _handle.rect().y();
370 xrect[1].width = _handle.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
371 xrect[1].height = _handle.height() + bwidth * 2;
375 XShapeCombineRectangles(otk::OBDisplay::display, window(),
376 ShapeBounding, 0, 0, xrect, num,
377 ShapeUnion, Unsorted);
383 void OBFrame::grabClient()
386 // reparent the client to the frame
387 XReparentWindow(otk::OBDisplay::display, _client->window(),
388 _plate.window(), 0, 0);
389 _client->ignore_unmaps++;
391 // select the event mask on the client's parent (to receive config req's)
392 XSelectInput(otk::OBDisplay::display, _plate.window(),
393 SubstructureRedirectMask);
395 // map the client so it maps when the frame does
396 XMapWindow(otk::OBDisplay::display, _client->window());
403 void OBFrame::releaseClient(bool remap)
405 // check if the app has already reparented its window to the root window
407 if (XCheckTypedWindowEvent(otk::OBDisplay::display, _client->window(),
408 ReparentNotify, &ev)) {
409 remap = true; // XXX: why do we remap the window if they already
410 // reparented to root?
412 // according to the ICCCM - if the client doesn't reparent to
413 // root, then we have to do it for them
414 XReparentWindow(otk::OBDisplay::display, _client->window(),
415 _screen->rootWindow(),
416 _client->area().x(), _client->area().y());
419 // if we want to remap the window, do so now
421 XMapWindow(otk::OBDisplay::display, _client->window());
425 void OBFrame::clientGravity(int &x, int &y)
427 x = _client->area().x();
428 y = _client->area().y();
431 switch (_client->gravity()) {
433 case NorthWestGravity:
434 case SouthWestGravity:
441 x -= (_size.left + _size.right) / 2;
444 case NorthEastGravity:
445 case SouthEastGravity:
447 x -= _size.left + _size.right;
457 switch (_client->gravity()) {
459 case NorthWestGravity:
460 case NorthEastGravity:
467 y -= (_size.top + _size.bottom) / 2;
470 case SouthWestGravity:
471 case SouthEastGravity:
473 y -= _size.top + _size.bottom;
484 void OBFrame::frameGravity(int &x, int &y)
490 switch (_client->gravity()) {
492 case NorthWestGravity:
494 case SouthWestGravity:
499 x += (_size.left + _size.right) / 2;
501 case NorthEastGravity:
503 case SouthEastGravity:
504 x += _size.left + _size.right;
513 switch (_client->gravity()) {
515 case NorthWestGravity:
517 case SouthWestGravity:
522 y += (_size.top + _size.bottom) / 2;
524 case NorthEastGravity:
526 case SouthEastGravity:
527 y += _size.top + _size.bottom;