]> Dogcows Code - chaz/openbox/blob - util/epist/window.cc
fix typos
[chaz/openbox] / util / epist / window.cc
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>
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 <iostream>
28
29 using std::cout;
30 using std::endl;
31 using std::hex;
32 using std::dec;
33
34 #include "window.hh"
35 #include "epist.hh"
36 #include "../../src/XAtom.hh"
37
38 XWindow::XWindow(epist *epist, Window window)
39 : _epist(epist), _xatom(epist->xatom()), _window(window) {
40
41 _unmapped = false;
42
43 XSelectInput(_epist->getXDisplay(), _window,
44 PropertyChangeMask | StructureNotifyMask);
45 updateState();
46 updateDesktop();
47 updateTitle();
48 updateClass();
49
50 _epist->addWindow(this);
51 }
52
53
54 XWindow::~XWindow() {
55 if (! _unmapped)
56 XSelectInput(_epist->getXDisplay(), _window, None);
57 _epist->removeWindow(this);
58 }
59
60
61 void XWindow::updateState() {
62 // set the defaults
63 _shaded = _iconic = _max_vert = _max_horz = false;
64
65 unsigned long num = (unsigned) -1;
66 Atom *state;
67 if (! _xatom->getValue(_window, XAtom::net_wm_state, XAtom::atom,
68 num, &state))
69 return;
70 for (unsigned long i = 0; i < num; ++i) {
71 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_vert))
72 _max_vert = true;
73 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_horz))
74 _max_horz = true;
75 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_shaded))
76 _shaded = true;
77 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_hidden))
78 _iconic = true;
79 }
80
81 delete [] state;
82 }
83
84
85 void XWindow::updateDesktop() {
86 if (! _xatom->getValue(_window, XAtom::net_wm_desktop, XAtom::cardinal,
87 static_cast<unsigned long>(_desktop)))
88 _desktop = 0;
89 }
90
91
92 void XWindow::updateTitle() {
93 _title = "";
94
95 // try netwm
96 if (! _xatom->getValue(_window, XAtom::net_wm_name, XAtom::utf8, _title)) {
97 // try old x stuff
98 _xatom->getValue(_window, XAtom::wm_name, XAtom::ansi, _title);
99 }
100
101 if (_title.empty())
102 _title = "Unnamed";
103 }
104
105
106 void XWindow::updateClass() {
107 // set the defaults
108 _app_name = _app_class = "";
109
110 XAtom::StringVect v;
111 unsigned long num = 2;
112
113 if (! _xatom->getValue(_window, XAtom::wm_class, XAtom::ansi, num, v))
114 return;
115
116 if (num > 0) _app_name = v[0];
117 if (num > 1) _app_class = v[1];
118 }
119
120
121 void XWindow::processEvent(const XEvent &e) {
122 assert(e.xany.window == _window);
123
124 switch (e.type) {
125 case PropertyNotify:
126 // a client window
127 if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_state))
128 updateState();
129 else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop))
130 updateDesktop();
131 else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_name) ||
132 e.xproperty.atom == _xatom->getAtom(XAtom::wm_name))
133 updateTitle();
134 else if (e.xproperty.atom == _xatom->getAtom(XAtom::wm_class))
135 updateClass();
136 break;
137 case DestroyNotify:
138 case UnmapNotify:
139 _unmapped = true;
140 break;
141 }
142 }
This page took 0.046673 seconds and 5 git commands to generate.