]>
Dogcows Code - chaz/openbox/blob - src/frame.cc
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();
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
134 const int bevel
= _style
->getBevelWidth();
136 if (_decorations
& OBClient::Decor_Border
) {
137 bwidth
= _style
->getBorderWidth();
138 cbwidth
= _style
->getFrameWidth();
140 bwidth
= cbwidth
= 0;
141 _innersize
.left
= _innersize
.top
= _innersize
.bottom
= _innersize
.right
=
143 width
= _client
->area().width() + cbwidth
* 2;
145 _plate
.setBorderWidth(cbwidth
);
147 setBorderWidth(bwidth
);
148 _titlebar
.setBorderWidth(bwidth
);
149 _grip_left
.setBorderWidth(bwidth
);
150 _grip_right
.setBorderWidth(bwidth
);
151 _handle
.setBorderWidth(bwidth
);
153 if (_decorations
& OBClient::Decor_Titlebar
) {
154 // set the titlebar size
155 _titlebar
.setGeometry(-bwidth
,
158 _style
->getFont()->height() + bevel
* 2);
159 _innersize
.top
+= _titlebar
.height() + bwidth
;
161 // set the label size
162 _label
.setGeometry(0, bevel
, width
, _style
->getFont()->height());
163 // set the buttons sizes
164 if (_decorations
& OBClient::Decor_Iconify
)
165 _button_iconify
.setGeometry(0, bevel
+ 1,
167 _label
.height() - 2);
168 if (_decorations
& OBClient::Decor_Maximize
)
169 _button_max
.setGeometry(0, bevel
+ 1,
171 _label
.height() - 2);
172 if (_decorations
& OBClient::Decor_Sticky
)
173 _button_stick
.setGeometry(0, bevel
+ 1,
175 _label
.height() - 2);
176 if (_decorations
& OBClient::Decor_Close
)
177 _button_close
.setGeometry(0, bevel
+ 1,
179 _label
.height() - 2);
181 // separation between titlebar elements
182 const int sep
= bevel
+ 1;
184 std::string layout
= "SLIMC"; // XXX: get this from somewhere
185 // XXX: it is REQUIRED that by this point, the string only has one of each
186 // possible letter, all of the letters are valid, and L exists somewhere in
189 // the size of the label. this ASSUMES the layout has only buttons other
190 // that the ONE LABEL!!
191 // adds an extra sep so that there's a space on either side of the
192 // titlebar.. note: x = sep, below.
193 int lwidth
= width
- sep
* 2 -
194 (_button_iconify
.width() + sep
) * (layout
.size() - 1);
195 // quick sanity check for really small windows. if this is needed, its
196 // obviously not going to be displayed right...
197 // XXX: maybe we should make this look better somehow? constraints?
198 if (lwidth
<= 0) lwidth
= 1;
199 _label
.setWidth(lwidth
);
202 for (int i
= 0, len
= layout
.size(); i
< len
; ++i
) {
205 _button_iconify
.move(x
, _button_iconify
.rect().y());
206 x
+= _button_iconify
.width();
209 _label
.move(x
, _label
.rect().y());
213 _button_max
.move(x
, _button_max
.rect().y());
214 x
+= _button_max
.width();
217 _button_stick
.move(x
, _button_stick
.rect().y());
218 x
+= _button_stick
.width();
221 _button_close
.move(x
, _button_close
.rect().y());
222 x
+= _button_close
.width();
225 assert(false); // the layout string is invalid!
231 if (_decorations
& OBClient::Decor_Handle
) {
232 _handle
.setGeometry(-bwidth
,
233 _innersize
.top
+ _client
->area().height() + cbwidth
,
234 width
, _style
->getHandleWidth());
235 _grip_left
.setGeometry(-bwidth
,
237 // XXX: get a Point class in otk and use that for
238 // the 'buttons size' since theyre all the same
239 _button_iconify
.width() * 2,
241 _grip_right
.setGeometry(((_handle
.rect().right() + 1) -
242 _button_iconify
.width() * 2),
244 // XXX: get a Point class in otk and use that for
245 // the 'buttons size' since theyre all the same
246 _button_iconify
.width() * 2,
248 _innersize
.bottom
+= _handle
.height() + bwidth
;
252 // position/size all the windows
254 resize(_innersize
.left
+ _innersize
.right
+ _client
->area().width(),
255 _innersize
.top
+ _innersize
.bottom
+ _client
->area().height());
257 _plate
.setGeometry(_innersize
.left
- cbwidth
, _innersize
.top
- cbwidth
,
258 _client
->area().width(), _client
->area().height());
260 // map/unmap all the windows
261 if (_decorations
& OBClient::Decor_Titlebar
) {
263 if (_decorations
& OBClient::Decor_Iconify
)
264 _button_iconify
.show();
266 _button_iconify
.hide();
267 if (_decorations
& OBClient::Decor_Maximize
)
271 if (_decorations
& OBClient::Decor_Sticky
)
272 _button_stick
.show();
274 _button_stick
.hide();
275 if (_decorations
& OBClient::Decor_Close
)
276 _button_close
.show();
278 _button_close
.hide();
281 _titlebar
.hide(true);
284 if (_decorations
& OBClient::Decor_Handle
)
289 _size
.left
= _innersize
.left
+ bwidth
;
290 _size
.right
= _innersize
.right
+ bwidth
;
291 _size
.top
= _innersize
.top
+ bwidth
;
292 _size
.bottom
= _innersize
.bottom
+ bwidth
;
300 void OBFrame::adjustPosition()
308 void OBFrame::adjustShape()
311 int bwidth
= (_decorations
& OBClient::Decor_Border
) ?
312 _style
->getBorderWidth() : 0;
314 if (!_client
->shaped()) {
315 // clear the shape on the frame window
316 XShapeCombineMask(otk::OBDisplay::display
, window(), ShapeBounding
,
321 // make the frame's shape match the clients
322 XShapeCombineShape(otk::OBDisplay::display
, window(), ShapeBounding
,
325 _client
->window(), ShapeBounding
, ShapeSet
);
330 if (_decorations
& OBClient::Decor_Titlebar
) {
331 xrect
[0].x
= _titlebar
.rect().x();
332 xrect
[0].y
= _titlebar
.rect().y();
333 xrect
[0].width
= _titlebar
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
334 xrect
[0].height
= _titlebar
.height() + bwidth
* 2;
338 if (_decorations
& OBClient::Decor_Handle
) {
339 xrect
[1].x
= _handle
.rect().x();
340 xrect
[1].y
= _handle
.rect().y();
341 xrect
[1].width
= _handle
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
342 xrect
[1].height
= _handle
.height() + bwidth
* 2;
346 XShapeCombineRectangles(otk::OBDisplay::display
, window(),
347 ShapeBounding
, 0, 0, xrect
, num
,
348 ShapeUnion
, Unsorted
);
354 void OBFrame::grabClient()
357 // reparent the client to the frame
358 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
359 _plate
.window(), 0, 0);
360 _client
->ignore_unmaps
++;
362 // select the event mask on the client's parent (to receive config req's)
363 XSelectInput(otk::OBDisplay::display
, _plate
.window(),
364 SubstructureRedirectMask
);
366 // map the client so it maps when the frame does
367 XMapWindow(otk::OBDisplay::display
, _client
->window());
374 void OBFrame::releaseClient(bool remap
)
376 // check if the app has already reparented its window to the root window
378 if (XCheckTypedWindowEvent(otk::OBDisplay::display
, _client
->window(),
379 ReparentNotify
, &ev
)) {
380 remap
= true; // XXX: why do we remap the window if they already
381 // reparented to root?
383 // according to the ICCCM - if the client doesn't reparent to
384 // root, then we have to do it for them
385 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
386 _screen
->rootWindow(),
387 _client
->area().x(), _client
->area().y());
390 // if we want to remap the window, do so now
392 XMapWindow(otk::OBDisplay::display
, _client
->window());
396 void OBFrame::clientGravity(int &x
, int &y
)
398 x
= _client
->area().x();
399 y
= _client
->area().y();
402 switch (_client
->gravity()) {
404 case NorthWestGravity
:
405 case SouthWestGravity
:
412 x
-= (_size
.left
+ _size
.right
) / 2;
415 case NorthEastGravity
:
416 case SouthEastGravity
:
418 x
-= _size
.left
+ _size
.right
;
428 switch (_client
->gravity()) {
430 case NorthWestGravity
:
431 case NorthEastGravity
:
438 y
-= (_size
.top
+ _size
.bottom
) / 2;
441 case SouthWestGravity
:
442 case SouthEastGravity
:
444 y
-= _size
.top
+ _size
.bottom
;
455 void OBFrame::frameGravity(int &x
, int &y
)
461 switch (_client
->gravity()) {
463 case NorthWestGravity
:
465 case SouthWestGravity
:
470 x
+= (_size
.left
+ _size
.right
) / 2;
472 case NorthEastGravity
:
474 case SouthEastGravity
:
475 x
+= _size
.left
+ _size
.right
;
484 switch (_client
->gravity()) {
486 case NorthWestGravity
:
488 case SouthWestGravity
:
493 y
+= (_size
.top
+ _size
.bottom
) / 2;
495 case NorthEastGravity
:
497 case SouthEastGravity
:
498 y
+= _size
.top
+ _size
.bottom
;
This page took 0.055587 seconds and 4 git commands to generate.