From 781526dac58619fa313ca9bf86bfd712c01cb68f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Jun 2022 13:42:20 +0200 Subject: added hyprctl kill --- src/managers/KeybindManager.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 10694e1b..aab79458 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -108,7 +108,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t return found; } -bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) { +bool CKeybindManager::handleVT(xkb_keysym_t keysym) { // Handles the CTRL+ALT+FX TTY keybinds if (!(keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12)) return false; @@ -119,19 +119,36 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) { wlr_session_change_vt(PSESSION, TTY); for (auto& m : g_pCompositor->m_lMonitors) { - g_pHyprOpenGL->destroyMonitorResources(&m); // mark resources as unusable anymore + g_pHyprOpenGL->destroyMonitorResources(&m); // mark resources as unusable anymore m.noFrameSchedule = true; m.framesToSkip = 2; } Debug::log(LOG, "Switched to VT %i, destroyed all render data, frames to skip for each: 2", TTY); - + return true; } return false; } +bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) { + if (handleVT(keysym)) + return true; + + // handle ESC while in kill mode + if (g_pInputManager->getClickMode() == CLICKMODE_KILL) { + const auto KBKEY = xkb_keysym_from_name("ESCAPE", XKB_KEYSYM_CASE_INSENSITIVE); + + if (keysym == KBKEY) { + g_pInputManager->setClickMode(CLICKMODE_DEFAULT); + return true; + } + } + + return false; +} + // Dispatchers void CKeybindManager::spawn(std::string args) { -- cgit v1.2.3 From 2cdb29aa105a8f045cf87b900d1cb30a76bfa915 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 27 Jun 2022 19:46:04 +0200 Subject: fix anims with special workspace --- src/managers/KeybindManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index aab79458..99b758b0 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -883,7 +883,10 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { g_pCompositor->m_pLastMonitor->specialWorkspaceOpen = true; g_pLayoutManager->getCurrentLayout()->recalculateMonitor(g_pCompositor->m_pLastMonitor->ID); - g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(true, true); + const auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID); + + PSPECIALWORKSPACE->startAnim(true, true); + PSPECIALWORKSPACE->m_iMonitorID = g_pCompositor->m_pLastMonitor->ID; } g_pInputManager->refocus(); -- cgit v1.2.3 From 3cbd69e7039c7ed020bde7f7a58ed5c8da93155b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 28 Jun 2022 12:39:56 +0200 Subject: added createworkspace destroyworkspace events --- src/managers/KeybindManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 99b758b0..14c535d8 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -336,7 +336,7 @@ void CKeybindManager::changeworkspace(std::string args) { if (const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); POLDWORKSPACE) POLDWORKSPACE->startAnim(false, ANIMTOLEFT); - g_pCompositor->m_lWorkspaces.emplace_back(PMONITOR->ID, workspaceToChangeTo == SPECIAL_WORKSPACE_ID); + g_pCompositor->m_lWorkspaces.emplace_back(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID); const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); // start anim on new workspace @@ -348,7 +348,6 @@ void CKeybindManager::changeworkspace(std::string args) { PWORKSPACE->m_iID = workspaceToChangeTo; PWORKSPACE->m_iMonitorID = PMONITOR->ID; - PWORKSPACE->m_szName = workspaceName; PMONITOR->specialWorkspaceOpen = false; -- cgit v1.2.3 From b0cd90a43c7281dc339b3dab6236646b1ed6439f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 30 Jun 2022 12:09:05 +0200 Subject: refactor a bunch of layout code --- src/managers/KeybindManager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 14c535d8..64c0d886 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -221,6 +221,9 @@ void CKeybindManager::toggleActiveFloating(std::string args) { const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow; if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) { + // remove drag status + g_pInputManager->currentlyDraggedWindow = nullptr; + ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating; if (ACTIVEWINDOW->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) { -- cgit v1.2.3 From 328b3fa4bc4f3776f2128f84709556569c4824d9 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 30 Jun 2022 15:44:26 +0200 Subject: mordernize pointers --- src/managers/KeybindManager.cpp | 65 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 64c0d886..e2a26781 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -118,10 +118,10 @@ bool CKeybindManager::handleVT(xkb_keysym_t keysym) { const int TTY = keysym - XKB_KEY_XF86Switch_VT_1 + 1; wlr_session_change_vt(PSESSION, TTY); - for (auto& m : g_pCompositor->m_lMonitors) { - g_pHyprOpenGL->destroyMonitorResources(&m); // mark resources as unusable anymore - m.noFrameSchedule = true; - m.framesToSkip = 2; + for (auto& m : g_pCompositor->m_vMonitors) { + g_pHyprOpenGL->destroyMonitorResources(m.get()); // mark resources as unusable anymore + m->noFrameSchedule = true; + m->framesToSkip = 2; } Debug::log(LOG, "Switched to VT %i, destroyed all render data, frames to skip for each: 2", TTY); @@ -339,8 +339,7 @@ void CKeybindManager::changeworkspace(std::string args) { if (const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); POLDWORKSPACE) POLDWORKSPACE->startAnim(false, ANIMTOLEFT); - g_pCompositor->m_lWorkspaces.emplace_back(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID); - const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); + const auto PWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID)).get(); // start anim on new workspace PWORKSPACE->startAnim(true, ANIMTOLEFT); @@ -456,8 +455,8 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { toggleSpecialWorkspace(""); g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false, true); - for (auto& m : g_pCompositor->m_lMonitors) - m.specialWorkspaceOpen = false; + for (auto& m : g_pCompositor->m_vMonitors) + m->specialWorkspaceOpen = false; } g_pInputManager->refocus(); @@ -662,7 +661,7 @@ void CKeybindManager::focusMonitor(std::string arg) { Debug::log(ERR, "Error in focusMonitor: invalid num"); } - if (monID > -1 && monID < (int)g_pCompositor->m_lMonitors.size()) { + if (monID > -1 && monID < (int)g_pCompositor->m_vMonitors.size()) { changeworkspace(std::to_string(g_pCompositor->getMonitorFromID(monID)->activeWorkspace)); } else { Debug::log(ERR, "Error in focusMonitor: invalid arg 1"); @@ -681,9 +680,9 @@ void CKeybindManager::focusMonitor(std::string arg) { return; } } else { - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.szName == arg) { - changeworkspace(std::to_string(m.activeWorkspace)); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->szName == arg) { + changeworkspace(std::to_string(m->activeWorkspace)); return; } } @@ -743,11 +742,11 @@ void CKeybindManager::workspaceOpt(std::string args) { PWORKSPACE->m_bDefaultPseudo = !PWORKSPACE->m_bDefaultPseudo; // apply - for (auto& w : g_pCompositor->m_lWindows) { - if (!w.m_bIsMapped || w.m_iWorkspaceID != PWORKSPACE->m_iID) + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID) continue; - w.m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo; + w->m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo; } } else if (args == "allfloat") { PWORKSPACE->m_bDefaultFloating = !PWORKSPACE->m_bDefaultFloating; @@ -755,8 +754,8 @@ void CKeybindManager::workspaceOpt(std::string args) { // we make a copy because changeWindowFloatingMode might invalidate the iterator std::deque ptrs; - for (auto& w : g_pCompositor->m_lWindows) - ptrs.push_back(&w); + for (auto& w : g_pCompositor->m_vWindows) + ptrs.push_back(w.get()); for (auto& w : ptrs) { if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID) @@ -860,8 +859,8 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { bool open = false; - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.specialWorkspaceOpen) { + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->specialWorkspaceOpen) { open = true; break; } @@ -873,10 +872,10 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { Debug::log(LOG, "Toggling special workspace to open"); if (open) { - for (auto& m : g_pCompositor->m_lMonitors) { - if (m.specialWorkspaceOpen != !open) { - m.specialWorkspaceOpen = !open; - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m.ID); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->specialWorkspaceOpen != !open) { + m->specialWorkspaceOpen = !open; + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false); } @@ -895,9 +894,9 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { } void CKeybindManager::forceRendererReload(std::string args) { - for (auto& m : g_pCompositor->m_lMonitors) { - auto rule = g_pConfigManager->getMonitorRuleFor(m.szName); - g_pHyprRenderer->applyMonitorRule(&m, &rule, true); + for (auto& m : g_pCompositor->m_vMonitors) { + auto rule = g_pConfigManager->getMonitorRuleFor(m->szName); + g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true); } } @@ -1013,22 +1012,22 @@ void CKeybindManager::circleNext(std::string) { void CKeybindManager::focusWindowByClass(std::string clazz) { std::regex classCheck(clazz); - for (auto& w : g_pCompositor->m_lWindows) { - if (!w.m_bIsMapped || w.m_bHidden) + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped || w->m_bHidden) continue; - const auto windowClass = g_pXWaylandManager->getAppIDClass(&w); + const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get()); if (!std::regex_search(windowClass, classCheck)) continue; - Debug::log(LOG, "Focusing to window name: %s", w.m_szTitle.c_str()); + Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str()); - changeworkspace(std::to_string(w.m_iWorkspaceID)); + changeworkspace(std::to_string(w->m_iWorkspaceID)); - g_pCompositor->focusWindow(&w); + g_pCompositor->focusWindow(w.get()); - const auto MIDPOINT = w.m_vRealPosition.goalv() + w.m_vRealSize.goalv() / 2.f; + const auto MIDPOINT = w->m_vRealPosition.goalv() + w->m_vRealSize.goalv() / 2.f; wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); -- cgit v1.2.3 From 91d68513de5b182103393ee4abd3eb37db905bee Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 30 Jun 2022 23:55:28 +0200 Subject: fix possible segfault by realloc --- src/managers/KeybindManager.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index e2a26781..f5554f57 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -894,10 +894,18 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { } void CKeybindManager::forceRendererReload(std::string args) { + bool overAgain = false; + for (auto& m : g_pCompositor->m_vMonitors) { auto rule = g_pConfigManager->getMonitorRuleFor(m->szName); - g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true); + if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true)) { + overAgain = true; + break; + } } + + if (overAgain) + forceRendererReload(args); } void CKeybindManager::resizeActive(std::string args) { -- cgit v1.2.3 From 2225dca57665059102cd0225b8843a1d90a4f076 Mon Sep 17 00:00:00 2001 From: Dakes Date: Fri, 1 Jul 2022 16:24:37 +0200 Subject: Add focusWindow dispatcher. Takes titles & classes Removed focusWindowByClass function, replaced with focusWindow. Either takes a class matching regex, or a title matching one, beginning with "title:" Kept the focuswindowbyclass dispatcher identifier to stay backwards compatible with existing configs. --- src/managers/KeybindManager.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index f5554f57..cb091c9f 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -30,7 +30,8 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["resizeactive"] = resizeActive; m_mDispatchers["moveactive"] = moveActive; m_mDispatchers["cyclenext"] = circleNext; - m_mDispatchers["focuswindowbyclass"] = focusWindowByClass; + m_mDispatchers["focuswindowbyclass"] = focusWindow; + m_mDispatchers["focuswindow"] = focusWindow; m_mDispatchers["submap"] = setSubmap; } @@ -1017,17 +1018,28 @@ void CKeybindManager::circleNext(std::string) { wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); } -void CKeybindManager::focusWindowByClass(std::string clazz) { - std::regex classCheck(clazz); +void CKeybindManager::focusWindow(std::string regexp) { + bool titleRegex = false; + std::regex regexCheck(regexp); + if (regexp.find("title:") == 0) { + titleRegex = true; + regexCheck = std::regex(regexp.substr(6)); + } for (auto& w : g_pCompositor->m_vWindows) { if (!w->m_bIsMapped || w->m_bHidden) continue; - const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get()); - - if (!std::regex_search(windowClass, classCheck)) - continue; + if (titleRegex) { + const auto windowTitle = g_pXWaylandManager->getTitle(w.get()); + if (!std::regex_search(windowTitle, regexCheck)) + continue; + } + else { + const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get()); + if (!std::regex_search(windowClass, regexCheck)) + continue; + } Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str()); -- cgit v1.2.3