mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Fixes #1261 size on startup
This commit is contained in:
parent
d796517eb3
commit
19960b5d8f
3 changed files with 76 additions and 9 deletions
|
@ -79,6 +79,24 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
|
|||
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
|
||||
{
|
||||
return this->overrideScale().value_or(this->scale_);
|
||||
|
@ -579,6 +597,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,
|
|||
returnValue = this->handleSIZE(msg);
|
||||
break;
|
||||
|
||||
case WM_MOVE:
|
||||
returnValue = this->handleMOVE(msg);
|
||||
*result = 0;
|
||||
break;
|
||||
|
||||
case WM_NCHITTEST:
|
||||
returnValue = this->handleNCHITTEST(msg, result);
|
||||
break;
|
||||
|
@ -709,12 +732,23 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg)
|
|||
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};
|
||||
DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow);
|
||||
const MARGINS shadow = {8, 8, 8, 8};
|
||||
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();
|
||||
|
@ -775,6 +809,15 @@ bool BaseWindow::handleSIZE(MSG *msg)
|
|||
{
|
||||
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;
|
||||
|
@ -783,6 +826,18 @@ bool BaseWindow::handleSIZE(MSG *msg)
|
|||
#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)
|
||||
{
|
||||
#ifdef USEWINSDK
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
|
||||
explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None);
|
||||
|
||||
void setInitialBounds(const QRect &bounds);
|
||||
QRect getBounds();
|
||||
|
||||
QWidget *getLayoutContainer();
|
||||
bool hasCustomWindowFrame();
|
||||
TitleBarButton *addTitleBarButton(const TitleBarButtonStyle &style,
|
||||
|
@ -95,6 +98,7 @@ private:
|
|||
bool handleSHOWWINDOW(MSG *msg);
|
||||
bool handleNCCALCSIZE(MSG *msg, long *result);
|
||||
bool handleSIZE(MSG *msg);
|
||||
bool handleMOVE(MSG *msg);
|
||||
bool handleNCHITTEST(MSG *msg, long *result);
|
||||
|
||||
bool enableCustomFrame_;
|
||||
|
@ -116,6 +120,12 @@ private:
|
|||
std::vector<Button *> buttons;
|
||||
} ui_;
|
||||
|
||||
#ifdef USEWINSDK
|
||||
QRect initalBounds_;
|
||||
QRect currentBounds_;
|
||||
bool isNotMinimizedOrMaximized_{};
|
||||
#endif
|
||||
|
||||
pajlada::Signals::SignalHolder connections_;
|
||||
std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
|
|||
// Have to offset x by one because qt moves the window 1px too
|
||||
// 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_obj.insert("x", window->x());
|
||||
window_obj.insert("y", window->y());
|
||||
window_obj.insert("width", window->width());
|
||||
window_obj.insert("height", window->height());
|
||||
auto rect = window->getBounds();
|
||||
|
||||
window_obj.insert("x", rect.x());
|
||||
window_obj.insert("y", rect.y());
|
||||
window_obj.insert("width", rect.width());
|
||||
window_obj.insert("height", rect.height());
|
||||
|
||||
// window tabs
|
||||
QJsonArray tabs_arr;
|
||||
|
|
Loading…
Reference in a new issue