mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-24 11:25:58 +01:00
add movefocusgroup command which moves focus through groups before continuing to the next window
This commit is contained in:
parent
3b657257ec
commit
f64e34eb78
4 changed files with 96 additions and 18 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "KeybindManager.hpp"
|
#include "KeybindManager.hpp"
|
||||||
|
#include "./directions/GroupActiveDirection.hpp"
|
||||||
#include "../render/decorations/CHyprGroupBarDecoration.hpp"
|
#include "../render/decorations/CHyprGroupBarDecoration.hpp"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
@ -28,6 +29,7 @@ CKeybindManager::CKeybindManager() {
|
||||||
m_mDispatchers["movetoworkspace"] = moveActiveToWorkspace;
|
m_mDispatchers["movetoworkspace"] = moveActiveToWorkspace;
|
||||||
m_mDispatchers["movetoworkspacesilent"] = moveActiveToWorkspaceSilent;
|
m_mDispatchers["movetoworkspacesilent"] = moveActiveToWorkspaceSilent;
|
||||||
m_mDispatchers["pseudo"] = toggleActivePseudo;
|
m_mDispatchers["pseudo"] = toggleActivePseudo;
|
||||||
|
m_mDispatchers["movegroupfocus"] = moveGroupFocusTo;
|
||||||
m_mDispatchers["movefocus"] = moveFocusTo;
|
m_mDispatchers["movefocus"] = moveFocusTo;
|
||||||
m_mDispatchers["movewindow"] = moveActiveTo;
|
m_mDispatchers["movewindow"] = moveActiveTo;
|
||||||
m_mDispatchers["swapwindow"] = swapActive;
|
m_mDispatchers["swapwindow"] = swapActive;
|
||||||
|
@ -257,6 +259,37 @@ void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CWindow *CKeybindManager::groupActiveInDirection(std::string args) {
|
||||||
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
||||||
|
|
||||||
|
if (!PWINDOW)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (!PWINDOW->m_sGroupData.pNextWindow)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (PWINDOW->m_sGroupData.pNextWindow == PWINDOW)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (isNumber(args, false)) {
|
||||||
|
// index starts from '1'; '0' means last window
|
||||||
|
const int INDEX = std::stoi(args);
|
||||||
|
if (INDEX > PWINDOW->getGroupSize())
|
||||||
|
return nullptr;
|
||||||
|
if (INDEX == 0)
|
||||||
|
return PWINDOW->getGroupTail();
|
||||||
|
|
||||||
|
return PWINDOW->getGroupWindowByIndex(INDEX - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupActiveDirection direction(std::move(args));
|
||||||
|
if (direction.isBackwards()) {
|
||||||
|
return PWINDOW->getGroupPrevious();
|
||||||
|
}
|
||||||
|
|
||||||
|
return PWINDOW->m_sGroupData.pNextWindow;
|
||||||
|
}
|
||||||
|
|
||||||
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
||||||
if (!g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
|
if (!g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
|
||||||
m_dPressedKeycodes.clear();
|
m_dPressedKeycodes.clear();
|
||||||
|
@ -995,6 +1028,25 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
|
||||||
g_pInputManager->refocus();
|
g_pInputManager->refocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CKeybindManager::moveGroupFocusTo(std::string args) {
|
||||||
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
||||||
|
|
||||||
|
GroupActiveDirection direction = GroupActiveDirection::fromFocusDirection(args);
|
||||||
|
CWindow *pNextWindow = groupActiveInDirection(direction.asString());
|
||||||
|
|
||||||
|
if(
|
||||||
|
pNextWindow == nullptr
|
||||||
|
|| pNextWindow == PWINDOW
|
||||||
|
|| (direction.isForward() && pNextWindow == PWINDOW->getGroupHead())
|
||||||
|
|| (direction.isBackwards() && pNextWindow == PWINDOW->getGroupTail())
|
||||||
|
) {
|
||||||
|
moveFocusTo(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PWINDOW->setGroupCurrent(pNextWindow);
|
||||||
|
}
|
||||||
|
|
||||||
void CKeybindManager::moveFocusTo(std::string args) {
|
void CKeybindManager::moveFocusTo(std::string args) {
|
||||||
char arg = args[0];
|
char arg = args[0];
|
||||||
|
|
||||||
|
@ -1163,7 +1215,8 @@ void CKeybindManager::toggleGroup(std::string args) {
|
||||||
void CKeybindManager::changeGroupActive(std::string args) {
|
void CKeybindManager::changeGroupActive(std::string args) {
|
||||||
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
||||||
|
|
||||||
if (!PWINDOW)
|
CWindow *pNextWindow = groupActiveInDirection(std::move(args));
|
||||||
|
if(!pNextWindow)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!PWINDOW->m_sGroupData.pNextWindow)
|
if (!PWINDOW->m_sGroupData.pNextWindow)
|
||||||
|
@ -1172,23 +1225,7 @@ void CKeybindManager::changeGroupActive(std::string args) {
|
||||||
if (PWINDOW->m_sGroupData.pNextWindow == PWINDOW)
|
if (PWINDOW->m_sGroupData.pNextWindow == PWINDOW)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isNumber(args, false)) {
|
PWINDOW->setGroupCurrent(pNextWindow);
|
||||||
// index starts from '1'; '0' means last window
|
|
||||||
const int INDEX = std::stoi(args);
|
|
||||||
if (INDEX > PWINDOW->getGroupSize())
|
|
||||||
return;
|
|
||||||
if (INDEX == 0)
|
|
||||||
PWINDOW->setGroupCurrent(PWINDOW->getGroupTail());
|
|
||||||
else
|
|
||||||
PWINDOW->setGroupCurrent(PWINDOW->getGroupWindowByIndex(INDEX - 1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args != "b" && args != "prev") {
|
|
||||||
PWINDOW->setGroupCurrent(PWINDOW->m_sGroupData.pNextWindow);
|
|
||||||
} else {
|
|
||||||
PWINDOW->setGroupCurrent(PWINDOW->getGroupPrevious());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeybindManager::toggleSplit(std::string args) {
|
void CKeybindManager::toggleSplit(std::string args) {
|
||||||
|
|
|
@ -94,6 +94,7 @@ class CKeybindManager {
|
||||||
static void moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir = "");
|
static void moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir = "");
|
||||||
static void moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection);
|
static void moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection);
|
||||||
static void switchToWindow(CWindow* PWINDOWTOCHANGETO);
|
static void switchToWindow(CWindow* PWINDOWTOCHANGETO);
|
||||||
|
static CWindow* groupActiveInDirection(std::string args);
|
||||||
|
|
||||||
// -------------- Dispatchers -------------- //
|
// -------------- Dispatchers -------------- //
|
||||||
static void killActive(std::string);
|
static void killActive(std::string);
|
||||||
|
@ -107,6 +108,7 @@ class CKeybindManager {
|
||||||
static void fakeFullscreenActive(std::string);
|
static void fakeFullscreenActive(std::string);
|
||||||
static void moveActiveToWorkspace(std::string);
|
static void moveActiveToWorkspace(std::string);
|
||||||
static void moveActiveToWorkspaceSilent(std::string);
|
static void moveActiveToWorkspaceSilent(std::string);
|
||||||
|
static void moveGroupFocusTo(std::string);
|
||||||
static void moveFocusTo(std::string);
|
static void moveFocusTo(std::string);
|
||||||
static void focusUrgentOrLast(std::string);
|
static void focusUrgentOrLast(std::string);
|
||||||
static void focusCurrentOrLast(std::string);
|
static void focusCurrentOrLast(std::string);
|
||||||
|
|
21
src/managers/directions/GroupActiveDirection.cpp
Normal file
21
src/managers/directions/GroupActiveDirection.cpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "GroupActiveDirection.hpp"
|
||||||
|
|
||||||
|
GroupActiveDirection::GroupActiveDirection(std::string direction) : direction(direction) {}
|
||||||
|
|
||||||
|
GroupActiveDirection GroupActiveDirection::fromFocusDirection(std::string direction) {
|
||||||
|
if(direction == "l") {
|
||||||
|
return GroupActiveDirection("b");
|
||||||
|
}
|
||||||
|
|
||||||
|
return GroupActiveDirection("f");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GroupActiveDirection::isForward() {
|
||||||
|
return !isBackwards();
|
||||||
|
}
|
||||||
|
bool GroupActiveDirection::isBackwards() {
|
||||||
|
return direction == "b" || direction == "prev";
|
||||||
|
}
|
||||||
|
std::string GroupActiveDirection::asString() {
|
||||||
|
return direction;
|
||||||
|
}
|
18
src/managers/directions/GroupActiveDirection.hpp
Normal file
18
src/managers/directions/GroupActiveDirection.hpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef HYPRLAND_GROUPACTIVEDIRECTION_HPP
|
||||||
|
#define HYPRLAND_GROUPACTIVEDIRECTION_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class GroupActiveDirection {
|
||||||
|
std::string direction;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GroupActiveDirection(std::string);
|
||||||
|
static GroupActiveDirection fromFocusDirection(std::string);
|
||||||
|
|
||||||
|
bool isForward();
|
||||||
|
bool isBackwards();
|
||||||
|
std::string asString();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //HYPRLAND_GROUPACTIVEDIRECTION_HPP
|
Loading…
Reference in a new issue