fluxbox/src/Workspace.cc

736 lines
19 KiB
C++
Raw Normal View History

2002-02-09 16:41:53 +00:00
// Workspace.cc for Fluxbox
// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
//
2001-12-11 20:47:02 +00:00
// Workspace.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
2002-08-04 15:37:37 +00:00
// $Id: Workspace.cc,v 1.22 2002/08/04 15:37:37 fluxgen Exp $
2002-01-20 02:08:12 +00:00
// use GNU extensions
2001-12-11 20:47:02 +00:00
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif // _GNU_SOURCE
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif // HAVE_CONFIG_H
#include "i18n.hh"
#include "fluxbox.hh"
#include "Clientmenu.hh"
#include "Screen.hh"
#include "Toolbar.hh"
#include "Window.hh"
#include "Workspace.hh"
#include "Windowmenu.hh"
2002-01-06 11:07:42 +00:00
#include "StringUtil.hh"
2001-12-11 20:47:02 +00:00
2002-05-07 13:57:09 +00:00
#include <stdio.h>
#include <string.h>
2001-12-11 20:47:02 +00:00
2002-01-20 02:08:12 +00:00
#include <X11/Xlib.h>
#include <X11/Xatom.h>
2002-02-08 14:06:35 +00:00
#include <algorithm>
2002-02-10 19:05:12 +00:00
#include <iostream>
using namespace std;
2002-02-08 14:06:35 +00:00
2002-05-07 13:57:09 +00:00
2002-03-23 15:14:45 +00:00
Workspace::Workspace(BScreen *scrn, unsigned int i):
2002-01-20 02:08:12 +00:00
screen(scrn),
lastfocus(0),
2002-05-07 13:57:09 +00:00
m_clientmenu(this),
2002-04-09 23:18:12 +00:00
m_name(""),
m_id(i),
2002-01-20 02:08:12 +00:00
cascade_x(32), cascade_y(32)
{
2001-12-11 20:47:02 +00:00
char *tmp;
2002-04-09 23:18:12 +00:00
screen->getNameOfWorkspace(m_id, &tmp);
2001-12-11 20:47:02 +00:00
setName(tmp);
if (tmp)
delete [] tmp;
}
2002-01-20 02:08:12 +00:00
Workspace::~Workspace() {
2002-05-07 13:57:09 +00:00
2001-12-11 20:47:02 +00:00
}
int Workspace::addWindow(FluxboxWindow *w, bool place) {
2002-01-20 02:08:12 +00:00
if (! w)
return -1;
2001-12-11 20:47:02 +00:00
2002-01-20 02:08:12 +00:00
if (place)
placeWindow(w);
2001-12-11 20:47:02 +00:00
2002-04-09 23:18:12 +00:00
w->setWorkspace(m_id);
2002-02-08 14:06:35 +00:00
w->setWindowNumber(windowList.size());
2001-12-11 20:47:02 +00:00
2002-02-08 14:06:35 +00:00
stackingList.push_front(w);
2002-04-02 23:14:07 +00:00
//insert window after the currently focused window
FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow();
2002-05-07 13:57:09 +00:00
2002-04-02 23:14:07 +00:00
//if there isn't any window that's focused, just add it to the end of the list
/*
2002-04-02 23:14:07 +00:00
if (focused == 0) {
windowList.push_back(w);
2002-05-07 13:57:09 +00:00
//Add client to clientmenu
m_clientmenu.insert(w->getTitle().c_str());
2002-04-02 23:14:07 +00:00
} else {
Windows::iterator it = windowList.begin();
2002-05-07 13:57:09 +00:00
size_t client_insertpoint=0;
for (; it != windowList.end(); ++it, ++client_insertpoint) {
2002-04-02 23:14:07 +00:00
if (*it == focused) {
2002-05-07 13:57:09 +00:00
++it;
2002-04-02 23:14:07 +00:00
break;
}
}
2001-12-11 20:47:02 +00:00
2002-05-07 13:57:09 +00:00
windowList.insert(it, w);
//Add client to clientmenu
m_clientmenu.insert(w->getTitle().c_str(), client_insertpoint);
2001-12-11 20:47:02 +00:00
2002-05-07 13:57:09 +00:00
}
*/
//add to list
m_clientmenu.insert(w->getTitle().c_str());
windowList.push_back(w);
2002-05-07 13:57:09 +00:00
//update menugraphics
m_clientmenu.update();
2002-04-09 23:18:12 +00:00
screen->updateNetizenWindowAdd(w->getClientWindow(), m_id);
2001-12-11 20:47:02 +00:00
raiseWindow(w);
return w->getWindowNumber();
}
int Workspace::removeWindow(FluxboxWindow *w) {
if (! w)
return -1;
2001-12-11 20:47:02 +00:00
2002-02-08 14:06:35 +00:00
stackingList.remove(w);
2001-12-11 20:47:02 +00:00
if (w->isFocused()) {
if (screen->isSloppyFocus())
Fluxbox::instance()->setFocusedWindow((FluxboxWindow *) 0);
else if (w->isTransient() && w->getTransientFor() &&
w->getTransientFor()->isVisible())
w->getTransientFor()->setInputFocus();
else {
2002-02-09 16:41:53 +00:00
FluxboxWindow *top = 0;
if (stackingList.size()!=0)
top = stackingList.front();
if (!top || !top->setInputFocus()) {
2001-12-11 20:47:02 +00:00
Fluxbox::instance()->setFocusedWindow((FluxboxWindow *) 0);
XSetInputFocus(Fluxbox::instance()->getXDisplay(),
2002-01-20 02:08:12 +00:00
screen->getToolbar()->getWindowID(),
RevertToParent, CurrentTime);
2001-12-11 20:47:02 +00:00
}
}
}
if (lastfocus == w)
lastfocus = (FluxboxWindow *) 0;
2002-04-02 23:14:07 +00:00
//could be faster?
Windows::iterator it = windowList.begin();
Windows::iterator it_end = windowList.end();
for (; it != it_end; ++it) {
if (*it == w) {
windowList.erase(it);
break;
}
}
2002-05-07 13:57:09 +00:00
m_clientmenu.remove(w->getWindowNumber());
m_clientmenu.update();
2001-12-11 20:47:02 +00:00
screen->updateNetizenWindowDel(w->getClientWindow());
2002-02-08 14:06:35 +00:00
{
Windows::iterator it = windowList.begin();
Windows::const_iterator it_end = windowList.end();
for (int i = 0; it != it_end; ++it, ++i) {
(*it)->setWindowNumber(i);
}
}
2001-12-11 20:47:02 +00:00
2002-02-08 14:06:35 +00:00
return windowList.size();
2001-12-11 20:47:02 +00:00
}
void Workspace::showAll(void) {
2002-02-08 14:06:35 +00:00
WindowStack::iterator it = stackingList.begin();
WindowStack::iterator it_end = stackingList.end();
for (; it != it_end; ++it) {
(*it)->deiconify(False, False);
}
2001-12-11 20:47:02 +00:00
}
void Workspace::hideAll(void) {
2002-02-08 14:06:35 +00:00
WindowStack::reverse_iterator it = stackingList.rbegin();
WindowStack::reverse_iterator it_end = stackingList.rend();
for (; it != it_end; ++it) {
if (! (*it)->isStuck())
(*it)->withdraw();
}
2001-12-11 20:47:02 +00:00
}
void Workspace::removeAll(void) {
2002-02-08 14:06:35 +00:00
Windows::iterator it = windowList.begin();
Windows::const_iterator it_end = windowList.end();
for (; it != it_end; ++it) {
(*it)->iconify();
}
2001-12-11 20:47:02 +00:00
}
void Workspace::raiseWindow(FluxboxWindow *w) {
FluxboxWindow *win = (FluxboxWindow *) 0, *bottom = w;
2002-02-26 22:34:49 +00:00
while (bottom->isTransient() && bottom->getTransientFor() &&
bottom->getTransientFor() != bottom) //prevent infinite loop
2001-12-11 20:47:02 +00:00
bottom = bottom->getTransientFor();
int i = 1;
win = bottom;
2002-02-26 22:34:49 +00:00
while (win->hasTransient() && win->getTransient() &&
win->getTransient() != win) {//prevent infinite loop
2001-12-11 20:47:02 +00:00
win = win->getTransient();
i++;
}
Window *nstack = new Window[i], *curr = nstack;
Workspace *wkspc;
win = bottom;
while (True) {
*(curr++) = win->getFrameWindow();
screen->updateNetizenWindowRaise(win->getClientWindow());
if (! win->isIconic()) {
wkspc = screen->getWorkspace(win->getWorkspaceNumber());
2002-02-08 14:06:35 +00:00
wkspc->stackingList.remove(win);
wkspc->stackingList.push_front(win);
2001-12-11 20:47:02 +00:00
}
2002-02-26 22:34:49 +00:00
if (! win->hasTransient() || ! win->getTransient() ||
win->getTransient() == win) //prevent infinite loop
2001-12-11 20:47:02 +00:00
break;
2002-02-26 22:34:49 +00:00
2001-12-11 20:47:02 +00:00
win = win->getTransient();
}
screen->raiseWindows(nstack, i);
delete [] nstack;
}
void Workspace::lowerWindow(FluxboxWindow *w) {
FluxboxWindow *win = (FluxboxWindow *) 0, *bottom = w;
2002-02-26 22:34:49 +00:00
while (bottom->isTransient() && bottom->getTransientFor()
&& bottom->getTransientFor() != bottom) //prevent infinite loop
2001-12-11 20:47:02 +00:00
bottom = bottom->getTransientFor();
int i = 1;
win = bottom;
2002-02-26 22:34:49 +00:00
while (win->hasTransient() && win->getTransient() &&
win->getTransient() != win) { //prevent infinite loop
2001-12-11 20:47:02 +00:00
win = win->getTransient();
i++;
}
Window *nstack = new Window[i], *curr = nstack;
Workspace *wkspc;
while (True) {
*(curr++) = win->getFrameWindow();
screen->updateNetizenWindowLower(win->getClientWindow());
if (! win->isIconic()) {
wkspc = screen->getWorkspace(win->getWorkspaceNumber());
2002-02-08 14:06:35 +00:00
wkspc->stackingList.remove(win);
wkspc->stackingList.push_back(win);
2001-12-11 20:47:02 +00:00
}
2002-02-26 22:34:49 +00:00
if (! win->getTransientFor() ||
win->getTransientFor() == win)//prevent infinite loop
2001-12-11 20:47:02 +00:00
break;
win = win->getTransientFor();
}
Fluxbox::instance()->grab();
XLowerWindow(screen->getBaseDisplay()->getXDisplay(), *nstack);
XRestackWindows(screen->getBaseDisplay()->getXDisplay(), nstack, i);
Fluxbox::instance()->ungrab();
delete [] nstack;
}
void Workspace::reconfigure(void) {
2002-05-07 13:57:09 +00:00
m_clientmenu.reconfigure();
2001-12-11 20:47:02 +00:00
2002-02-08 14:06:35 +00:00
Windows::iterator it = windowList.begin();
Windows::iterator it_end = windowList.end();
for (; it != it_end; ++it) {
if ((*it)->validateClient())
(*it)->reconfigure();
}
2001-12-11 20:47:02 +00:00
}
2002-05-07 13:57:09 +00:00
const FluxboxWindow *Workspace::getWindow(unsigned int index) const {
2002-03-23 15:14:45 +00:00
if (index < windowList.size())
2002-02-08 14:06:35 +00:00
return windowList[index];
2002-05-07 13:57:09 +00:00
return 0;
}
2002-03-23 15:14:45 +00:00
2002-05-07 13:57:09 +00:00
FluxboxWindow *Workspace::getWindow(unsigned int index) {
if (index < windowList.size())
return windowList[index];
2002-03-23 15:14:45 +00:00
return 0;
2001-12-11 20:47:02 +00:00
}
int Workspace::getCount(void) const {
2002-02-08 14:06:35 +00:00
return windowList.size();
2001-12-11 20:47:02 +00:00
}
void Workspace::update(void) {
2002-05-07 13:57:09 +00:00
m_clientmenu.update();
2001-12-11 20:47:02 +00:00
screen->getToolbar()->redrawWindowLabel(True);
}
2002-04-09 23:18:12 +00:00
bool Workspace::isCurrent(void) const{
return (m_id == screen->getCurrentWorkspaceID());
2001-12-11 20:47:02 +00:00
}
2002-04-09 23:18:12 +00:00
bool Workspace::isLastWindow(FluxboxWindow *w) const{
2002-02-08 14:06:35 +00:00
return (w == windowList.back());
2001-12-11 20:47:02 +00:00
}
void Workspace::setCurrent(void) {
2002-04-09 23:18:12 +00:00
screen->changeWorkspaceID(m_id);
2001-12-11 20:47:02 +00:00
}
2002-04-09 23:18:12 +00:00
void Workspace::setName(const char *name) {
2001-12-11 20:47:02 +00:00
2002-04-09 23:18:12 +00:00
if (name) {
m_name = name;
} else { //if name == 0 then set default name from nls
2002-01-20 02:08:12 +00:00
char tname[128];
sprintf(tname, I18n::instance()->
2002-01-18 01:35:27 +00:00
getMessage(
FBNLS::WorkspaceSet, FBNLS::WorkspaceDefaultNameFormat,
2002-04-09 23:18:12 +00:00
"Workspace %d"), m_id + 1); //m_id starts at 0
m_name = tname;
2001-12-11 20:47:02 +00:00
}
screen->updateWorkspaceNamesAtom();
2002-05-07 13:57:09 +00:00
m_clientmenu.setLabel(m_name.c_str());
m_clientmenu.update();
2001-12-11 20:47:02 +00:00
}
2002-02-16 11:28:16 +00:00
//------------ shutdown ---------
2002-03-19 14:30:43 +00:00
// Calls restore on all windows
// on the workspace and then
2002-02-16 11:28:16 +00:00
// clears the windowList
//-------------------------------
2001-12-11 20:47:02 +00:00
void Workspace::shutdown(void) {
2002-02-10 19:05:12 +00:00
while (!windowList.empty()) {
windowList.back()->restore();
delete windowList.back(); //delete window (the window removes it self from windowList)
2001-12-11 20:47:02 +00:00
}
}
void Workspace::placeWindow(FluxboxWindow *win) {
Bool placed = False;
2002-03-19 14:30:43 +00:00
int borderWidth4x = screen->getBorderWidth2x() * 2,
2001-12-11 20:47:02 +00:00
#ifdef SLIT
2002-08-04 15:37:37 +00:00
slit_x = screen->getSlit()->x() - screen->getBorderWidth(),
slit_y = screen->getSlit()->y() - screen->getBorderWidth(),
slit_w = screen->getSlit()->width() + borderWidth4x,
slit_h = screen->getSlit()->height() + borderWidth4x,
2001-12-11 20:47:02 +00:00
#endif // SLIT
toolbar_x = screen->getToolbar()->getX() - screen->getBorderWidth(),
toolbar_y = screen->getToolbar()->getY() - screen->getBorderWidth(),
2002-03-19 14:30:43 +00:00
toolbar_w = screen->getToolbar()->getWidth() + borderWidth4x,
toolbar_h = screen->getToolbar()->getHeight() + borderWidth4x,
2001-12-11 20:47:02 +00:00
place_x = 0, place_y = 0, change_x = 1, change_y = 1;
2002-01-11 10:43:55 +00:00
if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
2001-12-11 20:47:02 +00:00
change_y = -1;
2002-01-11 10:43:55 +00:00
if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
2001-12-11 20:47:02 +00:00
change_x = -1;
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
int head = 0,
head_x = 0,
head_y = 0;
int head_w, head_h;
if (screen->hasXinerama()) {
head = screen->getCurrHead();
head_x = screen->getHeadX(head);
head_y = screen->getHeadY(head);
head_w = screen->getHeadWidth(head);
head_h = screen->getHeadHeight(head);
} else { // no xinerama
head_w = screen->getWidth();
head_h = screen->getHeight();
}
#endif // XINERAMA
int win_w = win->getWidth() + screen->getBorderWidth2x(),
win_h = win->getHeight() + screen->getBorderWidth2x();
if (win->hasTab()) {
if ((! win->isShaded()) &&
screen->getTabPlacement() == Tab::PLEFT ||
screen->getTabPlacement() == Tab::PRIGHT)
win_w += (screen->isTabRotateVertical())
? screen->getTabHeight()
: screen->getTabWidth();
else // tab placement top or bottom or win is shaded
win_h += screen->getTabHeight();
}
register int test_x, test_y, curr_x, curr_y, curr_w, curr_h;
2001-12-11 20:47:02 +00:00
switch (screen->getPlacementPolicy()) {
2002-01-11 10:43:55 +00:00
case BScreen::ROWSMARTPLACEMENT: {
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_y = head_y;
#else // !XINERAMA
test_y = 0;
#endif // XINERAMA
2002-01-11 10:43:55 +00:00
if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_y = (head_y + head_h) - win_h - test_y;
#else // !XINERAMA
2001-12-11 20:47:02 +00:00
test_y = screen->getHeight() - win_h - test_y;
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
2001-12-11 20:47:02 +00:00
2002-01-11 10:43:55 +00:00
while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_y >= head_y : test_y + win_h <= (head_y + head_h)) &&
#else // !XINERAMA
test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
#endif // XINERAMA
! placed) {
#ifdef XINERAMA
test_x = head_x;
#else // !XINERAMA
test_x = 0;
#endif // XINERAMA
2002-01-11 10:43:55 +00:00
if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_x = (head_x + head_w) - win_w - test_x;
#else // !XINERAMA
2002-02-08 14:06:35 +00:00
test_x = screen->getWidth() - win_w - test_x;
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
2001-12-11 20:47:02 +00:00
2002-01-11 10:43:55 +00:00
while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_x >= head_x : test_x + win_w <= (head_x + head_w)) &&
#else // !XINERAMA
test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
#endif // XINERAMA
! placed) {
2001-12-11 20:47:02 +00:00
placed = True;
2002-03-19 14:30:43 +00:00
Windows::iterator it = windowList.begin();
Windows::iterator it_end = windowList.end();
for (; it != it_end && placed; ++it) {
curr_x = (*it)->getXFrame();
curr_y = (*it)->getYFrame();
curr_w = (*it)->getWidth() + screen->getBorderWidth2x();
2001-12-11 20:47:02 +00:00
curr_h =
2002-02-08 14:06:35 +00:00
(((*it)->isShaded())
? (*it)->getTitleHeight()
: (*it)->getHeight()) +
2002-03-19 14:30:43 +00:00
screen->getBorderWidth2x();
if ((*it)->hasTab()) {
if (! (*it)->isShaded()) { // not shaded window
switch(screen->getTabPlacement()) {
case Tab::PTOP:
curr_y -= screen->getTabHeight();
case Tab::PBOTTOM:
curr_h += screen->getTabHeight();
break;
case Tab::PLEFT:
curr_x -= (screen->isTabRotateVertical())
? screen->getTabHeight()
: screen->getTabWidth();
case Tab::PRIGHT:
curr_w += (screen->isTabRotateVertical())
? screen->getTabHeight()
: screen->getTabWidth();
break;
default:
#ifdef DEBUG
cerr << __FILE__ << ":" <<__LINE__ << ": " <<
"Unsupported Placement" << endl;
#endif // DEBUG
break;
}
} else { // shaded window
if (screen->getTabPlacement() == Tab::PTOP)
curr_y -= screen->getTabHeight();
curr_h += screen->getTabHeight();
}
} // tab cheking done
if (curr_x < test_x + win_w &&
curr_x + curr_w > test_x &&
curr_y < test_y + win_h &&
curr_y + curr_h > test_y) {
2001-12-11 20:47:02 +00:00
placed = False;
2002-03-19 14:30:43 +00:00
}
2001-12-11 20:47:02 +00:00
}
if ((toolbar_x < test_x + win_w &&
toolbar_x + toolbar_w > test_x &&
toolbar_y < test_y + win_h &&
toolbar_y + toolbar_h > test_y)
#ifdef SLIT
||
(slit_x < test_x + win_w &&
slit_x + slit_w > test_x &&
slit_y < test_y + win_h &&
slit_y + slit_h > test_y)
#endif // SLIT
)
placed = False;
if (placed) {
place_x = test_x;
place_y = test_y;
break;
}
test_x += change_x;
}
test_y += change_y;
}
break; }
2002-01-11 10:43:55 +00:00
case BScreen::COLSMARTPLACEMENT: {
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_x = head_x;
#else // !XINERAMA
test_x = 0;
#endif // XINERAMA
2002-01-11 10:43:55 +00:00
if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_x = (head_x + head_w) - win_w - test_x;
#else // !XINERAMA
2001-12-11 20:47:02 +00:00
test_x = screen->getWidth() - win_w - test_x;
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
2001-12-11 20:47:02 +00:00
2002-01-11 10:43:55 +00:00
while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_x >= 0 : test_x + win_w <= (head_x + head_w)) &&
#else // !XINERAMA
test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
#endif // XINERAMA
! placed) {
#ifdef XINERAMA
test_y = head_y;
#else // !XINERAMA
test_y = 0;
#endif // XINERAMA
2002-01-11 10:43:55 +00:00
if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_y = (head_y + head_h) - win_h - test_y;
#else // !XINERAMA
2002-02-08 14:06:35 +00:00
test_y = screen->getHeight() - win_h - test_y;
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
2001-12-11 20:47:02 +00:00
2002-01-11 10:43:55 +00:00
while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
test_y >= head_y : test_y + win_h <= (head_y + head_h)) &&
#else // !XINERAMA
test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
#endif // XINERAMA
! placed) {
2001-12-11 20:47:02 +00:00
placed = True;
2002-02-08 14:06:35 +00:00
Windows::iterator it = windowList.begin();
Windows::iterator it_end = windowList.end();
for (; it != it_end && placed; ++it) {
2002-03-19 14:30:43 +00:00
curr_x = (*it)->getXFrame();
curr_y = (*it)->getYFrame();
curr_w = (*it)->getWidth() + screen->getBorderWidth2x();
2001-12-11 20:47:02 +00:00
curr_h =
2002-02-08 14:06:35 +00:00
(((*it)->isShaded())
? (*it)->getTitleHeight()
: (*it)->getHeight()) +
2002-03-19 14:30:43 +00:00
screen->getBorderWidth2x();;
if ((*it)->hasTab()) {
if (! (*it)->isShaded()) { // not shaded window
switch(screen->getTabPlacement()) {
case Tab::PTOP:
curr_y -= screen->getTabHeight();
case Tab::PBOTTOM:
curr_h += screen->getTabHeight();
break;
case Tab::PLEFT:
curr_x -= (screen->isTabRotateVertical())
? screen->getTabHeight()
: screen->getTabWidth();
case Tab::PRIGHT:
curr_w += (screen->isTabRotateVertical())
? screen->getTabHeight()
: screen->getTabWidth();
break;
default:
#ifdef DEBUG
cerr << __FILE__ << ":" <<__LINE__ << ": " <<
"Unsupported Placement" << endl;
#endif // DEBUG
break;
}
} else { // shaded window
if (screen->getTabPlacement() == Tab::PTOP)
curr_y -= screen->getTabHeight();
curr_h += screen->getTabHeight();
}
} // tab cheking done
if (curr_x < test_x + win_w &&
curr_x + curr_w > test_x &&
curr_y < test_y + win_h &&
curr_y + curr_h > test_y) {
2001-12-11 20:47:02 +00:00
placed = False;
2002-03-19 14:30:43 +00:00
}
2001-12-11 20:47:02 +00:00
}
if ((toolbar_x < test_x + win_w &&
2002-01-18 01:35:27 +00:00
toolbar_x + toolbar_w > test_x &&
toolbar_y < test_y + win_h &&
toolbar_y + toolbar_h > test_y)
2001-12-11 20:47:02 +00:00
#ifdef SLIT
2002-01-18 01:35:27 +00:00
||
2001-12-11 20:47:02 +00:00
(slit_x < test_x + win_w &&
2002-01-18 01:35:27 +00:00
slit_x + slit_w > test_x &&
slit_y < test_y + win_h &&
slit_y + slit_h > test_y)
2001-12-11 20:47:02 +00:00
#endif // SLIT
2002-01-18 01:35:27 +00:00
)
placed = False;
2001-12-11 20:47:02 +00:00
2002-01-18 01:35:27 +00:00
if (placed) {
place_x = test_x;
place_y = test_y;
}
2001-12-11 20:47:02 +00:00
2002-01-18 01:35:27 +00:00
test_y += change_y;
}
2001-12-11 20:47:02 +00:00
2002-01-18 01:35:27 +00:00
test_x += change_x;
2001-12-11 20:47:02 +00:00
}
break; }
}
2002-03-19 14:30:43 +00:00
// cascade placement or smart placement failed
2001-12-11 20:47:02 +00:00
if (! placed) {
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
if ((cascade_x > (head_w / 2)) ||
(cascade_y > (head_h / 2)))
#else // !XINERAMA
2001-12-11 20:47:02 +00:00
if (((unsigned) cascade_x > (screen->getWidth() / 2)) ||
2002-01-18 01:35:27 +00:00
((unsigned) cascade_y > (screen->getHeight() / 2)))
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
2001-12-11 20:47:02 +00:00
2002-03-19 14:30:43 +00:00
cascade_x = cascade_y = 32;
#ifdef XINERAMA
place_x = head_x + cascade_x;
place_y = head_y + cascade_y;
#else // !XINERAMA
2001-12-11 20:47:02 +00:00
place_x = cascade_x;
place_y = cascade_y;
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
2001-12-11 20:47:02 +00:00
cascade_x += win->getTitleHeight();
cascade_y += win->getTitleHeight();
}
2002-03-19 14:30:43 +00:00
#ifdef XINERAMA
if (place_x + win_w > (head_x + head_w))
place_x = head_x + ((head_w - win_w) / 2);
if (place_y + win_h > (head_y + head_h))
place_y = head_y + ((head_h - win_h) / 2);
#else // !XINERAMA
2001-12-11 20:47:02 +00:00
if (place_x + win_w > (signed) screen->getWidth())
place_x = (((signed) screen->getWidth()) - win_w) / 2;
if (place_y + win_h > (signed) screen->getHeight())
place_y = (((signed) screen->getHeight()) - win_h) / 2;
2002-03-19 14:30:43 +00:00
#endif // XINERAMA
// fix window placement, think of tabs
if (win->hasTab()) {
if (screen->getTabPlacement() == Tab::PTOP)
place_y += screen->getTabHeight();
else if (screen->getTabPlacement() == Tab::PLEFT)
place_x += (screen->isTabRotateVertical())
? screen->getTabHeight()
: screen->getTabWidth();
}
2001-12-11 20:47:02 +00:00
win->configure(place_x, place_y, win->getWidth(), win->getHeight());
}