remember last window on workspace

This commit is contained in:
vaxerski 2022-08-31 17:02:44 +02:00
parent 0ad261aa9c
commit dacaf72e02
3 changed files with 27 additions and 3 deletions

View file

@ -8,6 +8,8 @@ enum eFullscreenMode : uint8_t {
FULLSCREEN_MAXIMIZED FULLSCREEN_MAXIMIZED
}; };
class CWindow;
class CWorkspace { class CWorkspace {
public: public:
CWorkspace(int monitorID, std::string name, bool special = false); CWorkspace(int monitorID, std::string name, bool special = false);
@ -36,6 +38,9 @@ public:
// "scratchpad" // "scratchpad"
bool m_bIsSpecialWorkspace = false; bool m_bIsSpecialWorkspace = false;
// last window
CWindow* m_pLastFocusedWindow = nullptr;
// user-set // user-set
bool m_bDefaultFloating = false; bool m_bDefaultFloating = false;
bool m_bDefaultPseudo = false; bool m_bDefaultPseudo = false;

View file

@ -651,6 +651,11 @@ void CKeybindManager::changeworkspace(std::string args) {
Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo); Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo);
// focus // focus
if (const auto PWINDOW = PWORKSPACETOCHANGETO->m_pLastFocusedWindow; g_pCompositor->windowValidMapped(PWINDOW)) {
// warp and focus
g_pCompositor->warpCursorTo(PWINDOW->m_vRealPosition.vec() + PWINDOW->m_vRealSize.vec() / 2.f);
g_pCompositor->focusWindow(PWINDOW, g_pXWaylandManager->getWindowSurface(PWINDOW));
} else
g_pInputManager->refocus(); g_pInputManager->refocus();
// mark the monitor dirty // mark the monitor dirty
@ -1222,14 +1227,23 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) {
Debug::log(LOG, "Toggling special workspace to open"); Debug::log(LOG, "Toggling special workspace to open");
if (open) { if (open) {
uint64_t monID = -1;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
if (m->specialWorkspaceOpen != !open) { if (m->specialWorkspaceOpen != !open) {
m->specialWorkspaceOpen = !open; m->specialWorkspaceOpen = !open;
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false); g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false);
monID = m->ID;
} }
} }
if (const auto PWINDOW = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace)->m_pLastFocusedWindow; g_pCompositor->windowValidMapped(PWINDOW) && PWINDOW->m_iMonitorID == monID)
g_pCompositor->focusWindow(PWINDOW);
else
g_pInputManager->refocus();
} else { } else {
auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID); auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID);
@ -1243,9 +1257,12 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) {
PSPECIALWORKSPACE->startAnim(true, true); PSPECIALWORKSPACE->startAnim(true, true);
PSPECIALWORKSPACE->m_iMonitorID = g_pCompositor->m_pLastMonitor->ID; PSPECIALWORKSPACE->m_iMonitorID = g_pCompositor->m_pLastMonitor->ID;
}
if (const auto PWINDOW = PSPECIALWORKSPACE->m_pLastFocusedWindow; g_pCompositor->windowValidMapped(PWINDOW))
g_pCompositor->focusWindow(PWINDOW);
else
g_pInputManager->refocus(); g_pInputManager->refocus();
}
} }
void CKeybindManager::forceRendererReload(std::string args) { void CKeybindManager::forceRendererReload(std::string args) {

View file

@ -62,6 +62,8 @@ void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) {
g_pCompositor->m_pLastFocus = getWindowSurface(pWindow); g_pCompositor->m_pLastFocus = getWindowSurface(pWindow);
g_pCompositor->m_pLastWindow = pWindow; g_pCompositor->m_pLastWindow = pWindow;
g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_pLastFocusedWindow = pWindow;
} }
void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) { void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) {