]> Dogcows Code - chaz/openbox/blobdiff - util/epist/screen.cc
add raising and lowering
[chaz/openbox] / util / epist / screen.cc
index ad2b17721ea39183fa257d35ee63b262613e67e6..db812878fdf250cee873b20f174ee12eaa1e2a1c 100644 (file)
@@ -1,5 +1,5 @@
 // -*- mode: C++; indent-tabs-mode: nil; -*-
-// screen.cc for Epistory - a key handler for NETWM/EWMH window managers.
+// screen.cc for Epistophy - a key handler for NETWM/EWMH window managers.
 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
 //
 // Permission is hereby granted, free of charge, to any person obtaining a
@@ -137,10 +137,64 @@ void screen::processEvent(const XEvent &e) {
     }
     break;
   case KeyPress:
+    handleKeypress(e);
     break;
   }
 }
 
+void screen::handleKeypress(const XEvent &e) {
+  ActionList::const_iterator it = _epist->actions().begin();
+  ActionList::const_iterator end = _epist->actions().end();
+  for (; it != end; ++it) {
+    if (e.xkey.keycode == it->keycode() &&
+        e.xkey.state == it->modifierMask()) {
+      switch (it->type()) {
+      case Action::nextWorkspace:
+        cycleWorkspace(true);
+        return;
+
+      case Action::prevWorkspace:
+        cycleWorkspace(false);
+        return;
+
+      case Action::nextWindow:
+        cycleWindow(true);
+        return;
+
+      case Action::prevWindow:
+        cycleWindow(false);
+        return;
+
+      case Action::changeWorkspace:
+        changeWorkspace(it->number());
+        return;
+      }
+
+      // these actions require an active window
+      if (_active != _clients.end()) {
+        XWindow *window = *_active;
+
+        switch (it->type()) {
+        case Action::close:
+          window->close();
+          return;
+
+        case Action::raise:
+          window->raise();
+          return;
+
+        case Action::lower:
+          window->lower();
+          return;
+
+        case Action::toggleshade:
+          window->shade(! window->shaded());
+          return;
+        }
+      }
+    }
+  }
+}
 
 // do we want to add this window to our list?
 bool screen::doAddWindow(Window window) const {
@@ -190,7 +244,8 @@ void screen::updateClientList() {
     if (it == end) {  // didn't already exist
       if (doAddWindow(rootclients[i])) {
         cout << "Added window: 0x" << hex << rootclients[i] << dec << endl;
-        _clients.insert(insert_point, new XWindow(_epist, rootclients[i]));
+        _clients.insert(insert_point, new XWindow(_epist, this,
+                                                  rootclients[i]));
       }
     }
   }
@@ -238,3 +293,62 @@ void screen::updateActiveWindow() {
         perror("putenv()");
       }
  */
+
+
+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;
+  
+  if (_xatom->getValue(_root, XAtom::net_current_desktop, XAtom::cardinal,
+                       currentDesktop)) {
+    if (forward)     
+      ++currentDesktop;
+    else
+      --currentDesktop;
+
+    _xatom->getValue(_root, XAtom::net_number_of_desktops, XAtom::cardinal,
+                     numDesktops);
+    
+    if ( ( (signed)currentDesktop) == -1)
+      currentDesktop = numDesktops - 1;
+    else if (currentDesktop >= numDesktops)
+      currentDesktop = 0;
+
+    changeWorkspace(currentDesktop);
+  }
+}
+
+
+void screen::changeWorkspace(const int num) const {
+  _xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root, num);
+}
This page took 0.022552 seconds and 4 git commands to generate.