diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea59f9d5..b5234d864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Bugfix: Fixed Usercard popup not floating on tiling WMs on Linux when "Automatically close user popup when it loses focus" setting is enabled. (#3511) - Bugfix: Fixed selection of tabs after closing a tab when using "Live Tabs Only". (#4770) - Bugfix: Fixed input in reply thread popup losing focus when dragging. (#4815) +- Bugfix: Fixed the Quick Switcher (CTRL+K) from sometimes showing up on the wrong window. (#4819) - Bugfix: Fixed too much text being copied when copying chat messages. (#4812) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) - Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767) diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 9e11f0c9e..39ae451df 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -492,9 +492,8 @@ void Window::addShortcuts() return ""; }}, {"openQuickSwitcher", - [](std::vector) -> QString { - auto quickSwitcher = - new QuickSwitcherPopup(&getApp()->windows->getMainWindow()); + [this](std::vector) -> QString { + auto *quickSwitcher = new QuickSwitcherPopup(this); quickSwitcher->show(); return ""; }}, diff --git a/src/widgets/dialogs/switcher/NewTabItem.cpp b/src/widgets/dialogs/switcher/NewTabItem.cpp index 2bd8867ec..7c8e25fd1 100644 --- a/src/widgets/dialogs/switcher/NewTabItem.cpp +++ b/src/widgets/dialogs/switcher/NewTabItem.cpp @@ -12,16 +12,17 @@ namespace chatterino { -NewTabItem::NewTabItem(const QString &channelName) +NewTabItem::NewTabItem(Window *window_, const QString &channelName) : AbstractSwitcherItem(QIcon(":/switcher/plus.svg")) , channelName_(channelName) , text_(QString(TEXT_FORMAT).arg(channelName)) + , window(window_) { } void NewTabItem::action() { - auto &nb = getApp()->windows->getMainWindow().getNotebook(); + auto &nb = this->window->getNotebook(); SplitContainer *container = nb.addPage(true); Split *split = new Split(container); diff --git a/src/widgets/dialogs/switcher/NewTabItem.hpp b/src/widgets/dialogs/switcher/NewTabItem.hpp index a527201b1..711a03fc1 100644 --- a/src/widgets/dialogs/switcher/NewTabItem.hpp +++ b/src/widgets/dialogs/switcher/NewTabItem.hpp @@ -4,6 +4,8 @@ namespace chatterino { +class Window; + class NewTabItem : public AbstractSwitcherItem { public: @@ -13,7 +15,7 @@ public: * * @param channelName name of channel to open */ - NewTabItem(const QString &channelName); + NewTabItem(Window *window_, const QString &channelName); /** * @brief Open the channel passed in the constructor in a new tab. @@ -27,6 +29,7 @@ private: static constexpr const char *TEXT_FORMAT = "Open channel \"%1\" in new tab"; QString channelName_; QString text_; + Window *window{}; }; } // namespace chatterino diff --git a/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp b/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp index 40792d3ff..5110b51e3 100644 --- a/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp +++ b/src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp @@ -15,30 +15,33 @@ #include "widgets/splits/SplitContainer.hpp" #include "widgets/Window.hpp" -namespace chatterino { - namespace { - QList openPages() + +using namespace chatterino; + +QList openPages(Window *window) +{ + QList pages; + + auto &nb = window->getNotebook(); + for (int i = 0; i < nb.getPageCount(); ++i) { - QList pages; - - auto &nb = getApp()->windows->getMainWindow().getNotebook(); - for (int i = 0; i < nb.getPageCount(); ++i) - { - pages.append(static_cast(nb.getPageAt(i))); - } - - return pages; + pages.append(static_cast(nb.getPageAt(i))); } + + return pages; +} + } // namespace -const QSize QuickSwitcherPopup::MINIMUM_SIZE(500, 300); +namespace chatterino { -QuickSwitcherPopup::QuickSwitcherPopup(QWidget *parent) +QuickSwitcherPopup::QuickSwitcherPopup(Window *parent) : BasePopup({BaseWindow::Flags::Frameless, BaseWindow::Flags::TopMost, BaseWindow::DisableLayoutSave}, parent) , switcherModel_(this) + , window(parent) { this->setWindowFlag(Qt::Dialog); this->setActionOnFocusLoss(BaseWindow::ActionOnFocusLoss::Delete); @@ -86,7 +89,7 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text) this->switcherModel_.clear(); // Add items for navigating to different splits - for (auto *sc : openPages()) + for (auto *sc : openPages(this->window)) { const QString &tabTitle = sc->getTab()->getTitle(); const auto splits = sc->getSplits(); @@ -119,7 +122,7 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text) // Add item for opening a channel in a new tab or new popup if (!text.isEmpty()) { - auto newTabItem = std::make_unique(text); + auto newTabItem = std::make_unique(this->window, text); this->switcherModel_.addItem(std::move(newTabItem)); auto newPopupItem = std::make_unique(text); diff --git a/src/widgets/dialogs/switcher/QuickSwitcherPopup.hpp b/src/widgets/dialogs/switcher/QuickSwitcherPopup.hpp index ffc707aa8..4f6fe37e6 100644 --- a/src/widgets/dialogs/switcher/QuickSwitcherPopup.hpp +++ b/src/widgets/dialogs/switcher/QuickSwitcherPopup.hpp @@ -10,6 +10,7 @@ namespace chatterino { class GenericListView; +class Window; class QuickSwitcherPopup : public BasePopup { @@ -17,19 +18,19 @@ public: /** * @brief Construct a new QuickSwitcherPopup. * - * @param parent Parent widget of the popup. The popup will be placed - * in the center of the parent widget. + * @param parent Parent window of the popup. The popup will be placed + * in the center of the window. */ - explicit QuickSwitcherPopup(QWidget *parent = nullptr); + explicit QuickSwitcherPopup(Window *parent); protected: - virtual void themeChangedEvent() override; + void themeChangedEvent() override; public slots: void updateSuggestions(const QString &text); private: - static const QSize MINIMUM_SIZE; + constexpr static const QSize MINIMUM_SIZE{500, 300}; struct { QLineEdit *searchEdit{}; @@ -38,6 +39,8 @@ private: QuickSwitcherModel switcherModel_; + Window *window{}; + void initWidgets(); };