From 3a2ac11e3e89a56c9d76f6432478e4bc2c582ced Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 10 Jun 2022 12:06:27 +0200 Subject: [PATCH] added focuswindowbyclass --- src/managers/KeybindManager.cpp | 26 ++++++++++++++++++++++++++ src/managers/KeybindManager.hpp | 1 + 2 files changed, 27 insertions(+) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index e1991354..b8084f96 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1,5 +1,7 @@ #include "KeybindManager.hpp" +#include + CKeybindManager::CKeybindManager() { // initialize all dispatchers @@ -27,6 +29,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["forcerendererreload"] = forceRendererReload; m_mDispatchers["resizeactive"] = resizeActive; m_mDispatchers["cyclenext"] = circleNext; + m_mDispatchers["focuswindowbyclass"] = focusWindowByClass; } void CKeybindManager::addKeybind(SKeybind kb) { @@ -881,3 +884,26 @@ void CKeybindManager::circleNext(std::string) { wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); } + +void CKeybindManager::focusWindowByClass(std::string clazz) { + std::regex classCheck(clazz); + + for (auto& w : g_pCompositor->m_lWindows) { + const auto windowClass = g_pXWaylandManager->getAppIDClass(&w); + + if (!std::regex_search(windowClass, classCheck)) + continue; + + Debug::log(LOG, "Focusing to window name: %s", w.m_szTitle.c_str()); + + changeworkspace(std::to_string(w.m_iWorkspaceID)); + + g_pCompositor->focusWindow(&w); + + const auto MIDPOINT = w.m_vRealPosition.goalv() + w.m_vRealSize.goalv() / 2.f; + + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); + + break; + } +} diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index e0958250..782f2ead 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -57,6 +57,7 @@ private: static void forceRendererReload(std::string); static void resizeActive(std::string); static void circleNext(std::string); + static void focusWindowByClass(std::string); friend class CCompositor; };