X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=util%2Fepist%2Fscreen.cc;h=e7ebd64cf1d1afb06abd79d40c69b74b6c49a88e;hb=41a38bbdaf245f12e58f2609092bfbcf8fba6f78;hp=f40bff3ca1cd15c37606935477b5ac4612e673a6;hpb=6d40002093a5d8e665d4f310ea028d22e93e88cb;p=chaz%2Fopenbox diff --git a/util/epist/screen.cc b/util/epist/screen.cc index f40bff3c..e7ebd64c 100644 --- a/util/epist/screen.cc +++ b/util/epist/screen.cc @@ -1,5 +1,5 @@ // -*- mode: C++; indent-tabs-mode: nil; -*- -// screen.cc for Epistophy - a key handler for NETWM/EWMH window managers. +// screen.cc for Epistrophy - a key handler for NETWM/EWMH window managers. // Copyright (c) 2002 - 2002 Ben Jansens // // Permission is hereby granted, free of charge, to any person obtaining a @@ -70,7 +70,7 @@ screen::screen(epist *epist, int number) } if (_managed) cout << "Found compatible window manager '" << _wm_name << "' for screen " - << _number << ".\n"; + << _number << ".\n"; else { cout << "Unable to find a compatible window manager for screen " << _number << ".\n"; @@ -154,154 +154,158 @@ void screen::handleKeypress(const XEvent &e) { const Action *it = _epist->getKeyTree().getAction(e, state, this); if (!it) - return; + return; switch (it->type()) { case Action::nextScreen: - _epist->cycleScreen(_number, true); - return; + _epist->cycleScreen(_number, true); + return; case Action::prevScreen: - _epist->cycleScreen(_number, false); - return; + _epist->cycleScreen(_number, false); + return; case Action::nextWorkspace: - cycleWorkspace(true); - return; + cycleWorkspace(true, it->number() != 0 ? it->number(): 1); + return; case Action::prevWorkspace: - cycleWorkspace(false); - return; + cycleWorkspace(false, it->number() != 0 ? it->number(): 1); + return; case Action::nextWindow: - cycleWindow(true); - return; + + cycleWindow(true, it->number() != 0 ? it->number(): 1); + return; case Action::prevWindow: - cycleWindow(false); - return; + cycleWindow(false, it->number() != 0 ? it->number(): 1); + return; case Action::nextWindowOnAllWorkspaces: - cycleWindow(true, false, true); - return; + cycleWindow(true, it->number() != 0 ? it->number(): 1, false, true); + return; case Action::prevWindowOnAllWorkspaces: - cycleWindow(false, false, true); - return; + cycleWindow(false, it->number() != 0 ? it->number(): 1, false, true); + return; case Action::nextWindowOnAllScreens: - cycleWindow(true, true); - return; + cycleWindow(true, it->number() != 0 ? it->number(): 1, true); + return; case Action::prevWindowOnAllScreens: - cycleWindow(false, true); - return; + cycleWindow(false, it->number() != 0 ? it->number(): 1, true); + return; case Action::nextWindowOfClass: - cycleWindow(true, false, false, true, it->string()); - return; + cycleWindow(true, it->number() != 0 ? it->number(): 1, + false, false, true, it->string()); + return; case Action::prevWindowOfClass: - cycleWindow(false, false, false, true, it->string()); - return; + cycleWindow(false, it->number() != 0 ? it->number(): 1, + false, false, true, it->string()); + return; case Action::nextWindowOfClassOnAllWorkspaces: - cycleWindow(true, false, true, true, it->string()); - return; + cycleWindow(true, it->number() != 0 ? it->number(): 1, + false, true, true, it->string()); + return; case Action::prevWindowOfClassOnAllWorkspaces: - cycleWindow(false, false, true, true, it->string()); - return; + cycleWindow(false, it->number() != 0 ? it->number(): 1, + false, true, true, it->string()); + return; case Action::changeWorkspace: - // we subtract one so counting starts at 1 in the config file - changeWorkspace(it->number() - 1); - return; + changeWorkspace(it->number()); + return; case Action::execute: - execCommand(it->string()); - return; + execCommand(it->string()); + return; default: - break; + break; } // these actions require an active window if (_active != _clients.end()) { - XWindow *window = *_active; + XWindow *window = *_active; - switch (it->type()) { - case Action::iconify: - window->iconify(); - return; - - case Action::close: - window->close(); - return; - - case Action::raise: - window->raise(); - return; - - case Action::lower: - window->lower(); - return; - - case Action::sendToWorkspace: - window->sendTo(it->number()); - return; - - case Action::toggleomnipresent: - if (window->desktop() == 0xffffffff) - window->sendTo(_active_desktop); - else - window->sendTo(0xffffffff); - return; - - case Action::moveWindowUp: - window->move(window->x(), window->y() - it->number()); - return; + switch (it->type()) { + case Action::iconify: + window->iconify(); + return; + + case Action::close: + window->close(); + return; + + case Action::raise: + window->raise(); + return; + + case Action::lower: + window->lower(); + return; + + case Action::sendToWorkspace: + window->sendTo(it->number()); + return; + + case Action::toggleomnipresent: + if (window->desktop() == 0xffffffff) + window->sendTo(_active_desktop); + else + window->sendTo(0xffffffff); + return; + + case Action::moveWindowUp: + window->move(window->x(), window->y() - it->number()); + return; - case Action::moveWindowDown: - window->move(window->x(), window->y() + it->number()); - return; + case Action::moveWindowDown: + window->move(window->x(), window->y() + it->number()); + return; - case Action::moveWindowLeft: - window->move(window->x() - it->number(), window->y()); - return; + case Action::moveWindowLeft: + window->move(window->x() - it->number(), window->y()); + return; - case Action::moveWindowRight: - window->move(window->x() + it->number(), window->y()); - return; + case Action::moveWindowRight: + window->move(window->x() + it->number(), window->y()); + return; - case Action::resizeWindowWidth: - window->resize(window->width() + it->number(), window->height()); - return; + case Action::resizeWindowWidth: + window->resizeRel(it->number(), 0); + return; - case Action::resizeWindowHeight: - window->resize(window->width(), window->height() + it->number()); - return; + case Action::resizeWindowHeight: + window->resizeRel(0, it->number()); + return; - case Action::toggleshade: - window->shade(! window->shaded()); - return; + case Action::toggleshade: + window->shade(! window->shaded()); + return; - case Action::toggleMaximizeHorizontal: - window->toggleMaximize(XWindow::Max_Horz); - return; + case Action::toggleMaximizeHorizontal: + window->toggleMaximize(XWindow::Max_Horz); + return; - case Action::toggleMaximizeVertical: - window->toggleMaximize(XWindow::Max_Vert); - return; + case Action::toggleMaximizeVertical: + window->toggleMaximize(XWindow::Max_Vert); + return; - case Action::toggleMaximizeFull: - window->toggleMaximize(XWindow::Max_Full); - return; + case Action::toggleMaximizeFull: + window->toggleMaximize(XWindow::Max_Full); + return; - default: - assert(false); // unhandled action type! - break; - } + default: + assert(false); // unhandled action type! + break; + } } } @@ -374,7 +378,7 @@ void screen::updateClientList() { break; if (it == end) { // didn't already exist if (doAddWindow(rootclients[i])) { -// cout << "Added window: 0x" << hex << rootclients[i] << dec << endl; + // cout << "Added window: 0x" << hex << rootclients[i] << dec << endl; _clients.insert(insert_point, new XWindow(_epist, this, rootclients[i])); } @@ -394,7 +398,7 @@ void screen::updateClientList() { if (**it2 == rootclients[i]) break; if (i == num) { // no longer exists -// cout << "Removed window: 0x" << hex << (*it2)->window() << dec << endl; + // cout << "Removed window: 0x" << hex << (*it2)->window() << dec << endl; // watch for the active and last-active window if (it2 == _active) _active = _clients.end(); @@ -440,13 +444,12 @@ void screen::updateActiveWindow() { } } _active = it; - if (it != end) - _last_active = it; + _last_active = it; -/* cout << "Active window is now: "; - if (_active == _clients.end()) cout << "None\n"; - else cout << "0x" << hex << (*_active)->window() << dec << endl; -*/ + /* cout << "Active window is now: "; + if (_active == _clients.end()) cout << "None\n"; + else cout << "0x" << hex << (*_active)->window() << dec << endl; + */ } @@ -467,74 +470,86 @@ void screen::execCommand(const string &cmd) const { } -void screen::cycleWindow(const bool forward, const bool allscreens, - const bool alldesktops, const bool sameclass, - const string &cn) const { +void screen::cycleWindow(const bool forward, const int increment, + const bool allscreens, const bool alldesktops, + const bool sameclass, const string &cn) const { assert(_managed); + assert(increment > 0); if (_clients.empty()) return; - + string classname(cn); if (sameclass && classname.empty() && _active != _clients.end()) classname = (*_active)->appClass(); WindowList::const_iterator target = _active, - begin = _clients.begin(), - end = _clients.end(); - - while (1) { - if (forward) { - if (target == end) { - target = begin; + begin = _clients.begin(), + end = _clients.end(); + + const XWindow *t = 0; + + for (int x = 0; x < increment; ++x) { + while (1) { + if (forward) { + if (target == end) { + target = begin; + } else { + ++target; + } } else { - ++target; + if (target == begin) + target = end; + --target; } - } else { - if (target == begin) - target = end; - --target; - } - - // must be no window to focus - if (target == _active) - return; - // start back at the beginning of the loop - if (target == end) - continue; + // must be no window to focus + if (target == _active) + return; - // determine if this window is invalid for cycling to - const XWindow *t = *target; - if (t->iconic()) continue; - if (! allscreens && t->getScreen() != this) continue; - if (! alldesktops && ! (t->desktop() == _active_desktop || - t->desktop() == 0xffffffff)) continue; - if (sameclass && ! classname.empty() && - t->appClass() != classname) continue; - if (! t->canFocus()) continue; - - // found a good window! - t->focus(); - return; + // start back at the beginning of the loop + if (target == end) + continue; + + // determine if this window is invalid for cycling to + t = *target; + if (t->iconic()) continue; + if (! allscreens && t->getScreen() != this) continue; + if (! alldesktops && ! (t->desktop() == _active_desktop || + t->desktop() == 0xffffffff)) continue; + if (sameclass && ! classname.empty() && + t->appClass() != classname) continue; + if (! t->canFocus()) continue; + + // found a good window so break out of the while, and perhaps continue + // with the for loop + break; + } } + + // phew. we found the window, so focus it. + t->focus(); } -void screen::cycleWorkspace(const bool forward, const bool loop) const { +void screen::cycleWorkspace(const bool forward, const int increment, + const bool loop) const { assert(_managed); + assert(increment > 0); unsigned int destination = _active_desktop; - if (forward) { - if (destination < _num_desktops - 1) - ++destination; - else if (loop) - destination = 0; - } else { - if (destination > 0) - --destination; - else if (loop) - destination = _num_desktops - 1; + for (int x = 0; x < increment; ++x) { + if (forward) { + if (destination < _num_desktops - 1) + ++destination; + else if (loop) + destination = 0; + } else { + if (destination > 0) + --destination; + else if (loop) + destination = _num_desktops - 1; + } } if (destination != _active_desktop)