]>
Dogcows Code - chaz/openbox/blob - util/epist/process.cc
893670c451ec972b2dee102e562d2e681219cacc
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
)
49 assert(it
!= end
); // this means a client somehow got removed from the
55 void processEvent(const XEvent
&e
) {
58 if (e
.xany
.window
== _root
) {
60 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_active_window
))
62 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_client_list
)) {
63 // catch any window unmaps first
65 if (XCheckTypedWindowEvent(_display
, e
.xany
.window
,
66 DestroyNotify
, &ev
) ||
67 XCheckTypedWindowEvent(_display
, e
.xany
.window
,
76 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_state
))
77 findWindow(e
).updateState();
78 if (e
.xproperty
.atom
== _xatom
->getAtom(XAtom::net_wm_desktop
))
79 findWindow(e
).updateDesktop();
84 cout
<< "unmap notify\n";
85 findWindow(e
).setUnmapped(true);
91 // do we want to add this window to our list?
92 bool doAddWindow(Window window
) {
94 if (! _xatom
->getValue(window
, XAtom::net_wm_window_type
, XAtom::atom
,
98 if (type
== _xatom
->getAtom(XAtom::net_wm_window_type_dock
) ||
99 type
== _xatom
->getAtom(XAtom::net_wm_window_type_menu
))
106 void updateClientList() {
107 WindowList::iterator insert_point
= _active
;
108 if (insert_point
!= _clients
.end())
109 ++insert_point
; // get to the item client the focused client
111 // get the client list from the root window
112 Window
*rootclients
= 0;
113 unsigned long num
= (unsigned) -1;
114 if (! _xatom
->getValue(_root
, XAtom::net_client_list
, XAtom::window
, num
,
116 while (! _clients
.empty()) {
117 delete _clients
.front();
118 _clients
.erase(_clients
.begin());
120 if (rootclients
) delete [] rootclients
;
124 WindowList::iterator it
, end
= _clients
.end();
127 // insert new clients after the active window
128 for (i
= 0; i
< num
; ++i
) {
129 for (it
= _clients
.begin(); it
!= end
; ++it
)
130 if (**it
== rootclients
[i
])
132 if (it
== end
) { // didn't already exist
133 if (doAddWindow(rootclients
[i
])) {
134 cout
<< "Added window: 0x" << hex
<< rootclients
[i
] << dec
<< endl
;
135 _clients
.insert(insert_point
, new XWindow(rootclients
[i
]));
140 // remove clients that no longer exist
141 for (it
= _clients
.begin(); it
!= end
;) {
142 WindowList::iterator it2
= it
++;
143 for (i
= 0; i
< num
; ++i
)
144 if (**it2
== rootclients
[i
])
146 if (i
== num
) { // no longer exists
147 cout
<< "Removed window: 0x" << hex
<< (*it2
)->window() << dec
<< endl
;
153 if (rootclients
) delete [] rootclients
;
157 void updateActiveWindow() {
159 _xatom
->getValue(_root
, XAtom::net_active_window
, XAtom::window
, a
);
161 WindowList::iterator it
, end
= _clients
.end();
162 for (it
= _clients
.begin(); it
!= end
; ++it
) {
168 cout
<< "Active window is now: ";
169 if (_active
== _clients
.end()) cout
<< "None\n";
170 else cout
<< "0x" << hex
<< (*_active
)->window() << dec
<< endl
;
This page took 0.041352 seconds and 4 git commands to generate.