]>
Dogcows Code - chaz/openbox/blob - util/epist/process.cc
7ff86963cb431caa8ec240e95b421e04af6e2af4
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
38 #include "../../src/XAtom.hh"
41 WindowList::iterator _active
= _clients
.end();
44 XWindow
*findWindow(const XEvent
&e
) {
45 WindowList::iterator it
, end
= _clients
.end();
46 for (it
= _clients
.begin(); it
!= end
; ++it
)
47 if (**it
== e
.xany
.window
)
55 void processEvent(const XEvent
&e
) {
57 if (e
.xany
.window
!= _root
) {
58 window
= findWindow(e
); // find the window
59 assert(window
); // we caught an event for a window we don't know about!?
64 if (e
.xany
.window
== _root
) {
66 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_active_window
))
68 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_client_list
)) {
69 // catch any window unmaps first
71 if (XCheckTypedWindowEvent(_display
, e
.xany
.window
,
72 DestroyNotify
, &ev
) ||
73 XCheckTypedWindowEvent(_display
, e
.xany
.window
,
82 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_state
))
83 window
->updateState();
84 else if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_desktop
))
85 window
->updateDesktop();
86 else if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_name
) ||
87 e
.xproperty
.atom
== _xatom
->getAtom(XAtom::wm_name
))
88 window
->updateTitle();
89 else if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::wm_class
))
90 window
->updateClass();
95 window
->setUnmapped(true);
101 // do we want to add this window to our list?
102 bool doAddWindow(Window window
) {
104 if (! _xatom
->getValue(window
, XAtom::net_wm_window_type
, XAtom::atom
,
108 if (type
== _xatom
->getAtom(XAtom::net_wm_window_type_dock
) ||
109 type
== _xatom
->getAtom(XAtom::net_wm_window_type_menu
))
116 void updateClientList() {
117 WindowList::iterator insert_point
= _active
;
118 if (insert_point
!= _clients
.end())
119 ++insert_point
; // get to the item client the focused client
121 // get the client list from the root window
122 Window
*rootclients
= 0;
123 unsigned long num
= (unsigned) -1;
124 if (! _xatom
->getValue(_root
, XAtom::net_client_list
, XAtom::window
, num
,
126 while (! _clients
.empty()) {
127 delete _clients
.front();
128 _clients
.erase(_clients
.begin());
130 if (rootclients
) delete [] rootclients
;
134 WindowList::iterator it
, end
= _clients
.end();
137 // insert new clients after the active window
138 for (i
= 0; i
< num
; ++i
) {
139 for (it
= _clients
.begin(); it
!= end
; ++it
)
140 if (**it
== rootclients
[i
])
142 if (it
== end
) { // didn't already exist
143 if (doAddWindow(rootclients
[i
])) {
144 cout
<< "Added window: 0x" << hex
<< rootclients
[i
] << dec
<< endl
;
145 _clients
.insert(insert_point
, new XWindow(rootclients
[i
]));
150 // remove clients that no longer exist
151 for (it
= _clients
.begin(); it
!= end
;) {
152 WindowList::iterator it2
= it
++;
153 for (i
= 0; i
< num
; ++i
)
154 if (**it2
== rootclients
[i
])
156 if (i
== num
) { // no longer exists
157 cout
<< "Removed window: 0x" << hex
<< (*it2
)->window() << dec
<< endl
;
163 if (rootclients
) delete [] rootclients
;
167 void updateActiveWindow() {
169 _xatom
->getValue(_root
, XAtom::net_active_window
, XAtom::window
, a
);
171 WindowList::iterator it
, end
= _clients
.end();
172 for (it
= _clients
.begin(); it
!= end
; ++it
) {
178 cout
<< "Active window is now: ";
179 if (_active
== _clients
.end()) cout
<< "None\n";
180 else cout
<< "0x" << hex
<< (*_active
)->window() << dec
<< endl
;
This page took 0.040854 seconds and 4 git commands to generate.