]>
Dogcows Code - chaz/openbox/blob - src/frame.cc
ee770b25375b54eba9d1ebb25629424dfd4ff1f6
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
70 void OBFrame::setTitle(const std::string
&text
)
77 void OBFrame::setStyle(otk::Style
*style
)
81 otk::OtkWidget::setStyle(style
);
83 // if a style was previously set, then 'replace' is true, cause we're
85 bool replace
= (_style
);
88 // XXX: do shit here whatever
93 setBorderColor(_style
->getBorderColor());
95 // if !replace, then adjust() will get called after the client is grabbed!
97 // size/position everything
104 void OBFrame::focus()
106 otk::OtkWidget::focus();
112 void OBFrame::unfocus()
114 otk::OtkWidget::unfocus();
119 void OBFrame::adjust()
121 // the party all happens in adjustSize
125 void OBFrame::adjustSize()
127 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
128 _decorations
= _client
->decorations();
130 // true/false for whether to show each element of the titlebar
131 bool tit_i
= false, tit_m
= false, tit_s
= false, tit_c
= false;
132 int width
; // the width of the client and its border
133 int bwidth
; // width to make borders
134 int cbwidth
; // width of the inner client border
135 const int bevel
= _style
->getBevelWidth();
137 if (_decorations
& OBClient::Decor_Border
) {
138 bwidth
= _style
->getBorderWidth();
139 cbwidth
= _style
->getFrameWidth();
141 bwidth
= cbwidth
= 0;
142 _innersize
.left
= _innersize
.top
= _innersize
.bottom
= _innersize
.right
=
144 width
= _client
->area().width() + cbwidth
* 2;
146 _plate
.setBorderWidth(cbwidth
);
148 setBorderWidth(bwidth
);
149 _titlebar
.setBorderWidth(bwidth
);
150 _grip_left
.setBorderWidth(bwidth
);
151 _grip_right
.setBorderWidth(bwidth
);
152 _handle
.setBorderWidth(bwidth
);
154 if (_decorations
& OBClient::Decor_Titlebar
) {
155 // set the titlebar size
156 _titlebar
.setGeometry(-bwidth
,
159 _style
->getFont()->height() + bevel
* 2);
160 _innersize
.top
+= _titlebar
.height() + bwidth
;
162 // set the label size
163 _label
.setGeometry(0, bevel
, width
, _style
->getFont()->height());
164 // set the buttons sizes
165 if (_decorations
& OBClient::Decor_Iconify
)
166 _button_iconify
.setGeometry(0, bevel
+ 1,
168 _label
.height() - 2);
169 if (_decorations
& OBClient::Decor_Maximize
)
170 _button_max
.setGeometry(0, bevel
+ 1,
172 _label
.height() - 2);
173 if (_decorations
& OBClient::Decor_Sticky
)
174 _button_stick
.setGeometry(0, bevel
+ 1,
176 _label
.height() - 2);
177 if (_decorations
& OBClient::Decor_Close
)
178 _button_close
.setGeometry(0, bevel
+ 1,
180 _label
.height() - 2);
182 // separation between titlebar elements
183 const int sep
= bevel
+ 1;
186 if (!python_get_string("titlebar_layout", &layout
))
189 // this code ensures that the string only has one of each possible
190 // letter, all of the letters are valid, and L exists somewhere in the
194 for (std::string::size_type i
= 0; i
< layout
.size(); ++i
) {
198 if (!tit_i
&& (_decorations
& OBClient::Decor_Iconify
)) {
210 if (!tit_m
&& (_decorations
& OBClient::Decor_Maximize
)) {
216 if (!tit_s
&& (_decorations
& OBClient::Decor_Sticky
)) {
222 if (!tit_c
&& (_decorations
& OBClient::Decor_Close
)) {
227 // if we get here then we don't want the letter, kill it
228 layout
.erase(i
--, 1);
233 // the size of the label. this ASSUMES the layout has only buttons other
234 // that the ONE LABEL!!
235 // adds an extra sep so that there's a space on either side of the
236 // titlebar.. note: x = sep, below.
237 int lwidth
= width
- sep
* 2 -
238 (_button_iconify
.width() + sep
) * (layout
.size() - 1);
239 // quick sanity check for really small windows. if this is needed, its
240 // obviously not going to be displayed right...
241 // XXX: maybe we should make this look better somehow? constraints?
242 if (lwidth
<= 0) lwidth
= 1;
243 _label
.setWidth(lwidth
);
246 for (int i
= 0, len
= layout
.size(); i
< len
; ++i
) {
249 _button_iconify
.move(x
, _button_iconify
.rect().y());
250 x
+= _button_iconify
.width();
253 _label
.move(x
, _label
.rect().y());
257 _button_max
.move(x
, _button_max
.rect().y());
258 x
+= _button_max
.width();
261 _button_stick
.move(x
, _button_stick
.rect().y());
262 x
+= _button_stick
.width();
265 _button_close
.move(x
, _button_close
.rect().y());
266 x
+= _button_close
.width();
269 assert(false); // the layout string is invalid!
275 if (_decorations
& OBClient::Decor_Handle
) {
276 _handle
.setGeometry(-bwidth
,
277 _innersize
.top
+ _client
->area().height() + cbwidth
,
278 width
, _style
->getHandleWidth());
279 _grip_left
.setGeometry(-bwidth
,
281 // XXX: get a Point class in otk and use that for
282 // the 'buttons size' since theyre all the same
283 _button_iconify
.width() * 2,
285 _grip_right
.setGeometry(((_handle
.rect().right() + 1) -
286 _button_iconify
.width() * 2),
288 // XXX: get a Point class in otk and use that for
289 // the 'buttons size' since theyre all the same
290 _button_iconify
.width() * 2,
292 _innersize
.bottom
+= _handle
.height() + bwidth
;
296 // position/size all the windows
298 if (_client
->shaded())
299 resize(_innersize
.left
+ _innersize
.right
+ _client
->area().width(),
302 resize(_innersize
.left
+ _innersize
.right
+ _client
->area().width(),
303 _innersize
.top
+ _innersize
.bottom
+ _client
->area().height());
305 _plate
.setGeometry(_innersize
.left
- cbwidth
, _innersize
.top
- cbwidth
,
306 _client
->area().width(), _client
->area().height());
308 // map/unmap all the windows
309 if (_decorations
& OBClient::Decor_Titlebar
) {
312 _button_iconify
.show();
314 _button_iconify
.hide();
320 _button_stick
.show();
322 _button_stick
.hide();
324 _button_close
.show();
326 _button_close
.hide();
329 _titlebar
.hide(true);
332 if (_decorations
& OBClient::Decor_Handle
)
337 _size
.left
= _innersize
.left
+ bwidth
;
338 _size
.right
= _innersize
.right
+ bwidth
;
339 _size
.top
= _innersize
.top
+ bwidth
;
340 _size
.bottom
= _innersize
.bottom
+ bwidth
;
348 void OBFrame::adjustPosition()
356 void OBFrame::adjustShape()
359 int bwidth
= (_decorations
& OBClient::Decor_Border
) ?
360 _style
->getBorderWidth() : 0;
362 if (!_client
->shaped()) {
363 // clear the shape on the frame window
364 XShapeCombineMask(otk::OBDisplay::display
, window(), ShapeBounding
,
369 // make the frame's shape match the clients
370 XShapeCombineShape(otk::OBDisplay::display
, window(), ShapeBounding
,
373 _client
->window(), ShapeBounding
, ShapeSet
);
378 if (_decorations
& OBClient::Decor_Titlebar
) {
379 xrect
[0].x
= _titlebar
.rect().x();
380 xrect
[0].y
= _titlebar
.rect().y();
381 xrect
[0].width
= _titlebar
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
382 xrect
[0].height
= _titlebar
.height() + bwidth
* 2;
386 if (_decorations
& OBClient::Decor_Handle
) {
387 xrect
[1].x
= _handle
.rect().x();
388 xrect
[1].y
= _handle
.rect().y();
389 xrect
[1].width
= _handle
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
390 xrect
[1].height
= _handle
.height() + bwidth
* 2;
394 XShapeCombineRectangles(otk::OBDisplay::display
, window(),
395 ShapeBounding
, 0, 0, xrect
, num
,
396 ShapeUnion
, Unsorted
);
402 void OBFrame::grabClient()
405 // reparent the client to the frame
406 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
407 _plate
.window(), 0, 0);
408 _client
->ignore_unmaps
++;
410 // select the event mask on the client's parent (to receive config req's)
411 XSelectInput(otk::OBDisplay::display
, _plate
.window(),
412 SubstructureRedirectMask
);
414 // map the client so it maps when the frame does
415 XMapWindow(otk::OBDisplay::display
, _client
->window());
422 void OBFrame::releaseClient(bool remap
)
424 // check if the app has already reparented its window to the root window
426 if (XCheckTypedWindowEvent(otk::OBDisplay::display
, _client
->window(),
427 ReparentNotify
, &ev
)) {
428 remap
= true; // XXX: why do we remap the window if they already
429 // reparented to root?
431 // according to the ICCCM - if the client doesn't reparent to
432 // root, then we have to do it for them
433 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
434 _screen
->rootWindow(),
435 _client
->area().x(), _client
->area().y());
438 // if we want to remap the window, do so now
440 XMapWindow(otk::OBDisplay::display
, _client
->window());
444 void OBFrame::clientGravity(int &x
, int &y
)
446 x
= _client
->area().x();
447 y
= _client
->area().y();
450 switch (_client
->gravity()) {
452 case NorthWestGravity
:
453 case SouthWestGravity
:
460 x
-= (_size
.left
+ _size
.right
) / 2;
463 case NorthEastGravity
:
464 case SouthEastGravity
:
466 x
-= _size
.left
+ _size
.right
;
476 switch (_client
->gravity()) {
478 case NorthWestGravity
:
479 case NorthEastGravity
:
486 y
-= (_size
.top
+ _size
.bottom
) / 2;
489 case SouthWestGravity
:
490 case SouthEastGravity
:
492 y
-= _size
.top
+ _size
.bottom
;
503 void OBFrame::frameGravity(int &x
, int &y
)
509 switch (_client
->gravity()) {
511 case NorthWestGravity
:
513 case SouthWestGravity
:
518 x
+= (_size
.left
+ _size
.right
) / 2;
520 case NorthEastGravity
:
522 case SouthEastGravity
:
523 x
+= _size
.left
+ _size
.right
;
532 switch (_client
->gravity()) {
534 case NorthWestGravity
:
536 case SouthWestGravity
:
541 y
+= (_size
.top
+ _size
.bottom
) / 2;
543 case NorthEastGravity
:
545 case SouthEastGravity
:
546 y
+= _size
.top
+ _size
.bottom
;
This page took 0.058839 seconds and 4 git commands to generate.