diff options
author | Vaxry <[email protected]> | 2024-06-15 18:20:09 +0200 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-06-15 18:20:41 +0200 |
commit | 91fe58f8f278d126852877eadc87c50ca7b9b78d (patch) | |
tree | e8fddf5d2659a432b36d1272548a07b2a482a8ff /src/desktop/Window.cpp | |
parent | 77f44bfcab6c3e553d26a776c011613efbfe6cfd (diff) | |
download | Hyprland-91fe58f8f278d126852877eadc87c50ca7b9b78d.tar.gz Hyprland-91fe58f8f278d126852877eadc87c50ca7b9b78d.zip |
window: improve swallowing functionality
cleanups, fixes, etc.
ref #6095
Diffstat (limited to 'src/desktop/Window.cpp')
-rw-r--r-- | src/desktop/Window.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index b02a53e0..d153b344 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1540,3 +1540,58 @@ void CWindow::warpCursor() { else g_pCompositor->warpCursorTo(middle()); } + +PHLWINDOW CWindow::getSwallower() { + static auto PSWALLOWREGEX = CConfigValue<std::string>("misc:swallow_regex"); + static auto PSWALLOWEXREGEX = CConfigValue<std::string>("misc:swallow_exception_regex"); + static auto PSWALLOW = CConfigValue<Hyprlang::INT>("misc:enable_swallow"); + + if (!*PSWALLOW || (*PSWALLOWREGEX).empty()) + return nullptr; + + // check parent + std::vector<PHLWINDOW> candidates; + pid_t currentPid = getPID(); + // walk up the tree until we find someone, 25 iterations max. + for (size_t i = 0; i < 25; ++i) { + currentPid = getPPIDof(currentPid); + + if (!currentPid) + break; + + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->isHidden()) + continue; + + if (w->getPID() == currentPid) + candidates.push_back(w); + } + } + + if (!(*PSWALLOWREGEX).empty()) + std::erase_if(candidates, [&](const auto& other) { return !std::regex_match(other->m_szClass, std::regex(*PSWALLOWREGEX)); }); + + if (candidates.size() <= 0) + return nullptr; + + if (!(*PSWALLOWEXREGEX).empty()) + std::erase_if(candidates, [&](const auto& other) { return std::regex_match(other->m_szTitle, std::regex(*PSWALLOWEXREGEX)); }); + + if (candidates.size() <= 0) + return nullptr; + + if (candidates.size() == 1) + return candidates.at(0); + + // walk up the focus history and find the last focused + for (auto& w : g_pCompositor->m_vWindowFocusHistory) { + if (!w) + continue; + + if (std::find(candidates.begin(), candidates.end(), w.lock()) != candidates.end()) + return w.lock(); + } + + // if none are found (??) then just return the first one + return candidates.at(0); +} |