From 5112b6270431cf1fe288d63e15bfbe689c0624bf Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 12 Jul 2002 02:48:43 +0000 Subject: [PATCH] gets a whole lotta window information now, and updtes when it changes! --- util/epist/process.cc | 28 +++++++++++++++++++--------- util/epist/window.cc | 32 +++++++++++++++++++++++++++++++- util/epist/window.hh | 14 ++++++++++++++ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/util/epist/process.cc b/util/epist/process.cc index 893670c4..7ff86963 100644 --- a/util/epist/process.cc +++ b/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 @@ void processEvent(const XEvent &e) { } 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; } } diff --git a/util/epist/window.cc b/util/epist/window.cc index 15f8b11c..62087283 100644 --- a/util/epist/window.cc +++ b/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 @@ void XWindow::updateDesktop() { static_cast(_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]; +} diff --git a/util/epist/window.hh b/util/epist/window.hh index c544091a..c83f020c 100644 --- a/util/epist/window.hh +++ b/util/epist/window.hh @@ -28,6 +28,7 @@ extern "C" { } #include +#include class XWindow; @@ -36,7 +37,13 @@ typedef std::list WindowList; 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 @@ public: 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 @@ public: 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; } -- 2.39.2