From edcecae7a074f76d6e0a9c7c29e796621c5b9e52 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 16 Jul 2022 19:55:40 +0200 Subject: dont cycle on fullscreen --- src/managers/KeybindManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 60e4cdd6..86fb2275 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1047,6 +1047,11 @@ void CKeybindManager::circleNext(std::string arg) { if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) return; + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastWindow->m_iWorkspaceID); + + if (PWORKSPACE->m_bHasFullscreenWindow) + return; + if (arg == "last" || arg == "l" || arg == "prev" || arg == "p") g_pCompositor->focusWindow(g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow)); else -- cgit v1.2.3 From dc1f34c5fad7c4067808cfcff4d1fde74331de4c Mon Sep 17 00:00:00 2001 From: Daniel Gerblick Date: Sun, 17 Jul 2022 19:00:12 -0400 Subject: added PID and address-based options for focuswindow, as well as updated `hyprctl clients` to be consistent with logs and `hyprctl activewindow` --- src/managers/KeybindManager.cpp | 51 ++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 86fb2275..67e331b8 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1063,28 +1063,57 @@ void CKeybindManager::circleNext(std::string arg) { } void CKeybindManager::focusWindow(std::string regexp) { - bool titleRegex = false; + eFocusWindowMode mode = MODE_CLASS_REGEX; + std::regex regexCheck(regexp); + std::string matchCheck; if (regexp.find("title:") == 0) { - titleRegex = true; + mode = MODE_TITLE_REGEX; regexCheck = std::regex(regexp.substr(6)); } + else if (regexp.find("address:") == 0) { + mode = MODE_ADDRESS; + matchCheck = regexp.substr(8); + } + else if (regexp.find("pid:") == 0) { + mode = MODE_PID; + matchCheck = regexp.substr(4); + } for (auto& w : g_pCompositor->m_vWindows) { if (!w->m_bIsMapped || w->m_bHidden) 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; + switch (mode) { + case MODE_CLASS_REGEX: { + const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get()); + if (!std::regex_search(g_pXWaylandManager->getAppIDClass(w.get()), regexCheck)) + continue; + break; + } + case MODE_TITLE_REGEX: { + const auto windowTitle = g_pXWaylandManager->getTitle(w.get()); + if (!std::regex_search(windowTitle, regexCheck)) + continue; + break; + } + case MODE_ADDRESS: { + std::string addr = getFormat("0x%x", w.get()); + if (matchCheck != addr) + continue; + break; + } + case MODE_PID: { + std::string pid = getFormat("%d", w->getPID()); + if (matchCheck != pid) + continue; + break; + } + default: + break; } + Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str()); changeworkspace("[internal]" + std::to_string(w->m_iWorkspaceID)); -- cgit v1.2.3 From 8bcfda22300d3b656b6f098f9dba5ce5f0914595 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 18 Jul 2022 20:53:29 +0200 Subject: update moveactivetoworkspace logic --- src/managers/KeybindManager.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 86fb2275..1ad338cd 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -429,6 +429,9 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { return; } + auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec(); + auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec(); + g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); g_pKeybindManager->changeworkspace(args); @@ -456,20 +459,21 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { PWORKSPACE->m_bHasFullscreenWindow = false; } + if (PWINDOW->m_bIsFullscreen) { + PWINDOW->m_bIsFullscreen = false; + PSAVEDPOS = PSAVEDPOS + Vector2D(10, 10); + PSAVEDSIZE = PSAVEDSIZE - Vector2D(20, 20); + } + // Hack: So that the layout doesnt find our window at the cursor PWINDOW->m_vPosition = Vector2D(-42069, -42069); - // Save the real position and size because the layout might set its own - const auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec(); - const auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec(); g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); - // and restore it - PWINDOW->m_vRealPosition.setValue(PSAVEDPOS); - PWINDOW->m_vRealSize.setValue(PSAVEDSIZE); + // and restore it if (PWINDOW->m_bIsFloating) { - PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition); - PWINDOW->m_vRealPosition.setValue(PWINDOW->m_vRealPosition.vec() + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition); + PWINDOW->m_vRealSize.setValue(PSAVEDSIZE); + PWINDOW->m_vRealPosition.setValueAndWarp(PSAVEDPOS - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition); PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); } -- cgit v1.2.3 From 641aaff998d6297831b9b139e5ff8767ab5c0c79 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 20 Jul 2022 18:39:08 +0200 Subject: minor code adjustments --- src/managers/KeybindManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 2c91f81f..1d7a4ba4 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -230,7 +230,7 @@ void CKeybindManager::killActive(std::string args) { g_pXWaylandManager->sendCloseWindow(g_pCompositor->m_pLastWindow); g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastWindow = nullptr; - g_pEventManager->postEvent(SHyprIPCEvent("activewindow", ",")); // post an activewindow event to empty, as we are currently unfocused + g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","}); // post an activewindow event to empty, as we are currently unfocused } g_pCompositor->focusWindow(g_pCompositor->windowFromCursor()); @@ -325,7 +325,7 @@ void CKeybindManager::changeworkspace(std::string args) { // start anim on new workspace PWORKSPACETOCHANGETO->startAnim(true, ANIMTOLEFT); - g_pEventManager->postEvent(SHyprIPCEvent("workspace", PWORKSPACETOCHANGETO->m_szName)); + g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PWORKSPACETOCHANGETO->m_szName}); } // If the monitor is not the one our cursor's at, warp to it. @@ -398,7 +398,7 @@ void CKeybindManager::changeworkspace(std::string args) { g_pInputManager->refocus(); // Event - g_pEventManager->postEvent(SHyprIPCEvent("workspace", PWORKSPACE->m_szName)); + g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PWORKSPACE->m_szName}); Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo); } -- cgit v1.2.3 From fa2bd3b1a846e7395f96b3bd3587a5ef92ed30be Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 20 Jul 2022 22:45:06 +0200 Subject: added keybinds on key up --- src/managers/KeybindManager.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1d7a4ba4..52afbfdd 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -82,7 +82,31 @@ uint32_t CKeybindManager::stringToModMask(std::string mods) { return modMask; } -bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode) { +bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) { + const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput + + const xkb_keysym_t* keysyms; + int syms = xkb_state_key_get_syms(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE, &keysyms); + + const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); + + bool found = false; + if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) { + for (int i = 0; i < syms; ++i) + found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0, true) || found; + + found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, true) || found; + } else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) { + for (int i = 0; i < syms; ++i) + found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0, false) || found; + + found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, false) || found; + } + + return !found; +} + +bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode, bool pressed) { bool found = false; if (handleInternalKeybinds(key)) @@ -92,10 +116,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t Debug::log(LOG, "Keybind handling only locked (inhibitor)"); for (auto& k : m_lKeybinds) { - if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap) + if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release)) continue; - if (k.keycode != -1) { if (keycode != k.keycode) continue; @@ -114,6 +137,11 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t continue; } + if (pressed && k.release) { + // suppress down event + return true; + } + const auto DISPATCHER = m_mDispatchers.find(k.handler); // Should never happen, as we check in the ConfigManager, but oh well -- cgit v1.2.3 From 189cbe9f098816231673e9ebe1ac5fa5872f33e7 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 20 Jul 2022 23:17:26 +0200 Subject: added shadowing keybinds --- src/managers/KeybindManager.cpp | 62 ++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 52afbfdd..74cecc45 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -85,28 +85,35 @@ uint32_t CKeybindManager::stringToModMask(std::string mods) { bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) { const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput - const xkb_keysym_t* keysyms; - int syms = xkb_state_key_get_syms(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE, &keysyms); + const xkb_keysym_t keysym = xkb_state_key_get_one_sym(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE); const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); + bool found = false; if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) { - for (int i = 0; i < syms; ++i) - found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0, true) || found; + m_dPressedKeycodes.push_back(KEYCODE); + m_dPressedKeysyms.push_back(keysym); + + found = g_pKeybindManager->handleKeybinds(MODS, keysym, 0, true, e->time_msec) || found; - found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, true) || found; + found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, true, e->time_msec) || found; } else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) { - for (int i = 0; i < syms; ++i) - found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0, false) || found; - found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, false) || found; + m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE)); + m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym)); + + found = g_pKeybindManager->handleKeybinds(MODS, keysym, 0, false, e->time_msec) || found; + + found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, false, e->time_msec) || found; + + shadowKeybinds(); } return !found; } -bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode, bool pressed) { +bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode, bool pressed, uint32_t time) { bool found = false; if (handleInternalKeybinds(key)) @@ -115,8 +122,14 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t if (g_pCompositor->m_sSeat.exclusiveClient) Debug::log(LOG, "Keybind handling only locked (inhibitor)"); + if (pressed && m_kHeldBack) { + // release the held back event + wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, time, m_kHeldBack, WL_KEYBOARD_KEY_STATE_PRESSED); + m_kHeldBack = 0; + } + for (auto& k : m_lKeybinds) { - if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release)) + if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release) || k.shadowed) continue; if (k.keycode != -1) { @@ -139,6 +152,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t if (pressed && k.release) { // suppress down event + m_kHeldBack = key; return true; } @@ -153,12 +167,40 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t DISPATCHER->second(k.arg); } + shadowKeybinds(); + found = true; } return found; } +void CKeybindManager::shadowKeybinds() { + // shadow disables keybinds after one has been triggered + + for (auto& k : m_lKeybinds) { + + bool shadow = false; + + const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); + const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY); + + for (auto& pk : m_dPressedKeysyms) { + if ((pk == KBKEY || pk == KBKEYUPPER)) { + shadow = true; + } + } + + for (auto& pk : m_dPressedKeycodes) { + if (pk == (unsigned int)k.keycode) { + shadow = true; + } + } + + k.shadowed = shadow; + } +} + 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)) -- cgit v1.2.3