Merge pull request #292 from Dakes/focus-window-title

Changed dispatcher: focusWindowByClass -> focusWindow. Now supports titles & classes
This commit is contained in:
Vaxry 2022-07-01 18:20:10 +02:00 committed by GitHub
commit 3d294b1aaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View file

@ -30,7 +30,8 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["resizeactive"] = resizeActive; m_mDispatchers["resizeactive"] = resizeActive;
m_mDispatchers["moveactive"] = moveActive; m_mDispatchers["moveactive"] = moveActive;
m_mDispatchers["cyclenext"] = circleNext; m_mDispatchers["cyclenext"] = circleNext;
m_mDispatchers["focuswindowbyclass"] = focusWindowByClass; m_mDispatchers["focuswindowbyclass"] = focusWindow;
m_mDispatchers["focuswindow"] = focusWindow;
m_mDispatchers["submap"] = setSubmap; m_mDispatchers["submap"] = setSubmap;
} }
@ -1017,17 +1018,28 @@ void CKeybindManager::circleNext(std::string) {
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y);
} }
void CKeybindManager::focusWindowByClass(std::string clazz) { void CKeybindManager::focusWindow(std::string regexp) {
std::regex classCheck(clazz); bool titleRegex = false;
std::regex regexCheck(regexp);
if (regexp.find("title:") == 0) {
titleRegex = true;
regexCheck = std::regex(regexp.substr(6));
}
for (auto& w : g_pCompositor->m_vWindows) { for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped || w->m_bHidden) if (!w->m_bIsMapped || w->m_bHidden)
continue; continue;
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get()); if (titleRegex) {
const auto windowTitle = g_pXWaylandManager->getTitle(w.get());
if (!std::regex_search(windowClass, classCheck)) if (!std::regex_search(windowTitle, regexCheck))
continue; continue;
}
else {
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get());
if (!std::regex_search(windowClass, regexCheck))
continue;
}
Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str()); Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str());

View file

@ -61,7 +61,7 @@ private:
static void resizeActive(std::string); static void resizeActive(std::string);
static void moveActive(std::string); static void moveActive(std::string);
static void circleNext(std::string); static void circleNext(std::string);
static void focusWindowByClass(std::string); static void focusWindow(std::string);
static void setSubmap(std::string); static void setSubmap(std::string);
friend class CCompositor; friend class CCompositor;