mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Track window activation history.
This commit is contained in:
parent
bbd937115c
commit
c737e2f91b
3 changed files with 46 additions and 11 deletions
Telegram/SourceFiles
|
@ -191,6 +191,7 @@ Application::~Application() {
|
|||
Local::writeSettings();
|
||||
}
|
||||
|
||||
_windowStack.clear();
|
||||
setLastActiveWindow(nullptr);
|
||||
_windowInSettings = _lastActivePrimaryWindow = nullptr;
|
||||
_closingAsyncWindows.clear();
|
||||
|
@ -514,18 +515,26 @@ void Application::startTray() {
|
|||
}
|
||||
|
||||
void Application::activate() {
|
||||
const auto last = _lastActiveWindow;
|
||||
const auto primary = _lastActivePrimaryWindow;
|
||||
enumerateWindows([&](not_null<Window::Controller*> w) {
|
||||
if (w != last && w != primary) {
|
||||
w->widget()->showFromTray();
|
||||
for (const auto &window : _windowStack) {
|
||||
if (window == _lastActiveWindow) {
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
last->widget()->showFromTray();
|
||||
if (_lastActiveWindow) {
|
||||
_lastActiveWindow->widget()->showFromTray();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1312,6 +1321,14 @@ void Application::setLastActiveWindow(Window::Controller *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) {
|
||||
_floatPlayers = nullptr;
|
||||
return;
|
||||
|
@ -1333,17 +1350,32 @@ void Application::setLastActiveWindow(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.back().second.get() != window)
|
||||
? _primaryWindows.back().second.get()
|
||||
: nullptr;
|
||||
Assert(next != window);
|
||||
|
||||
if (_lastActivePrimaryWindow == window) {
|
||||
_lastActivePrimaryWindow = next;
|
||||
}
|
||||
if (_windowInSettings == window) {
|
||||
_windowInSettings = next;
|
||||
}
|
||||
if (stackIt != end(_windowStack)) {
|
||||
_windowStack.erase(stackIt);
|
||||
}
|
||||
if (_lastActiveWindow == window) {
|
||||
setLastActiveWindow(next);
|
||||
if (_lastActiveWindow) {
|
||||
|
|
|
@ -397,6 +397,7 @@ private:
|
|||
base::flat_map<
|
||||
not_null<History*>,
|
||||
std::unique_ptr<Window::Controller>> _secondaryWindows;
|
||||
std::vector<not_null<Window::Controller*>> _windowStack;
|
||||
Window::Controller *_lastActiveWindow = nullptr;
|
||||
Window::Controller *_lastActivePrimaryWindow = nullptr;
|
||||
Window::Controller *_windowInSettings = nullptr;
|
||||
|
|
|
@ -1287,6 +1287,8 @@ bool MainWidget::showHistoryInDifferentWindow(
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if (!peerId) {
|
||||
return true;
|
||||
} else if (singlePeer()->id == peerId) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue