diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-06-27 13:42:20 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-06-27 13:42:20 +0200 |
| commit | 781526dac58619fa313ca9bf86bfd712c01cb68f (patch) | |
| tree | 93139652439c65fc49b66437292dacb4c2efb258 /src/managers | |
| parent | b9a5fc0d2f76718833b49ec01234496f5002a677 (diff) | |
added hyprctl kill
Diffstat (limited to 'src/managers')
| -rw-r--r-- | src/managers/KeybindManager.cpp | 23 | ||||
| -rw-r--r-- | src/managers/KeybindManager.hpp | 1 | ||||
| -rw-r--r-- | src/managers/input/InputManager.cpp | 96 | ||||
| -rw-r--r-- | src/managers/input/InputManager.hpp | 15 |
4 files changed, 127 insertions, 8 deletions
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) { diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index c9132a11..117a5ec4 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -33,6 +33,7 @@ private: inline static std::string m_szCurrentSelectedSubmap = ""; bool handleInternalKeybinds(xkb_keysym_t); + bool handleVT(xkb_keysym_t); // -------------- Dispatchers -------------- // static void killActive(std::string); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index f99c6ab4..e5780608 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -164,7 +164,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfaceCoords); if (!foundSurface) { - wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor); + if (m_ecbClickBehavior == CLICKMODE_KILL) + wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "crosshair", g_pCompositor->m_sWLRCursor); + else + wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor); wlr_seat_pointer_clear_focus(g_pCompositor->m_sSeat.seat); @@ -211,10 +214,70 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) { m_tmrLastCursorMovement.reset(); + switch (m_ecbClickBehavior) { + case CLICKMODE_DEFAULT: + processMouseDownNormal(e); + break; + case CLICKMODE_KILL: + processMouseDownKill(e); + break; + default: + break; + } +} + +void CInputManager::processMouseRequest(wlr_seat_pointer_request_set_cursor_event* e) { + if (!g_pHyprRenderer->shouldRenderCursor()) + return; + + if (!e->surface) { + g_pHyprRenderer->m_bWindowRequestedCursorHide = true; + } else { + g_pHyprRenderer->m_bWindowRequestedCursorHide = false; + } + + if (m_ecbClickBehavior == CLICKMODE_KILL) { + wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "crosshair", g_pCompositor->m_sWLRCursor); + return; + } + + if (e->seat_client == g_pCompositor->m_sSeat.seat->pointer_state.focused_client) + wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, e->surface, e->hotspot_x, e->hotspot_y); +} + +eClickBehaviorMode CInputManager::getClickMode() { + return m_ecbClickBehavior; +} + +void CInputManager::setClickMode(eClickBehaviorMode mode) { + switch (mode) { + case CLICKMODE_DEFAULT: + Debug::log(LOG, "SetClickMode: DEFAULT"); + m_ecbClickBehavior = CLICKMODE_DEFAULT; + wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor); + break; + + case CLICKMODE_KILL: + Debug::log(LOG, "SetClickMode: KILL"); + m_ecbClickBehavior = CLICKMODE_KILL; + + // remove constraints + g_pCompositor->m_sSeat.mouse->constraintActive = false; + refocus(); + + // set cursor + wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "crosshair", g_pCompositor->m_sWLRCursor); + break; + default: + break; + } +} + +void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { const auto PKEYBOARD = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); - if (!PKEYBOARD) { // ??? - Debug::log(ERR, "No active keyboard in onMouseButton??"); + if (!PKEYBOARD) { // ??? + Debug::log(ERR, "No active keyboard in processMouseDownNormal??"); return; } @@ -242,7 +305,7 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) { currentlyDraggedWindow = nullptr; dragButton = -1; } - + break; } @@ -250,7 +313,30 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) { if (g_pCompositor->doesSeatAcceptInput(g_pCompositor->m_pLastFocus)) { wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, e->time_msec, e->button, e->state); } - +} + +void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { + switch (e->state) { + case WLR_BUTTON_PRESSED: { + const auto PWINDOW = g_pCompositor->m_pLastWindow; + + if (!g_pCompositor->windowValidMapped(PWINDOW)){ + Debug::log(ERR, "Cannot kill invalid window!"); + break; + } + + // kill the mf + kill(PWINDOW->getPID(), SIGKILL); + break; + } + case WLR_BUTTON_RELEASED: + break; + default: + break; + } + + // reset click behavior mode + m_ecbClickBehavior = CLICKMODE_DEFAULT; } Vector2D CInputManager::getMouseCoordsInternal() { diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 73c59b8f..5089e5e1 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -6,6 +6,11 @@ #include "../../Window.hpp" #include "../../helpers/Timer.hpp" +enum eClickBehaviorMode { + CLICKMODE_DEFAULT = 0, + CLICKMODE_KILL +}; + class CInputManager { public: @@ -31,6 +36,10 @@ public: void updateDragIcon(); void updateCapabilities(wlr_input_device*); + void setClickMode(eClickBehaviorMode); + eClickBehaviorMode getClickMode(); + void processMouseRequest(wlr_seat_pointer_request_set_cursor_event*); + // for dragging floating windows CWindow* currentlyDraggedWindow = nullptr; @@ -57,6 +66,12 @@ public: private: + // for click behavior override + eClickBehaviorMode m_ecbClickBehavior = CLICKMODE_DEFAULT; + + void processMouseDownNormal(wlr_pointer_button_event* e); + void processMouseDownKill(wlr_pointer_button_event* e); + uint32_t m_uiCapabilities = 0; void mouseMoveUnified(uint32_t, bool refocus = false); |
