]> Dogcows Code - chaz/openbox/commitdiff
gets a whole lotta window information now, and updtes when it changes!
authorDana Jansens <danakj@orodu.net>
Fri, 12 Jul 2002 02:48:43 +0000 (02:48 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 12 Jul 2002 02:48:43 +0000 (02:48 +0000)
util/epist/process.cc
util/epist/window.cc
util/epist/window.hh

index 893670c451ec972b2dee102e562d2e681219cacc..7ff86963cb431caa8ec240e95b421e04af6e2af4 100644 (file)
@@ -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;
   }
 }
index 15f8b11c54eac41b71e3a7006679b4125f152f74..62087283b4de9152ed74cce24544775455edcc2a 100644 (file)
@@ -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<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];
+}
index c544091a9593bc009b8e370a464fcb9c76e52657..c83f020c2f64fd712e0eae3376a2e1c2514b70bb 100644 (file)
@@ -28,6 +28,7 @@ extern "C" {
 }
 
 #include <list>
+#include <string>
 
 class XWindow;
 
@@ -36,7 +37,13 @@ typedef std::list<XWindow *> 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; }
This page took 0.027401 seconds and 4 git commands to generate.