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
- Bugfix: Fixed unnecessary saving of windows layout. (#4201)
- Dev: Ignore `WM_SHOWWINDOW` hide events, causing fewer attempted rescales. (#4198)
## 2.4.0

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -58,7 +58,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName,
}
SearchPopup::SearchPopup(QWidget *parent, Split *split)
: BasePopup({}, parent)
: BasePopup({BaseWindow::DisableLayoutSave}, parent)
, split_(split)
{
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>");
QObject::connect(
b, &QLabel::linkActivated, [parent = this, name, licenseLink] {
auto window =
new BasePopup(BaseWindow::Flags::EnableCustomFrame, parent);
auto window = new BasePopup({BaseWindow::Flags::EnableCustomFrame,
BaseWindow::DisableLayoutSave},
parent);
window->setWindowTitle("Chatterino - License for " + name);
window->setAttribute(Qt::WA_DeleteOnClose);
auto layout = new QVBoxLayout();

View file

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