]> Dogcows Code - chaz/openbox/blobdiff - util/epist/screen.cc
added window cycling
[chaz/openbox] / util / epist / screen.cc
index 0d7f90d3d46907a0104e93f0c0f2da17d9a8d783..0d97b6143a301c661370c96a6ba4bb65e3c44cd4 100644 (file)
@@ -151,22 +151,35 @@ void screen::handleKeypress(const XEvent &e) {
       switch (it->type()) {
       case Action::nextWorkspace:
         cycleWorkspace(true);
-        break;
+        return;
 
       case Action::prevWorkspace:
         cycleWorkspace(false);
-        break;
+        return;
+
+      case Action::nextWindow:
+        cycleWindow(true);
+        return;
+
+      case Action::prevWindow:
+        cycleWindow(false);
+        return;
 
       case Action::changeWorkspace:
         changeWorkspace(it->number());
-        break;
-
-      case Action::shade:
-        (*_active)->shade(! (*_active)->shaded());
-        break;
+        return;
       }
 
-      break;
+      // these actions require an active window
+      if (_active != _clients.end()) {
+        XWindow *window = *_active;
+
+        switch (it->type()) {
+        case Action::toggleshade:
+          window->shade(! window->shaded());
+          return;
+        }
+      }
     }
   }
 }
@@ -269,6 +282,37 @@ void screen::updateActiveWindow() {
       }
  */
 
+
+void screen::cycleWindow(const bool forward) const {
+  if (_clients.empty()) return;
+    
+  WindowList::const_iterator target = _active;
+
+  if (target == _clients.end())
+    target = _clients.begin();
+  do {
+    if (forward) {
+      ++target;
+      if (target == _clients.end())
+        target = _clients.begin();
+    } else {
+      if (target == _clients.begin())
+        target = _clients.end();
+      --target;
+    }
+  } while (target == _clients.end() || (*target)->iconic());
+  
+  if (target != _clients.end()) {
+    // we dont send an ACTIVE_WINDOW client message because that would also
+    // unshade the window if it was shaded
+    XSetInputFocus(_epist->getXDisplay(), (*target)->window(), RevertToNone,
+                   CurrentTime);
+    XRaiseWindow(_epist->getXDisplay(), (*target)->window());
+  }
+}
+
+
 void screen::cycleWorkspace(const bool forward) const {
   unsigned long currentDesktop = 0;
   unsigned long numDesktops = 0;
@@ -292,6 +336,7 @@ void screen::cycleWorkspace(const bool forward) const {
   }
 }
 
+
 void screen::changeWorkspace(const int num) const {
   _xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root, num);
 }
This page took 0.022252 seconds and 4 git commands to generate.