summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <51529891+Truenya@users.noreply.github.com>2025-02-03 04:34:30 +0300
committerGitHub <noreply@github.com>2025-02-03 02:34:30 +0100
commit708d16636047c6a311c4e44424cf7d2090219a47 (patch)
treeac363d6ab464b90afdff3b44a2a85d6c8b00f420
parent44004abc0189b9ba49444431e2a39d2df7e930bb (diff)
dispatchers: add cyclenext hist option (#9055)
-rw-r--r--src/Compositor.cpp79
-rw-r--r--src/Compositor.hpp7
-rw-r--r--src/managers/KeybindManager.cpp32
-rw-r--r--src/managers/KeybindManager.hpp2
4 files changed, 65 insertions, 55 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 0aa0f13d..95a57e03 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -1058,7 +1058,7 @@ PHLMONITOR CCompositor::getRealMonitorFromOutput(SP<Aquamarine::IOutput> out) {
return nullptr;
}
-void CCompositor::focusWindow(PHLWINDOW pWindow, SP<CWLSurfaceResource> pSurface) {
+void CCompositor::focusWindow(PHLWINDOW pWindow, SP<CWLSurfaceResource> pSurface, bool preserveFocusHistory) {
static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse");
static auto PSPECIALFALLTHROUGH = CConfigValue<Hyprlang::INT>("input:special_fallthrough");
@@ -1178,12 +1178,13 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP<CWLSurfaceResource> pSurface
g_pInputManager->recheckIdleInhibitorStatus();
- // move to front of the window history
- const auto HISTORYPIVOT = std::find_if(m_vWindowFocusHistory.begin(), m_vWindowFocusHistory.end(), [&](const auto& other) { return other.lock() == pWindow; });
- if (HISTORYPIVOT == m_vWindowFocusHistory.end()) {
- Debug::log(ERR, "BUG THIS: {} has no pivot in history", pWindow);
- } else {
- std::rotate(m_vWindowFocusHistory.begin(), HISTORYPIVOT, HISTORYPIVOT + 1);
+ if (!preserveFocusHistory) {
+ // move to front of the window history
+ const auto HISTORYPIVOT = std::ranges::find_if(m_vWindowFocusHistory, [&](const auto& other) { return other.lock() == pWindow; });
+ if (HISTORYPIVOT == m_vWindowFocusHistory.end())
+ Debug::log(ERR, "BUG THIS: {} has no pivot in history", pWindow);
+ else
+ std::rotate(m_vWindowFocusHistory.begin(), HISTORYPIVOT, HISTORYPIVOT + 1);
}
if (*PFOLLOWMOUSE == 0)
@@ -1396,7 +1397,6 @@ void CCompositor::changeWindowZOrder(PHLWINDOW pWindow, bool top) {
};
x11Stack(pWindow, top, x11Stack);
-
for (const auto& it : toMove) {
moveToZ(it, top);
}
@@ -1647,37 +1647,52 @@ PHLWINDOW CCompositor::getWindowInDirection(const CBox& box, PHLWORKSPACE pWorks
return nullptr;
}
-PHLWINDOW CCompositor::getNextWindowOnWorkspace(PHLWINDOW pWindow, bool focusableOnly, std::optional<bool> floating, bool visible) {
- auto it = std::ranges::find(m_vWindows, pWindow);
- const auto FINDER = [&](const PHLWINDOW& w) { return isWindowAvailableForCycle(pWindow, w, focusableOnly, floating, visible); };
- const auto IN_RIGHT = std::find_if(it, m_vWindows.end(), FINDER);
- if (IN_RIGHT != m_vWindows.end())
- return *IN_RIGHT;
- const auto IN_LEFT = std::find_if(m_vWindows.begin(), it, FINDER);
- return *IN_LEFT;
+template <typename WINDOWPTR>
+static bool isWorkspaceMatches(WINDOWPTR pWindow, const WINDOWPTR w, bool anyWorkspace) {
+ return anyWorkspace ? w->m_pWorkspace && w->m_pWorkspace->isVisible() : w->m_pWorkspace == pWindow->m_pWorkspace;
}
-PHLWINDOW CCompositor::getPrevWindowOnWorkspace(PHLWINDOW pWindow, bool focusableOnly, std::optional<bool> floating, bool visible) {
- auto it = std::ranges::find(std::ranges::reverse_view(m_vWindows), pWindow);
- const auto FINDER = [&](const PHLWINDOW& w) { return isWindowAvailableForCycle(pWindow, w, focusableOnly, floating, visible); };
- const auto IN_LEFT = std::find_if(it, m_vWindows.rend(), FINDER);
- if (IN_LEFT != m_vWindows.rend())
- return *IN_LEFT;
- const auto IN_RIGHT = std::find_if(m_vWindows.rbegin(), it, FINDER);
- return *IN_RIGHT;
+template <typename WINDOWPTR>
+static bool isFloatingMatches(WINDOWPTR w, std::optional<bool> floating) {
+ return !floating.has_value() || w->m_bIsFloating == floating.value();
}
-inline static bool isWorkspaceMatches(PHLWINDOW pWindow, const PHLWINDOW w, bool anyWorkspace) {
- return anyWorkspace ? w->m_pWorkspace && w->m_pWorkspace->isVisible() : w->m_pWorkspace == pWindow->m_pWorkspace;
+template <typename WINDOWPTR>
+static bool isWindowAvailableForCycle(WINDOWPTR pWindow, WINDOWPTR w, bool focusableOnly, std::optional<bool> floating, bool anyWorkspace = false) {
+ return isFloatingMatches(w, floating) &&
+ (w != pWindow && isWorkspaceMatches(pWindow, w, anyWorkspace) && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sWindowData.noFocus.valueOrDefault()));
}
-inline static bool isFloatingMatches(PHLWINDOW w, std::optional<bool> floating) {
- return !floating.has_value() || w->m_bIsFloating == floating.value();
-};
+template <typename Iterator>
+static PHLWINDOW getWindowPred(Iterator cur, Iterator end, Iterator begin, const std::function<bool(const PHLWINDOW&)> PRED) {
+ const auto IN_ONE_SIDE = std::find_if(cur, end, PRED);
+ if (IN_ONE_SIDE != end)
+ return *IN_ONE_SIDE;
+ const auto IN_OTHER_SIDE = std::find_if(begin, cur, PRED);
+ return *IN_OTHER_SIDE;
+}
+
+template <typename Iterator>
+static PHLWINDOW getWeakWindowPred(Iterator cur, Iterator end, Iterator begin, const std::function<bool(const PHLWINDOWREF&)> PRED) {
+ const auto IN_ONE_SIDE = std::find_if(cur, end, PRED);
+ if (IN_ONE_SIDE != end)
+ return IN_ONE_SIDE->lock();
+ const auto IN_OTHER_SIDE = std::find_if(begin, cur, PRED);
+ return IN_OTHER_SIDE->lock();
+}
+
+PHLWINDOW CCompositor::getWindowCycleHist(PHLWINDOWREF cur, bool focusableOnly, std::optional<bool> floating, bool visible, bool next) {
+ const auto FINDER = [&](const PHLWINDOWREF& w) { return isWindowAvailableForCycle(cur, w, focusableOnly, floating, visible); };
+ // also m_vWindowFocusHistory has reverse order, so when it is next - we need to reverse again
+ return next ?
+ getWeakWindowPred(std::ranges::find(std::ranges::reverse_view(m_vWindowFocusHistory), cur), m_vWindowFocusHistory.rend(), m_vWindowFocusHistory.rbegin(), FINDER) :
+ getWeakWindowPred(std::ranges::find(m_vWindowFocusHistory, cur), m_vWindowFocusHistory.end(), m_vWindowFocusHistory.begin(), FINDER);
+}
-bool CCompositor::isWindowAvailableForCycle(PHLWINDOW pWindow, const PHLWINDOW w, bool focusableOnly, std::optional<bool> floating, bool anyWorkspace) {
- return isFloatingMatches(w, floating) && w != pWindow && isWorkspaceMatches(pWindow, w, anyWorkspace) && w->m_bIsMapped && !w->isHidden() &&
- (!focusableOnly || !w->m_sWindowData.noFocus.valueOrDefault());
+PHLWINDOW CCompositor::getWindowCycle(PHLWINDOW cur, bool focusableOnly, std::optional<bool> floating, bool visible, bool prev) {
+ const auto FINDER = [&](const PHLWINDOW& w) { return isWindowAvailableForCycle(cur, w, focusableOnly, floating, visible); };
+ return prev ? getWindowPred(std::ranges::find(std::ranges::reverse_view(m_vWindows), cur), m_vWindows.rend(), m_vWindows.rbegin(), FINDER) :
+ getWindowPred(std::ranges::find(m_vWindows, cur), m_vWindows.end(), m_vWindows.begin(), FINDER);
}
WORKSPACEID CCompositor::getNextAvailableNamedWorkspace() {
diff --git a/src/Compositor.hpp b/src/Compositor.hpp
index 787ead08..a57095a3 100644
--- a/src/Compositor.hpp
+++ b/src/Compositor.hpp
@@ -83,7 +83,7 @@ class CCompositor {
PHLMONITOR getMonitorFromCursor();
PHLMONITOR getMonitorFromVector(const Vector2D&);
void removeWindowFromVectorSafe(PHLWINDOW);
- void focusWindow(PHLWINDOW, SP<CWLSurfaceResource> pSurface = nullptr);
+ void focusWindow(PHLWINDOW, SP<CWLSurfaceResource> pSurface = nullptr, bool preserveFocusHistory = false);
void focusSurface(SP<CWLSurfaceResource>, PHLWINDOW pWindowOwner = nullptr);
bool monitorExists(PHLMONITOR);
PHLWINDOW vectorToWindowUnified(const Vector2D&, uint8_t properties, PHLWINDOW pIgnoreWindow = nullptr);
@@ -105,8 +105,8 @@ class CCompositor {
void cleanupFadingOut(const MONITORID& monid);
PHLWINDOW getWindowInDirection(PHLWINDOW, char);
PHLWINDOW getWindowInDirection(const CBox& box, PHLWORKSPACE pWorkspace, char dir, PHLWINDOW ignoreWindow = nullptr, bool useVectorAngles = false);
- PHLWINDOW getNextWindowOnWorkspace(PHLWINDOW, bool focusableOnly = false, std::optional<bool> floating = {}, bool visible = false);
- PHLWINDOW getPrevWindowOnWorkspace(PHLWINDOW, bool focusableOnly = false, std::optional<bool> floating = {}, bool visible = false);
+ PHLWINDOW getWindowCycle(PHLWINDOW cur, bool focusableOnly = false, std::optional<bool> floating = std::nullopt, bool visible = false, bool prev = false);
+ PHLWINDOW getWindowCycleHist(PHLWINDOWREF cur, bool focusableOnly = false, std::optional<bool> floating = std::nullopt, bool visible = false, bool next = false);
WORKSPACEID getNextAvailableNamedWorkspace();
bool isPointOnAnyMonitor(const Vector2D&);
bool isPointOnReservedArea(const Vector2D& point, const PHLMONITOR monitor = nullptr);
@@ -163,7 +163,6 @@ class CCompositor {
void setRandomSplash();
void initManagers(eManagersInitStage stage);
void prepareFallbackOutput();
- bool isWindowAvailableForCycle(PHLWINDOW pWindow, PHLWINDOW w, bool focusableOnly, std::optional<bool> floating, bool anyWorkspace = false);
uint64_t m_iHyprlandPID = 0;
wl_event_source* m_critSigSource = nullptr;
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index bc5d36c8..47cc4f67 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -367,7 +367,7 @@ bool CKeybindManager::tryMoveFocusToMonitor(PHLMONITOR monitor) {
return true;
}
-void CKeybindManager::switchToWindow(PHLWINDOW PWINDOWTOCHANGETO) {
+void CKeybindManager::switchToWindow(PHLWINDOW PWINDOWTOCHANGETO, bool preserveFocusHistory) {
static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse");
static auto PNOWARPS = CConfigValue<Hyprlang::INT>("cursor:no_warps");
@@ -386,7 +386,7 @@ void CKeybindManager::switchToWindow(PHLWINDOW PWINDOWTOCHANGETO) {
if (!PWINDOWTOCHANGETO->m_bPinned)
g_pCompositor->setWindowFullscreenInternal(PLASTWINDOW, FSMODE_NONE);
- g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
+ g_pCompositor->focusWindow(PWINDOWTOCHANGETO, nullptr, preserveFocusHistory);
if (!PWINDOWTOCHANGETO->m_bPinned)
g_pCompositor->setWindowFullscreenInternal(PWINDOWTOCHANGETO, MODE);
@@ -396,7 +396,7 @@ void CKeybindManager::switchToWindow(PHLWINDOW PWINDOWTOCHANGETO) {
PWINDOWTOCHANGETO->m_vRealSize->warp();
} else {
updateRelativeCursorCoords();
- g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
+ g_pCompositor->focusWindow(PWINDOWTOCHANGETO, nullptr, preserveFocusHistory);
PWINDOWTOCHANGETO->warpCursor();
// Move mouse focus to the new window if required by current follow_mouse and warp modes
@@ -1473,7 +1473,7 @@ SDispatchResult CKeybindManager::moveFocusTo(std::string args) {
}
const auto PWINDOWTOCHANGETO = *PFULLCYCLE && PLASTWINDOW->isFullscreen() ?
- (arg == 'd' || arg == 'b' || arg == 'r' ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true) : g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true)) :
+ g_pCompositor->getWindowCycle(PLASTWINDOW, true, {}, false, arg != 'd' && arg != 'b' && arg != 'r') :
g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
// Prioritize focus change within groups if the window is a part of it.
@@ -2221,11 +2221,13 @@ SDispatchResult CKeybindManager::circleNext(std::string arg) {
floatStatus = true;
const auto VISIBLE = args.contains("visible") || args.contains("v");
- const auto& w = (args.contains("prev") || args.contains("p") || args.contains("last") || args.contains("l")) ?
- g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow.lock(), true, floatStatus, VISIBLE) :
- g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow.lock(), true, floatStatus, VISIBLE);
+ const auto PREV = args.contains("prev") || args.contains("p") || args.contains("last") || args.contains("l");
+ const auto NEXT = args.contains("next") || args.contains("n"); // prev is default in classic alt+tab
+ const auto HIST = args.contains("hist") || args.contains("h");
+ const auto& w = HIST ? g_pCompositor->getWindowCycleHist(g_pCompositor->m_pLastWindow, true, floatStatus, VISIBLE, NEXT) :
+ g_pCompositor->getWindowCycle(g_pCompositor->m_pLastWindow.lock(), true, floatStatus, VISIBLE, PREV);
- switchToWindow(w);
+ switchToWindow(w, HIST);
return {};
}
@@ -2620,18 +2622,12 @@ SDispatchResult CKeybindManager::swapnext(std::string arg) {
g_pCompositor->m_pLastWindow->m_pLastCycledWindow.lock() :
nullptr;
- if (arg == "last" || arg == "l" || arg == "prev" || arg == "p")
- toSwap = g_pCompositor->getPrevWindowOnWorkspace(PLASTCYCLED ? PLASTCYCLED : PLASTWINDOW, true);
- else
- toSwap = g_pCompositor->getNextWindowOnWorkspace(PLASTCYCLED ? PLASTCYCLED : PLASTWINDOW, true);
+ const bool NEED_PREV = arg == "last" || arg == "l" || arg == "prev" || arg == "p";
+ toSwap = g_pCompositor->getWindowCycle(PLASTCYCLED ? PLASTCYCLED : PLASTWINDOW, true, std::nullopt, false, NEED_PREV);
// sometimes we may come back to ourselves.
- if (toSwap == PLASTWINDOW) {
- if (arg == "last" || arg == "l" || arg == "prev" || arg == "p")
- toSwap = g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true);
- else
- toSwap = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true);
- }
+ if (toSwap == PLASTWINDOW)
+ toSwap = g_pCompositor->getWindowCycle(PLASTWINDOW, true, std::nullopt, false, NEED_PREV);
g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, toSwap);
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index 1848ca78..cea3e3cf 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -148,7 +148,7 @@ class CKeybindManager {
static bool tryMoveFocusToMonitor(PHLMONITOR monitor);
static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = "");
static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection);
- static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO);
+ static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO, bool preserveFocusHistory = false);
static uint64_t spawnRawProc(std::string, PHLWORKSPACE pInitialWorkspace);
static uint64_t spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);