]> Dogcows Code - chaz/openbox/blob - util/epist/window.cc
some of the actions I came up with
[chaz/openbox] / 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 XWindow::XWindow(Window window) : _window(window) {
39 _unmapped = false;
40
41 XSelectInput(_display, _window, PropertyChangeMask | StructureNotifyMask);
42 updateState();
43 updateDesktop();
44 updateTitle();
45 updateClass();
46 }
47
48
49 XWindow::~XWindow() {
50 if (! _unmapped)
51 XSelectInput(_display, _window, None);
52 }
53
54
55 void XWindow::updateState() {
56 // set the defaults
57 _shaded = _iconic = _max_vert = _max_horz = false;
58
59 unsigned long num = (unsigned) -1;
60 Atom *state;
61 if (! _xatom->getValue(_window, XAtom::net_wm_state, XAtom::atom,
62 num, &state))
63 return;
64 for (unsigned long i = 0; i < num; ++i) {
65 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_vert))
66 _max_vert = true;
67 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_maximized_horz))
68 _max_horz = true;
69 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_shaded))
70 _shaded = true;
71 if (state[i] == _xatom->getAtom(XAtom::net_wm_state_hidden))
72 _iconic = true;
73 }
74
75 delete [] state;
76 }
77
78
79 void XWindow::updateDesktop() {
80 if (! _xatom->getValue(_window, XAtom::net_wm_desktop, XAtom::cardinal,
81 static_cast<unsigned long>(_desktop)))
82 _desktop = 0;
83 }
84
85
86 void XWindow::updateTitle() {
87 _title = "";
88
89 // try netwm
90 if (! _xatom->getValue(_window, XAtom::net_wm_name, XAtom::utf8, _title)) {
91 // try old x stuff
92 _xatom->getValue(_window, XAtom::wm_name, XAtom::ansi, _title);
93 }
94
95 if (_title.empty())
96 _title = "Unnamed";
97 }
98
99
100 void XWindow::updateClass() {
101 // set the defaults
102 _app_name = _app_class = "";
103
104 XAtom::StringVect v;
105 unsigned long num = 2;
106
107 if (! _xatom->getValue(_window, XAtom::wm_class, XAtom::ansi, num, v))
108 return;
109
110 if (num > 0) _app_name = v[0];
111 if (num > 1) _app_class = v[1];
112 }
This page took 0.036427 seconds and 4 git commands to generate.