]> icculus.org git repositories - mikachu/openbox.git/blob - util/epist/window.cc
we now know for every window its state and its desktop
[mikachu/openbox.git] / util / epist / window.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // window.cc for Epistory - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifdef    HAVE_CONFIG_H
24 #  include "../../config.h"
25 #endif // HAVE_CONFIG_H
26
27 #include "window.hh"
28 #include "epist.hh"
29 #include "../../src/XAtom.hh"
30
31 #include <iostream>
32
33 using std::cout;
34 using std::endl;
35 using std::hex;
36 using std::dec;
37
38
39 XWindow::XWindow(Window window) : _window(window) {
40   _unmapped = false;
41
42   XSelectInput(_display, _window, PropertyChangeMask | StructureNotifyMask);
43   updateState();
44   updateDesktop();
45 }
46
47
48 XWindow::~XWindow() {
49   if (! _unmapped)
50     XSelectInput(_display, _window, None);
51 }
52
53
54 void XWindow::updateState() {
55   // set the defaults
56   _shaded = _iconic = _max_vert = _max_horz = false;
57   
58   unsigned long num = (unsigned) -1;
59   Atom *state;
60   if (! _xatom->getValue(_window, XAtom::net_wm_state, XAtom::atom,
61                          num, &state))
62     return;
63   for (unsigned long i = 0; i < num; ++i) {
64     if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_vert))
65       _max_vert = true;
66     if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_horz))
67       _max_horz = true;
68     if (state[i] == _xatom->getAtom(XAtom::net_wm_state_shaded))
69       _shaded = true;
70     if (state[i] == _xatom->getAtom(XAtom::net_wm_state_hidden))
71       _iconic = true;
72   }
73
74   delete [] state;
75 }
76
77
78 void XWindow::updateDesktop() {
79   if (! _xatom->getValue(_window, XAtom::net_wm_desktop, XAtom::cardinal,
80                          static_cast<unsigned long>(_desktop)))
81     _desktop = 0;
82 }