Fixes #1261 size on startup

This commit is contained in:
fourtf 2019-09-01 14:06:30 +02:00
parent d796517eb3
commit 19960b5d8f
3 changed files with 76 additions and 9 deletions

View file

@ -79,6 +79,24 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
this->resize(300, 150); this->resize(300, 150);
} }
void BaseWindow::setInitialBounds(const QRect &bounds)
{
#ifdef USEWINSDK
this->initalBounds_ = bounds;
#else
this->setGeometry(bounds);
#endif
}
QRect BaseWindow::getBounds()
{
#ifdef USEWINSDK
return this->currentBounds_;
#else
return this->geometry();
#endif
}
float BaseWindow::scale() const float BaseWindow::scale() const
{ {
return this->overrideScale().value_or(this->scale_); return this->overrideScale().value_or(this->scale_);
@ -579,6 +597,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,
returnValue = this->handleSIZE(msg); returnValue = this->handleSIZE(msg);
break; break;
case WM_MOVE:
returnValue = this->handleMOVE(msg);
*result = 0;
break;
case WM_NCHITTEST: case WM_NCHITTEST:
returnValue = this->handleNCHITTEST(msg, result); returnValue = this->handleNCHITTEST(msg, result);
break; break;
@ -709,12 +732,23 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg)
this->updateScale(); this->updateScale();
} }
if (!this->shown_ && this->isVisible() && this->hasCustomWindowFrame()) if (!this->shown_ && this->isVisible())
{ {
this->shown_ = true; if (this->hasCustomWindowFrame())
{
this->shown_ = true;
const MARGINS shadow = {8, 8, 8, 8}; const MARGINS shadow = {8, 8, 8, 8};
DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow); DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow);
}
if (!this->initalBounds_.isNull())
{
::SetWindowPos(msg->hwnd, nullptr, this->initalBounds_.x(),
this->initalBounds_.y(), this->initalBounds_.width(),
this->initalBounds_.height(),
SWP_NOZORDER | SWP_NOACTIVATE);
this->currentBounds_ = this->initalBounds_;
}
} }
this->calcButtonsSizes(); this->calcButtonsSizes();
@ -775,6 +809,15 @@ bool BaseWindow::handleSIZE(MSG *msg)
{ {
this->ui_.windowLayout->setContentsMargins(0, 1, 0, 0); this->ui_.windowLayout->setContentsMargins(0, 1, 0, 0);
} }
if ((this->isNotMinimizedOrMaximized_ =
msg->wParam == SIZE_RESTORED))
{
RECT rect;
::GetWindowRect(msg->hwnd, &rect);
this->currentBounds_ =
QRect(QPoint(rect.left, rect.top),
QPoint(rect.right - 1, rect.bottom - 1));
}
} }
} }
return false; return false;
@ -783,6 +826,18 @@ bool BaseWindow::handleSIZE(MSG *msg)
#endif #endif
} }
bool BaseWindow::handleMOVE(MSG *msg)
{
if (this->isNotMinimizedOrMaximized_)
{
RECT rect;
::GetWindowRect(msg->hwnd, &rect);
this->currentBounds_ = QRect(QPoint(rect.left, rect.top),
QPoint(rect.right - 1, rect.bottom - 1));
}
return false;
}
bool BaseWindow::handleNCHITTEST(MSG *msg, long *result) bool BaseWindow::handleNCHITTEST(MSG *msg, long *result)
{ {
#ifdef USEWINSDK #ifdef USEWINSDK

View file

@ -34,6 +34,9 @@ public:
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None); explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);
void setInitialBounds(const QRect &bounds);
QRect getBounds();
QWidget *getLayoutContainer(); QWidget *getLayoutContainer();
bool hasCustomWindowFrame(); bool hasCustomWindowFrame();
TitleBarButton *addTitleBarButton(const TitleBarButtonStyle &style, TitleBarButton *addTitleBarButton(const TitleBarButtonStyle &style,
@ -95,6 +98,7 @@ private:
bool handleSHOWWINDOW(MSG *msg); bool handleSHOWWINDOW(MSG *msg);
bool handleNCCALCSIZE(MSG *msg, long *result); bool handleNCCALCSIZE(MSG *msg, long *result);
bool handleSIZE(MSG *msg); bool handleSIZE(MSG *msg);
bool handleMOVE(MSG *msg);
bool handleNCHITTEST(MSG *msg, long *result); bool handleNCHITTEST(MSG *msg, long *result);
bool enableCustomFrame_; bool enableCustomFrame_;
@ -116,6 +120,12 @@ private:
std::vector<Button *> buttons; std::vector<Button *> buttons;
} ui_; } ui_;
#ifdef USEWINSDK
QRect initalBounds_;
QRect currentBounds_;
bool isNotMinimizedOrMaximized_{};
#endif
pajlada::Signals::SignalHolder connections_; pajlada::Signals::SignalHolder connections_;
std::vector<pajlada::Signals::ScopedConnection> managedConnections_; std::vector<pajlada::Signals::ScopedConnection> managedConnections_;

View file

@ -338,7 +338,7 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
// Have to offset x by one because qt moves the window 1px too // Have to offset x by one because qt moves the window 1px too
// far to the left:w // far to the left:w
window.setGeometry(x + 1, y, width, height); window.setInitialBounds({x, y, width, height});
} }
} }
@ -465,10 +465,12 @@ void WindowManager::save()
} }
// window geometry // window geometry
window_obj.insert("x", window->x()); auto rect = window->getBounds();
window_obj.insert("y", window->y());
window_obj.insert("width", window->width()); window_obj.insert("x", rect.x());
window_obj.insert("height", window->height()); window_obj.insert("y", rect.y());
window_obj.insert("width", rect.width());
window_obj.insert("height", rect.height());
// window tabs // window tabs
QJsonArray tabs_arr; QJsonArray tabs_arr;