mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 10:05:59 +01:00
feat: add focus to urgent or last window (#1402)
* feat: add focus to urgent or last window * Rename dispatcher Co-authored-by: Maxim Baz <git@maximbaz.com>
This commit is contained in:
parent
e811394603
commit
fcbfd19393
4 changed files with 49 additions and 0 deletions
|
@ -1084,6 +1084,15 @@ int CCompositor::getWindowsOnWorkspace(const int& id) {
|
|||
return no;
|
||||
}
|
||||
|
||||
CWindow* CCompositor::getUrgentWindow() {
|
||||
for (auto& w : m_vWindows) {
|
||||
if (w->m_bIsMapped && w->m_bIsUrgent)
|
||||
return w.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CCompositor::hasUrgentWindowOnWorkspace(const int& id) {
|
||||
for (auto& w : m_vWindows) {
|
||||
if (w->m_iWorkspaceID == id && w->m_bIsMapped && w->m_bIsUrgent)
|
||||
|
|
|
@ -137,6 +137,7 @@ class CCompositor {
|
|||
void sanityCheckWorkspaces();
|
||||
void updateWorkspaceWindowDecos(const int&);
|
||||
int getWindowsOnWorkspace(const int&);
|
||||
CWindow* getUrgentWindow();
|
||||
bool hasUrgentWindowOnWorkspace(const int&);
|
||||
CWindow* getFirstWindowOnWorkspace(const int&);
|
||||
CWindow* getFullscreenWindowOnWorkspace(const int&);
|
||||
|
|
|
@ -48,6 +48,7 @@ CKeybindManager::CKeybindManager() {
|
|||
m_mDispatchers["pin"] = pinActive;
|
||||
m_mDispatchers["mouse"] = mouse;
|
||||
m_mDispatchers["bringactivetotop"] = bringActiveToTop;
|
||||
m_mDispatchers["focusurgentorlast"] = focusUrgentOrLast;
|
||||
|
||||
m_tScrollTimer.reset();
|
||||
}
|
||||
|
@ -1099,6 +1100,43 @@ void CKeybindManager::moveFocusTo(std::string args) {
|
|||
}
|
||||
}
|
||||
|
||||
void CKeybindManager::focusUrgentOrLast(std::string args) {
|
||||
const auto PWINDOWURGENT = g_pCompositor->getUrgentWindow();
|
||||
const auto PWINDOWPREV = g_pCompositor->m_pLastWindow
|
||||
? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1])
|
||||
: (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0]);
|
||||
|
||||
if (!PWINDOWURGENT && !PWINDOWPREV)
|
||||
return;
|
||||
|
||||
// remove constraints
|
||||
g_pInputManager->unconstrainMouse();
|
||||
|
||||
auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) {
|
||||
if (PWINDOWTOCHANGETO == g_pCompositor->m_pLastWindow || !PWINDOWTOCHANGETO)
|
||||
return;
|
||||
|
||||
if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsFullscreen) {
|
||||
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastWindow->m_iWorkspaceID);
|
||||
const auto FSMODE = PWORKSPACE->m_efFullscreenMode;
|
||||
|
||||
if (!PWINDOWTOCHANGETO->m_bPinned)
|
||||
g_pCompositor->setWindowFullscreen(g_pCompositor->m_pLastWindow, false, FULLSCREEN_FULL);
|
||||
|
||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||
|
||||
if (!PWINDOWTOCHANGETO->m_bPinned)
|
||||
g_pCompositor->setWindowFullscreen(PWINDOWTOCHANGETO, true, FSMODE);
|
||||
} else {
|
||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||
Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f;
|
||||
g_pCompositor->warpCursorTo(middle);
|
||||
}
|
||||
};
|
||||
|
||||
switchToWindow(PWINDOWURGENT ? PWINDOWURGENT : PWINDOWPREV);
|
||||
}
|
||||
|
||||
void CKeybindManager::moveActiveTo(std::string args) {
|
||||
char arg = args[0];
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ class CKeybindManager {
|
|||
static void moveActiveToWorkspace(std::string);
|
||||
static void moveActiveToWorkspaceSilent(std::string);
|
||||
static void moveFocusTo(std::string);
|
||||
static void focusUrgentOrLast(std::string);
|
||||
static void centerWindow(std::string);
|
||||
static void moveActiveTo(std::string);
|
||||
static void toggleGroup(std::string);
|
||||
|
|
Loading…
Reference in a new issue