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:
Hilmar Wiegand 2023-04-10 15:40:03 +02:00 committed by GitHub
parent 16d05a5c8b
commit 6a4bda60f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 8 deletions

View file

@ -63,6 +63,7 @@ void CConfigManager::setDefaultVars() {
((CGradientValueData*)configValues["general:col.group_border_active"].data.get())->reset(0x66ffff00);
configValues["general:cursor_inactive_timeout"].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:extend_border_grab_area"].intValue = 15;
configValues["general:hover_icon_on_border"].intValue = 1;

View file

@ -174,6 +174,32 @@ bool CKeybindManager::ensureMouseBindState() {
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) {
if (!g_pCompositor->m_bSessionActive) {
m_dPressedKeycodes.clear();
@ -1121,9 +1147,10 @@ void CKeybindManager::moveFocusTo(std::string args) {
}
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
if (!PLASTWINDOW)
if (!PLASTWINDOW) {
tryMoveFocusToMonitorInDirection(arg);
return;
}
// remove constraints
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') :
g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
// Found window in direction, switch to it
if (PWINDOWTOCHANGETO) {
switchToWindow(PWINDOWTOCHANGETO);
} else {
const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true);
if (PWINDOWNEXT) {
switchToWindow(PWINDOWNEXT);
}
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);
if (PWINDOWNEXT)
switchToWindow(PWINDOWNEXT);
}
void CKeybindManager::focusUrgentOrLast(std::string args) {

View file

@ -90,6 +90,8 @@ class CKeybindManager {
void updateXKBTranslationState();
bool ensureMouseBindState();
static bool tryMoveFocusToMonitorInDirection(const char&);
// -------------- Dispatchers -------------- //
static void killActive(std::string);
static void kill(std::string);