Do bounds-checking on more windows (#4797)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2023-12-02 12:56:03 +01:00 committed by GitHub
parent e327ed4166
commit c4c94473ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 120 additions and 38 deletions

View file

@ -43,6 +43,7 @@
- Bugfix: Fixed lookahead/-behind not working in _Ignores_. (#4965)
- Bugfix: Fixed Image Uploader accidentally deleting images with some hosts when link resolver was enabled. (#4971)
- Bugfix: Fixed rare crash with Image Uploader when closing a split right after starting an upload. (#4971)
- Bugfix: Fixed some windows appearing between screens. (#4797)
- Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978)
- Dev: Change clang-format from v14 to v16. (#4929)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)

View file

@ -87,8 +87,7 @@ void WindowManager::showAccountSelectPopup(QPoint point)
w->refresh();
QPoint buttonPos = point;
w->move(buttonPos.x() - 30, buttonPos.y());
w->moveTo(point - QPoint(30, 0), widgets::BoundsChecking::CursorPosition);
w->show();
w->setFocus();
}

View file

@ -24,7 +24,7 @@ void initUpdateButton(Button &button,
globalPoint.setX(0);
}
dialog->move(globalPoint);
dialog->moveTo(globalPoint, widgets::BoundsChecking::DesiredPosition);
dialog->show();
dialog->raise();

View file

@ -79,4 +79,17 @@ void moveWindowTo(QWidget *window, QPoint position, BoundsChecking mode)
}
}
void showAndMoveWindowTo(QWidget *window, QPoint position, BoundsChecking mode)
{
#ifdef Q_OS_WINDOWS
window->show();
moveWindowTo(window, position, mode);
#else
moveWindowTo(window, position, mode);
window->show();
#endif
}
} // namespace chatterino::widgets

View file

@ -26,4 +26,14 @@ enum class BoundsChecking {
void moveWindowTo(QWidget *window, QPoint position,
BoundsChecking mode = BoundsChecking::DesiredPosition);
/// Moves the `window` to the (global) `position`
/// while doing bounds-checking according to `mode` to ensure the window stays on one screen.
/// Will also call show on the `window`, order is dependant on platform.
///
/// @param window The window to move.
/// @param position The global position to move the window to.
/// @param mode The desired bounds checking.
void showAndMoveWindowTo(QWidget *window, QPoint position,
BoundsChecking mode = BoundsChecking::DesiredPosition);
} // namespace chatterino::widgets

View file

@ -508,6 +508,11 @@ void BaseWindow::moveTo(QPoint point, widgets::BoundsChecking mode)
widgets::moveWindowTo(this, point, mode);
}
void BaseWindow::showAndMoveTo(QPoint point, widgets::BoundsChecking mode)
{
widgets::showAndMoveWindowTo(this, point, mode);
}
void BaseWindow::resizeEvent(QResizeEvent *)
{
// Queue up save because: Window resized
@ -559,6 +564,12 @@ void BaseWindow::closeEvent(QCloseEvent *)
void BaseWindow::showEvent(QShowEvent *)
{
#ifdef Q_OS_WIN
if (this->flags_.has(BoundsCheckOnShow))
{
this->moveTo(this->pos(), widgets::BoundsChecking::CursorPosition);
}
#endif
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)

View file

@ -27,14 +27,15 @@ class BaseWindow : public BaseWidget
public:
enum Flags {
None = 0,
EnableCustomFrame = 1,
Frameless = 2,
TopMost = 4,
DisableCustomScaling = 8,
FramelessDraggable = 16,
DontFocus = 32,
Dialog = 64,
DisableLayoutSave = 128,
EnableCustomFrame = 1 << 0,
Frameless = 1 << 1,
TopMost = 1 << 2,
DisableCustomScaling = 1 << 3,
FramelessDraggable = 1 << 4,
DontFocus = 1 << 5,
Dialog = 1 << 6,
DisableLayoutSave = 1 << 7,
BoundsCheckOnShow = 1 << 8,
};
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
@ -57,6 +58,12 @@ public:
void moveTo(QPoint point, widgets::BoundsChecking mode);
/**
* Moves the window to the given point and does bounds checking according to `mode`
* Depending on the platform, either the move or the show will take place first
**/
void showAndMoveTo(QPoint point, widgets::BoundsChecking mode);
float scale() const override;
float qtFontScale() const;

View file

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

View file

@ -9,8 +9,12 @@
namespace chatterino {
QualityPopup::QualityPopup(const QString &channelURL, QStringList options)
: BasePopup({BaseWindow::DisableLayoutSave},
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
: BasePopup(
{
BaseWindow::DisableLayoutSave,
BaseWindow::BoundsCheckOnShow,
},
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
, channelURL_(channelURL)
{
this->ui_.selector = new QComboBox(this);

View file

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

View file

@ -6,6 +6,7 @@
#include "controllers/hotkeys/HotkeyController.hpp"
#include "singletons/Settings.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/BaseWindow.hpp"
#include "widgets/helper/Button.hpp"
#include "widgets/helper/SettingsDialogTab.hpp"
#include "widgets/settingspages/AboutPage.hpp"
@ -29,9 +30,14 @@
namespace chatterino {
SettingsDialog::SettingsDialog(QWidget *parent)
: BaseWindow({BaseWindow::Flags::DisableCustomScaling,
BaseWindow::Flags::Dialog, BaseWindow::DisableLayoutSave},
parent)
: BaseWindow(
{
BaseWindow::Flags::DisableCustomScaling,
BaseWindow::Flags::Dialog,
BaseWindow::DisableLayoutSave,
BaseWindow::BoundsCheckOnShow,
},
parent)
{
this->setObjectName("SettingsDialog");
this->setWindowTitle("Chatterino Settings");
@ -380,9 +386,10 @@ void SettingsDialog::themeChangedEvent()
this->setPalette(palette);
}
void SettingsDialog::showEvent(QShowEvent *)
void SettingsDialog::showEvent(QShowEvent *e)
{
this->ui_.search->setText("");
BaseWindow::showEvent(e);
}
///// Widget creation helpers

View file

@ -37,9 +37,14 @@ QList<SplitContainer *> openPages(Window *window)
namespace chatterino {
QuickSwitcherPopup::QuickSwitcherPopup(Window *parent)
: BasePopup({BaseWindow::Flags::Frameless, BaseWindow::Flags::TopMost,
BaseWindow::DisableLayoutSave},
parent)
: BasePopup(
{
BaseWindow::Flags::Frameless,
BaseWindow::Flags::TopMost,
BaseWindow::DisableLayoutSave,
BaseWindow::BoundsCheckOnShow,
},
parent)
, switcherModel_(this)
, window(parent)
{

View file

@ -2914,8 +2914,8 @@ void ChannelView::showReplyThreadPopup(const MessagePtr &message)
popup->setThread(message->replyThread);
QPoint offset(int(150 * this->scale()), int(70 * this->scale()));
popup->move(QCursor::pos() - offset);
popup->show();
popup->showAndMoveTo(QCursor::pos() - offset,
widgets::BoundsChecking::CursorPosition);
popup->giveFocus(Qt::MouseFocusReason);
}

View file

@ -63,7 +63,12 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName,
}
SearchPopup::SearchPopup(QWidget *parent, Split *split)
: BasePopup({BaseWindow::DisableLayoutSave}, parent)
: BasePopup(
{
BaseWindow::DisableLayoutSave,
BaseWindow::BoundsCheckOnShow,
},
parent)
, split_(split)
{
this->initLayout();
@ -180,9 +185,10 @@ void SearchPopup::updateWindowTitle()
this->setWindowTitle("Searching in " + historyName + " history");
}
void SearchPopup::showEvent(QShowEvent *)
void SearchPopup::showEvent(QShowEvent *e)
{
this->search();
BaseWindow::showEvent(e);
}
bool SearchPopup::eventFilter(QObject *object, QEvent *event)

View file

@ -227,9 +227,13 @@ 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,
BaseWindow::DisableLayoutSave},
parent);
auto *window = new BasePopup(
{
BaseWindow::EnableCustomFrame,
BaseWindow::DisableLayoutSave,
BaseWindow::BoundsCheckOnShow,
},
parent);
window->setWindowTitle("Chatterino - License for " + name);
window->setAttribute(Qt::WA_DeleteOnClose);
auto layout = new QVBoxLayout();

View file

@ -45,9 +45,8 @@ FiltersPage::FiltersPage()
});
// We can safely ignore this signal connection since we own the view
std::ignore = view->addButtonPressed.connect([] {
ChannelFilterEditorDialog d(
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())));
std::ignore = view->addButtonPressed.connect([this] {
ChannelFilterEditorDialog d(this->window());
if (d.exec() == QDialog::Accepted)
{
getSettings()->filterRecords.append(

View file

@ -192,8 +192,12 @@ namespace {
void showTutorialVideo(QWidget *parent, const QString &source,
const QString &title, const QString &description)
{
auto window =
new BasePopup(BaseWindow::Flags::EnableCustomFrame, parent);
auto *window = new BasePopup(
{
BaseWindow::EnableCustomFrame,
BaseWindow::BoundsCheckOnShow,
},
parent);
window->setWindowTitle("Chatterino - " + title);
window->setAttribute(Qt::WA_DeleteOnClose);
auto layout = new QVBoxLayout();
@ -1393,7 +1397,9 @@ void Split::showChatterList()
multiWidget->setLayout(dockVbox);
chatterDock->setWidget(multiWidget);
chatterDock->setFloating(true);
chatterDock->show();
widgets::showAndMoveWindowTo(
chatterDock, this->mapToGlobal(QPoint{0, this->header_->height()}),
widgets::BoundsChecking::CursorPosition);
chatterDock->activateWindow();
}