WindowList::iterator _active = _clients.end();
-XWindow &findWindow(const XEvent &e) {
+XWindow *findWindow(const XEvent &e) {
WindowList::iterator it, end = _clients.end();
for (it = _clients.begin(); it != end; ++it)
if (**it == e.xany.window)
break;
- assert(it != end); // this means a client somehow got removed from the
- // list!
- return **it;
+ if(it == end)
+ return 0;
+ return *it;
}
void processEvent(const XEvent &e) {
+ XWindow *window = 0;
+ if (e.xany.window != _root) {
+ window = findWindow(e); // find the window
+ assert(window); // we caught an event for a window we don't know about!?
+ }
+
switch (e.type) {
case PropertyNotify:
if (e.xany.window == _root) {
} else {
// a client window
if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_state))
- findWindow(e).updateState();
- if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop))
- findWindow(e).updateDesktop();
+ window->updateState();
+ else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop))
+ window->updateDesktop();
+ else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_name) ||
+ e.xproperty.atom == _xatom->getAtom(XAtom::wm_name))
+ window->updateTitle();
+ else if (e.xproperty.atom == _xatom->getAtom(XAtom::wm_class))
+ window->updateClass();
}
break;
case DestroyNotify:
case UnmapNotify:
- cout << "unmap notify\n";
- findWindow(e).setUnmapped(true);
+ window->setUnmapped(true);
break;
}
}
using std::hex;
using std::dec;
-
XWindow::XWindow(Window window) : _window(window) {
_unmapped = false;
XSelectInput(_display, _window, PropertyChangeMask | StructureNotifyMask);
updateState();
updateDesktop();
+ updateTitle();
+ updateClass();
}
static_cast<unsigned long>(_desktop)))
_desktop = 0;
}
+
+
+void XWindow::updateTitle() {
+ _title = "";
+
+ // try netwm
+ if (! _xatom->getValue(_window, XAtom::net_wm_name, XAtom::utf8, _title)) {
+ // try old x stuff
+ _xatom->getValue(_window, XAtom::wm_name, XAtom::ansi, _title);
+ }
+
+ if (_title.empty())
+ _title = "Unnamed";
+}
+
+
+void XWindow::updateClass() {
+ // set the defaults
+ _app_name = _app_class = "";
+
+ XAtom::StringVect v;
+ unsigned long num = 2;
+
+ if (! _xatom->getValue(_window, XAtom::wm_class, XAtom::ansi, num, v))
+ return;
+
+ if (num > 0) _app_name = v[0];
+ if (num > 1) _app_class = v[1];
+}
}
#include <list>
+#include <string>
class XWindow;
class XWindow {
private:
Window _window;
+
unsigned int _desktop;
+ std::string _title;
+ std::string _app_name;
+ std::string _app_class;
+
+ // states
bool _shaded;
bool _iconic;
bool _max_vert;
virtual ~XWindow();
inline Window window() const { return _window; }
+
inline unsigned int desktop() const { return _desktop; }
+ inline const std::string &title() const { return _title; }
+ inline const std::string &appName() const { return _app_name; }
+ inline const std::string &appClass() const { return _app_name; }
+
inline bool shaded() const { return _shaded; }
inline bool iconic() const { return _iconic; }
inline bool maxVert() const { return _max_vert; }
void updateState();
void updateDesktop();
+ void updateTitle();
+ void updateClass();
bool operator == (const XWindow &w) const { return w._window == _window; }
bool operator == (const Window &w) const { return w == _window; }