1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // process.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.
28 # include "../../config.h"
29 #endif // HAVE_CONFIG_H
36 #include "../../src/XAtom.hh"
39 WindowList::iterator _active = _clients.end();
41 void processEvent(const XEvent &e) {
44 if (e.xany.window == _root) {
46 if (e.xproperty.atom == _xatom->getAtom(XAtom::net_active_window))
48 if (e.xproperty.atom == _xatom->getAtom(XAtom::net_client_list))
52 WindowList::iterator it, end = _clients.end();
53 for (it = _clients.begin(); it != end; ++it)
54 if (*it == e.xproperty.window)
56 assert(it != end); // this means a client somehow got removed from the
65 void updateClientList() {
66 WindowList::iterator insert_point = _active;
67 if (insert_point != _clients.end())
68 ++insert_point; // get to the item client the focused client
70 // get the client list from the root window
71 Window *rootclients = 0;
72 unsigned long num = (unsigned) -1;
73 if (! _xatom->getValue(_root, XAtom::net_client_list, XAtom::window, num,
75 _clients.clear(); // no clients left
76 if (rootclients) delete [] rootclients;
80 WindowList::iterator it, end = _clients.end();
83 // insert new clients after the active window
84 for (i = 0; i < num; ++i) {
85 for (it = _clients.begin(); it != end; ++it)
86 if (*it == rootclients[i])
88 if (it == end) { // didn't already exist
89 _clients.insert(insert_point, rootclients[i]);
90 cout << "Added window: " << rootclients[i] << endl;
94 // remove clients that no longer exist
95 for (it = _clients.begin(); it != end;) {
96 WindowList::iterator it2 = it++;
97 for (i = 0; i < num; ++i)
98 if (*it2 == rootclients[i])
100 if (i == num) { // no longer exists
102 cout << "Removed window: " << it2->window() << endl;
106 if (rootclients) delete [] rootclients;
110 void updateActiveWindow() {
112 _xatom->getValue(_root, XAtom::net_active_window, XAtom::window, a);
114 WindowList::iterator it, end = _clients.end();
115 for (it = _clients.begin(); it != end; ++it) {
121 cout << "Active window is now: ";
122 if (_active == _clients.end()) cout << "None\n";
123 else cout << _active->window() << endl;