fix: prevent unnecessary layout saves (#4201)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
kornes 2022-12-03 10:50:22 +00:00 committed by GitHub
parent edd4789bf7
commit 188782ddca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 42 additions and 24 deletions

View file

@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Bugfix: Fixed unnecessary saving of windows layout. (#4201)
- Dev: Ignore `WM_SHOWWINDOW` hide events, causing fewer attempted rescales. (#4198) - Dev: Ignore `WM_SHOWWINDOW` hide events, causing fewer attempted rescales. (#4198)
## 2.4.0 ## 2.4.0

View file

@ -11,7 +11,9 @@
namespace chatterino { namespace chatterino {
AccountSwitchPopup::AccountSwitchPopup(QWidget *parent) AccountSwitchPopup::AccountSwitchPopup(QWidget *parent)
: BaseWindow({BaseWindow::TopMost, BaseWindow::Frameless}, parent) : BaseWindow({BaseWindow::TopMost, BaseWindow::Frameless,
BaseWindow::DisableLayoutSave},
parent)
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
this->setWindowFlag(Qt::Popup); this->setWindowFlag(Qt::Popup);

View file

@ -540,7 +540,11 @@ void BaseWindow::resizeEvent(QResizeEvent *)
{ {
// Queue up save because: Window resized // Queue up save because: Window resized
#ifdef CHATTERINO #ifdef CHATTERINO
getApp()->windows->queueSave(); if (!flags_.has(DisableLayoutSave))
{
getApp()->windows->queueSave();
}
#endif #endif
//this->moveIntoDesktopRect(this); //this->moveIntoDesktopRect(this);
@ -572,7 +576,10 @@ void BaseWindow::moveEvent(QMoveEvent *event)
{ {
// Queue up save because: Window position changed // Queue up save because: Window position changed
#ifdef CHATTERINO #ifdef CHATTERINO
getApp()->windows->queueSave(); if (!flags_.has(DisableLayoutSave))
{
getApp()->windows->queueSave();
}
#endif #endif
BaseWidget::moveEvent(event); BaseWidget::moveEvent(event);

View file

@ -32,6 +32,7 @@ public:
FramelessDraggable = 16, FramelessDraggable = 16,
DontFocus = 32, DontFocus = 32,
Dialog = 64, Dialog = 64,
DisableLayoutSave = 128,
}; };
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide }; enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };

View file

@ -23,8 +23,11 @@ namespace {
} // namespace } // namespace
DraggablePopup::DraggablePopup(bool closeAutomatically, QWidget *parent) DraggablePopup::DraggablePopup(bool closeAutomatically, QWidget *parent)
: BaseWindow(closeAutomatically ? popupFlagsCloseAutomatically : popupFlags, : BaseWindow(
parent) closeAutomatically
? popupFlagsCloseAutomatically | BaseWindow::DisableLayoutSave
: popupFlags | BaseWindow::DisableLayoutSave,
parent)
, lifetimeHack_(std::make_shared<bool>(false)) , lifetimeHack_(std::make_shared<bool>(false))
, dragTimer_(this) , dragTimer_(this)

View file

@ -17,7 +17,7 @@
namespace chatterino { namespace chatterino {
FramelessEmbedWindow::FramelessEmbedWindow() FramelessEmbedWindow::FramelessEmbedWindow()
: BaseWindow(BaseWindow::Frameless) : BaseWindow({BaseWindow::Frameless, BaseWindow::DisableLayoutSave})
{ {
this->split_ = new Split((QWidget *)nullptr); this->split_ = new Split((QWidget *)nullptr);
auto layout = new QHBoxLayout; auto layout = new QHBoxLayout;

View file

@ -22,7 +22,9 @@ TooltipWidget *TooltipWidget::instance()
} }
TooltipWidget::TooltipWidget(BaseWidget *parent) TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow({BaseWindow::TopMost, BaseWindow::DontFocus}, parent) : BaseWindow({BaseWindow::TopMost, BaseWindow::DontFocus,
BaseWindow::DisableLayoutSave},
parent)
, displayImage_(new QLabel()) , displayImage_(new QLabel())
, displayText_(new QLabel()) , displayText_(new QLabel())
{ {

View file

@ -9,7 +9,8 @@
namespace chatterino { namespace chatterino {
ColorPickerDialog::ColorPickerDialog(const QColor &initial, QWidget *parent) ColorPickerDialog::ColorPickerDialog(const QColor &initial, QWidget *parent)
: BasePopup(BaseWindow::EnableCustomFrame, parent) : BasePopup({BaseWindow::EnableCustomFrame, BaseWindow::DisableLayoutSave},
parent)
, color_() , color_()
, dialogConfirmed_(false) , dialogConfirmed_(false)
{ {

View file

@ -12,7 +12,7 @@
namespace chatterino { namespace chatterino {
NotificationPopup::NotificationPopup() NotificationPopup::NotificationPopup()
: BaseWindow(BaseWindow::Frameless) : BaseWindow({BaseWindow::Frameless, BaseWindow::DisableLayoutSave})
, channel_(std::make_shared<Channel>("notifications", Channel::Type::None)) , channel_(std::make_shared<Channel>("notifications", Channel::Type::None))
{ {

View file

@ -9,7 +9,7 @@
namespace chatterino { namespace chatterino {
QualityPopup::QualityPopup(const QString &channelURL, QStringList options) QualityPopup::QualityPopup(const QString &channelURL, QStringList options)
: BasePopup({}, : BasePopup({BaseWindow::DisableLayoutSave},
static_cast<QWidget *>(&(getApp()->windows->getMainWindow()))) static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
, channelURL_(channelURL) , channelURL_(channelURL)
{ {

View file

@ -28,9 +28,9 @@
namespace chatterino { namespace chatterino {
SelectChannelDialog::SelectChannelDialog(QWidget *parent) SelectChannelDialog::SelectChannelDialog(QWidget *parent)
: BaseWindow( : BaseWindow({BaseWindow::Flags::EnableCustomFrame,
{BaseWindow::Flags::EnableCustomFrame, BaseWindow::Flags::Dialog}, BaseWindow::Flags::Dialog, BaseWindow::DisableLayoutSave},
parent) parent)
, selectedChannel_(Channel::getEmpty()) , selectedChannel_(Channel::getEmpty())
{ {
this->setWindowTitle("Select a channel to join"); this->setWindowTitle("Select a channel to join");

View file

@ -26,9 +26,9 @@
namespace chatterino { namespace chatterino {
SettingsDialog::SettingsDialog(QWidget *parent) SettingsDialog::SettingsDialog(QWidget *parent)
: BaseWindow( : BaseWindow({BaseWindow::Flags::DisableCustomScaling,
{BaseWindow::Flags::DisableCustomScaling, BaseWindow::Flags::Dialog}, BaseWindow::Flags::Dialog, BaseWindow::DisableLayoutSave},
parent) parent)
{ {
this->setObjectName("SettingsDialog"); this->setObjectName("SettingsDialog");
this->setWindowTitle("Chatterino Settings"); this->setWindowTitle("Chatterino Settings");

View file

@ -12,7 +12,7 @@ namespace chatterino {
UpdateDialog::UpdateDialog() UpdateDialog::UpdateDialog()
: BaseWindow({BaseWindow::Frameless, BaseWindow::TopMost, : BaseWindow({BaseWindow::Frameless, BaseWindow::TopMost,
BaseWindow::EnableCustomFrame}) BaseWindow::EnableCustomFrame, BaseWindow::DisableLayoutSave})
{ {
auto layout = auto layout =
LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>(); LayoutCreator<UpdateDialog>(this).setLayoutType<QVBoxLayout>();

View file

@ -3,7 +3,7 @@
namespace chatterino { namespace chatterino {
WelcomeDialog::WelcomeDialog() WelcomeDialog::WelcomeDialog()
: BaseWindow(BaseWindow::EnableCustomFrame) : BaseWindow({BaseWindow::EnableCustomFrame, BaseWindow::DisableLayoutSave})
{ {
this->setWindowTitle("Chatterino quick setup"); this->setWindowTitle("Chatterino quick setup");
} }

View file

@ -32,8 +32,8 @@ namespace {
const QSize QuickSwitcherPopup::MINIMUM_SIZE(500, 300); const QSize QuickSwitcherPopup::MINIMUM_SIZE(500, 300);
QuickSwitcherPopup::QuickSwitcherPopup(QWidget *parent) QuickSwitcherPopup::QuickSwitcherPopup(QWidget *parent)
: BasePopup(FlagsEnum<BaseWindow::Flags>{BaseWindow::Flags::Frameless, : BasePopup({BaseWindow::Flags::Frameless, BaseWindow::Flags::TopMost,
BaseWindow::Flags::TopMost}, BaseWindow::DisableLayoutSave},
parent) parent)
, switcherModel_(this) , switcherModel_(this)
{ {

View file

@ -58,7 +58,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName,
} }
SearchPopup::SearchPopup(QWidget *parent, Split *split) SearchPopup::SearchPopup(QWidget *parent, Split *split)
: BasePopup({}, parent) : BasePopup({BaseWindow::DisableLayoutSave}, parent)
, split_(split) , split_(split)
{ {
this->initLayout(); this->initLayout();

View file

@ -204,8 +204,9 @@ void AboutPage::addLicense(QFormLayout *form, const QString &name,
auto *b = new QLabel("<a href=\"" + licenseLink + "\">show license</a>"); auto *b = new QLabel("<a href=\"" + licenseLink + "\">show license</a>");
QObject::connect( QObject::connect(
b, &QLabel::linkActivated, [parent = this, name, licenseLink] { b, &QLabel::linkActivated, [parent = this, name, licenseLink] {
auto window = auto window = new BasePopup({BaseWindow::Flags::EnableCustomFrame,
new BasePopup(BaseWindow::Flags::EnableCustomFrame, parent); BaseWindow::DisableLayoutSave},
parent);
window->setWindowTitle("Chatterino - License for " + name); window->setWindowTitle("Chatterino - License for " + name);
window->setAttribute(Qt::WA_DeleteOnClose); window->setAttribute(Qt::WA_DeleteOnClose);
auto layout = new QVBoxLayout(); auto layout = new QVBoxLayout();

View file

@ -44,7 +44,7 @@ namespace {
InputCompletionPopup::InputCompletionPopup(QWidget *parent) InputCompletionPopup::InputCompletionPopup(QWidget *parent)
: BasePopup({BasePopup::EnableCustomFrame, BasePopup::Frameless, : BasePopup({BasePopup::EnableCustomFrame, BasePopup::Frameless,
BasePopup::DontFocus}, BasePopup::DontFocus, BaseWindow::DisableLayoutSave},
parent) parent)
, model_(this) , model_(this)
{ {