]> Dogcows Code - chaz/openbox/blob - src/client.cc
07d754624ad29aacbb4b635d52d54e3548ec6572
[chaz/openbox] / src / client.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 #include "client.hh"
8 #include "frame.hh"
9 #include "screen.hh"
10 #include "bbscreen.hh"
11 #include "openbox.hh"
12 #include "otk/display.hh"
13 #include "otk/property.hh"
14
15 extern "C" {
16 #include <X11/Xlib.h>
17 #include <X11/Xutil.h>
18
19 #include <assert.h>
20
21 #include "gettext.h"
22 #define _(str) gettext(str)
23 }
24
25 namespace ob {
26
27 OBClient::OBClient(int screen, Window window)
28 : otk::OtkEventHandler(),
29 frame(0), _screen(screen), _window(window)
30 {
31 assert(screen >= 0);
32 assert(window);
33
34 ignore_unmaps = 0;
35
36 // update EVERYTHING the first time!!
37
38 // the state is kinda assumed to be normal. is this right? XXX
39 _wmstate = NormalState;
40 // no default decors or functions, each has to be enabled
41 _decorations = _functions = 0;
42
43 getArea();
44 getDesktop();
45 getType();
46
47 // set the decorations and functions
48 switch (_type) {
49 case Type_Normal:
50 // normal windows retain all of the possible decorations and
51 // functionality
52 _decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
53 Decor_Iconify | Decor_Maximize;
54 _functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize;
55
56 case Type_Dialog:
57 // dialogs cannot be maximized
58 _decorations &= ~Decor_Maximize;
59 _functions &= ~Func_Maximize;
60 break;
61
62 case Type_Menu:
63 case Type_Toolbar:
64 case Type_Utility:
65 // these windows get less functionality
66 _decorations &= ~(Decor_Iconify | Decor_Handle);
67 _functions &= ~(Func_Iconify | Func_Resize);
68 break;
69
70 case Type_Desktop:
71 case Type_Dock:
72 case Type_Splash:
73 // none of these windows are manipulated by the window manager
74 _decorations = 0;
75 _functions = 0;
76 break;
77 }
78
79 getMwmHints(); // this fucks (in good ways) with the decors and functions
80 getState();
81 getShaped();
82
83 updateProtocols();
84 updateNormalHints();
85 updateWMHints();
86 // XXX: updateTransientFor();
87 updateTitle();
88 updateIconTitle();
89 updateClass();
90
91 /*
92 #ifdef DEBUG
93 printf("Mapped window: 0x%lx\n"
94 " title: \t%s\t icon title: \t%s\n"
95 " app name: \t%s\t\t class: \t%s\n"
96 " position: \t%d, %d\t\t size: \t%d, %d\n"
97 " desktop: \t%lu\t\t group: \t0x%lx\n"
98 " type: \t%d\t\t min size \t%d, %d\n"
99 " base size \t%d, %d\t\t max size \t%d, %d\n"
100 " size incr \t%d, %d\t\t gravity \t%d\n"
101 " wm state \t%ld\t\t can be focused:\t%s\n"
102 " notify focus: \t%s\t\t urgent: \t%s\n"
103 " shaped: \t%s\t\t modal: \t%s\n"
104 " shaded: \t%s\t\t iconic: \t%s\n"
105 " vert maximized:\t%s\t\t horz maximized:\t%s\n"
106 " fullscreen: \t%s\t\t floating: \t%s\n"
107 " requested pos: \t%s\n",
108 _window,
109 _title.c_str(),
110 _icon_title.c_str(),
111 _app_name.c_str(),
112 _app_class.c_str(),
113 _area.x(), _area.y(),
114 _area.width(), _area.height(),
115 _desktop,
116 _group,
117 _type,
118 _min_x, _min_y,
119 _base_x, _base_y,
120 _max_x, _max_y,
121 _inc_x, _inc_y,
122 _gravity,
123 _wmstate,
124 _can_focus ? "yes" : "no",
125 _focus_notify ? "yes" : "no",
126 _urgent ? "yes" : "no",
127 _shaped ? "yes" : "no",
128 _modal ? "yes" : "no",
129 _shaded ? "yes" : "no",
130 _iconic ? "yes" : "no",
131 _max_vert ? "yes" : "no",
132 _max_horz ? "yes" : "no",
133 _fullscreen ? "yes" : "no",
134 _floating ? "yes" : "no",
135 _positioned ? "yes" : "no");
136 #endif
137 */
138 }
139
140
141 OBClient::~OBClient()
142 {
143 const otk::OBProperty *property = Openbox::instance->property();
144
145 // these values should not be persisted across a window unmapping/mapping
146 property->erase(_window, otk::OBProperty::net_wm_desktop);
147 property->erase(_window, otk::OBProperty::net_wm_state);
148 }
149
150
151 void OBClient::getDesktop()
152 {
153 const otk::OBProperty *property = Openbox::instance->property();
154
155 // defaults to the current desktop
156 _desktop = 0; // XXX: change this to the current desktop!
157
158 property->get(_window, otk::OBProperty::net_wm_desktop,
159 otk::OBProperty::Atom_Cardinal,
160 &_desktop);
161 }
162
163
164 void OBClient::getType()
165 {
166 const otk::OBProperty *property = Openbox::instance->property();
167
168 _type = (WindowType) -1;
169
170 unsigned long *val;
171 unsigned long num = (unsigned) -1;
172 if (property->get(_window, otk::OBProperty::net_wm_window_type,
173 otk::OBProperty::Atom_Atom,
174 &num, &val)) {
175 // use the first value that we know about in the array
176 for (unsigned long i = 0; i < num; ++i) {
177 if (val[i] ==
178 property->atom(otk::OBProperty::net_wm_window_type_desktop))
179 _type = Type_Desktop;
180 else if (val[i] ==
181 property->atom(otk::OBProperty::net_wm_window_type_dock))
182 _type = Type_Dock;
183 else if (val[i] ==
184 property->atom(otk::OBProperty::net_wm_window_type_toolbar))
185 _type = Type_Toolbar;
186 else if (val[i] ==
187 property->atom(otk::OBProperty::net_wm_window_type_menu))
188 _type = Type_Menu;
189 else if (val[i] ==
190 property->atom(otk::OBProperty::net_wm_window_type_utility))
191 _type = Type_Utility;
192 else if (val[i] ==
193 property->atom(otk::OBProperty::net_wm_window_type_splash))
194 _type = Type_Splash;
195 else if (val[i] ==
196 property->atom(otk::OBProperty::net_wm_window_type_dialog))
197 _type = Type_Dialog;
198 else if (val[i] ==
199 property->atom(otk::OBProperty::net_wm_window_type_normal))
200 _type = Type_Normal;
201 // else if (val[i] ==
202 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
203 // mwm_decorations = 0; // prevent this window from getting any decor
204 // XXX: make this work again
205 }
206 delete val;
207 }
208
209 if (_type == (WindowType) -1) {
210 /*
211 * the window type hint was not set, which means we either classify ourself
212 * as a normal window or a dialog, depending on if we are a transient.
213 */
214 // XXX: make this code work!
215 //if (isTransient())
216 // _type = Type_Dialog;
217 //else
218 _type = Type_Normal;
219 }
220 }
221
222
223 void OBClient::getMwmHints()
224 {
225 const otk::OBProperty *property = Openbox::instance->property();
226
227 unsigned long num;
228 MwmHints *hints;
229
230 num = MwmHints::elements;
231 if (!property->get(_window, otk::OBProperty::motif_wm_hints,
232 otk::OBProperty::motif_wm_hints, &num,
233 (unsigned long **)&hints))
234 return;
235
236 if (num < MwmHints::elements) {
237 delete [] hints;
238 return;
239 }
240
241 // retrieved the hints
242 // Mwm Hints are applied subtractively to what has already been chosen for
243 // decor and functionality
244
245 if (hints->flags & MwmFlag_Decorations) {
246 if (! (hints->decorations & MwmDecor_All)) {
247 if (! (hints->decorations & MwmDecor_Border))
248 _decorations &= ~Decor_Border;
249 if (! (hints->decorations & MwmDecor_Handle))
250 _decorations &= ~Decor_Handle;
251 if (! (hints->decorations & MwmDecor_Title))
252 _decorations &= ~Decor_Titlebar;
253 if (! (hints->decorations & MwmDecor_Iconify))
254 _decorations &= ~Decor_Iconify;
255 if (! (hints->decorations & MwmDecor_Maximize))
256 _decorations &= ~Decor_Maximize;
257 }
258 }
259
260 if (hints->flags & MwmFlag_Functions) {
261 if (! (hints->functions & MwmFunc_All)) {
262 if (! (hints->functions & MwmFunc_Resize))
263 _functions &= ~Func_Resize;
264 if (! (hints->functions & MwmFunc_Move))
265 _functions &= ~Func_Move;
266 if (! (hints->functions & MwmFunc_Iconify))
267 _functions &= ~Func_Iconify;
268 if (! (hints->functions & MwmFunc_Maximize))
269 _functions &= ~Func_Maximize;
270 //if (! (hints->functions & MwmFunc_Close))
271 // _functions &= ~Func_Close;
272 }
273 }
274 delete [] hints;
275 }
276
277
278 void OBClient::getArea()
279 {
280 XWindowAttributes wattrib;
281 Status ret;
282
283 ret = XGetWindowAttributes(otk::OBDisplay::display, _window, &wattrib);
284 assert(ret != BadWindow);
285
286 _area.setRect(wattrib.x, wattrib.y, wattrib.width, wattrib.height);
287 _border_width = wattrib.border_width;
288 }
289
290
291 void OBClient::getState()
292 {
293 const otk::OBProperty *property = Openbox::instance->property();
294
295 _modal = _shaded = _max_horz = _max_vert = _fullscreen = _floating = false;
296
297 unsigned long *state;
298 unsigned long num = (unsigned) -1;
299
300 if (property->get(_window, otk::OBProperty::net_wm_state,
301 otk::OBProperty::Atom_Atom, &num, &state)) {
302 for (unsigned long i = 0; i < num; ++i) {
303 if (state[i] == property->atom(otk::OBProperty::net_wm_state_modal))
304 _modal = true;
305 else if (state[i] ==
306 property->atom(otk::OBProperty::net_wm_state_shaded))
307 _shaded = true;
308 else if (state[i] ==
309 property->atom(otk::OBProperty::net_wm_state_fullscreen))
310 _fullscreen = true;
311 else if (state[i] ==
312 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
313 _max_vert = true;
314 else if (state[i] ==
315 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
316 _max_horz = true;
317 }
318
319 delete [] state;
320 }
321 }
322
323
324 void OBClient::getShaped()
325 {
326 _shaped = false;
327 #ifdef SHAPE
328 if (otk::OBDisplay::shape()) {
329 int foo;
330 unsigned int ufoo;
331 int s;
332
333 XShapeSelectInput(otk::OBDisplay::display, _window, ShapeNotifyMask);
334
335 XShapeQueryExtents(otk::OBDisplay::display, _window, &s, &foo,
336 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
337 _shaped = (s != 0);
338 }
339 #endif // SHAPE
340 }
341
342
343 void OBClient::updateProtocols()
344 {
345 const otk::OBProperty *property = Openbox::instance->property();
346
347 Atom *proto;
348 int num_return = 0;
349
350 _focus_notify = false;
351 _decorations &= ~Decor_Close;
352 _functions &= ~Func_Close;
353
354 if (XGetWMProtocols(otk::OBDisplay::display, _window, &proto, &num_return)) {
355 for (int i = 0; i < num_return; ++i) {
356 if (proto[i] == property->atom(otk::OBProperty::wm_delete_window)) {
357 _decorations |= Decor_Close;
358 _functions |= Func_Close;
359 // XXX: update the decor?
360 } else if (proto[i] == property->atom(otk::OBProperty::wm_take_focus))
361 // if this protocol is requested, then the window will be notified
362 // by the window manager whenever it receives focus
363 _focus_notify = true;
364 }
365 XFree(proto);
366 }
367 }
368
369
370 void OBClient::updateNormalHints()
371 {
372 XSizeHints size;
373 long ret;
374 int oldgravity = _gravity;
375
376 // defaults
377 _gravity = NorthWestGravity;
378 _size_inc.setPoint(1, 1);
379 _base_size.setPoint(0, 0);
380 _min_size.setPoint(0, 0);
381 _max_size.setPoint(INT_MAX, INT_MAX);
382
383 // XXX: might want to cancel any interactive resizing of the window at this
384 // point..
385
386 // get the hints from the window
387 if (XGetWMNormalHints(otk::OBDisplay::display, _window, &size, &ret)) {
388 _positioned = (size.flags & (PPosition|USPosition));
389
390 if (size.flags & PWinGravity)
391 _gravity = size.win_gravity;
392
393 if (size.flags & PMinSize)
394 _min_size.setPoint(size.min_width, size.min_height);
395
396 if (size.flags & PMaxSize)
397 _max_size.setPoint(size.max_width, size.max_height);
398
399 if (size.flags & PBaseSize)
400 _base_size.setPoint(size.base_width, size.base_height);
401
402 if (size.flags & PResizeInc)
403 _size_inc.setPoint(size.width_inc, size.height_inc);
404 }
405
406 // if the client has a frame, i.e. has already been mapped and is
407 // changing its gravity
408 if (frame && _gravity != oldgravity) {
409 // move our idea of the client's position based on its new gravity
410 int x, y;
411 frame->frameGravity(x, y);
412 _area.setPos(x, y);
413 }
414 }
415
416
417 void OBClient::updateWMHints()
418 {
419 XWMHints *hints;
420
421 // assume a window takes input if it doesnt specify
422 _can_focus = true;
423 _urgent = false;
424
425 if ((hints = XGetWMHints(otk::OBDisplay::display, _window)) != NULL) {
426 if (hints->flags & InputHint)
427 _can_focus = hints->input;
428
429 if (hints->flags & XUrgencyHint)
430 _urgent = true;
431
432 if (hints->flags & WindowGroupHint) {
433 if (hints->window_group != _group) {
434 // XXX: remove from the old group if there was one
435 _group = hints->window_group;
436 // XXX: do stuff with the group
437 }
438 } else // no group!
439 _group = None;
440
441 XFree(hints);
442 }
443 }
444
445
446 void OBClient::updateTitle()
447 {
448 const otk::OBProperty *property = Openbox::instance->property();
449
450 _title = "";
451
452 // try netwm
453 if (! property->get(_window, otk::OBProperty::net_wm_name,
454 otk::OBProperty::utf8, &_title)) {
455 // try old x stuff
456 property->get(_window, otk::OBProperty::wm_name,
457 otk::OBProperty::ascii, &_title);
458 }
459
460 if (_title.empty())
461 _title = _("Unnamed Window");
462 }
463
464
465 void OBClient::updateIconTitle()
466 {
467 const otk::OBProperty *property = Openbox::instance->property();
468
469 _icon_title = "";
470
471 // try netwm
472 if (! property->get(_window, otk::OBProperty::net_wm_icon_name,
473 otk::OBProperty::utf8, &_icon_title)) {
474 // try old x stuff
475 property->get(_window, otk::OBProperty::wm_icon_name,
476 otk::OBProperty::ascii, &_icon_title);
477 }
478
479 if (_title.empty())
480 _icon_title = _("Unnamed Window");
481 }
482
483
484 void OBClient::updateClass()
485 {
486 const otk::OBProperty *property = Openbox::instance->property();
487
488 // set the defaults
489 _app_name = _app_class = "";
490
491 otk::OBProperty::StringVect v;
492 unsigned long num = 2;
493
494 if (! property->get(_window, otk::OBProperty::wm_class,
495 otk::OBProperty::ascii, &num, &v))
496 return;
497
498 if (num > 0) _app_name = v[0];
499 if (num > 1) _app_class = v[1];
500 }
501
502
503 void OBClient::propertyHandler(const XPropertyEvent &e)
504 {
505 otk::OtkEventHandler::propertyHandler(e);
506
507 const otk::OBProperty *property = Openbox::instance->property();
508
509 // compress changes to a single property into a single change
510 XEvent ce;
511 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
512 // XXX: it would be nice to compress ALL changes to a property, not just
513 // changes in a row without other props between.
514 if (ce.xproperty.atom != e.atom) {
515 XPutBackEvent(otk::OBDisplay::display, &ce);
516 break;
517 }
518 }
519
520 if (e.atom == XA_WM_NORMAL_HINTS)
521 updateNormalHints();
522 else if (e.atom == XA_WM_HINTS)
523 updateWMHints();
524 else if (e.atom == property->atom(otk::OBProperty::net_wm_name) ||
525 e.atom == property->atom(otk::OBProperty::wm_name))
526 updateTitle();
527 else if (e.atom == property->atom(otk::OBProperty::net_wm_icon_name) ||
528 e.atom == property->atom(otk::OBProperty::wm_icon_name))
529 updateIconTitle();
530 else if (e.atom == property->atom(otk::OBProperty::wm_class))
531 updateClass();
532 else if (e.atom == property->atom(otk::OBProperty::wm_protocols))
533 updateProtocols();
534 // XXX: transient for hint
535 // XXX: strut hint
536 }
537
538
539 void OBClient::setWMState(long state)
540 {
541 if (state == _wmstate) return; // no change
542
543 switch (state) {
544 case IconicState:
545 // XXX: cause it to iconify
546 break;
547 case NormalState:
548 // XXX: cause it to uniconify
549 break;
550 }
551 _wmstate = state;
552 }
553
554
555 void OBClient::setDesktop(long target)
556 {
557 assert(target >= 0);
558 //assert(target == 0xffffffff || target < MAX);
559
560 // XXX: move the window to the new desktop
561 _desktop = target;
562 }
563
564
565 void OBClient::setState(StateAction action, long data1, long data2)
566 {
567 const otk::OBProperty *property = Openbox::instance->property();
568
569 if (!(action == State_Add || action == State_Remove ||
570 action == State_Toggle))
571 return; // an invalid action was passed to the client message, ignore it
572
573 for (int i = 0; i < 2; ++i) {
574 Atom state = i == 0 ? data1 : data2;
575
576 if (! state) continue;
577
578 // if toggling, then pick whether we're adding or removing
579 if (action == State_Toggle) {
580 if (state == property->atom(otk::OBProperty::net_wm_state_modal))
581 action = _modal ? State_Remove : State_Add;
582 else if (state ==
583 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
584 action = _max_vert ? State_Remove : State_Add;
585 else if (state ==
586 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
587 action = _max_horz ? State_Remove : State_Add;
588 else if (state == property->atom(otk::OBProperty::net_wm_state_shaded))
589 action = _shaded ? State_Remove : State_Add;
590 else if (state ==
591 property->atom(otk::OBProperty::net_wm_state_fullscreen))
592 action = _fullscreen ? State_Remove : State_Add;
593 else if (state == property->atom(otk::OBProperty::net_wm_state_floating))
594 action = _floating ? State_Remove : State_Add;
595 }
596
597 if (action == State_Add) {
598 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
599 if (_modal) continue;
600 _modal = true;
601 // XXX: give it focus if another window has focus that shouldnt now
602 } else if (state ==
603 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
604 if (_max_vert) continue;
605 _max_vert = true;
606 // XXX: resize the window etc
607 } else if (state ==
608 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
609 if (_max_horz) continue;
610 _max_horz = true;
611 // XXX: resize the window etc
612 } else if (state ==
613 property->atom(otk::OBProperty::net_wm_state_shaded)) {
614 if (_shaded) continue;
615 _shaded = true;
616 // XXX: hide the client window
617 } else if (state ==
618 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
619 if (_fullscreen) continue;
620 _fullscreen = true;
621 // XXX: raise the window n shit
622 } else if (state ==
623 property->atom(otk::OBProperty::net_wm_state_floating)) {
624 if (_floating) continue;
625 _floating = true;
626 // XXX: raise the window n shit
627 }
628
629 } else { // action == State_Remove
630 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
631 if (!_modal) continue;
632 _modal = false;
633 } else if (state ==
634 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
635 if (!_max_vert) continue;
636 _max_vert = false;
637 // XXX: resize the window etc
638 } else if (state ==
639 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
640 if (!_max_horz) continue;
641 _max_horz = false;
642 // XXX: resize the window etc
643 } else if (state ==
644 property->atom(otk::OBProperty::net_wm_state_shaded)) {
645 if (!_shaded) continue;
646 _shaded = false;
647 // XXX: show the client window
648 } else if (state ==
649 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
650 if (!_fullscreen) continue;
651 _fullscreen = false;
652 // XXX: lower the window to its proper layer
653 } else if (state ==
654 property->atom(otk::OBProperty::net_wm_state_floating)) {
655 if (!_floating) continue;
656 _floating = false;
657 // XXX: lower the window to its proper layer
658 }
659 }
660 }
661 }
662
663
664 void OBClient::toggleClientBorder(bool addborder)
665 {
666 // adjust our idea of where the client is, based on its border. When the
667 // border is removed, the client should now be considered to be in a
668 // different position.
669 // when re-adding the border to the client, the same operation needs to be
670 // reversed.
671 int x = _area.x(), y = _area.y();
672 switch(_gravity) {
673 case NorthWestGravity:
674 case WestGravity:
675 case SouthWestGravity:
676 if (addborder) x += _border_width;
677 else x -= _border_width;
678 break;
679 case NorthEastGravity:
680 case EastGravity:
681 case SouthEastGravity:
682 if (addborder) x -= _border_width * 2;
683 else x += _border_width * 2;
684 break;
685 }
686 switch(_gravity) {
687 case NorthWestGravity:
688 case NorthGravity:
689 case NorthEastGravity:
690 if (addborder) y += _border_width;
691 else y -= _border_width;
692 break;
693 case SouthWestGravity:
694 case SouthGravity:
695 case SouthEastGravity:
696 if (addborder) y -= _border_width * 2;
697 else y += _border_width * 2;
698 break;
699 default:
700 // no change for StaticGravity etc.
701 break;
702 }
703 _area.setPos(x, y);
704
705 if (addborder) {
706 XSetWindowBorderWidth(otk::OBDisplay::display, _window, _border_width);
707
708 // move the client so it is back it the right spot _with_ its border!
709 XMoveWindow(otk::OBDisplay::display, _window, x, y);
710 } else
711 XSetWindowBorderWidth(otk::OBDisplay::display, _window, 0);
712 }
713
714
715 void OBClient::clientMessageHandler(const XClientMessageEvent &e)
716 {
717 otk::OtkEventHandler::clientMessageHandler(e);
718
719 if (e.format != 32) return;
720
721 const otk::OBProperty *property = Openbox::instance->property();
722
723 if (e.message_type == property->atom(otk::OBProperty::wm_change_state)) {
724 // compress changes into a single change
725 bool compress = false;
726 XEvent ce;
727 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
728 // XXX: it would be nice to compress ALL messages of a type, not just
729 // messages in a row without other message types between.
730 if (ce.xclient.message_type != e.message_type) {
731 XPutBackEvent(otk::OBDisplay::display, &ce);
732 break;
733 }
734 compress = true;
735 }
736 if (compress)
737 setWMState(ce.xclient.data.l[0]); // use the found event
738 else
739 setWMState(e.data.l[0]); // use the original event
740 } else if (e.message_type ==
741 property->atom(otk::OBProperty::net_wm_desktop)) {
742 // compress changes into a single change
743 bool compress = false;
744 XEvent ce;
745 while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
746 // XXX: it would be nice to compress ALL messages of a type, not just
747 // messages in a row without other message types between.
748 if (ce.xclient.message_type != e.message_type) {
749 XPutBackEvent(otk::OBDisplay::display, &ce);
750 break;
751 }
752 compress = true;
753 }
754 if (compress)
755 setDesktop(e.data.l[0]); // use the found event
756 else
757 setDesktop(e.data.l[0]); // use the original event
758 }
759 else if (e.message_type == property->atom(otk::OBProperty::net_wm_state))
760 // can't compress these
761 setState((StateAction)e.data.l[0], e.data.l[1], e.data.l[2]);
762 }
763
764
765 #if defined(SHAPE) || defined(DOXYGEN_IGNORE)
766 void OBClient::shapeHandler(const XShapeEvent &e)
767 {
768 otk::OtkEventHandler::shapeHandler(e);
769
770 _shaped = e.shaped;
771 }
772 #endif
773
774
775 void OBClient::resize(Corner anchor, int w, int h)
776 {
777 w -= _base_size.x();
778 h -= _base_size.y();
779
780 // is the window resizable? if it is not, then don't check its sizes, the
781 // client can do what it wants and the user can't change it anyhow
782 if (_min_size.x() <= _max_size.x() && _min_size.y() <= _max_size.y()) {
783 // smaller than min size or bigger than max size?
784 if (w < _min_size.x()) w = _min_size.x();
785 else if (w > _max_size.x()) w = _max_size.x();
786 if (h < _min_size.y()) h = _min_size.y();
787 else if (h > _max_size.y()) h = _max_size.y();
788 }
789
790 // keep to the increments
791 w /= _size_inc.x();
792 h /= _size_inc.y();
793
794 // store the logical size
795 _logical_size.setPoint(w, h);
796
797 w *= _size_inc.x();
798 h *= _size_inc.y();
799
800 w += _base_size.x();
801 h += _base_size.y();
802
803 int x = _area.x(), y = _area.y();
804 switch (anchor) {
805 case TopLeft:
806 break;
807 case TopRight:
808 x -= w - _area.width();
809 break;
810 case BottomLeft:
811 y -= h - _area.height();
812 break;
813 case BottomRight:
814 x -= w - _area.width();
815 y -= h - _area.height();
816 break;
817 }
818
819 _area.setSize(w, h);
820 XResizeWindow(otk::OBDisplay::display, _window, w, h);
821
822 // resize the frame to match the request
823 frame->adjustSize();
824 move(x, y);
825 }
826
827
828 void OBClient::move(int x, int y)
829 {
830 _area.setPos(x, y);
831 // move the frame to be in the requested position
832 frame->adjustPosition();
833 }
834
835
836 void OBClient::configureRequestHandler(const XConfigureRequestEvent &e)
837 {
838 OtkEventHandler::configureRequestHandler(e);
839
840 // XXX: if we are iconic (or shaded? (fvwm does that)) ignore the event
841
842 if (e.value_mask & CWBorderWidth)
843 _border_width = e.border_width;
844
845 // resize, then move, as specified in the EWMH section 7.7
846 if (e.value_mask & (CWWidth | CWHeight)) {
847 int w = (e.value_mask & CWWidth) ? e.width : _area.width();
848 int h = (e.value_mask & CWHeight) ? e.height : _area.height();
849
850 Corner corner;
851 switch (_gravity) {
852 case NorthEastGravity:
853 case EastGravity:
854 corner = TopRight;
855 break;
856 case SouthWestGravity:
857 case SouthGravity:
858 corner = BottomLeft;
859 break;
860 case SouthEastGravity:
861 corner = BottomRight;
862 break;
863 default: // NorthWest, Static, etc
864 corner = TopLeft;
865 }
866
867 resize(corner, w, h);
868 }
869
870 if (e.value_mask & (CWX | CWY)) {
871 int x = (e.value_mask & CWX) ? e.x : _area.x();
872 int y = (e.value_mask & CWY) ? e.y : _area.y();
873 move(x, y);
874 }
875
876 if (e.value_mask & CWStackMode) {
877 switch (e.detail) {
878 case Below:
879 case BottomIf:
880 // XXX: lower the window
881 break;
882
883 case Above:
884 case TopIf:
885 default:
886 // XXX: raise the window
887 break;
888 }
889 }
890 }
891
892
893 void OBClient::unmapHandler(const XUnmapEvent &e)
894 {
895 #ifdef DEBUG
896 printf("UnmapNotify for 0x%lx\n", e.window);
897 #endif // DEBUG
898
899 if (ignore_unmaps) {
900 ignore_unmaps--;
901 return;
902 }
903
904 OtkEventHandler::unmapHandler(e);
905
906 // this deletes us etc
907 Openbox::instance->screen(_screen)->unmanageWindow(this);
908 }
909
910
911 void OBClient::destroyHandler(const XDestroyWindowEvent &e)
912 {
913 #ifdef DEBUG
914 printf("DestroyNotify for 0x%lx\n", e.window);
915 #endif // DEBUG
916
917 OtkEventHandler::destroyHandler(e);
918
919 // this deletes us etc
920 Openbox::instance->screen(_screen)->unmanageWindow(this);
921 }
922
923
924 }
This page took 0.078564 seconds and 4 git commands to generate.