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),
27 _screen(otk::OBDisplay::screenInfo(client->screen())),
28 _plate(this, OBWidget::Type_Plate),
29 _titlebar(this, OBWidget::Type_Titlebar),
30 _button_close(&_titlebar),
31 _button_iconify(&_titlebar),
32 _button_max(&_titlebar),
33 _button_stick(&_titlebar),
35 _handle(this, OBWidget::Type_Handle),
37 _grip_right(&_handle),
38 _decorations(client->decorations())
43 XSelectInput(otk::OBDisplay::display, getWindow(), OBFrame::event_mask);
46 _titlebar.unmanaged();
47 _button_close.unmanaged();
48 _button_iconify.unmanaged();
49 _button_max.unmanaged();
50 _button_stick.unmanaged();
53 _grip_left.unmanaged();
54 _grip_right.unmanaged();
57 _grip_left.setCursor(Openbox::instance->cursors().ll_angle);
58 _grip_right.setCursor(Openbox::instance->cursors().lr_angle);
60 _button_close.setText("X");
61 _button_iconify.setText("I");
62 _button_max.setText("M");
63 _button_stick.setText("S");
64 _label.setText(_client->title());
69 //XXX: uncomment me unfocus(); // stuff starts out focused in otk
71 _plate.show(); // the other stuff is shown based on decor settings
83 void OBFrame::setStyle(otk::Style *style)
87 otk::OtkWidget::setStyle(style);
88 // set the grips' textures
89 _grip_left.setTexture(style->getGripFocus());
90 _grip_left.setUnfocusTexture(style->getGripUnfocus());
91 _grip_left.setPressedFocusTexture(style->getGripFocus());
92 _grip_left.setPressedUnfocusTexture(style->getGripUnfocus());
93 _grip_right.setTexture(style->getGripFocus());
94 _grip_right.setUnfocusTexture(style->getGripUnfocus());
95 _grip_right.setPressedFocusTexture(style->getGripFocus());
96 _grip_right.setPressedUnfocusTexture(style->getGripUnfocus());
98 // if a style was previously set, then 'replace' is true, cause we're
100 bool replace = (_style);
103 // XXX: do shit here whatever
108 // XXX: change when focus changes!
109 XSetWindowBorder(otk::OBDisplay::display, getWindow(),
110 _style->getBorderColor()->pixel());
111 XSetWindowBorder(otk::OBDisplay::display, _grip_left.getWindow(),
112 _style->getBorderColor()->pixel());
113 XSetWindowBorder(otk::OBDisplay::display, _grip_right.getWindow(),
114 _style->getBorderColor()->pixel());
116 // if !replace, then adjust() will get called after the client is grabbed!
118 // size/position everything
125 void OBFrame::adjustSize()
127 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
128 _decorations = _client->decorations();
129 _decorations = 0xffffffff;
131 int width; // the width of the client and its border
132 int bwidth; // width to make borders
133 int cbwidth; // width of the inner client border
135 if (_decorations & OBClient::Decor_Border) {
136 bwidth = _style->getBorderWidth();
137 cbwidth = _style->getFrameWidth();
139 bwidth = cbwidth = 0;
140 _innersize.left = _innersize.top = _innersize.bottom = _innersize.right =
142 width = _client->area().width() + cbwidth * 2;
144 _plate.setBorderWidth(cbwidth);
146 setBorderWidth(bwidth);
147 _titlebar.setBorderWidth(bwidth);
148 _grip_left.setBorderWidth(bwidth);
149 _grip_right.setBorderWidth(bwidth);
150 _handle.setBorderWidth(bwidth);
152 if (_decorations & OBClient::Decor_Titlebar) {
153 // set the titlebar size
154 _titlebar.setGeometry(-bwidth,
157 (_style->getFont().height() +
158 _style->getBevelWidth() * 2));
159 _innersize.top += _titlebar.height() + bwidth;
161 // set the label size
162 _label.setGeometry(0, _style->getBevelWidth(),
163 width, _style->getFont().height());
164 // set the buttons sizes
165 if (_decorations & OBClient::Decor_Iconify)
166 _button_iconify.setGeometry(0, _style->getBevelWidth() + 1,
168 _label.height() - 2);
169 if (_decorations & OBClient::Decor_Maximize)
170 _button_max.setGeometry(0, _style->getBevelWidth() + 1,
172 _label.height() - 2);
173 if (_decorations & OBClient::Decor_Sticky)
174 _button_stick.setGeometry(0, _style->getBevelWidth() + 1,
176 _label.height() - 2);
177 if (_decorations & OBClient::Decor_Close)
178 _button_close.setGeometry(0, _style->getBevelWidth() + 1,
180 _label.height() - 2);
182 // separation between titlebar elements
183 const int sep = _style->getBevelWidth() + 1;
185 std::string layout = "SLIMC"; // XXX: get this from somewhere
186 // XXX: it is REQUIRED that by this point, the string only has one of each
187 // possible letter, all of the letters are valid, and L exists somewhere in
190 // the size of the label. this ASSUMES the layout has only buttons other
191 // that the ONE LABEL!!
192 // adds an extra sep so that there's a space on either side of the
193 // titlebar.. note: x = sep, below.
194 int lwidth = width - sep * 2 -
195 (_button_iconify.width() + sep) * (layout.size() - 1);
196 // quick sanity check for really small windows. if this is needed, its
197 // obviously not going to be displayed right...
198 // XXX: maybe we should make this look better somehow? constraints?
199 if (lwidth <= 0) lwidth = 1;
200 _label.setWidth(lwidth);
203 for (int i = 0, len = layout.size(); i < len; ++i) {
206 _button_iconify.move(x, _button_iconify.getRect().y());
207 x += _button_iconify.width();
210 _label.move(x, _label.getRect().y());
214 _button_max.move(x, _button_max.getRect().y());
215 x += _button_max.width();
218 _button_stick.move(x, _button_stick.getRect().y());
219 x += _button_stick.width();
222 _button_close.move(x, _button_close.getRect().y());
223 x += _button_close.width();
226 assert(false); // the layout string is invalid!
232 if (_decorations & OBClient::Decor_Handle) {
233 _handle.setGeometry(-bwidth,
234 _innersize.top + _client->area().height() + cbwidth,
235 width, _style->getHandleWidth());
236 _grip_left.setGeometry(-bwidth,
238 // XXX: get a Point class in otk and use that for
239 // the 'buttons size' since theyre all the same
240 _button_iconify.width() * 2,
242 _grip_right.setGeometry(((_handle.getRect().right() + 1) -
243 _button_iconify.width() * 2),
245 // XXX: get a Point class in otk and use that for
246 // the 'buttons size' since theyre all the same
247 _button_iconify.width() * 2,
249 _innersize.bottom += _handle.height() + bwidth;
253 // position/size all the windows
255 resize(_innersize.left + _innersize.right + _client->area().width(),
256 _innersize.top + _innersize.bottom + _client->area().height());
258 _plate.setGeometry(_innersize.left - cbwidth, _innersize.top - cbwidth,
259 _client->area().width(), _client->area().height());
261 // map/unmap all the windows
262 if (_decorations & OBClient::Decor_Titlebar) {
264 if (_decorations & OBClient::Decor_Iconify)
265 _button_iconify.show();
267 _button_iconify.hide();
268 if (_decorations & OBClient::Decor_Maximize)
272 if (_decorations & OBClient::Decor_Sticky)
273 _button_stick.show();
275 _button_stick.hide();
276 if (_decorations & OBClient::Decor_Close)
277 _button_close.show();
279 _button_close.hide();
282 _titlebar.hide(true);
285 if (_decorations & OBClient::Decor_Handle)
290 // XXX: more is gunna have to happen here
292 _size.left = _innersize.left + bwidth;
293 _size.right = _innersize.right + bwidth;
294 _size.top = _innersize.top + bwidth;
295 _size.bottom = _innersize.bottom + bwidth;
303 void OBFrame::adjustPosition()
311 void OBFrame::adjustShape()
314 int bwidth = (_decorations & OBClient::Decor_Border) ?
315 _style->getBorderWidth() : 0;
317 if (!_client->shaped()) {
318 // clear the shape on the frame window
319 XShapeCombineMask(otk::OBDisplay::display, getWindow(), ShapeBounding,
324 // make the frame's shape match the clients
325 XShapeCombineShape(otk::OBDisplay::display, getWindow(), ShapeBounding,
328 _client->window(), ShapeBounding, ShapeSet);
333 if (_decorations & OBClient::Decor_Titlebar) {
334 xrect[0].x = _titlebar.getRect().x();
335 xrect[0].y = _titlebar.getRect().y();
336 xrect[0].width = _titlebar.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
337 xrect[0].height = _titlebar.height() + bwidth * 2;
341 if (_decorations & OBClient::Decor_Handle) {
342 xrect[1].x = _handle.getRect().x();
343 xrect[1].y = _handle.getRect().y();
344 xrect[1].width = _handle.width() + bwidth * 2; // XXX: this is useless once the widget handles borders!
345 xrect[1].height = _handle.height() + bwidth * 2;
349 XShapeCombineRectangles(otk::OBDisplay::display, getWindow(),
350 ShapeBounding, 0, 0, xrect, num,
351 ShapeUnion, Unsorted);
357 void OBFrame::grabClient()
360 // reparent the client to the frame
361 XReparentWindow(otk::OBDisplay::display, _client->window(),
362 _plate.getWindow(), 0, 0);
363 _client->ignore_unmaps++;
365 // select the event mask on the client's parent (to receive config req's)
366 XSelectInput(otk::OBDisplay::display, _plate.getWindow(),
367 SubstructureRedirectMask);
369 // map the client so it maps when the frame does
370 XMapWindow(otk::OBDisplay::display, _client->window());
377 void OBFrame::releaseClient(bool remap)
379 // check if the app has already reparented its window to the root window
381 if (XCheckTypedWindowEvent(otk::OBDisplay::display, _client->window(),
382 ReparentNotify, &ev)) {
383 remap = true; // XXX: why do we remap the window if they already
384 // reparented to root?
386 // according to the ICCCM - if the client doesn't reparent to
387 // root, then we have to do it for them
388 XReparentWindow(otk::OBDisplay::display, _client->window(),
389 _screen->getRootWindow(),
390 _client->area().x(), _client->area().y());
393 // if we want to remap the window, do so now
395 XMapWindow(otk::OBDisplay::display, _client->window());
399 void OBFrame::clientGravity(int &x, int &y)
401 x = _client->area().x();
402 y = _client->area().y();
405 switch (_client->gravity()) {
407 case NorthWestGravity:
408 case SouthWestGravity:
415 x -= (_size.left + _size.right) / 2;
418 case NorthEastGravity:
419 case SouthEastGravity:
421 x -= _size.left + _size.right;
431 switch (_client->gravity()) {
433 case NorthWestGravity:
434 case NorthEastGravity:
441 y -= (_size.top + _size.bottom) / 2;
444 case SouthWestGravity:
445 case SouthEastGravity:
447 y -= _size.top + _size.bottom;
458 void OBFrame::frameGravity(int &x, int &y)
464 switch (_client->gravity()) {
466 case NorthWestGravity:
468 case SouthWestGravity:
473 x += (_size.left + _size.right) / 2;
475 case NorthEastGravity:
477 case SouthEastGravity:
478 x += _size.left + _size.right;
487 switch (_client->gravity()) {
489 case NorthWestGravity:
491 case SouthWestGravity:
496 y += (_size.top + _size.bottom) / 2;
498 case NorthEastGravity:
500 case SouthEastGravity:
501 y += _size.top + _size.bottom;