]>
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()
119 // the party all happens in adjustSize
123 void OBFrame::adjustSize()
125 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
126 _decorations
= _client
->decorations();
127 _decorations
= 0xffffffff;
129 int width
; // the width of the client and its border
130 int bwidth
; // width to make borders
131 int cbwidth
; // width of the inner client border
132 const int bevel
= _style
->getBevelWidth();
134 if (_decorations
& OBClient::Decor_Border
) {
135 bwidth
= _style
->getBorderWidth();
136 cbwidth
= _style
->getFrameWidth();
138 bwidth
= cbwidth
= 0;
139 _innersize
.left
= _innersize
.top
= _innersize
.bottom
= _innersize
.right
=
141 width
= _client
->area().width() + cbwidth
* 2;
143 _plate
.setBorderWidth(cbwidth
);
145 setBorderWidth(bwidth
);
146 _titlebar
.setBorderWidth(bwidth
);
147 _grip_left
.setBorderWidth(bwidth
);
148 _grip_right
.setBorderWidth(bwidth
);
149 _handle
.setBorderWidth(bwidth
);
151 if (_decorations
& OBClient::Decor_Titlebar
) {
152 // set the titlebar size
153 _titlebar
.setGeometry(-bwidth
,
156 _style
->getFont()->height() + bevel
* 2);
157 _innersize
.top
+= _titlebar
.height() + bwidth
;
159 // set the label size
160 _label
.setGeometry(0, bevel
, width
, _style
->getFont()->height());
161 // set the buttons sizes
162 if (_decorations
& OBClient::Decor_Iconify
)
163 _button_iconify
.setGeometry(0, bevel
+ 1,
165 _label
.height() - 2);
166 if (_decorations
& OBClient::Decor_Maximize
)
167 _button_max
.setGeometry(0, bevel
+ 1,
169 _label
.height() - 2);
170 if (_decorations
& OBClient::Decor_Sticky
)
171 _button_stick
.setGeometry(0, bevel
+ 1,
173 _label
.height() - 2);
174 if (_decorations
& OBClient::Decor_Close
)
175 _button_close
.setGeometry(0, bevel
+ 1,
177 _label
.height() - 2);
179 // separation between titlebar elements
180 const int sep
= bevel
+ 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 _size
.left
= _innersize
.left
+ bwidth
;
288 _size
.right
= _innersize
.right
+ bwidth
;
289 _size
.top
= _innersize
.top
+ bwidth
;
290 _size
.bottom
= _innersize
.bottom
+ bwidth
;
298 void OBFrame::adjustPosition()
306 void OBFrame::adjustShape()
309 int bwidth
= (_decorations
& OBClient::Decor_Border
) ?
310 _style
->getBorderWidth() : 0;
312 if (!_client
->shaped()) {
313 // clear the shape on the frame window
314 XShapeCombineMask(otk::OBDisplay::display
, window(), ShapeBounding
,
319 // make the frame's shape match the clients
320 XShapeCombineShape(otk::OBDisplay::display
, window(), ShapeBounding
,
323 _client
->window(), ShapeBounding
, ShapeSet
);
328 if (_decorations
& OBClient::Decor_Titlebar
) {
329 xrect
[0].x
= _titlebar
.rect().x();
330 xrect
[0].y
= _titlebar
.rect().y();
331 xrect
[0].width
= _titlebar
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
332 xrect
[0].height
= _titlebar
.height() + bwidth
* 2;
336 if (_decorations
& OBClient::Decor_Handle
) {
337 xrect
[1].x
= _handle
.rect().x();
338 xrect
[1].y
= _handle
.rect().y();
339 xrect
[1].width
= _handle
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
340 xrect
[1].height
= _handle
.height() + bwidth
* 2;
344 XShapeCombineRectangles(otk::OBDisplay::display
, window(),
345 ShapeBounding
, 0, 0, xrect
, num
,
346 ShapeUnion
, Unsorted
);
352 void OBFrame::grabClient()
355 // reparent the client to the frame
356 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
357 _plate
.window(), 0, 0);
358 _client
->ignore_unmaps
++;
360 // select the event mask on the client's parent (to receive config req's)
361 XSelectInput(otk::OBDisplay::display
, _plate
.window(),
362 SubstructureRedirectMask
);
364 // map the client so it maps when the frame does
365 XMapWindow(otk::OBDisplay::display
, _client
->window());
372 void OBFrame::releaseClient(bool remap
)
374 // check if the app has already reparented its window to the root window
376 if (XCheckTypedWindowEvent(otk::OBDisplay::display
, _client
->window(),
377 ReparentNotify
, &ev
)) {
378 remap
= true; // XXX: why do we remap the window if they already
379 // reparented to root?
381 // according to the ICCCM - if the client doesn't reparent to
382 // root, then we have to do it for them
383 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
384 _screen
->rootWindow(),
385 _client
->area().x(), _client
->area().y());
388 // if we want to remap the window, do so now
390 XMapWindow(otk::OBDisplay::display
, _client
->window());
394 void OBFrame::clientGravity(int &x
, int &y
)
396 x
= _client
->area().x();
397 y
= _client
->area().y();
400 switch (_client
->gravity()) {
402 case NorthWestGravity
:
403 case SouthWestGravity
:
410 x
-= (_size
.left
+ _size
.right
) / 2;
413 case NorthEastGravity
:
414 case SouthEastGravity
:
416 x
-= _size
.left
+ _size
.right
;
426 switch (_client
->gravity()) {
428 case NorthWestGravity
:
429 case NorthEastGravity
:
436 y
-= (_size
.top
+ _size
.bottom
) / 2;
439 case SouthWestGravity
:
440 case SouthEastGravity
:
442 y
-= _size
.top
+ _size
.bottom
;
453 void OBFrame::frameGravity(int &x
, int &y
)
459 switch (_client
->gravity()) {
461 case NorthWestGravity
:
463 case SouthWestGravity
:
468 x
+= (_size
.left
+ _size
.right
) / 2;
470 case NorthEastGravity
:
472 case SouthEastGravity
:
473 x
+= _size
.left
+ _size
.right
;
482 switch (_client
->gravity()) {
484 case NorthWestGravity
:
486 case SouthWestGravity
:
491 y
+= (_size
.top
+ _size
.bottom
) / 2;
493 case NorthEastGravity
:
495 case SouthEastGravity
:
496 y
+= _size
.top
+ _size
.bottom
;
This page took 0.057774 seconds and 4 git commands to generate.