mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Add debug logs for window position and autoupdate.
This commit is contained in:
parent
ebb10fb8ed
commit
f316e3bd17
7 changed files with 71 additions and 39 deletions
|
@ -427,9 +427,10 @@ void UpdateChecker::unpackUpdate() {
|
|||
LOG(("Update Error: cant open file '%1' for writing").arg(tempDirPath + '/' + relativeName));
|
||||
return fatalFail();
|
||||
}
|
||||
if (f.write(fileInnerData) != fileSize) {
|
||||
auto writtenBytes = f.write(fileInnerData);
|
||||
if (writtenBytes != fileSize) {
|
||||
f.close();
|
||||
LOG(("Update Error: cant write file '%1'").arg(tempDirPath + '/' + relativeName));
|
||||
LOG(("Update Error: cant write file '%1', desiredSize: %2, write result: %3").arg(tempDirPath + '/' + relativeName).arg(fileSize).arg(writtenBytes));
|
||||
return fatalFail();
|
||||
}
|
||||
f.close();
|
||||
|
|
|
@ -546,6 +546,7 @@ void MainWindow::psFirstShow() {
|
|||
show();
|
||||
//_private.enableShadow(winId());
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
|
||||
|
|
|
@ -383,6 +383,7 @@ void MainWindow::psFirstShow() {
|
|||
show();
|
||||
_private->enableShadow(winId());
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
|
||||
|
|
|
@ -808,10 +808,12 @@ void MainWindow::psFirstShow() {
|
|||
|
||||
show();
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
|
||||
if ((cLaunchMode() == LaunchModeAutoStart && cStartMinimized() && !App::passcoded()) || cStartInTray()) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting minimized after."));
|
||||
setWindowState(Qt::WindowMinimized);
|
||||
if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) {
|
||||
hide();
|
||||
|
|
|
@ -91,10 +91,14 @@ DeclareSetting(bool, CtrlEnter);
|
|||
DeclareSetting(bool, AutoUpdate);
|
||||
|
||||
struct TWindowPos {
|
||||
TWindowPos() : moncrc(0), maximized(0), x(0), y(0), w(0), h(0) {
|
||||
}
|
||||
int32 moncrc, maximized;
|
||||
int32 x, y, w, h;
|
||||
TWindowPos() = default;
|
||||
|
||||
int32 moncrc = 0;
|
||||
int maximized = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
};
|
||||
DeclareSetting(TWindowPos, WindowPos);
|
||||
DeclareSetting(bool, SupportTray);
|
||||
|
|
|
@ -1270,11 +1270,13 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
|||
} break;
|
||||
|
||||
case dbiWindowPosition: {
|
||||
TWindowPos pos;
|
||||
stream >> pos.x >> pos.y >> pos.w >> pos.h >> pos.moncrc >> pos.maximized;
|
||||
auto position = TWindowPos();
|
||||
stream >> position.x >> position.y >> position.w >> position.h;
|
||||
stream >> position.moncrc >> position.maximized;
|
||||
if (!_checkStreamStatus(stream)) return false;
|
||||
|
||||
cSetWindowPos(pos);
|
||||
DEBUG_LOG(("Window Pos: Read from storage %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
|
||||
cSetWindowPos(position);
|
||||
} break;
|
||||
|
||||
case dbiLoggedPhoneNumber: {
|
||||
|
@ -2380,8 +2382,11 @@ void writeSettings() {
|
|||
data.stream << quint32(dbiLangPackKey) << quint64(_langPackKey);
|
||||
}
|
||||
|
||||
TWindowPos pos(cWindowPos());
|
||||
data.stream << quint32(dbiWindowPosition) << qint32(pos.x) << qint32(pos.y) << qint32(pos.w) << qint32(pos.h) << qint32(pos.moncrc) << qint32(pos.maximized);
|
||||
auto position = cWindowPos();
|
||||
data.stream << quint32(dbiWindowPosition) << qint32(position.x) << qint32(position.y) << qint32(position.w) << qint32(position.h);
|
||||
data.stream << qint32(position.moncrc) << qint32(position.maximized);
|
||||
|
||||
DEBUG_LOG(("Window Pos: Writing to storage %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
|
||||
|
||||
settings.writeEncrypted(data, SettingsKey);
|
||||
}
|
||||
|
|
|
@ -250,32 +250,38 @@ void MainWindow::initSize() {
|
|||
setMinimumWidth(st::windowMinWidth);
|
||||
setMinimumHeight((_title ? _title->height() : 0) + st::windowMinHeight);
|
||||
|
||||
auto pos = cWindowPos();
|
||||
auto position = cWindowPos();
|
||||
DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
|
||||
|
||||
auto avail = QDesktopWidget().availableGeometry();
|
||||
bool maximized = false;
|
||||
auto geom = QRect(avail.x() + (avail.width() - st::windowDefaultWidth) / 2, avail.y() + (avail.height() - st::windowDefaultHeight) / 2, st::windowDefaultWidth, st::windowDefaultHeight);
|
||||
if (pos.w && pos.h) {
|
||||
if (position.w && position.h) {
|
||||
for (auto screen : QGuiApplication::screens()) {
|
||||
if (pos.moncrc == screenNameChecksum(screen->name())) {
|
||||
if (position.moncrc == screenNameChecksum(screen->name())) {
|
||||
auto screenGeometry = screen->geometry();
|
||||
DEBUG_LOG(("Window Pos: Screen found, screen geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
|
||||
|
||||
auto w = screenGeometry.width(), h = screenGeometry.height();
|
||||
if (w >= st::windowMinWidth && h >= st::windowMinHeight) {
|
||||
if (pos.w > w) pos.w = w;
|
||||
if (pos.h > h) pos.h = h;
|
||||
pos.x += screenGeometry.x();
|
||||
pos.y += screenGeometry.y();
|
||||
if (pos.x + st::windowMinWidth <= screenGeometry.x() + screenGeometry.width() &&
|
||||
pos.y + st::windowMinHeight <= screenGeometry.y() + screenGeometry.height()) {
|
||||
geom = QRect(pos.x, pos.y, pos.w, pos.h);
|
||||
if (position.w > w) position.w = w;
|
||||
if (position.h > h) position.h = h;
|
||||
position.x += screenGeometry.x();
|
||||
position.y += screenGeometry.y();
|
||||
if (position.x + st::windowMinWidth <= screenGeometry.x() + screenGeometry.width() &&
|
||||
position.y + st::windowMinHeight <= screenGeometry.y() + screenGeometry.height()) {
|
||||
DEBUG_LOG(("Window Pos: Resulting geometry is %1, %2, %3, %4").arg(position.x).arg(position.y).arg(position.w).arg(position.h));
|
||||
geom = QRect(position.x, position.y, position.w, position.h);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos.y < 0) pos.y = 0;
|
||||
maximized = pos.maximized;
|
||||
if (position.y < 0) position.y = 0;
|
||||
maximized = position.maximized;
|
||||
}
|
||||
DEBUG_LOG(("Window Pos: Setting first %1, %2, %3, %4").arg(geom.x()).arg(geom.y()).arg(geom.width()).arg(geom.height()));
|
||||
setGeometry(geom);
|
||||
}
|
||||
|
||||
|
@ -335,39 +341,51 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
|||
if (state == Qt::WindowActive) state = windowHandle()->windowState();
|
||||
if (state == Qt::WindowMinimized || !positionInited()) return;
|
||||
|
||||
auto pos = cWindowPos(), curPos = pos;
|
||||
auto savedPosition = cWindowPos();
|
||||
auto realPosition = savedPosition;
|
||||
|
||||
if (state == Qt::WindowMaximized) {
|
||||
curPos.maximized = 1;
|
||||
realPosition.maximized = 1;
|
||||
} else {
|
||||
auto r = geometry();
|
||||
curPos.x = r.x();
|
||||
curPos.y = r.y();
|
||||
curPos.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
|
||||
curPos.h = r.height();
|
||||
curPos.maximized = 0;
|
||||
realPosition.x = r.x();
|
||||
realPosition.y = r.y();
|
||||
realPosition.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
|
||||
realPosition.h = r.height();
|
||||
realPosition.maximized = 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)));
|
||||
|
||||
int px = curPos.x + curPos.w / 2, py = curPos.y + curPos.h / 2;
|
||||
auto centerX = realPosition.x + realPosition.w / 2;
|
||||
auto centerY = realPosition.y + realPosition.h / 2;
|
||||
int minDelta = 0;
|
||||
QScreen *chosen = 0;
|
||||
QScreen *chosen = nullptr;
|
||||
auto screens = QGuiApplication::screens();
|
||||
for (auto screen : QGuiApplication::screens()) {
|
||||
auto delta = (screen->geometry().center() - QPoint(px, py)).manhattanLength();
|
||||
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
|
||||
if (!chosen || delta < minDelta) {
|
||||
minDelta = delta;
|
||||
chosen = screen;
|
||||
}
|
||||
}
|
||||
if (chosen) {
|
||||
curPos.x -= chosen->geometry().x();
|
||||
curPos.y -= chosen->geometry().y();
|
||||
curPos.moncrc = screenNameChecksum(chosen->name());
|
||||
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 (curPos.w >= st::windowMinWidth && curPos.h >= st::windowMinHeight) {
|
||||
if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) {
|
||||
cSetWindowPos(curPos);
|
||||
if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
|
||||
if (realPosition.x != savedPosition.x
|
||||
|| realPosition.y != savedPosition.y
|
||||
|| realPosition.w != savedPosition.w
|
||||
|| realPosition.h != savedPosition.h
|
||||
|| realPosition.moncrc != savedPosition.moncrc
|
||||
|| realPosition.maximized != savedPosition.maximized) {
|
||||
DEBUG_LOG(("Window Pos: Writing: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
|
||||
cSetWindowPos(realPosition);
|
||||
Local::writeSettings();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue