mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Add WindowManager::getLastSelectedWindow()
to replace getMainWindow()
(#4816)
1. No longer can return a nullptr if no window was ever focused 2. When closing a window, it will no longer return an invalid pointer
This commit is contained in:
parent
38c994be49
commit
d752ce86fd
|
@ -18,6 +18,7 @@
|
||||||
- Dev: Fix clang-tidy `cppcoreguidelines-pro-type-member-init` warnings. (#4426)
|
- Dev: Fix clang-tidy `cppcoreguidelines-pro-type-member-init` warnings. (#4426)
|
||||||
- Dev: Immediate layout for invisible `ChannelView`s is skipped. (#4811)
|
- Dev: Immediate layout for invisible `ChannelView`s is skipped. (#4811)
|
||||||
- Dev: Refactor `Image` & Image's `Frames`. (#4773)
|
- Dev: Refactor `Image` & Image's `Frames`. (#4773)
|
||||||
|
- Dev: Add `WindowManager::getLastSelectedWindow()` to replace `getMainWindow()`. (#4816)
|
||||||
- Dev: Clarify signal connection lifetimes where applicable. (#4818)
|
- Dev: Clarify signal connection lifetimes where applicable. (#4818)
|
||||||
|
|
||||||
## 2.4.5
|
## 2.4.5
|
||||||
|
|
|
@ -243,11 +243,15 @@ Window &WindowManager::getMainWindow()
|
||||||
return *this->mainWindow_;
|
return *this->mainWindow_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window &WindowManager::getSelectedWindow()
|
Window *WindowManager::getLastSelectedWindow() const
|
||||||
{
|
{
|
||||||
assertInGuiThread();
|
assertInGuiThread();
|
||||||
|
if (this->selectedWindow_ == nullptr)
|
||||||
|
{
|
||||||
|
return this->mainWindow_;
|
||||||
|
}
|
||||||
|
|
||||||
return *this->selectedWindow_;
|
return this->selectedWindow_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window &WindowManager::createWindow(WindowType type, bool show, QWidget *parent)
|
Window &WindowManager::createWindow(WindowType type, bool show, QWidget *parent)
|
||||||
|
|
|
@ -65,7 +65,14 @@ public:
|
||||||
void repaintGifEmotes();
|
void repaintGifEmotes();
|
||||||
|
|
||||||
Window &getMainWindow();
|
Window &getMainWindow();
|
||||||
Window &getSelectedWindow();
|
|
||||||
|
// Returns a pointer to the last selected window.
|
||||||
|
// Edge cases:
|
||||||
|
// - If the application was not focused since the start, this will return a pointer to the main window.
|
||||||
|
// - If the window was closed this points to the main window.
|
||||||
|
// - If the window was unfocused since being selected, this function will still return it.
|
||||||
|
Window *getLastSelectedWindow() const;
|
||||||
|
|
||||||
Window &createWindow(WindowType type, bool show = true,
|
Window &createWindow(WindowType type, bool show = true,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
@ -153,6 +160,8 @@ private:
|
||||||
|
|
||||||
QTimer *saveTimer;
|
QTimer *saveTimer;
|
||||||
QTimer miscUpdateTimer_;
|
QTimer miscUpdateTimer_;
|
||||||
|
|
||||||
|
friend class Window; // this is for selectedWindow_
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -103,8 +103,10 @@ bool Window::event(QEvent *event)
|
||||||
{
|
{
|
||||||
switch (event->type())
|
switch (event->type())
|
||||||
{
|
{
|
||||||
case QEvent::WindowActivate:
|
case QEvent::WindowActivate: {
|
||||||
|
getApp()->windows->selectedWindow_ = this;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case QEvent::WindowDeactivate: {
|
case QEvent::WindowDeactivate: {
|
||||||
auto page = this->notebook_->getOrAddSelectedPage();
|
auto page = this->notebook_->getOrAddSelectedPage();
|
||||||
|
@ -142,6 +144,11 @@ void Window::closeEvent(QCloseEvent *)
|
||||||
app->windows->closeAll();
|
app->windows->closeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure selectedWindow_ is never an invalid pointer.
|
||||||
|
// WindowManager will return the main window if no window is pointed to by
|
||||||
|
// `selectedWindow_`.
|
||||||
|
getApp()->windows->selectedWindow_ = nullptr;
|
||||||
|
|
||||||
this->closed.invoke();
|
this->closed.invoke();
|
||||||
|
|
||||||
if (this->type_ == WindowType::Main)
|
if (this->type_ == WindowType::Main)
|
||||||
|
|
Loading…
Reference in a new issue