From 7e4a25cb260df0834c8bd5ed96c74ddcfe819411 Mon Sep 17 00:00:00 2001 From: deezhizyu Date: Thu, 8 May 2025 11:14:47 +0200 Subject: [PATCH] Implement super + click dragging --- README.md | 6 ++---- src/Globals.hpp | 2 ++ src/Input.cpp | 41 ++++++++++++++++++++++++++++++++--------- src/main.cpp | 10 +++++----- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 146d6e7..069fc8d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ https://github.com/KZDKM/Hyprspace/assets/41317840/ed1a585a-30d5-4a79-a6da-8cc07 - [x] Autodrag windows - [x] Autoscroll workspaces - [x] Responsive workspace switching - - [x] Responsive exiting + - [x] Responsive exiting - [x] Exit on click / switch - [x] Exit with escape key - [x] Blacklisting workspaces @@ -151,7 +151,7 @@ Refer to the [Hyprland wiki](https://wiki.hyprland.org/Nix/Hyprland-on-Home-Mana - Use `plugin:overview:overrideAnimSpeed` to override the animation speed ### Behaviors -- `plugin:overview:autoDrag` mouse click always drags window when overview is open +- `plugin:overview:autoDrag` mouse click always drags window when overview is open; otherwise, it requires holding Super + mouse click - `plugin:overview:autoScroll` mouse scroll on active workspace area always switch workspace - `plugin:overview:exitOnClick` mouse click without dragging exits overview - `plugin:overview:switchOnDrop` switch to the workspace when a window is droppped into it @@ -166,5 +166,3 @@ Refer to the [Hyprland wiki](https://wiki.hyprland.org/Nix/Hyprland-on-Home-Mana - `gestures:workspace_swipe_fingers` - `gestures:workspace_swipe_cancel_ratio` - `gestures:workspace_swipe_min_speed_to_force` - - diff --git a/src/Globals.hpp b/src/Globals.hpp index e1c956d..c4c71a4 100644 --- a/src/Globals.hpp +++ b/src/Globals.hpp @@ -4,8 +4,10 @@ #include #include #include +#include #include #include +#include #include inline HANDLE pHandle = NULL; diff --git a/src/Input.cpp b/src/Input.cpp index af3fcf1..c433b05 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -34,17 +34,40 @@ bool CHyprspaceWidget::buttonEvent(bool pressed, Vector2D coords) { } // if the cursor is hovering over workspace, clicking should switch workspace instead of starting window drag - if (Config::autoDrag && (targetWorkspace == nullptr || !pressed)) { - // when overview is active, always drag windows on mouse click - if (const auto curWindow = g_pInputManager->currentlyDraggedWindow.lock()) { - g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); - g_pInputManager->currentlyDraggedWindow.reset(); - g_pInputManager->dragMode = MBIND_INVALID; + if (targetWorkspace == nullptr || !pressed) { + bool canDrag = Config::autoDrag; + + // if auto drag is disabled, check if super is pressed + if (!canDrag) { + uint32_t currentModifiers = 0; + + if (g_pInputManager && g_pSeatManager->keyboard) { + currentModifiers = g_pSeatManager->keyboard->modifiersState.depressed; + } + + const uint32_t HYPRLAND_SUPER_MOD = HL_MODIFIER_META; + const uint32_t HYPRLAND_OTHER_SIGNIFICANT_MODS = HL_MODIFIER_SHIFT | HL_MODIFIER_CTRL | HL_MODIFIER_ALT; + + bool isOnlySuperPressed = (currentModifiers & HYPRLAND_SUPER_MOD) && + !(currentModifiers & HYPRLAND_OTHER_SIGNIFICANT_MODS); + + canDrag = isOnlySuperPressed; } - std::string keybind = (pressed ? "1" : "0") + std::string("movewindow"); - (*(tMouseKeybind)pMouseKeybind)(keybind); + + if (canDrag) { + // when overview is active, always drag windows on mouse click/super + mouse click + if (const auto curWindow = g_pInputManager->currentlyDraggedWindow.lock()) { + g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); + g_pInputManager->currentlyDraggedWindow.reset(); + g_pInputManager->dragMode = MBIND_INVALID; + } + + std::string keybind = (pressed ? "1" : "0") + std::string("movewindow"); + (*(tMouseKeybind)pMouseKeybind)(keybind); + } + + Return = false; } - Return = false; // release window on workspace to drop it in if (targetWindow && targetWorkspace != nullptr && !pressed) { diff --git a/src/main.cpp b/src/main.cpp index 1e95560..1b64d09 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,7 @@ bool Config::overrideGaps = true; int Config::gapsIn = 20; int Config::gapsOut = 60; -bool Config::autoDrag = true; +bool Config::autoDrag = false; bool Config::autoScroll = true; bool Config::exitOnClick = true; bool Config::switchOnDrop = false; @@ -259,11 +259,11 @@ void onKeyPress(void* thisptr, SCallbackInfo& info, std::any args) { // Get configured exit key (default to ESC if not configured) const auto exitKey = std::any_cast(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:exitKey")->getValue()); - + // If exit key is 0, disable keyboard exit if (exitKey == 0) return; - + if (e.keycode == exitKey) { // close all panels bool overviewActive = false; @@ -425,7 +425,7 @@ void reloadConfig() { Config::disableBlur = std::any_cast(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:disableBlur")->getValue()); Config::overrideAnimSpeed = std::any_cast(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:overrideAnimSpeed")->getValue()); - + // We don't need to store exitKey in Config namespace as it's only used in onKeyPress for (auto& widget : g_overviewWidgets) { @@ -486,7 +486,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE inHandle) { HyprlandAPI::addConfigValue(pHandle, "plugin:overview:gapsIn", Hyprlang::INT{20}); HyprlandAPI::addConfigValue(pHandle, "plugin:overview:gapsOut", Hyprlang::INT{60}); - HyprlandAPI::addConfigValue(pHandle, "plugin:overview:autoDrag", Hyprlang::INT{1}); + HyprlandAPI::addConfigValue(pHandle, "plugin:overview:autoDrag", Hyprlang::INT{0}); HyprlandAPI::addConfigValue(pHandle, "plugin:overview:autoScroll", Hyprlang::INT{1}); HyprlandAPI::addConfigValue(pHandle, "plugin:overview:exitOnClick", Hyprlang::INT{1}); HyprlandAPI::addConfigValue(pHandle, "plugin:overview:switchOnDrop", Hyprlang::INT{0});