1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // window.cc for Epistophy - 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
37 #include "../../src/XAtom.hh"
39 XWindow::XWindow(epist
*epist
, screen
*screen
, Window window
)
40 : _epist(epist
), _screen(screen
), _xatom(epist
->xatom()), _window(window
) {
44 XSelectInput(_epist
->getXDisplay(), _window
,
45 PropertyChangeMask
| StructureNotifyMask
);
51 _epist
->addWindow(this);
57 XSelectInput(_epist
->getXDisplay(), _window
, None
);
58 _epist
->removeWindow(this);
62 void XWindow::updateState() {
64 _shaded
= _iconic
= _max_vert
= _max_horz
= false;
66 unsigned long num
= (unsigned) -1;
68 if (! _xatom
->getValue(_window
, XAtom::net_wm_state
, XAtom::atom
,
71 for (unsigned long i
= 0; i
< num
; ++i
) {
72 if (state
[i
] == _xatom
->getAtom(XAtom::net_wm_state_maximized_vert
))
74 if (state
[i
] == _xatom
->getAtom(XAtom::net_wm_state_maximized_horz
))
76 if (state
[i
] == _xatom
->getAtom(XAtom::net_wm_state_shaded
))
78 if (state
[i
] == _xatom
->getAtom(XAtom::net_wm_state_hidden
))
86 void XWindow::updateDesktop() {
87 if (! _xatom
->getValue(_window
, XAtom::net_wm_desktop
, XAtom::cardinal
,
88 static_cast<unsigned long>(_desktop
)))
93 void XWindow::updateTitle() {
97 if (! _xatom
->getValue(_window
, XAtom::net_wm_name
, XAtom::utf8
, _title
)) {
99 _xatom
->getValue(_window
, XAtom::wm_name
, XAtom::ansi
, _title
);
107 void XWindow::updateClass() {
109 _app_name
= _app_class
= "";
112 unsigned long num
= 2;
114 if (! _xatom
->getValue(_window
, XAtom::wm_class
, XAtom::ansi
, num
, v
))
117 if (num
> 0) _app_name
= v
[0];
118 if (num
> 1) _app_class
= v
[1];
122 void XWindow::processEvent(const XEvent
&e
) {
123 assert(e
.xany
.window
== _window
);
128 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_state
))
130 else if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_desktop
))
132 else if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_name
) ||
133 e
.xproperty
.atom
== _xatom
->getAtom(XAtom::wm_name
))
135 else if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::wm_class
))
146 void XWindow::shade(const bool sh
) const {
147 _xatom
->sendClientMessage(_screen
->rootWindow(), XAtom::net_wm_state
,
148 _window
, (sh
? 1 : 0),
149 _xatom
->getAtom(XAtom::net_wm_state_shaded
));
153 void XWindow::close() const {
154 _xatom
->sendClientMessage(_screen
->rootWindow(), XAtom::net_close_window
,
159 void XWindow::raise() const {
160 XRaiseWindow(_epist
->getXDisplay(), _window
);
164 void XWindow::lower() const {
165 XLowerWindow(_epist
->getXDisplay(), _window
);
169 void XWindow::iconify() const {
170 _xatom
->sendClientMessage(_screen
->rootWindow(), XAtom::wm_change_state
,
171 _window
, IconicState
);
175 void XWindow::focus() const {
176 // this will also unshade the window..
177 _xatom
->sendClientMessage(_screen
->rootWindow(), XAtom::net_active_window
,