This commit is contained in:
fluxgen 2002-02-08 14:06:35 +00:00
parent affd3c2afb
commit be93c21b2f
2 changed files with 87 additions and 71 deletions

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: Workspace.cc,v 1.6 2002/01/20 02:08:12 fluxgen Exp $ // $Id: Workspace.cc,v 1.7 2002/02/08 14:04:51 fluxgen Exp $
// use GNU extensions // use GNU extensions
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
@ -51,6 +51,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <algorithm>
Workspace::Workspace(BScreen *scrn, int i): Workspace::Workspace(BScreen *scrn, int i):
screen(scrn), screen(scrn),
lastfocus(0), lastfocus(0),
@ -63,8 +65,6 @@ cascade_x(32), cascade_y(32)
id = i; id = i;
stackingList = new LinkedList<FluxboxWindow>;
windowList = new LinkedList<FluxboxWindow>;
clientmenu = new Clientmenu(this); clientmenu = new Clientmenu(this);
char *tmp; char *tmp;
@ -77,8 +77,6 @@ cascade_x(32), cascade_y(32)
Workspace::~Workspace() { Workspace::~Workspace() {
delete stackingList;
delete windowList;
delete clientmenu; delete clientmenu;
} }
@ -91,10 +89,10 @@ const int Workspace::addWindow(FluxboxWindow *w, Bool place) {
placeWindow(w); placeWindow(w);
w->setWorkspace(id); w->setWorkspace(id);
w->setWindowNumber(windowList->count()); w->setWindowNumber(windowList.size());
stackingList->insert(w, 0); stackingList.push_front(w);
windowList->insert(w); windowList.push_back(w);
clientmenu->insert((const char **) w->getTitle()); clientmenu->insert((const char **) w->getTitle());
clientmenu->update(); clientmenu->update();
@ -110,7 +108,7 @@ const int Workspace::addWindow(FluxboxWindow *w, Bool place) {
const int Workspace::removeWindow(FluxboxWindow *w) { const int Workspace::removeWindow(FluxboxWindow *w) {
if (! w) return -1; if (! w) return -1;
stackingList->remove(w); stackingList.remove(w);
if (w->isFocused()) { if (w->isFocused()) {
if (screen->isSloppyFocus()) if (screen->isSloppyFocus())
@ -120,7 +118,7 @@ const int Workspace::removeWindow(FluxboxWindow *w) {
w->getTransientFor()->setInputFocus(); w->getTransientFor()->setInputFocus();
else { else {
FluxboxWindow *top = stackingList->first(); FluxboxWindow *top = stackingList.front();
if (! top || ! top->setInputFocus()) { if (! top || ! top->setInputFocus()) {
Fluxbox::instance()->setFocusedWindow((FluxboxWindow *) 0); Fluxbox::instance()->setFocusedWindow((FluxboxWindow *) 0);
@ -134,45 +132,49 @@ const int Workspace::removeWindow(FluxboxWindow *w) {
if (lastfocus == w) if (lastfocus == w)
lastfocus = (FluxboxWindow *) 0; lastfocus = (FluxboxWindow *) 0;
windowList->remove(w->getWindowNumber()); windowList.erase(windowList.begin() + w->getWindowNumber());
clientmenu->remove(w->getWindowNumber()); clientmenu->remove(w->getWindowNumber());
clientmenu->update(); clientmenu->update();
screen->updateNetizenWindowDel(w->getClientWindow()); screen->updateNetizenWindowDel(w->getClientWindow());
LinkedListIterator<FluxboxWindow> it(windowList); {
for (int i = 0; it.current(); it++, i++) Windows::iterator it = windowList.begin();
it.current()->setWindowNumber(i); Windows::const_iterator it_end = windowList.end();
for (int i = 0; it != it_end; ++it, ++i) {
(*it)->setWindowNumber(i);
}
}
return windowList->count(); return windowList.size();
} }
void Workspace::showAll(void) { void Workspace::showAll(void) {
LinkedListIterator<FluxboxWindow> it(stackingList); WindowStack::iterator it = stackingList.begin();
for (; it.current(); it++) WindowStack::iterator it_end = stackingList.end();
it.current()->deiconify(False, False); for (; it != it_end; ++it) {
(*it)->deiconify(False, False);
}
} }
void Workspace::hideAll(void) { void Workspace::hideAll(void) {
LinkedList<FluxboxWindow> lst; WindowStack::reverse_iterator it = stackingList.rbegin();
WindowStack::reverse_iterator it_end = stackingList.rend();
LinkedListIterator<FluxboxWindow> it(stackingList); for (; it != it_end; ++it) {
for (; it.current(); it++) if (! (*it)->isStuck())
lst.insert(it.current(), 0); (*it)->withdraw();
}
LinkedListIterator<FluxboxWindow> it2(&lst);
for (; it2.current(); it2++)
if (! it2.current()->isStuck())
it2.current()->withdraw();
} }
void Workspace::removeAll(void) { void Workspace::removeAll(void) {
LinkedListIterator<FluxboxWindow> it(windowList); Windows::iterator it = windowList.begin();
for (; it.current(); it++) Windows::const_iterator it_end = windowList.end();
it.current()->iconify(); for (; it != it_end; ++it) {
(*it)->iconify();
}
} }
@ -200,8 +202,8 @@ void Workspace::raiseWindow(FluxboxWindow *w) {
if (! win->isIconic()) { if (! win->isIconic()) {
wkspc = screen->getWorkspace(win->getWorkspaceNumber()); wkspc = screen->getWorkspace(win->getWorkspaceNumber());
wkspc->stackingList->remove(win); wkspc->stackingList.remove(win);
wkspc->stackingList->insert(win, 0); wkspc->stackingList.push_front(win);
} }
if (! win->hasTransient() || ! win->getTransient()) if (! win->hasTransient() || ! win->getTransient())
@ -239,8 +241,8 @@ void Workspace::lowerWindow(FluxboxWindow *w) {
if (! win->isIconic()) { if (! win->isIconic()) {
wkspc = screen->getWorkspace(win->getWorkspaceNumber()); wkspc = screen->getWorkspace(win->getWorkspaceNumber());
wkspc->stackingList->remove(win); wkspc->stackingList.remove(win);
wkspc->stackingList->insert(win); wkspc->stackingList.push_back(win);
} }
if (! win->getTransientFor()) if (! win->getTransientFor())
@ -263,23 +265,25 @@ void Workspace::lowerWindow(FluxboxWindow *w) {
void Workspace::reconfigure(void) { void Workspace::reconfigure(void) {
clientmenu->reconfigure(); clientmenu->reconfigure();
LinkedListIterator<FluxboxWindow> it(windowList); Windows::iterator it = windowList.begin();
for (; it.current(); it++) Windows::iterator it_end = windowList.end();
if (it.current()->validateClient()) for (; it != it_end; ++it) {
it.current()->reconfigure(); if ((*it)->validateClient())
(*it)->reconfigure();
}
} }
FluxboxWindow *Workspace::getWindow(int index) { FluxboxWindow *Workspace::getWindow(int index) {
if ((index >= 0) && (index < windowList->count())) if ((index >= 0) && (index < windowList.size()))
return windowList->find(index); return windowList[index];
else else
return 0; return 0;
} }
const int Workspace::getCount(void) { const int Workspace::getCount(void) {
return windowList->count(); return windowList.size();
} }
@ -295,7 +299,7 @@ Bool Workspace::isCurrent(void) {
Bool Workspace::isLastWindow(FluxboxWindow *w) { Bool Workspace::isLastWindow(FluxboxWindow *w) {
return (w == windowList->last()); return (w == windowList.back());
} }
void Workspace::setCurrent(void) { void Workspace::setCurrent(void) {
@ -328,16 +332,17 @@ void Workspace::setName(char *new_name) {
void Workspace::shutdown(void) { void Workspace::shutdown(void) {
while (windowList->count()) { Windows::iterator it = windowList.begin();
windowList->first()->restore(); Windows::iterator it_end= windowList.end();
delete windowList->first(); for (; it != it_end; ++it) {
(*it)->restore();
delete (*it);
} }
} }
void Workspace::placeWindow(FluxboxWindow *win) { void Workspace::placeWindow(FluxboxWindow *win) {
Bool placed = False; Bool placed = False;
LinkedListIterator<FluxboxWindow> it(windowList);
int win_w = win->getWidth() + (screen->getBorderWidth2x() * 2), int win_w = win->getWidth() + (screen->getBorderWidth2x() * 2),
win_h = win->getHeight() + (screen->getBorderWidth2x() * 2), win_h = win->getHeight() + (screen->getBorderWidth2x() * 2),
#ifdef SLIT #ifdef SLIT
@ -374,26 +379,29 @@ void Workspace::placeWindow(FluxboxWindow *win) {
! placed) { ! placed) {
test_x = screen->getBorderWidth() + screen->getEdgeSnapThreshold(); test_x = screen->getBorderWidth() + screen->getEdgeSnapThreshold();
if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
test_x = screen->getWidth() - win_w - test_x; test_x = screen->getWidth() - win_w - test_x;
while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ? while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
test_x > 0 : test_x + win_w < (signed) screen->getWidth()) && test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
! placed) { ! placed) {
placed = True; placed = True;
it.reset(); Windows::iterator it = windowList.begin();
for (; it.current() && placed; it++) { Windows::iterator it_end = windowList.end();
curr_w = it.current()->getWidth() + screen->getBorderWidth2x() + for (; it != it_end && placed; ++it) {
curr_w = (*it)->getWidth() + screen->getBorderWidth2x() +
screen->getBorderWidth2x(); screen->getBorderWidth2x();
curr_h = curr_h =
((it.current()->isShaded()) ? it.current()->getTitleHeight() : (((*it)->isShaded())
it.current()->getHeight()) + ? (*it)->getTitleHeight()
screen->getBorderWidth2x() + screen->getBorderWidth2x(); : (*it)->getHeight()) +
screen->getBorderWidth2x() +
screen->getBorderWidth2x();
if (it.current()->getXFrame() < test_x + win_w && if ((*it)->getXFrame() < test_x + win_w &&
it.current()->getXFrame() + curr_w > test_x && (*it)->getXFrame() + curr_w > test_x &&
it.current()->getYFrame() < test_y + win_h && (*it)->getYFrame() < test_y + win_h &&
it.current()->getYFrame() + curr_h > test_y) (*it)->getYFrame() + curr_h > test_y)
placed = False; placed = False;
} }
@ -436,26 +444,29 @@ void Workspace::placeWindow(FluxboxWindow *win) {
! placed) { ! placed) {
test_y = screen->getBorderWidth() + screen->getEdgeSnapThreshold(); test_y = screen->getBorderWidth() + screen->getEdgeSnapThreshold();
if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP) if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
test_y = screen->getHeight() - win_h - test_y; test_y = screen->getHeight() - win_h - test_y;
while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ? while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
test_y > 0 : test_y + win_h < (signed) screen->getHeight()) && test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
! placed) { ! placed) {
placed = True; placed = True;
it.reset(); Windows::iterator it = windowList.begin();
for (; it.current() && placed; it++) { Windows::iterator it_end = windowList.end();
curr_w = it.current()->getWidth() + screen->getBorderWidth2x() + for (; it != it_end && placed; ++it) {
curr_w = (*it)->getWidth() + screen->getBorderWidth2x() +
screen->getBorderWidth2x(); screen->getBorderWidth2x();
curr_h = curr_h =
((it.current()->isShaded()) ? it.current()->getTitleHeight() : (((*it)->isShaded())
it.current()->getHeight()) + ? (*it)->getTitleHeight()
screen->getBorderWidth2x() + screen->getBorderWidth2x(); : (*it)->getHeight()) +
screen->getBorderWidth2x() +
screen->getBorderWidth2x();
if (it.current()->getXFrame() < test_x + win_w && if ((*it)->getXFrame() < test_x + win_w &&
it.current()->getXFrame() + curr_w > test_x && (*it)->getXFrame() + curr_w > test_x &&
it.current()->getYFrame() < test_y + win_h && (*it)->getYFrame() < test_y + win_h &&
it.current()->getYFrame() + curr_h > test_y) (*it)->getYFrame() + curr_h > test_y)
placed = False; placed = False;
} }

View file

@ -22,9 +22,10 @@
#ifndef _WORKSPACE_HH_ #ifndef _WORKSPACE_HH_
#define _WORKSPACE_HH_ #define _WORKSPACE_HH_
#include "LinkedList.hh"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <string> #include <string>
#include <vector>
#include <list>
class BScreen; class BScreen;
class Clientmenu; class Clientmenu;
@ -38,7 +39,11 @@ private:
FluxboxWindow *lastfocus; FluxboxWindow *lastfocus;
Clientmenu *clientmenu; Clientmenu *clientmenu;
LinkedList<FluxboxWindow> *stackingList, *windowList; typedef std::list<FluxboxWindow *> WindowStack;
typedef std::vector<FluxboxWindow *> Windows;
WindowStack stackingList;
Windows windowList;
std::string name; std::string name;
int id, cascade_x, cascade_y; int id, cascade_x, cascade_y;