]>
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
71 void OBFrame::grabButtons(bool grab
)
74 // grab simple button clicks on the client, but pass them through too
75 otk::OBDisplay::grabButton(Button1
, 0, _plate
.window(), true,
76 ButtonPressMask
, GrabModeSync
, GrabModeSync
,
77 _plate
.window(), None
, false);
78 otk::OBDisplay::grabButton(Button2
, 0, _plate
.window(), true,
79 ButtonPressMask
, GrabModeSync
, GrabModeSync
,
80 _plate
.window(), None
, false);
81 otk::OBDisplay::grabButton(Button3
, 0, _plate
.window(), true,
82 ButtonPressMask
, GrabModeSync
, GrabModeSync
,
83 _plate
.window(), None
, false);
84 otk::OBDisplay::grabButton(Button4
, 0, _plate
.window(), true,
85 ButtonPressMask
, GrabModeSync
, GrabModeSync
,
86 _plate
.window(), None
, false);
87 otk::OBDisplay::grabButton(Button5
, 0, _plate
.window(), true,
88 ButtonPressMask
, GrabModeSync
, GrabModeSync
,
89 _plate
.window(), None
, false);
93 // grab any requested buttons on the entire frame
96 otk::OBDisplay::grabButton(Button1
, 0, _plate
.window(), true,
97 ButtonPressMask
, GrabModeSync
, GrabModeSync
,
98 _plate
.window(), None
, false);
104 void OBFrame::setTitle(const std::string
&text
)
106 _label
.setText(text
);
111 void OBFrame::setStyle(otk::Style
*style
)
115 otk::OtkWidget::setStyle(style
);
117 // if a style was previously set, then 'replace' is true, cause we're
119 bool replace
= (_style
);
122 // XXX: do shit here whatever
127 setBorderColor(_style
->getBorderColor());
129 // if !replace, then adjust() will get called after the client is grabbed!
131 // size/position everything
138 void OBFrame::focus()
140 otk::OtkWidget::focus();
146 void OBFrame::unfocus()
148 otk::OtkWidget::unfocus();
153 void OBFrame::adjust()
155 // the party all happens in adjustSize
159 void OBFrame::adjustSize()
161 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
162 _decorations
= _client
->decorations();
163 _decorations
= 0xffffffff;
165 int width
; // the width of the client and its border
166 int bwidth
; // width to make borders
167 int cbwidth
; // width of the inner client border
168 const int bevel
= _style
->getBevelWidth();
170 if (_decorations
& OBClient::Decor_Border
) {
171 bwidth
= _style
->getBorderWidth();
172 cbwidth
= _style
->getFrameWidth();
174 bwidth
= cbwidth
= 0;
175 _innersize
.left
= _innersize
.top
= _innersize
.bottom
= _innersize
.right
=
177 width
= _client
->area().width() + cbwidth
* 2;
179 _plate
.setBorderWidth(cbwidth
);
181 setBorderWidth(bwidth
);
182 _titlebar
.setBorderWidth(bwidth
);
183 _grip_left
.setBorderWidth(bwidth
);
184 _grip_right
.setBorderWidth(bwidth
);
185 _handle
.setBorderWidth(bwidth
);
187 if (_decorations
& OBClient::Decor_Titlebar
) {
188 // set the titlebar size
189 _titlebar
.setGeometry(-bwidth
,
192 _style
->getFont()->height() + bevel
* 2);
193 _innersize
.top
+= _titlebar
.height() + bwidth
;
195 // set the label size
196 _label
.setGeometry(0, bevel
, width
, _style
->getFont()->height());
197 // set the buttons sizes
198 if (_decorations
& OBClient::Decor_Iconify
)
199 _button_iconify
.setGeometry(0, bevel
+ 1,
201 _label
.height() - 2);
202 if (_decorations
& OBClient::Decor_Maximize
)
203 _button_max
.setGeometry(0, bevel
+ 1,
205 _label
.height() - 2);
206 if (_decorations
& OBClient::Decor_Sticky
)
207 _button_stick
.setGeometry(0, bevel
+ 1,
209 _label
.height() - 2);
210 if (_decorations
& OBClient::Decor_Close
)
211 _button_close
.setGeometry(0, bevel
+ 1,
213 _label
.height() - 2);
215 // separation between titlebar elements
216 const int sep
= bevel
+ 1;
218 std::string layout
= "SLIMC"; // XXX: get this from somewhere
219 // XXX: it is REQUIRED that by this point, the string only has one of each
220 // possible letter, all of the letters are valid, and L exists somewhere in
223 // the size of the label. this ASSUMES the layout has only buttons other
224 // that the ONE LABEL!!
225 // adds an extra sep so that there's a space on either side of the
226 // titlebar.. note: x = sep, below.
227 int lwidth
= width
- sep
* 2 -
228 (_button_iconify
.width() + sep
) * (layout
.size() - 1);
229 // quick sanity check for really small windows. if this is needed, its
230 // obviously not going to be displayed right...
231 // XXX: maybe we should make this look better somehow? constraints?
232 if (lwidth
<= 0) lwidth
= 1;
233 _label
.setWidth(lwidth
);
236 for (int i
= 0, len
= layout
.size(); i
< len
; ++i
) {
239 _button_iconify
.move(x
, _button_iconify
.rect().y());
240 x
+= _button_iconify
.width();
243 _label
.move(x
, _label
.rect().y());
247 _button_max
.move(x
, _button_max
.rect().y());
248 x
+= _button_max
.width();
251 _button_stick
.move(x
, _button_stick
.rect().y());
252 x
+= _button_stick
.width();
255 _button_close
.move(x
, _button_close
.rect().y());
256 x
+= _button_close
.width();
259 assert(false); // the layout string is invalid!
265 if (_decorations
& OBClient::Decor_Handle
) {
266 _handle
.setGeometry(-bwidth
,
267 _innersize
.top
+ _client
->area().height() + cbwidth
,
268 width
, _style
->getHandleWidth());
269 _grip_left
.setGeometry(-bwidth
,
271 // XXX: get a Point class in otk and use that for
272 // the 'buttons size' since theyre all the same
273 _button_iconify
.width() * 2,
275 _grip_right
.setGeometry(((_handle
.rect().right() + 1) -
276 _button_iconify
.width() * 2),
278 // XXX: get a Point class in otk and use that for
279 // the 'buttons size' since theyre all the same
280 _button_iconify
.width() * 2,
282 _innersize
.bottom
+= _handle
.height() + bwidth
;
286 // position/size all the windows
288 resize(_innersize
.left
+ _innersize
.right
+ _client
->area().width(),
289 _innersize
.top
+ _innersize
.bottom
+ _client
->area().height());
291 _plate
.setGeometry(_innersize
.left
- cbwidth
, _innersize
.top
- cbwidth
,
292 _client
->area().width(), _client
->area().height());
294 // map/unmap all the windows
295 if (_decorations
& OBClient::Decor_Titlebar
) {
297 if (_decorations
& OBClient::Decor_Iconify
)
298 _button_iconify
.show();
300 _button_iconify
.hide();
301 if (_decorations
& OBClient::Decor_Maximize
)
305 if (_decorations
& OBClient::Decor_Sticky
)
306 _button_stick
.show();
308 _button_stick
.hide();
309 if (_decorations
& OBClient::Decor_Close
)
310 _button_close
.show();
312 _button_close
.hide();
315 _titlebar
.hide(true);
318 if (_decorations
& OBClient::Decor_Handle
)
323 _size
.left
= _innersize
.left
+ bwidth
;
324 _size
.right
= _innersize
.right
+ bwidth
;
325 _size
.top
= _innersize
.top
+ bwidth
;
326 _size
.bottom
= _innersize
.bottom
+ bwidth
;
334 void OBFrame::adjustPosition()
342 void OBFrame::adjustShape()
345 int bwidth
= (_decorations
& OBClient::Decor_Border
) ?
346 _style
->getBorderWidth() : 0;
348 if (!_client
->shaped()) {
349 // clear the shape on the frame window
350 XShapeCombineMask(otk::OBDisplay::display
, window(), ShapeBounding
,
355 // make the frame's shape match the clients
356 XShapeCombineShape(otk::OBDisplay::display
, window(), ShapeBounding
,
359 _client
->window(), ShapeBounding
, ShapeSet
);
364 if (_decorations
& OBClient::Decor_Titlebar
) {
365 xrect
[0].x
= _titlebar
.rect().x();
366 xrect
[0].y
= _titlebar
.rect().y();
367 xrect
[0].width
= _titlebar
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
368 xrect
[0].height
= _titlebar
.height() + bwidth
* 2;
372 if (_decorations
& OBClient::Decor_Handle
) {
373 xrect
[1].x
= _handle
.rect().x();
374 xrect
[1].y
= _handle
.rect().y();
375 xrect
[1].width
= _handle
.width() + bwidth
* 2; // XXX: this is useless once the widget handles borders!
376 xrect
[1].height
= _handle
.height() + bwidth
* 2;
380 XShapeCombineRectangles(otk::OBDisplay::display
, window(),
381 ShapeBounding
, 0, 0, xrect
, num
,
382 ShapeUnion
, Unsorted
);
388 void OBFrame::grabClient()
391 // reparent the client to the frame
392 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
393 _plate
.window(), 0, 0);
394 _client
->ignore_unmaps
++;
396 // select the event mask on the client's parent (to receive config req's)
397 XSelectInput(otk::OBDisplay::display
, _plate
.window(),
398 SubstructureRedirectMask
);
400 // map the client so it maps when the frame does
401 XMapWindow(otk::OBDisplay::display
, _client
->window());
408 void OBFrame::releaseClient(bool remap
)
410 // check if the app has already reparented its window to the root window
412 if (XCheckTypedWindowEvent(otk::OBDisplay::display
, _client
->window(),
413 ReparentNotify
, &ev
)) {
414 remap
= true; // XXX: why do we remap the window if they already
415 // reparented to root?
417 // according to the ICCCM - if the client doesn't reparent to
418 // root, then we have to do it for them
419 XReparentWindow(otk::OBDisplay::display
, _client
->window(),
420 _screen
->rootWindow(),
421 _client
->area().x(), _client
->area().y());
424 // if we want to remap the window, do so now
426 XMapWindow(otk::OBDisplay::display
, _client
->window());
430 void OBFrame::clientGravity(int &x
, int &y
)
432 x
= _client
->area().x();
433 y
= _client
->area().y();
436 switch (_client
->gravity()) {
438 case NorthWestGravity
:
439 case SouthWestGravity
:
446 x
-= (_size
.left
+ _size
.right
) / 2;
449 case NorthEastGravity
:
450 case SouthEastGravity
:
452 x
-= _size
.left
+ _size
.right
;
462 switch (_client
->gravity()) {
464 case NorthWestGravity
:
465 case NorthEastGravity
:
472 y
-= (_size
.top
+ _size
.bottom
) / 2;
475 case SouthWestGravity
:
476 case SouthEastGravity
:
478 y
-= _size
.top
+ _size
.bottom
;
489 void OBFrame::frameGravity(int &x
, int &y
)
495 switch (_client
->gravity()) {
497 case NorthWestGravity
:
499 case SouthWestGravity
:
504 x
+= (_size
.left
+ _size
.right
) / 2;
506 case NorthEastGravity
:
508 case SouthEastGravity
:
509 x
+= _size
.left
+ _size
.right
;
518 switch (_client
->gravity()) {
520 case NorthWestGravity
:
522 case SouthWestGravity
:
527 y
+= (_size
.top
+ _size
.bottom
) / 2;
529 case NorthEastGravity
:
531 case SouthEastGravity
:
532 y
+= _size
.top
+ _size
.bottom
;
This page took 0.056914 seconds and 4 git commands to generate.