X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=util%2Fepist%2Fscreen.cc;h=db812878fdf250cee873b20f174ee12eaa1e2a1c;hb=b94699afc339c469534521c44470aa6d19e5b4cc;hp=d8f055401645cd7b39e4e55a5705eb7a74d60cbb;hpb=a0e50e15b507f1f8752bd7858c9e758265a34fc4;p=chaz%2Fopenbox diff --git a/util/epist/screen.cc b/util/epist/screen.cc index d8f05540..db812878 100644 --- a/util/epist/screen.cc +++ b/util/epist/screen.cc @@ -143,22 +143,56 @@ void screen::processEvent(const XEvent &e) { } void screen::handleKeypress(const XEvent &e) { - list::const_iterator it = _epist->actions().begin(); - list::const_iterator end = _epist->actions().end(); + 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() ) - { + 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::nextDesktop: - cycleWorkspace(true); - break; - case Action::prevDesktop: - cycleWorkspace(false); - break; + 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; } - break; } + } } } @@ -210,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])); } } } @@ -259,9 +294,38 @@ void screen::updateActiveWindow() { } */ -void screen::cycleWorkspace(const bool forward) { - cout << "blef" << endl; +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; @@ -272,9 +336,6 @@ void screen::cycleWorkspace(const bool forward) { else --currentDesktop; - cout << currentDesktop << endl; - - _xatom->getValue(_root, XAtom::net_number_of_desktops, XAtom::cardinal, numDesktops); @@ -283,10 +344,11 @@ void screen::cycleWorkspace(const bool forward) { else if (currentDesktop >= numDesktops) currentDesktop = 0; - - _xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root, - currentDesktop); - + changeWorkspace(currentDesktop); } } - + + +void screen::changeWorkspace(const int num) const { + _xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root, num); +}