]>
Dogcows Code - chaz/openbox/blob - src/frame.cc
979d9575ee2ea2ad81cf3436d9bb2d2230fce826
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
, OBWidget::Type_CloseButton
),
31 _button_iconify(&_titlebar
, OBWidget::Type_IconifyButton
),
32 _button_max(&_titlebar
, OBWidget::Type_MaximizeButton
),
33 _button_stick(&_titlebar
, OBWidget::Type_StickyButton
),
34 _label(&_titlebar
, OBWidget::Type_Label
),
35 _handle(this, OBWidget::Type_Handle
),
36 _grip_left(&_handle
, OBWidget::Type_LeftGrip
),
37 _grip_right(&_handle
, OBWidget::Type_RightGrip
),
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
);
89 // if a style was previously set, then 'replace' is true, cause we're
91 bool replace
= (_style
);
94 // XXX: do shit here whatever
99 // XXX: change when focus changes!
100 XSetWindowBorder(otk::OBDisplay::display
, getWindow(),
101 _style
->getBorderColor()->pixel());
103 // if !replace, then adjust() will get called after the client is grabbed!
105 // size/position everything
112 void OBFrame::adjustSize()
114 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
115 _decorations
= _client
->decorations();
116 _decorations
= 0xffffffff;
118 int width
; // the width of the client and its border
119 int bwidth
; // width to make borders
120 int cbwidth
; // width of the inner client border
122 if (_decorations
& OBClient::Decor_Border
) {
123 bwidth
= _style
->getBorderWidth();
124 cbwidth
= _style
->getFrameWidth();
126 bwidth
= cbwidth
= 0;
127 _innersize
.left
= _innersize
.top
= _innersize
.bottom
= _innersize
.right
=
129 width
= _client
->area().width() + cbwidth
* 2;
131 _plate
.setBorderWidth(cbwidth
);
133 setBorderWidth(bwidth
);
134 _titlebar
.setBorderWidth(bwidth
);
135 _grip_left
.setBorderWidth(bwidth
);
136 _grip_right
.setBorderWidth(bwidth
);
137 _handle
.setBorderWidth(bwidth
);
139 if (_decorations
& OBClient::Decor_Titlebar
) {
140 // set the titlebar size
141 _titlebar
.setGeometry(-bwidth
,
144 (_style
->getFont().height() +
145 _style
->getBevelWidth() * 2));
146 _innersize
.top
+= _titlebar
.height() + bwidth
;
148 // set the label size
149 _label
.setGeometry(0, _style
->getBevelWidth(),
150 width
, _style
->getFont().height());
151 // set the buttons sizes
152 if (_decorations
& OBClient::Decor_Iconify
)
153 _button_iconify
.setGeometry(0, _style
->getBevelWidth() + 1,
155 _label
.height() - 2);
156 if (_decorations
& OBClient::Decor_Maximize
)
157 _button_max
.setGeometry(0, _style
->getBevelWidth() + 1,
159 _label
.height() - 2);
160 if (_decorations
& OBClient::Decor_Sticky
)
161 _button_stick
.setGeometry(0, _style
->getBevelWidth() + 1,
163 _label
.height() - 2);
164 if (_decorations
& OBClient::Decor_Close
)
165 _button_close
.setGeometry(0, _style
->getBevelWidth() + 1,
167 _label
.height() - 2);
169 // separation between titlebar elements
170 const int sep
= _style
->getBevelWidth() + 1;
172 std::string layout
= "SLIMC"; // XXX: get this from somewhere
173 // XXX: it is REQUIRED that by this point, the string only has one of each
174 // possible letter, all of the letters are valid, and L exists somewhere in
177 // the size of the label. this ASSUMES the layout has only buttons other
178 // that the ONE LABEL!!
179 // adds an extra sep so that there's a space on either side of the
180 // titlebar.. note: x = sep, below.
181 int lwidth
= width
- sep
* 2 -
182 (_button_iconify
.width() + sep
) * (layout
.size() - 1);
183 // quick sanity check for really small windows. if this is needed, its
184 // obviously not going to be displayed right...
185 // XXX: maybe we should make this look better somehow? constraints?
186 if (lwidth
<= 0) lwidth
= 1;
187 _label
.setWidth(lwidth
);
190 for (int i
= 0, len
= layout
.size(); i
< len
; ++i
) {
193 _button_iconify
.move(x
, _button_iconify
.getRect().y());
194 x
+= _button_iconify
.width();
197 _label
.move(x
, _label
.getRect().y());
201 _button_max
.move(x
, _button_max
.getRect().y());
202 x
+= _button_max
.width();
205 _button_stick
.move(x
, _button_stick
.getRect().y());
206 x
+= _button_stick
.width();
209 _button_close
.move(x
, _button_close
.getRect().y());
210 x
+= _button_close
.width();
213 assert(false); // the layout string is invalid!
219 if (_decorations
& OBClient::Decor_Handle
) {
220 _handle
.setGeometry(-bwidth
,
221 _innersize
.top
+ _client
->area().height() + cbwidth
,
222 width
, _style
->getHandleWidth());
223 _grip_left
.setGeometry(-bwidth
,
225 // XXX: get a Point class in otk and use that for
226 // the 'buttons size' since theyre all the same
227 _button_iconify
.width() * 2,
229 _grip_right
.setGeometry(((_handle
.getRect().right() + 1) -
230 _button_iconify
.width() * 2),
232 // XXX: get a Point class in otk and use that for
233 // the 'buttons size' since theyre all the same
234 _button_iconify
.width() * 2,
236 _innersize
.bottom
+= _handle
.height() + bwidth
;
240 // position/size all the windows
242 resize(_innersize
.left
+ _innersize
.right
+ _client
->area().width(),
243 _innersize
.top
+ _innersize
.bottom
+ _client
->area().height());
245 _plate
.setGeometry(_innersize
.left
- cbwidth
, _innersize
.top
- cbwidth
,
246 _client
->area().width(), _client
->area().height());
248 // map/unmap all the windows
249 if (_decorations
& OBClient::Decor_Titlebar
) {
251 if (_decorations
& OBClient::Decor_Iconify
)
252 _button_iconify
.show();
254 _button_iconify
.hide();
255 if (_decorations
& OBClient::Decor_Maximize
)
259 if (_decorations
& OBClient::Decor_Sticky
)
260 _button_stick
.show();
262 _button_stick
.hide();
263 if (_decorations
& OBClient::Decor_Close
)
264 _button_close
.show();
266 _button_close
.hide();
269 _titlebar
.hide(true);
272 if (_decorations
& OBClient::Decor_Handle
)
277 // XXX: more is gunna have to happen here
279 _size
.left
= _innersize
.left
+ bwidth
;
280 _size
.right
= _innersize
.right
+ bwidth
;
281 _size
.top
= _innersize
.top
+ bwidth
;
282 _size
.bottom
= _innersize
.bottom
+ bwidth
;
290 void OBFrame::adjustPosition()
298 void OBFrame::adjustShape()
301 int bwidth
= (_decorations
& OBClient::Decor_Border
) ?
302 _style
->getBorderWidth() : 0;
304 if (!_client
->shaped()) {
305 // clear the shape on the frame window
306 XShapeCombineMask(otk::OBDisplay::display
, getWindow(), ShapeBounding
,
311 // make the frame's shape match the clients
312 XShapeCombineShape(otk::OBDisplay::display
, getWindow(), ShapeBounding
,
315 _client
->window(), ShapeBounding
, ShapeSet
);
320 if (_decorations
& OBClient::Decor_Titlebar
) {
321 xrect
[0].x
= _titlebar
.getRect().x();
322 xrect
[0].y
= _titlebar
.getRect().y();
323 xrect
[0].width
= _titlebar
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
324 xrect
[0].height
= _titlebar
.height() + bwidth
* 2;
328 if (_decorations
& OBClient::Decor_Handle
) {
329 xrect
[1].x
= _handle
.getRect().x();
330 xrect
[1].y
= _handle
.getRect().y();
331 xrect
[1].width
= _handle
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
332 xrect
[1].height
= _handle
.height() + bwidth
* 2;
336 XShapeCombineRectangles(otk::OBDisplay::display
, getWindow(),
337 ShapeBounding
, 0, 0, xrect
, num
,
338 ShapeUnion
, Unsorted
);
344 void OBFrame::grabClient()
347 // reparent the client to the frame
348 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
349 _plate
.getWindow(), 0, 0);
350 _client
->ignore_unmaps
++;
352 // select the event mask on the client's parent (to receive config req's)
353 XSelectInput(otk::OBDisplay::display
, _plate
.getWindow(),
354 SubstructureRedirectMask
);
356 // map the client so it maps when the frame does
357 XMapWindow(otk::OBDisplay::display
, _client
->window());
364 void OBFrame::releaseClient(bool remap
)
366 // check if the app has already reparented its window to the root window
368 if (XCheckTypedWindowEvent(otk::OBDisplay::display
, _client
->window(),
369 ReparentNotify
, &ev
)) {
370 remap
= true; // XXX: why do we remap the window if they already
371 // reparented to root?
373 // according to the ICCCM - if the client doesn't reparent to
374 // root, then we have to do it for them
375 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
376 _screen
->getRootWindow(),
377 _client
->area().x(), _client
->area().y());
380 // if we want to remap the window, do so now
382 XMapWindow(otk::OBDisplay::display
, _client
->window());
386 void OBFrame::clientGravity(int &x
, int &y
)
388 x
= _client
->area().x();
389 y
= _client
->area().y();
392 switch (_client
->gravity()) {
394 case NorthWestGravity
:
395 case SouthWestGravity
:
402 x
-= (_size
.left
+ _size
.right
) / 2;
405 case NorthEastGravity
:
406 case SouthEastGravity
:
408 x
-= _size
.left
+ _size
.right
;
418 switch (_client
->gravity()) {
420 case NorthWestGravity
:
421 case NorthEastGravity
:
428 y
-= (_size
.top
+ _size
.bottom
) / 2;
431 case SouthWestGravity
:
432 case SouthEastGravity
:
434 y
-= _size
.top
+ _size
.bottom
;
445 void OBFrame::frameGravity(int &x
, int &y
)
451 switch (_client
->gravity()) {
453 case NorthWestGravity
:
455 case SouthWestGravity
:
460 x
+= (_size
.left
+ _size
.right
) / 2;
462 case NorthEastGravity
:
464 case SouthEastGravity
:
465 x
+= _size
.left
+ _size
.right
;
474 switch (_client
->gravity()) {
476 case NorthWestGravity
:
478 case SouthWestGravity
:
483 y
+= (_size
.top
+ _size
.bottom
) / 2;
485 case NorthEastGravity
:
487 case SouthEastGravity
:
488 y
+= _size
.top
+ _size
.bottom
;
This page took 0.052946 seconds and 4 git commands to generate.