xinerama support for window placement
This commit is contained in:
parent
6ea8fb9afa
commit
e18ff901fc
8 changed files with 141 additions and 33 deletions
|
@ -2074,16 +2074,12 @@ const Rect& BScreen::availableArea(void) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RectList BScreen::allAvailableAreas(void) const {
|
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
if (isXineramaActive())
|
RectList BScreen::allAvailableAreas(void) const {
|
||||||
return xineramaUsableArea;
|
assert(isXineramaActive());
|
||||||
#endif // XINERAMA
|
return xineramaUsableArea;
|
||||||
|
|
||||||
RectList list;
|
|
||||||
list.push_back(availableArea());
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
#endif // XINERAMA
|
||||||
|
|
||||||
|
|
||||||
void BScreen::updateAvailableArea(void) {
|
void BScreen::updateAvailableArea(void) {
|
||||||
|
|
|
@ -312,7 +312,9 @@ public:
|
||||||
// allAvailableAreas should be used whenever possible instead of this function
|
// allAvailableAreas should be used whenever possible instead of this function
|
||||||
// as then Xinerama will work correctly.
|
// as then Xinerama will work correctly.
|
||||||
const Rect& availableArea(void) const;
|
const Rect& availableArea(void) const;
|
||||||
|
#ifdef XINERAMA
|
||||||
RectList allAvailableAreas(void) const;
|
RectList allAvailableAreas(void) const;
|
||||||
|
#endif // XINERAMA
|
||||||
void updateAvailableArea(void);
|
void updateAvailableArea(void);
|
||||||
void addStrut(Strut *strut);
|
void addStrut(Strut *strut);
|
||||||
void removeStrut(Strut *strut);
|
void removeStrut(Strut *strut);
|
||||||
|
|
12
src/Util.cc
12
src/Util.cc
|
@ -141,6 +141,18 @@ bool Rect::intersects(const Rect &a) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Rect::contains(int __x, int __y) const {
|
||||||
|
return __x >= _x1 && __x <= _x2 &&
|
||||||
|
__y >= _y1 && __y <= _y2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Rect::contains(const Rect& a) const {
|
||||||
|
return a._x1 >= _x1 && a._x2 <= _x2 &&
|
||||||
|
a._y1 >= _y1 && a._y2 <= _y2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string expandTilde(const string& s) {
|
string expandTilde(const string& s) {
|
||||||
if (s[0] != '~') return s;
|
if (s[0] != '~') return s;
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
|
inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
|
||||||
|
|
||||||
bool intersects(const Rect &a) const;
|
bool intersects(const Rect &a) const;
|
||||||
|
bool contains(int __x, int __y) const;
|
||||||
|
bool contains(const Rect &a) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _x1, _y1, _x2, _y2;
|
int _x1, _y1, _x2, _y2;
|
||||||
|
|
|
@ -584,9 +584,22 @@ static bool colRLBT(const Rect &first, const Rect &second) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Workspace::smartPlacement(Rect& win, const Rect& availableArea) {
|
bool Workspace::smartPlacement(Rect& win) {
|
||||||
rectList spaces;
|
rectList spaces;
|
||||||
spaces.push_back(availableArea); //initially the entire screen is free
|
|
||||||
|
//initially the entire screen is free
|
||||||
|
#ifdef XINERAMA
|
||||||
|
if (screen->isXineramaActive() &&
|
||||||
|
screen->getBlackbox()->doXineramaPlacement()) {
|
||||||
|
RectList availableAreas = screen->allAvailableAreas();
|
||||||
|
assert(availableAreas.size() > 0);
|
||||||
|
RectList::iterator it, end = availableAreas.end();
|
||||||
|
|
||||||
|
for (it = availableAreas.begin(); it != end; ++it)
|
||||||
|
spaces.push_back(*it);
|
||||||
|
} else
|
||||||
|
#endif // XINERAMA
|
||||||
|
spaces.push_back(screen->availableArea());
|
||||||
|
|
||||||
//Find Free Spaces
|
//Find Free Spaces
|
||||||
BlackboxWindowList::const_iterator wit = windowList.begin(),
|
BlackboxWindowList::const_iterator wit = windowList.begin(),
|
||||||
|
@ -661,23 +674,40 @@ bool Workspace::smartPlacement(Rect& win, const Rect& availableArea) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Workspace::underMousePlacement(Rect &win, const Rect &availableArea) {
|
bool Workspace::underMousePlacement(Rect &win) {
|
||||||
int x, y, rx, ry;
|
int x, y, rx, ry;
|
||||||
Window c, r;
|
Window c, r;
|
||||||
unsigned int m;
|
unsigned int m;
|
||||||
XQueryPointer(screen->getBlackbox()->getXDisplay(), screen->getRootWindow(),
|
XQueryPointer(screen->getBlackbox()->getXDisplay(), screen->getRootWindow(),
|
||||||
&r, &c, &rx, &ry, &x, &y, &m);
|
&r, &c, &rx, &ry, &x, &y, &m);
|
||||||
|
|
||||||
|
Rect area;
|
||||||
|
#ifdef XINERAMA
|
||||||
|
if (screen->isXineramaActive() &&
|
||||||
|
screen->getBlackbox()->doXineramaPlacement()) {
|
||||||
|
RectList availableAreas = screen->allAvailableAreas();
|
||||||
|
assert(availableAreas.size() > 0);
|
||||||
|
RectList::iterator it, end = availableAreas.end();
|
||||||
|
|
||||||
|
for (it = availableAreas.begin(); it != end; ++it)
|
||||||
|
if (it->contains(rx, ry)) break;
|
||||||
|
assert(it != end); // the mouse isn't inside an area?
|
||||||
|
area = *it;
|
||||||
|
} else
|
||||||
|
#endif // XINERAMA
|
||||||
|
area = screen->availableArea();
|
||||||
|
|
||||||
x = rx - win.width() / 2;
|
x = rx - win.width() / 2;
|
||||||
y = ry - win.height() / 2;
|
y = ry - win.height() / 2;
|
||||||
|
|
||||||
if (x < availableArea.x())
|
if (x < area.x())
|
||||||
x = availableArea.x();
|
x = area.x();
|
||||||
if (y < availableArea.y())
|
if (y < area.y())
|
||||||
y = availableArea.y();
|
y = area.y();
|
||||||
if (x + win.width() > availableArea.x() + availableArea.width())
|
if (x + win.width() > area.x() + area.width())
|
||||||
x = availableArea.x() + availableArea.width() - win.width();
|
x = area.x() + area.width() - win.width();
|
||||||
if (y + win.height() > availableArea.y() + availableArea.height())
|
if (y + win.height() > area.y() + area.height())
|
||||||
y = availableArea.y() + availableArea.height() - win.height();
|
y = area.y() + area.height() - win.height();
|
||||||
|
|
||||||
win.setX(x);
|
win.setX(x);
|
||||||
win.setY(y);
|
win.setY(y);
|
||||||
|
@ -686,7 +716,9 @@ bool Workspace::underMousePlacement(Rect &win, const Rect &availableArea) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Workspace::cascadePlacement(Rect &win, const Rect &availableArea) {
|
bool Workspace::cascadePlacement(Rect &win) {
|
||||||
|
const Rect &availableArea = screen->availableArea();
|
||||||
|
|
||||||
if ((cascade_x > static_cast<signed>(availableArea.width() / 2)) ||
|
if ((cascade_x > static_cast<signed>(availableArea.width() / 2)) ||
|
||||||
(cascade_y > static_cast<signed>(availableArea.height() / 2)))
|
(cascade_y > static_cast<signed>(availableArea.height() / 2)))
|
||||||
cascade_x = cascade_y = 32;
|
cascade_x = cascade_y = 32;
|
||||||
|
@ -703,32 +735,29 @@ bool Workspace::cascadePlacement(Rect &win, const Rect &availableArea) {
|
||||||
|
|
||||||
|
|
||||||
void Workspace::placeWindow(BlackboxWindow *win) {
|
void Workspace::placeWindow(BlackboxWindow *win) {
|
||||||
Rect availableArea(screen->availableArea()),
|
Rect new_win(0, 0, win->frameRect().width(), win->frameRect().height());
|
||||||
new_win(availableArea.x(), availableArea.y(),
|
|
||||||
win->frameRect().width(), win->frameRect().height());
|
|
||||||
bool placed = False;
|
bool placed = False;
|
||||||
|
|
||||||
switch (screen->getPlacementPolicy()) {
|
switch (screen->getPlacementPolicy()) {
|
||||||
case BScreen::RowSmartPlacement:
|
case BScreen::RowSmartPlacement:
|
||||||
case BScreen::ColSmartPlacement:
|
case BScreen::ColSmartPlacement:
|
||||||
placed = smartPlacement(new_win, availableArea);
|
placed = smartPlacement(new_win);
|
||||||
break;
|
break;
|
||||||
case BScreen::UnderMousePlacement:
|
case BScreen::UnderMousePlacement:
|
||||||
case BScreen::ClickMousePlacement:
|
case BScreen::ClickMousePlacement:
|
||||||
placed = underMousePlacement(new_win, availableArea);
|
placed = underMousePlacement(new_win);
|
||||||
default:
|
default:
|
||||||
break; // handled below
|
break; // handled below
|
||||||
} // switch
|
} // switch
|
||||||
|
|
||||||
if (placed == False) {
|
if (placed == False) {
|
||||||
cascadePlacement(new_win, availableArea);
|
cascadePlacement(new_win);
|
||||||
cascade_x += win->getTitleHeight() + (screen->getBorderWidth() * 2);
|
cascade_x += win->getTitleHeight() + (screen->getBorderWidth() * 2);
|
||||||
cascade_y += win->getTitleHeight() + (screen->getBorderWidth() * 2);
|
cascade_y += win->getTitleHeight() + (screen->getBorderWidth() * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_win.right() > availableArea.right())
|
// make sure the placement was valid
|
||||||
new_win.setX(availableArea.left());
|
assert(screen->availableArea().contains(new_win));
|
||||||
if (new_win.bottom() > availableArea.bottom())
|
|
||||||
new_win.setY(availableArea.top());
|
|
||||||
win->configure(new_win.x(), new_win.y(), new_win.width(), new_win.height());
|
win->configure(new_win.x(), new_win.y(), new_win.width(), new_win.height());
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,9 @@ private:
|
||||||
StackVector::iterator &stack);
|
StackVector::iterator &stack);
|
||||||
|
|
||||||
void placeWindow(BlackboxWindow *win);
|
void placeWindow(BlackboxWindow *win);
|
||||||
bool cascadePlacement(Rect& win, const Rect& availableArea);
|
bool cascadePlacement(Rect& win);
|
||||||
bool smartPlacement(Rect& win, const Rect& availableArea);
|
bool smartPlacement(Rect& win);
|
||||||
bool underMousePlacement(Rect& win, const Rect& availableArea);
|
bool underMousePlacement(Rect& win);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Workspace(BScreen *scrn, unsigned int i = 0);
|
Workspace(BScreen *scrn, unsigned int i = 0);
|
||||||
|
|
|
@ -1164,6 +1164,32 @@ void Blackbox::shutdown(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XINERAMA
|
||||||
|
void Blackbox::saveXineramaPlacement(bool x) {
|
||||||
|
resource.xinerama_placement = x;
|
||||||
|
config.setValue("session.xineramaSupport.windowPlacement",
|
||||||
|
resource.xinerama_placement);
|
||||||
|
reconfigure(); // make sure all screens get this change
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Blackbox::saveXineramaMaximizing(bool x) {
|
||||||
|
resource.xinerama_maximize = x;
|
||||||
|
config.setValue("session.xineramaSupport.windowMaximizing",
|
||||||
|
resource.xinerama_maximize);
|
||||||
|
reconfigure(); // make sure all screens get this change
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Blackbox::saveXineramaSnapping(bool x) {
|
||||||
|
resource.xinerama_snap = x;
|
||||||
|
config.setValue("session.xineramaSupport.windowSnapping",
|
||||||
|
resource.xinerama_snap);
|
||||||
|
reconfigure(); // make sure all screens get this change
|
||||||
|
}
|
||||||
|
#endif // XINERAMA
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save all values as they are so that the defaults will be written to the rc
|
* Save all values as they are so that the defaults will be written to the rc
|
||||||
* file
|
* file
|
||||||
|
@ -1182,6 +1208,12 @@ void Blackbox::save_rc(void) {
|
||||||
config.setValue("session.styleFile", resource.style_file);
|
config.setValue("session.styleFile", resource.style_file);
|
||||||
config.setValue("session.titlebarLayout", resource.titlebar_layout);
|
config.setValue("session.titlebarLayout", resource.titlebar_layout);
|
||||||
|
|
||||||
|
#ifdef XINERAMA
|
||||||
|
saveXineramaPlacement(resource.xinerama_placement);
|
||||||
|
saveXineramaMaximizing(resource.xinerama_maximize);
|
||||||
|
saveXineramaSnapping(resource.xinerama_snap);
|
||||||
|
#endif // XINERAMA
|
||||||
|
|
||||||
std::for_each(screenList.begin(), screenList.end(),
|
std::for_each(screenList.begin(), screenList.end(),
|
||||||
std::mem_fun(&BScreen::save_rc));
|
std::mem_fun(&BScreen::save_rc));
|
||||||
|
|
||||||
|
@ -1228,10 +1260,28 @@ void Blackbox::load_rc(void) {
|
||||||
|
|
||||||
if (! config.getValue("session.titlebarLayout", resource.titlebar_layout))
|
if (! config.getValue("session.titlebarLayout", resource.titlebar_layout))
|
||||||
resource.titlebar_layout = "ILMC";
|
resource.titlebar_layout = "ILMC";
|
||||||
|
|
||||||
|
#ifdef XINERAMA
|
||||||
|
if (! config.getValue("session.xineramaSupport.windowPlacement",
|
||||||
|
resource.xinerama_placement))
|
||||||
|
resource.xinerama_placement = true;
|
||||||
|
|
||||||
|
if (! config.getValue("session.xineramaSupport.windowMaximizing",
|
||||||
|
resource.xinerama_maximize))
|
||||||
|
resource.xinerama_maximize = true;
|
||||||
|
|
||||||
|
if (! config.getValue("session.xineramaSupport.windowSnapping",
|
||||||
|
resource.xinerama_snap))
|
||||||
|
resource.xinerama_snap = true;
|
||||||
|
#endif // XINERAMA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Blackbox::reconfigure(void) {
|
void Blackbox::reconfigure(void) {
|
||||||
|
// don't reconfigure while saving the initial rc file, it's a waste and it
|
||||||
|
// breaks somethings (workspace names)
|
||||||
|
if (isStartup()) return;
|
||||||
|
|
||||||
reconfigure_wait = True;
|
reconfigure_wait = True;
|
||||||
|
|
||||||
if (! timer->isTiming()) timer->start();
|
if (! timer->isTiming()) timer->start();
|
||||||
|
|
|
@ -115,6 +115,10 @@ private:
|
||||||
timeval auto_raise_delay;
|
timeval auto_raise_delay;
|
||||||
unsigned long cache_life, cache_max;
|
unsigned long cache_life, cache_max;
|
||||||
std::string titlebar_layout;
|
std::string titlebar_layout;
|
||||||
|
|
||||||
|
#ifdef XINERAMA
|
||||||
|
bool xinerama_placement, xinerama_maximize, xinerama_snap;
|
||||||
|
#endif // XINERAMA
|
||||||
} resource;
|
} resource;
|
||||||
|
|
||||||
typedef std::map<Window, BlackboxWindow*> WindowLookup;
|
typedef std::map<Window, BlackboxWindow*> WindowLookup;
|
||||||
|
@ -181,6 +185,19 @@ public:
|
||||||
Toolbar *searchToolbar(Window);
|
Toolbar *searchToolbar(Window);
|
||||||
Slit *searchSlit(Window);
|
Slit *searchSlit(Window);
|
||||||
|
|
||||||
|
#ifdef XINERAMA
|
||||||
|
inline bool doXineramaPlacement(void) const
|
||||||
|
{ return resource.xinerama_placement; }
|
||||||
|
inline bool doXineramaMaximizing(void) const
|
||||||
|
{ return resource.xinerama_maximize; }
|
||||||
|
inline bool doXineramaSnapping(void) const
|
||||||
|
{ return resource.xinerama_snap; }
|
||||||
|
|
||||||
|
void saveXineramaPlacement(bool x);
|
||||||
|
void saveXineramaMaximizing(bool x);
|
||||||
|
void saveXineramaSnapping(bool x);
|
||||||
|
#endif // XINERAMA
|
||||||
|
|
||||||
void saveMenuSearch(Window window, Basemenu *data);
|
void saveMenuSearch(Window window, Basemenu *data);
|
||||||
void saveSystrayWindowSearch(Window window, BScreen *screen);
|
void saveSystrayWindowSearch(Window window, BScreen *screen);
|
||||||
void saveWindowSearch(Window window, BlackboxWindow *data);
|
void saveWindowSearch(Window window, BlackboxWindow *data);
|
||||||
|
|
Loading…
Reference in a new issue