desktop/window: go back to the previously focused window in a group (#12763)
This commit is contained in:
parent
293d3e5de9
commit
529559712b
2 changed files with 55 additions and 1 deletions
|
|
@ -373,6 +373,41 @@ static void testMaximizeSize() {
|
||||||
EXPECT(Tests::windowCount(), 0);
|
EXPECT(Tests::windowCount(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void testGroupFallbackFocus() {
|
||||||
|
NLog::log("{}Testing group fallback focus", Colors::GREEN);
|
||||||
|
|
||||||
|
EXPECT(spawnKitty("kitty_A"), true);
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch togglegroup"));
|
||||||
|
|
||||||
|
EXPECT(spawnKitty("kitty_B"), true);
|
||||||
|
EXPECT(spawnKitty("kitty_C"), true);
|
||||||
|
EXPECT(spawnKitty("kitty_D"), true);
|
||||||
|
|
||||||
|
{
|
||||||
|
auto str = getFromSocket("/activewindow");
|
||||||
|
EXPECT(str.contains("class: kitty_D"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch focuswindow class:kitty_B"));
|
||||||
|
OK(getFromSocket("/dispatch focuswindow class:kitty_D"));
|
||||||
|
OK(getFromSocket("/dispatch killactive"));
|
||||||
|
|
||||||
|
Tests::waitUntilWindowsN(3);
|
||||||
|
|
||||||
|
// Focus must return to the last focus, in this case B.
|
||||||
|
{
|
||||||
|
auto str = getFromSocket("/activewindow");
|
||||||
|
EXPECT(str.contains("class: kitty_B"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
NLog::log("{}Killing all windows", Colors::YELLOW);
|
||||||
|
Tests::killAllWindows();
|
||||||
|
|
||||||
|
NLog::log("{}Expecting 0 windows", Colors::YELLOW);
|
||||||
|
EXPECT(Tests::windowCount(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
static void testBringActiveToTopMouseMovement() {
|
static void testBringActiveToTopMouseMovement() {
|
||||||
NLog::log("{}Testing bringactivetotop mouse movement", Colors::GREEN);
|
NLog::log("{}Testing bringactivetotop mouse movement", Colors::GREEN);
|
||||||
|
|
||||||
|
|
@ -847,6 +882,8 @@ static bool test() {
|
||||||
|
|
||||||
testBringActiveToTopMouseMovement();
|
testBringActiveToTopMouseMovement();
|
||||||
|
|
||||||
|
testGroupFallbackFocus();
|
||||||
|
|
||||||
NLog::log("{}Reloading config", Colors::YELLOW);
|
NLog::log("{}Reloading config", Colors::YELLOW);
|
||||||
OK(getFromSocket("/reload"));
|
OK(getFromSocket("/reload"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2437,7 +2437,24 @@ void CWindow::unmapWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wasLastWindow = false;
|
bool wasLastWindow = false;
|
||||||
PHLWINDOW nextInGroup = m_groupData.pNextWindow ? m_groupData.pNextWindow.lock() : nullptr;
|
PHLWINDOW nextInGroup = [this] -> PHLWINDOW {
|
||||||
|
if (!m_groupData.pNextWindow)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// walk the history to find a suitable window
|
||||||
|
const auto HISTORY = Desktop::History::windowTracker()->fullHistory();
|
||||||
|
for (const auto& w : HISTORY | std::views::reverse) {
|
||||||
|
if (!w || !w->m_isMapped || w == m_self)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!hasInGroup(w.lock()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return w.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}();
|
||||||
|
|
||||||
if (m_self.lock() == Desktop::focusState()->window()) {
|
if (m_self.lock() == Desktop::focusState()->window()) {
|
||||||
wasLastWindow = true;
|
wasLastWindow = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue