mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix maximized window on secondary screen.
This commit is contained in:
parent
a88423a33f
commit
0beec6e335
1 changed files with 21 additions and 20 deletions
|
@ -525,6 +525,7 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||||
|
|
||||||
if (state == Qt::WindowMaximized) {
|
if (state == Qt::WindowMaximized) {
|
||||||
realPosition.maximized = 1;
|
realPosition.maximized = 1;
|
||||||
|
DEBUG_LOG(("Window Pos: Saving maximized position."));
|
||||||
} else {
|
} else {
|
||||||
auto r = geometry();
|
auto r = geometry();
|
||||||
realPosition.x = r.x();
|
realPosition.x = r.x();
|
||||||
|
@ -533,29 +534,29 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||||
realPosition.h = r.height();
|
realPosition.h = r.height();
|
||||||
realPosition.maximized = 0;
|
realPosition.maximized = 0;
|
||||||
realPosition.moncrc = 0;
|
realPosition.moncrc = 0;
|
||||||
}
|
|
||||||
DEBUG_LOG(("Window Pos: Saving position: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
|
|
||||||
|
|
||||||
auto centerX = realPosition.x + realPosition.w / 2;
|
DEBUG_LOG(("Window Pos: Saving non-maximized position: %1, %2, %3, %4").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h));
|
||||||
auto centerY = realPosition.y + realPosition.h / 2;
|
|
||||||
int minDelta = 0;
|
auto centerX = realPosition.x + realPosition.w / 2;
|
||||||
QScreen *chosen = nullptr;
|
auto centerY = realPosition.y + realPosition.h / 2;
|
||||||
auto screens = QGuiApplication::screens();
|
int minDelta = 0;
|
||||||
for (auto screen : QGuiApplication::screens()) {
|
QScreen *chosen = nullptr;
|
||||||
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
|
auto screens = QGuiApplication::screens();
|
||||||
if (!chosen || delta < minDelta) {
|
for (auto screen : QGuiApplication::screens()) {
|
||||||
minDelta = delta;
|
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
|
||||||
chosen = screen;
|
if (!chosen || delta < minDelta) {
|
||||||
|
minDelta = delta;
|
||||||
|
chosen = screen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (chosen) {
|
||||||
|
auto screenGeometry = chosen->geometry();
|
||||||
|
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
|
||||||
|
realPosition.x -= screenGeometry.x();
|
||||||
|
realPosition.y -= screenGeometry.y();
|
||||||
|
realPosition.moncrc = screenNameChecksum(chosen->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chosen) {
|
|
||||||
auto screenGeometry = chosen->geometry();
|
|
||||||
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
|
|
||||||
realPosition.x -= screenGeometry.x();
|
|
||||||
realPosition.y -= screenGeometry.y();
|
|
||||||
realPosition.moncrc = screenNameChecksum(chosen->name());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
|
if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
|
||||||
if (realPosition.x != savedPosition.x
|
if (realPosition.x != savedPosition.x
|
||||||
|| realPosition.y != savedPosition.y
|
|| realPosition.y != savedPosition.y
|
||||||
|
|
Loading…
Add table
Reference in a new issue