Skip to content

Commit

Permalink
added focuswindowbyclass
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jun 10, 2022
1 parent 90a859a commit 3a2ac11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "KeybindManager.hpp"

#include <regex>

CKeybindManager::CKeybindManager() {
// initialize all dispatchers

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CKeybindManager {
static void forceRendererReload(std::string);
static void resizeActive(std::string);
static void circleNext(std::string);
static void focusWindowByClass(std::string);

friend class CCompositor;
};
Expand Down

0 comments on commit 3a2ac11

Please sign in to comment.