]>
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>
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();
110 void OBFrame::unfocus()
112 otk::OtkWidget::unfocus();
117 void OBFrame::adjust()
122 void OBFrame::adjustSize()
124 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
125 _decorations
= _client
->decorations();
126 _decorations
= 0xffffffff;
128 int width
; // the width of the client and its border
129 int bwidth
; // width to make borders
130 int cbwidth
; // width of the inner client border
132 if (_decorations
& OBClient::Decor_Border
) {
133 bwidth
= _style
->getBorderWidth();
134 cbwidth
= _style
->getFrameWidth();
136 bwidth
= cbwidth
= 0;
137 _innersize
.left
= _innersize
.top
= _innersize
.bottom
= _innersize
.right
=
139 width
= _client
->area().width() + cbwidth
* 2;
141 _plate
.setBorderWidth(cbwidth
);
143 setBorderWidth(bwidth
);
144 _titlebar
.setBorderWidth(bwidth
);
145 _grip_left
.setBorderWidth(bwidth
);
146 _grip_right
.setBorderWidth(bwidth
);
147 _handle
.setBorderWidth(bwidth
);
149 if (_decorations
& OBClient::Decor_Titlebar
) {
150 // set the titlebar size
151 _titlebar
.setGeometry(-bwidth
,
154 (_style
->getFont()->height() +
155 _style
->getBevelWidth() * 2));
156 _innersize
.top
+= _titlebar
.height() + bwidth
;
158 // set the label size
159 _label
.setGeometry(0, _style
->getBevelWidth(),
160 width
, _style
->getFont()->height());
161 // set the buttons sizes
162 if (_decorations
& OBClient::Decor_Iconify
)
163 _button_iconify
.setGeometry(0, _style
->getBevelWidth() + 1,
165 _label
.height() - 2);
166 if (_decorations
& OBClient::Decor_Maximize
)
167 _button_max
.setGeometry(0, _style
->getBevelWidth() + 1,
169 _label
.height() - 2);
170 if (_decorations
& OBClient::Decor_Sticky
)
171 _button_stick
.setGeometry(0, _style
->getBevelWidth() + 1,
173 _label
.height() - 2);
174 if (_decorations
& OBClient::Decor_Close
)
175 _button_close
.setGeometry(0, _style
->getBevelWidth() + 1,
177 _label
.height() - 2);
179 // separation between titlebar elements
180 const int sep
= _style
->getBevelWidth() + 1;
182 std::string layout
= "SLIMC"; // XXX: get this from somewhere
183 // XXX: it is REQUIRED that by this point, the string only has one of each
184 // possible letter, all of the letters are valid, and L exists somewhere in
187 // the size of the label. this ASSUMES the layout has only buttons other
188 // that the ONE LABEL!!
189 // adds an extra sep so that there's a space on either side of the
190 // titlebar.. note: x = sep, below.
191 int lwidth
= width
- sep
* 2 -
192 (_button_iconify
.width() + sep
) * (layout
.size() - 1);
193 // quick sanity check for really small windows. if this is needed, its
194 // obviously not going to be displayed right...
195 // XXX: maybe we should make this look better somehow? constraints?
196 if (lwidth
<= 0) lwidth
= 1;
197 _label
.setWidth(lwidth
);
200 for (int i
= 0, len
= layout
.size(); i
< len
; ++i
) {
203 _button_iconify
.move(x
, _button_iconify
.rect().y());
204 x
+= _button_iconify
.width();
207 _label
.move(x
, _label
.rect().y());
211 _button_max
.move(x
, _button_max
.rect().y());
212 x
+= _button_max
.width();
215 _button_stick
.move(x
, _button_stick
.rect().y());
216 x
+= _button_stick
.width();
219 _button_close
.move(x
, _button_close
.rect().y());
220 x
+= _button_close
.width();
223 assert(false); // the layout string is invalid!
229 if (_decorations
& OBClient::Decor_Handle
) {
230 _handle
.setGeometry(-bwidth
,
231 _innersize
.top
+ _client
->area().height() + cbwidth
,
232 width
, _style
->getHandleWidth());
233 _grip_left
.setGeometry(-bwidth
,
235 // XXX: get a Point class in otk and use that for
236 // the 'buttons size' since theyre all the same
237 _button_iconify
.width() * 2,
239 _grip_right
.setGeometry(((_handle
.rect().right() + 1) -
240 _button_iconify
.width() * 2),
242 // XXX: get a Point class in otk and use that for
243 // the 'buttons size' since theyre all the same
244 _button_iconify
.width() * 2,
246 _innersize
.bottom
+= _handle
.height() + bwidth
;
250 // position/size all the windows
252 resize(_innersize
.left
+ _innersize
.right
+ _client
->area().width(),
253 _innersize
.top
+ _innersize
.bottom
+ _client
->area().height());
255 _plate
.setGeometry(_innersize
.left
- cbwidth
, _innersize
.top
- cbwidth
,
256 _client
->area().width(), _client
->area().height());
258 // map/unmap all the windows
259 if (_decorations
& OBClient::Decor_Titlebar
) {
261 if (_decorations
& OBClient::Decor_Iconify
)
262 _button_iconify
.show();
264 _button_iconify
.hide();
265 if (_decorations
& OBClient::Decor_Maximize
)
269 if (_decorations
& OBClient::Decor_Sticky
)
270 _button_stick
.show();
272 _button_stick
.hide();
273 if (_decorations
& OBClient::Decor_Close
)
274 _button_close
.show();
276 _button_close
.hide();
279 _titlebar
.hide(true);
282 if (_decorations
& OBClient::Decor_Handle
)
287 // XXX: more is gunna have to happen here
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.053745 seconds and 4 git commands to generate.