mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-30 04:45:59 +01:00
Allow movefocus for empty workspaces (#2011)
* Allow switching to empty workspaces using movefocus * Allow switching to other workspaces when no windows are focused * Implement review feedback * Add option to disable focus fallback * Remove unnecessary braces
This commit is contained in:
parent
16d05a5c8b
commit
6a4bda60f2
3 changed files with 50 additions and 8 deletions
|
@ -63,6 +63,7 @@ void CConfigManager::setDefaultVars() {
|
||||||
((CGradientValueData*)configValues["general:col.group_border_active"].data.get())->reset(0x66ffff00);
|
((CGradientValueData*)configValues["general:col.group_border_active"].data.get())->reset(0x66ffff00);
|
||||||
configValues["general:cursor_inactive_timeout"].intValue = 0;
|
configValues["general:cursor_inactive_timeout"].intValue = 0;
|
||||||
configValues["general:no_cursor_warps"].intValue = 0;
|
configValues["general:no_cursor_warps"].intValue = 0;
|
||||||
|
configValues["general:no_focus_fallback"].intValue = 0;
|
||||||
configValues["general:resize_on_border"].intValue = 0;
|
configValues["general:resize_on_border"].intValue = 0;
|
||||||
configValues["general:extend_border_grab_area"].intValue = 15;
|
configValues["general:extend_border_grab_area"].intValue = 15;
|
||||||
configValues["general:hover_icon_on_border"].intValue = 1;
|
configValues["general:hover_icon_on_border"].intValue = 1;
|
||||||
|
|
|
@ -174,6 +174,32 @@ bool CKeybindManager::ensureMouseBindState() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CKeybindManager::tryMoveFocusToMonitorInDirection(const char& dir) {
|
||||||
|
const auto PNEWMONITOR = g_pCompositor->getMonitorInDirection(dir);
|
||||||
|
if (!PNEWMONITOR)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Debug::log(LOG, "switching to monitor");
|
||||||
|
const auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(PNEWMONITOR->activeWorkspace);
|
||||||
|
g_pCompositor->setActiveMonitor(PNEWMONITOR);
|
||||||
|
g_pCompositor->deactivateAllWLRWorkspaces(PNEWWORKSPACE->m_pWlrHandle);
|
||||||
|
PNEWWORKSPACE->setActive(true);
|
||||||
|
|
||||||
|
// Focus window on new monitor
|
||||||
|
const auto PNEWWINDOW = PNEWWORKSPACE->getLastFocusedWindow();
|
||||||
|
if (PNEWWINDOW) {
|
||||||
|
g_pCompositor->focusWindow(PNEWWINDOW);
|
||||||
|
Vector2D middle = PNEWWINDOW->m_vRealPosition.goalv() + PNEWWINDOW->m_vRealSize.goalv() / 2.f;
|
||||||
|
g_pCompositor->warpCursorTo(middle);
|
||||||
|
} else {
|
||||||
|
g_pCompositor->focusWindow(nullptr);
|
||||||
|
Vector2D middle = PNEWMONITOR->vecPosition + PNEWMONITOR->vecSize / 2.f;
|
||||||
|
g_pCompositor->warpCursorTo(middle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
if (!g_pCompositor->m_bSessionActive) {
|
||||||
m_dPressedKeycodes.clear();
|
m_dPressedKeycodes.clear();
|
||||||
|
@ -1121,9 +1147,10 @@ void CKeybindManager::moveFocusTo(std::string args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
||||||
|
if (!PLASTWINDOW) {
|
||||||
if (!PLASTWINDOW)
|
tryMoveFocusToMonitorInDirection(arg);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// remove constraints
|
// remove constraints
|
||||||
g_pInputManager->unconstrainMouse();
|
g_pInputManager->unconstrainMouse();
|
||||||
|
@ -1161,14 +1188,26 @@ void CKeybindManager::moveFocusTo(std::string args) {
|
||||||
const auto PWINDOWTOCHANGETO = PLASTWINDOW->m_bIsFullscreen ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, arg == 'u' || arg == 't' || arg == 'r') :
|
const auto PWINDOWTOCHANGETO = PLASTWINDOW->m_bIsFullscreen ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, arg == 'u' || arg == 't' || arg == 'r') :
|
||||||
g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
||||||
|
|
||||||
|
// Found window in direction, switch to it
|
||||||
if (PWINDOWTOCHANGETO) {
|
if (PWINDOWTOCHANGETO) {
|
||||||
switchToWindow(PWINDOWTOCHANGETO);
|
switchToWindow(PWINDOWTOCHANGETO);
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug::log(LOG, "No window found in direction %c, looking for a monitor", arg);
|
||||||
|
|
||||||
|
if (tryMoveFocusToMonitorInDirection(arg))
|
||||||
|
return;
|
||||||
|
|
||||||
|
static auto* const PNOFALLBACK = &g_pConfigManager->getConfigValuePtr("general:no_focus_fallback")->intValue;
|
||||||
|
if (*PNOFALLBACK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Debug::log(LOG, "No monitor found in direction %c, falling back to next window on current workspace", arg);
|
||||||
|
|
||||||
const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true);
|
const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true);
|
||||||
if (PWINDOWNEXT) {
|
if (PWINDOWNEXT)
|
||||||
switchToWindow(PWINDOWNEXT);
|
switchToWindow(PWINDOWNEXT);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeybindManager::focusUrgentOrLast(std::string args) {
|
void CKeybindManager::focusUrgentOrLast(std::string args) {
|
||||||
|
|
|
@ -90,6 +90,8 @@ class CKeybindManager {
|
||||||
void updateXKBTranslationState();
|
void updateXKBTranslationState();
|
||||||
bool ensureMouseBindState();
|
bool ensureMouseBindState();
|
||||||
|
|
||||||
|
static bool tryMoveFocusToMonitorInDirection(const char&);
|
||||||
|
|
||||||
// -------------- Dispatchers -------------- //
|
// -------------- Dispatchers -------------- //
|
||||||
static void killActive(std::string);
|
static void killActive(std::string);
|
||||||
static void kill(std::string);
|
static void kill(std::string);
|
||||||
|
|
Loading…
Reference in a new issue