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:
@@ -243,11 +243,15 @@ Window &WindowManager::getMainWindow()
|
||||
return *this->mainWindow_;
|
||||
}
|
||||
|
||||
Window &WindowManager::getSelectedWindow()
|
||||
Window *WindowManager::getLastSelectedWindow() const
|
||||
{
|
||||
assertInGuiThread();
|
||||
if (this->selectedWindow_ == nullptr)
|
||||
{
|
||||
return this->mainWindow_;
|
||||
}
|
||||
|
||||
return *this->selectedWindow_;
|
||||
return this->selectedWindow_;
|
||||
}
|
||||
|
||||
Window &WindowManager::createWindow(WindowType type, bool show, QWidget *parent)
|
||||
|
||||
@@ -65,7 +65,14 @@ public:
|
||||
void repaintGifEmotes();
|
||||
|
||||
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,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
@@ -153,6 +160,8 @@ private:
|
||||
|
||||
QTimer *saveTimer;
|
||||
QTimer miscUpdateTimer_;
|
||||
|
||||
friend class Window; // this is for selectedWindow_
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user