mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Improve window "move within desktop rectangle" code (#1685)
This is used by tooltips to make sure they're always visible Behaviour changed to stick to screen instead and flip up if no space left below cursor
This commit is contained in:
parent
d9aab1f6ec
commit
dd5455d1cf
1 changed files with 11 additions and 0 deletions
|
@ -566,10 +566,14 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
||||||
|
|
||||||
// move the widget into the screen geometry if it's not already in there
|
// move the widget into the screen geometry if it's not already in there
|
||||||
QDesktopWidget *desktop = QApplication::desktop();
|
QDesktopWidget *desktop = QApplication::desktop();
|
||||||
|
QPoint globalCursorPos = QCursor::pos();
|
||||||
|
|
||||||
QRect s = desktop->availableGeometry(parent);
|
QRect s = desktop->availableGeometry(parent);
|
||||||
QPoint p = this->pos();
|
QPoint p = this->pos();
|
||||||
|
|
||||||
|
bool stickRight = false;
|
||||||
|
bool stickBottom = false;
|
||||||
|
|
||||||
if (p.x() < s.left())
|
if (p.x() < s.left())
|
||||||
{
|
{
|
||||||
p.setX(s.left());
|
p.setX(s.left());
|
||||||
|
@ -580,13 +584,20 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
||||||
}
|
}
|
||||||
if (p.x() + this->width() > s.right())
|
if (p.x() + this->width() > s.right())
|
||||||
{
|
{
|
||||||
|
stickRight = true;
|
||||||
p.setX(s.right() - this->width());
|
p.setX(s.right() - this->width());
|
||||||
}
|
}
|
||||||
if (p.y() + this->height() > s.bottom())
|
if (p.y() + this->height() > s.bottom())
|
||||||
{
|
{
|
||||||
|
stickBottom = true;
|
||||||
p.setY(s.bottom() - this->height());
|
p.setY(s.bottom() - this->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stickRight && stickBottom)
|
||||||
|
{
|
||||||
|
p.setY(globalCursorPos.y() - this->height() - 16);
|
||||||
|
}
|
||||||
|
|
||||||
if (p != this->pos())
|
if (p != this->pos())
|
||||||
this->move(p);
|
this->move(p);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue