gets a whole lotta window information now, and updtes when it changes!
Dana Jansens danakj@orodu.net
3 files changed,
64 insertions(+),
10 deletions(-)
M
util/epist/process.cc
→
util/epist/process.cc
@@ -41,18 +41,24 @@ WindowList _clients;
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) {@@ -74,15 +80,19 @@ }
} 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; } }
M
util/epist/window.cc
→
util/epist/window.cc
@@ -35,13 +35,14 @@ using std::endl;
using std::hex; using std::dec; - XWindow::XWindow(Window window) : _window(window) { _unmapped = false; XSelectInput(_display, _window, PropertyChangeMask | StructureNotifyMask); updateState(); updateDesktop(); + updateTitle(); + updateClass(); }@@ -80,3 +81,32 @@ if (! _xatom->getValue(_window, XAtom::net_wm_desktop, XAtom::cardinal,
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]; +}
M
util/epist/window.hh
→
util/epist/window.hh
@@ -28,6 +28,7 @@ #include <X11/Xlib.h>
} #include <list> +#include <string> class XWindow;@@ -36,7 +37,13 @@
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;@@ -49,7 +56,12 @@ XWindow(Window window);
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; }@@ -59,6 +71,8 @@ inline void setUnmapped(bool u) { _unmapped = u; }
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; }