mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Track window activation history.
This commit is contained in:
parent
bbd937115c
commit
c737e2f91b
3 changed files with 46 additions and 11 deletions
|
@ -191,6 +191,7 @@ Application::~Application() {
|
||||||
Local::writeSettings();
|
Local::writeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_windowStack.clear();
|
||||||
setLastActiveWindow(nullptr);
|
setLastActiveWindow(nullptr);
|
||||||
_windowInSettings = _lastActivePrimaryWindow = nullptr;
|
_windowInSettings = _lastActivePrimaryWindow = nullptr;
|
||||||
_closingAsyncWindows.clear();
|
_closingAsyncWindows.clear();
|
||||||
|
@ -514,18 +515,26 @@ void Application::startTray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::activate() {
|
void Application::activate() {
|
||||||
const auto last = _lastActiveWindow;
|
for (const auto &window : _windowStack) {
|
||||||
const auto primary = _lastActivePrimaryWindow;
|
if (window == _lastActiveWindow) {
|
||||||
enumerateWindows([&](not_null<Window::Controller*> w) {
|
break;
|
||||||
if (w != last && w != primary) {
|
}
|
||||||
w->widget()->showFromTray();
|
const auto widget = window->widget();
|
||||||
|
const auto wasHidden = !widget->isVisible();
|
||||||
|
const auto state = widget->windowState();
|
||||||
|
if (state & Qt::WindowMinimized) {
|
||||||
|
widget->setWindowState(state & ~Qt::WindowMinimized);
|
||||||
|
}
|
||||||
|
widget->setVisible(true);
|
||||||
|
widget->activateWindow();
|
||||||
|
if (wasHidden) {
|
||||||
|
if (const auto session = window->sessionController()) {
|
||||||
|
session->content()->windowShown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (primary) {
|
|
||||||
primary->widget()->showFromTray();
|
|
||||||
}
|
}
|
||||||
if (last && last != primary) {
|
if (_lastActiveWindow) {
|
||||||
last->widget()->showFromTray();
|
_lastActiveWindow->widget()->showFromTray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,6 +1321,14 @@ void Application::setLastActiveWindow(Window::Controller *window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_lastActiveWindow = window;
|
_lastActiveWindow = window;
|
||||||
|
if (window) {
|
||||||
|
const auto i = ranges::find(_windowStack, not_null(window));
|
||||||
|
if (i == end(_windowStack)) {
|
||||||
|
_windowStack.push_back(window);
|
||||||
|
} else if (i + 1 != end(_windowStack)) {
|
||||||
|
std::rotate(i, i + 1, end(_windowStack));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!window) {
|
if (!window) {
|
||||||
_floatPlayers = nullptr;
|
_floatPlayers = nullptr;
|
||||||
return;
|
return;
|
||||||
|
@ -1333,17 +1350,32 @@ void Application::setLastActiveWindow(Window::Controller *window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::closeWindow(not_null<Window::Controller*> window) {
|
void Application::closeWindow(not_null<Window::Controller*> window) {
|
||||||
const auto next = (_primaryWindows.front().second.get() != window)
|
const auto stackIt = ranges::find(_windowStack, window);
|
||||||
|
const auto nextFromStack = _windowStack.empty()
|
||||||
|
? nullptr
|
||||||
|
: (stackIt == end(_windowStack) || stackIt + 1 != end(_windowStack))
|
||||||
|
? _windowStack.back().get()
|
||||||
|
: (_windowStack.size() > 1)
|
||||||
|
? (stackIt - 1)->get()
|
||||||
|
: nullptr;
|
||||||
|
const auto next = nextFromStack
|
||||||
|
? nextFromStack
|
||||||
|
: (_primaryWindows.front().second.get() != window)
|
||||||
? _primaryWindows.front().second.get()
|
? _primaryWindows.front().second.get()
|
||||||
: (_primaryWindows.back().second.get() != window)
|
: (_primaryWindows.back().second.get() != window)
|
||||||
? _primaryWindows.back().second.get()
|
? _primaryWindows.back().second.get()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
Assert(next != window);
|
||||||
|
|
||||||
if (_lastActivePrimaryWindow == window) {
|
if (_lastActivePrimaryWindow == window) {
|
||||||
_lastActivePrimaryWindow = next;
|
_lastActivePrimaryWindow = next;
|
||||||
}
|
}
|
||||||
if (_windowInSettings == window) {
|
if (_windowInSettings == window) {
|
||||||
_windowInSettings = next;
|
_windowInSettings = next;
|
||||||
}
|
}
|
||||||
|
if (stackIt != end(_windowStack)) {
|
||||||
|
_windowStack.erase(stackIt);
|
||||||
|
}
|
||||||
if (_lastActiveWindow == window) {
|
if (_lastActiveWindow == window) {
|
||||||
setLastActiveWindow(next);
|
setLastActiveWindow(next);
|
||||||
if (_lastActiveWindow) {
|
if (_lastActiveWindow) {
|
||||||
|
|
|
@ -397,6 +397,7 @@ private:
|
||||||
base::flat_map<
|
base::flat_map<
|
||||||
not_null<History*>,
|
not_null<History*>,
|
||||||
std::unique_ptr<Window::Controller>> _secondaryWindows;
|
std::unique_ptr<Window::Controller>> _secondaryWindows;
|
||||||
|
std::vector<not_null<Window::Controller*>> _windowStack;
|
||||||
Window::Controller *_lastActiveWindow = nullptr;
|
Window::Controller *_lastActiveWindow = nullptr;
|
||||||
Window::Controller *_lastActivePrimaryWindow = nullptr;
|
Window::Controller *_lastActivePrimaryWindow = nullptr;
|
||||||
Window::Controller *_windowInSettings = nullptr;
|
Window::Controller *_windowInSettings = nullptr;
|
||||||
|
|
|
@ -1287,6 +1287,8 @@ bool MainWidget::showHistoryInDifferentWindow(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
} else if (!peerId) {
|
||||||
|
return true;
|
||||||
} else if (singlePeer()->id == peerId) {
|
} else if (singlePeer()->id == peerId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue