]> Dogcows Code - chaz/openbox/blob - src/frame.cc
handle configure requests
[chaz/openbox] / src / frame.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 extern "C" {
8 #ifdef SHAPE
9 #include <X11/extensions/shape.h>
10 #endif // SHAPE
11 }
12
13 #include "openbox.hh"
14 #include "frame.hh"
15 #include "client.hh"
16 #include "otk/display.hh"
17
18 #include <string>
19 #include <iostream> // TEMP
20
21 namespace ob {
22
23 OBFrame::OBFrame(OBClient *client, otk::Style *style)
24 : otk::OtkWidget(Openbox::instance, style),
25 _client(client),
26 _screen(otk::OBDisplay::screenInfo(client->screen())),
27 _plate(this),
28 _titlebar(this),
29 _button_close(&_titlebar),
30 _button_iconify(&_titlebar),
31 _button_max(&_titlebar),
32 _button_stick(&_titlebar),
33 _label(&_titlebar),
34 _handle(this),
35 _grip_left(&_handle),
36 _grip_right(&_handle),
37 _decorations(client->decorations())
38 {
39 assert(client);
40 assert(style);
41
42 unmanaged();
43 _titlebar.unmanaged();
44 _button_close.unmanaged();
45 _button_iconify.unmanaged();
46 _button_max.unmanaged();
47 _button_stick.unmanaged();
48 _label.unmanaged();
49 _handle.unmanaged();
50 _grip_left.unmanaged();
51 _grip_right.unmanaged();
52 _plate.unmanaged();
53
54 _plate.show();
55
56 _button_close.setText("X");
57 _button_iconify.setText("I");
58 _button_max.setText("M");
59 _button_stick.setText("S");
60 _label.setText(_client->title());
61
62 _style = 0;
63 setStyle(style);
64
65 grabClient();
66 }
67
68
69 OBFrame::~OBFrame()
70 {
71 releaseClient(false);
72 }
73
74
75 void OBFrame::setStyle(otk::Style *style)
76 {
77 assert(style);
78
79 otk::OtkWidget::setStyle(style);
80 // set the grips' textures
81 _grip_left.setTexture(style->getGripFocus());
82 _grip_left.setUnfocusTexture(style->getGripUnfocus());
83 _grip_left.setPressedFocusTexture(style->getGripFocus());
84 _grip_left.setPressedUnfocusTexture(style->getGripUnfocus());
85 _grip_right.setTexture(style->getGripFocus());
86 _grip_right.setUnfocusTexture(style->getGripUnfocus());
87 _grip_right.setPressedFocusTexture(style->getGripFocus());
88 _grip_right.setPressedUnfocusTexture(style->getGripUnfocus());
89
90 _titlebar.setTexture(style->getTitleFocus());
91 _titlebar.setUnfocusTexture(style->getTitleUnfocus());
92 _handle.setTexture(style->getHandleFocus());
93 _handle.setUnfocusTexture(style->getHandleUnfocus());
94
95 // if a style was previously set, then 'replace' is true, cause we're
96 // replacing a style
97 bool replace = (_style);
98
99 if (replace) {
100 // XXX: do shit here whatever
101 // XXX: save the position based on gravity
102 }
103
104 _style = style;
105
106 // XXX: change when focus changes!
107 XSetWindowBorder(otk::OBDisplay::display, _plate.getWindow(),
108 _style->getFrameFocus()->color().pixel());
109
110 XSetWindowBorder(otk::OBDisplay::display, getWindow(),
111 _style->getBorderColor()->pixel());
112 XSetWindowBorder(otk::OBDisplay::display, _titlebar.getWindow(),
113 _style->getBorderColor()->pixel());
114 XSetWindowBorder(otk::OBDisplay::display, _grip_left.getWindow(),
115 _style->getBorderColor()->pixel());
116 XSetWindowBorder(otk::OBDisplay::display, _grip_right.getWindow(),
117 _style->getBorderColor()->pixel());
118 XSetWindowBorder(otk::OBDisplay::display, _handle.getWindow(),
119 _style->getBorderColor()->pixel());
120
121 // if !replace, then adjust() will get called after the client is grabbed!
122 if (replace)
123 adjust(); // size/position everything
124 }
125
126
127 void OBFrame::adjust()
128 {
129 // XXX: only if not overridden or something!!! MORE LOGIC HERE!!
130 _decorations = _client->decorations();
131 _decorations = 0xffffffff;
132
133 int width; // the width of the client and its border
134 int bwidth; // width to make borders
135 int cbwidth; // width of the inner client border
136
137 if (_decorations & OBClient::Decor_Border) {
138 bwidth = _style->getBorderWidth();
139 cbwidth = _style->getFrameWidth();
140 } else
141 bwidth = cbwidth = 0;
142 _innersize.left = _innersize.top = _innersize.bottom = _innersize.right =
143 cbwidth;
144 width = _client->area().width() + cbwidth * 2;
145
146 XSetWindowBorderWidth(otk::OBDisplay::display, _plate.getWindow(), cbwidth);
147
148 XSetWindowBorderWidth(otk::OBDisplay::display, getWindow(), bwidth);
149 XSetWindowBorderWidth(otk::OBDisplay::display, _titlebar.getWindow(),
150 bwidth);
151 XSetWindowBorderWidth(otk::OBDisplay::display, _grip_left.getWindow(),
152 bwidth);
153 XSetWindowBorderWidth(otk::OBDisplay::display, _grip_right.getWindow(),
154 bwidth);
155 XSetWindowBorderWidth(otk::OBDisplay::display, _handle.getWindow(), bwidth);
156
157 if (_decorations & OBClient::Decor_Titlebar) {
158 // set the titlebar size
159 _titlebar.setGeometry(-bwidth,
160 -bwidth,
161 width,
162 (_style->getFont().height() +
163 _style->getBevelWidth() * 2));
164 _innersize.top += _titlebar.height() + bwidth;
165
166 // set the label size
167 _label.setGeometry(0, _style->getBevelWidth(),
168 width, _style->getFont().height());
169 // set the buttons sizes
170 if (_decorations & OBClient::Decor_Iconify)
171 _button_iconify.setGeometry(0, _style->getBevelWidth() + 1,
172 _label.height() - 2,
173 _label.height() - 2);
174 if (_decorations & OBClient::Decor_Maximize)
175 _button_max.setGeometry(0, _style->getBevelWidth() + 1,
176 _label.height() - 2,
177 _label.height() - 2);
178 if (_decorations & OBClient::Decor_Sticky)
179 _button_stick.setGeometry(0, _style->getBevelWidth() + 1,
180 _label.height() - 2,
181 _label.height() - 2);
182 if (_decorations & OBClient::Decor_Close)
183 _button_close.setGeometry(0, _style->getBevelWidth() + 1,
184 _label.height() - 2,
185 _label.height() - 2);
186
187 // separation between titlebar elements
188 const int sep = _style->getBevelWidth() + 1;
189
190 std::string layout = "SLIMC"; // XXX: get this from somewhere
191 // XXX: it is REQUIRED that by this point, the string only has one of each
192 // possible letter, all of the letters are valid, and L exists somewhere in
193 // the string!
194
195 // the size of the label. this ASSUMES the layout has only buttons other
196 // that the ONE LABEL!!
197 // adds an extra sep so that there's a space on either side of the
198 // titlebar.. note: x = sep, below.
199 int lwidth = width - sep * 2 -
200 (_button_iconify.width() + sep) * (layout.size() - 1);
201 // quick sanity check for really small windows. if this is needed, its
202 // obviously not going to be displayed right...
203 // XXX: maybe we should make this look better somehow? constraints?
204 if (lwidth <= 0) lwidth = 1;
205 _label.setWidth(lwidth);
206
207 int x = sep;
208 for (int i = 0, len = layout.size(); i < len; ++i) {
209 switch (layout[i]) {
210 case 'I':
211 _button_iconify.move(x, _button_iconify.getRect().y());
212 x += _button_iconify.width();
213 break;
214 case 'L':
215 _label.move(x, _label.getRect().y());
216 x += _label.width();
217 break;
218 case 'M':
219 _button_max.move(x, _button_max.getRect().y());
220 x += _button_max.width();
221 break;
222 case 'S':
223 _button_stick.move(x, _button_stick.getRect().y());
224 x += _button_stick.width();
225 break;
226 case 'C':
227 _button_close.move(x, _button_close.getRect().y());
228 x += _button_close.width();
229 break;
230 default:
231 assert(false); // the layout string is invalid!
232 }
233 x += sep;
234 }
235 }
236
237 if (_decorations & OBClient::Decor_Handle) {
238 _handle.setGeometry(-bwidth,
239 _innersize.top + _client->area().height() + cbwidth,
240 width, _style->getHandleWidth());
241 _grip_left.setGeometry(-bwidth,
242 -bwidth,
243 // XXX: get a Point class in otk and use that for
244 // the 'buttons size' since theyre all the same
245 _button_iconify.width() * 2,
246 _handle.height());
247 _grip_right.setGeometry(((_handle.getRect().right() + 1) -
248 _button_iconify.width() * 2),
249 -bwidth,
250 // XXX: get a Point class in otk and use that for
251 // the 'buttons size' since theyre all the same
252 _button_iconify.width() * 2,
253 _handle.height());
254 _innersize.bottom += _handle.height() + bwidth;
255 }
256
257
258 // position/size all the windows
259
260 resize(_innersize.left + _innersize.right + _client->area().width(),
261 _innersize.top + _innersize.bottom + _client->area().height());
262
263 _plate.setGeometry(_innersize.left - cbwidth, _innersize.top - cbwidth,
264 _client->area().width(), _client->area().height());
265
266 // map/unmap all the windows
267 if (_decorations & OBClient::Decor_Titlebar) {
268 _label.show();
269 if (_decorations & OBClient::Decor_Iconify)
270 _button_iconify.show();
271 else
272 _button_iconify.hide();
273 if (_decorations & OBClient::Decor_Maximize)
274 _button_max.show();
275 else
276 _button_max.hide();
277 if (_decorations & OBClient::Decor_Sticky)
278 _button_stick.show();
279 else
280 _button_stick.hide();
281 if (_decorations & OBClient::Decor_Close)
282 _button_close.show();
283 else
284 _button_close.hide();
285 _titlebar.show();
286 } else {
287 _titlebar.hide(true);
288 }
289
290 if (_decorations & OBClient::Decor_Handle)
291 _handle.show(true);
292 else
293 _handle.hide(true);
294
295 // XXX: more is gunna have to happen here
296
297 _size.left = _innersize.left + bwidth;
298 _size.right = _innersize.right + bwidth;
299 _size.top = _innersize.top + bwidth;
300 _size.bottom = _innersize.bottom + bwidth;
301
302 adjustShape();
303
304 update();
305 }
306
307
308 void OBFrame::adjustShape()
309 {
310 #ifdef SHAPE
311 int bwidth = (_decorations & OBClient::Decor_Border) ?
312 _style->getBorderWidth() : 0;
313
314 if (!_client->shaped()) {
315 // clear the shape on the frame window
316 XShapeCombineMask(otk::OBDisplay::display, getWindow(), ShapeBounding,
317 _innersize.left,
318 _innersize.top,
319 None, ShapeSet);
320 } else {
321 // make the frame's shape match the clients
322 XShapeCombineShape(otk::OBDisplay::display, getWindow(), ShapeBounding,
323 _innersize.left,
324 _innersize.top,
325 _client->window(), ShapeBounding, ShapeSet);
326
327 int num = 0;
328 XRectangle xrect[2];
329
330 if (_decorations & OBClient::Decor_Titlebar) {
331 xrect[0].x = _titlebar.getRect().x();
332 xrect[0].y = _titlebar.getRect().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;
335 ++num;
336 }
337
338 if (_decorations & OBClient::Decor_Handle) {
339 xrect[1].x = _handle.getRect().x();
340 xrect[1].y = _handle.getRect().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;
343 ++num;
344 }
345
346 XShapeCombineRectangles(otk::OBDisplay::display, getWindow(),
347 ShapeBounding, 0, 0, xrect, num,
348 ShapeUnion, Unsorted);
349 }
350 #endif // SHAPE
351 }
352
353
354 void OBFrame::grabClient()
355 {
356
357 // select the event mask on the frame
358 //XSelectInput(otk::OBDisplay::display, _window, SubstructureRedirectMask);
359
360 // reparent the client to the frame
361 XReparentWindow(otk::OBDisplay::display, _client->window(),
362 _plate.getWindow(), 0, 0);
363 _client->ignore_unmaps++;
364
365 // raise the client above the frame
366 //XRaiseWindow(otk::OBDisplay::display, _client->window());
367 // map the client so it maps when the frame does
368 XMapWindow(otk::OBDisplay::display, _client->window());
369
370 adjust();
371 applyGravity();
372 }
373
374
375 void OBFrame::releaseClient(bool remap)
376 {
377 // check if the app has already reparented its window to the root window
378 XEvent ev;
379 if (XCheckTypedWindowEvent(otk::OBDisplay::display, _client->window(),
380 ReparentNotify, &ev)) {
381 remap = true; // XXX: why do we remap the window if they already
382 // reparented to root?
383 } else {
384 // according to the ICCCM - if the client doesn't reparent to
385 // root, then we have to do it for them
386 XReparentWindow(otk::OBDisplay::display, _client->window(),
387 _screen->getRootWindow(),
388 _client->area().x(), _client->area().y());
389 }
390
391 // if we want to remap the window, do so now
392 if (remap)
393 XMapWindow(otk::OBDisplay::display, _client->window());
394 }
395
396
397 void OBFrame::applyGravity()
398 {
399 int x, y;
400 // apply horizontal window gravity
401 switch (_client->gravity()) {
402 default:
403 case NorthWestGravity:
404 case SouthWestGravity:
405 case WestGravity:
406 x = _client->area().x();
407 break;
408
409 case NorthGravity:
410 case SouthGravity:
411 case CenterGravity:
412 x = _client->area().x() - (_size.left + _size.right) / 2;
413 break;
414
415 case NorthEastGravity:
416 case SouthEastGravity:
417 case EastGravity:
418 x = _client->area().x() - _size.left - _size.right + 2;
419 break;
420
421 case ForgetGravity:
422 case StaticGravity:
423 x = _client->area().x() - _size.left;
424 break;
425 }
426
427 // apply vertical window gravity
428 switch (_client->gravity()) {
429 default:
430 case NorthWestGravity:
431 case NorthEastGravity:
432 case NorthGravity:
433 y = _client->area().y();
434 break;
435
436 case CenterGravity:
437 case EastGravity:
438 case WestGravity:
439 y = _client->area().y() - (_size.top + _size.bottom) / 2;
440 break;
441
442 case SouthWestGravity:
443 case SouthEastGravity:
444 case SouthGravity:
445 y = _client->area().y() - _size.top - _size.bottom + 2;
446 break;
447
448 case ForgetGravity:
449 case StaticGravity:
450 y = _client->area().y() - _size.top;
451 break;
452 }
453 move(x, y);
454 }
455
456
457 void OBFrame::reverseGravity()
458 {
459 move(_client->area().x() - _size.left, _client->area().y() - _size.top);
460 }
461
462
463 }
This page took 0.056757 seconds and 5 git commands to generate.