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>
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
24 # include "../../config.h"
25 #endif // HAVE_CONFIG_H
36 #include "../../src/XAtom.hh"
38 XWindow::XWindow(epist *epist, Window window)
39 : _epist(epist), _xatom(epist->xatom()), _window(window) {
43 XSelectInput(_epist->getXDisplay(), _window,
44 PropertyChangeMask | StructureNotifyMask);
50 _epist->addWindow(this);
56 XSelectInput(_epist->getXDisplay(), _window, None);
57 _epist->removeWindow(this);
61 void XWindow::updateState() {
63 _shaded = _iconic = _max_vert = _max_horz = false;
65 unsigned long num = (unsigned) -1;
67 if (! _xatom->getValue(_window, XAtom::net_wm_state, XAtom::atom,
70 for (unsigned long i = 0; i < num; ++i) {
71 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_vert))
73 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_horz))
75 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_shaded))
77 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_hidden))
85 void XWindow::updateDesktop() {
86 if (! _xatom->getValue(_window, XAtom::net_wm_desktop, XAtom::cardinal,
87 static_cast<unsigned long>(_desktop)))
92 void XWindow::updateTitle() {
96 if (! _xatom->getValue(_window, XAtom::net_wm_name, XAtom::utf8, _title)) {
98 _xatom->getValue(_window, XAtom::wm_name, XAtom::ansi, _title);
106 void XWindow::updateClass() {
108 _app_name = _app_class = "";
111 unsigned long num = 2;
113 if (! _xatom->getValue(_window, XAtom::wm_class, XAtom::ansi, num, v))
116 if (num > 0) _app_name = v[0];
117 if (num > 1) _app_class = v[1];
121 void XWindow::processEvent(const XEvent &e) {
122 assert(e.xany.window == _window);
127 if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_state))
129 else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop))
131 else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_name) ||
132 e.xproperty.atom == _xatom->getAtom(XAtom::wm_name))
134 else if (e.xproperty.atom == _xatom->getAtom(XAtom::wm_class))