Added movefocus dispatcher

This commit is contained in:
vaxerski 2022-04-09 13:26:55 +02:00
parent 7449a0c44c
commit 3d5e2c1dc3
5 changed files with 88 additions and 0 deletions

View File

@ -63,6 +63,11 @@ bind=SUPER,V,togglefloating,
bind=SUPER,R,exec,wofi --show drun -o DP-3
bind=SUPER,P,pseudo,
bind=SUPER,left,movefocus,l
bind=SUPER,right,movefocus,r
bind=SUPER,up,movefocus,u
bind=SUPER,down,movefocus,d
bind=SUPER,1,workspace,1
bind=SUPER,2,workspace,2
bind=SUPER,3,workspace,3

View File

@ -568,4 +568,65 @@ void CCompositor::cleanupWindows() {
return;
}
}
}
CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) {
const auto POSA = pWindow->m_vPosition;
const auto SIZEA = pWindow->m_vSize;
auto longestIntersect = -1;
CWindow* longestIntersectWindow = nullptr;
for (auto& w : m_lWindows) {
if (&w == pWindow || !windowValidMapped(&w) || w.m_bIsFloating || w.m_iWorkspaceID != pWindow->m_iWorkspaceID)
continue;
const auto POSB = w.m_vPosition;
const auto SIZEB = w.m_vSize;
switch (dir) {
case 'l':
if (STICKS(POSA.x, POSB.x + SIZEB.x)) {
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN;
longestIntersectWindow = &w;
}
}
break;
case 'r':
if (STICKS(POSA.x + SIZEA.x, POSB.x)) {
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN;
longestIntersectWindow = &w;
}
}
break;
case 't':
case 'u':
if (STICKS(POSA.y, POSB.y + SIZEB.y)) {
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN;
longestIntersectWindow = &w;
}
}
break;
case 'b':
case 'd':
if (STICKS(POSA.y + SIZEA.y, POSB.y)) {
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
if (INTERSECTLEN > longestIntersect) {
longestIntersect = INTERSECTLEN;
longestIntersectWindow = &w;
}
}
break;
}
}
if (longestIntersect != -1)
return longestIntersectWindow;
return nullptr;
}

View File

@ -100,6 +100,7 @@ public:
bool isWindowActive(CWindow*);
void moveWindowToTop(CWindow*);
void cleanupWindows();
CWindow* getWindowInDirection(CWindow*, char);
private:
void initAllSignals();

View File

@ -54,6 +54,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
else if (k.handler == "fullscreen") { fullscreenActive(k.arg); }
else if (k.handler == "movetoworkspace") { moveActiveToWorkspace(k.arg); }
else if (k.handler == "pseudo") { toggleActivePseudo(k.arg); }
else if (k.handler == "movefocus") { moveFocusTo(k.arg); }
found = true;
}
@ -244,3 +245,22 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(NEWWORKSPACE->monitorID)->vecPosition;
}
}
void CKeybindManager::moveFocusTo(std::string args) {
char arg = args[0];
if (arg != 'l' && arg != 'r' && arg != 'u' && arg != 'd' && arg != 't' && arg != 'b') {
Debug::log(ERR, "Cannot move window in direction %c, unsupported direction. Supported: l,r,u/t,d/b", arg);
return;
}
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
return;
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
if (PWINDOWTOCHANGETO)
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
}

View File

@ -31,6 +31,7 @@ private:
void changeworkspace(std::string);
void fullscreenActive(std::string);
void moveActiveToWorkspace(std::string);
void moveFocusTo(std::string);
};
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;