mirror of
https://github.com/hyprwm/hyprland-plugins.git
synced 2024-11-21 18:25:58 +01:00
expo: add option for gesture fingers (#174)
This commit is contained in:
parent
22e1e1e5b4
commit
83cbe9af3f
3 changed files with 54 additions and 39 deletions
|
@ -15,7 +15,8 @@ plugin {
|
||||||
bg_col = rgb(111111)
|
bg_col = rgb(111111)
|
||||||
workspace_method = center current # [center/first] [workspace] e.g. first 1 or center m+1
|
workspace_method = center current # [center/first] [workspace] e.g. first 1 or center m+1
|
||||||
|
|
||||||
enable_gesture = true # laptop touchpad, 4 fingers
|
enable_gesture = true # laptop touchpad
|
||||||
|
gesture_fingers = 3 # 3 or 4
|
||||||
gesture_distance = 300 # how far is the "max"
|
gesture_distance = 300 # how far is the "max"
|
||||||
gesture_positive = true # positive = swipe down. Negative = swipe up.
|
gesture_positive = true # positive = swipe down. Negative = swipe up.
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,15 +14,9 @@
|
||||||
inline CFunctionHook* g_pRenderWorkspaceHook = nullptr;
|
inline CFunctionHook* g_pRenderWorkspaceHook = nullptr;
|
||||||
inline CFunctionHook* g_pAddDamageHookA = nullptr;
|
inline CFunctionHook* g_pAddDamageHookA = nullptr;
|
||||||
inline CFunctionHook* g_pAddDamageHookB = nullptr;
|
inline CFunctionHook* g_pAddDamageHookB = nullptr;
|
||||||
inline CFunctionHook* g_pSwipeBeginHook = nullptr;
|
typedef void (*origRenderWorkspace)(void*, CMonitor*, PHLWORKSPACE, timespec*, const CBox&);
|
||||||
inline CFunctionHook* g_pSwipeEndHook = nullptr;
|
typedef void (*origAddDamageA)(void*, const CBox*);
|
||||||
inline CFunctionHook* g_pSwipeUpdateHook = nullptr;
|
typedef void (*origAddDamageB)(void*, const pixman_region32_t*);
|
||||||
typedef void (*origRenderWorkspace)(void*, CMonitor*, PHLWORKSPACE, timespec*, const CBox&);
|
|
||||||
typedef void (*origAddDamageA)(void*, const CBox*);
|
|
||||||
typedef void (*origAddDamageB)(void*, const pixman_region32_t*);
|
|
||||||
typedef void (*origSwipeBegin)(void*, wlr_pointer_swipe_begin_event*);
|
|
||||||
typedef void (*origSwipeEnd)(void*, wlr_pointer_swipe_end_event*);
|
|
||||||
typedef void (*origSwipeUpdate)(void*, wlr_pointer_swipe_update_event*);
|
|
||||||
|
|
||||||
// Do NOT change this function.
|
// Do NOT change this function.
|
||||||
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
||||||
|
@ -61,43 +55,52 @@ static void hkAddDamageB(void* thisptr, const pixman_region32_t* rg) {
|
||||||
g_pOverview->onDamageReported();
|
g_pOverview->onDamageReported();
|
||||||
}
|
}
|
||||||
|
|
||||||
static float gestured = 0;
|
static float gestured = 0;
|
||||||
|
bool swipeActive = false;
|
||||||
|
char swipeDirection = 0; // 0 = no direction, 'v' = vertical, 'h' = horizontal
|
||||||
|
|
||||||
//
|
static void swipeBegin(void* self, SCallbackInfo& info, std::any param) {
|
||||||
static void swipeBegin(void* self, SCallbackInfo& info, std::any param) {
|
swipeActive = false;
|
||||||
static auto* const* PENABLE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:enable_gesture")->getDataStaticPtr();
|
swipeDirection = 0;
|
||||||
|
|
||||||
if (g_pOverview) {
|
|
||||||
info.cancelled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto e = std::any_cast<IPointer::SSwipeBeginEvent>(param);
|
|
||||||
|
|
||||||
if (!**PENABLE || e.fingers != 4)
|
|
||||||
return;
|
|
||||||
|
|
||||||
info.cancelled = true;
|
|
||||||
|
|
||||||
renderingOverview = true;
|
|
||||||
g_pOverview = std::make_unique<COverview>(g_pCompositor->m_pLastMonitor->activeWorkspace, true);
|
|
||||||
renderingOverview = false;
|
|
||||||
|
|
||||||
gestured = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swipeUpdate(void* self, SCallbackInfo& info, std::any param) {
|
static void swipeUpdate(void* self, SCallbackInfo& info, std::any param) {
|
||||||
if (!g_pOverview)
|
static auto* const* PENABLE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:enable_gesture")->getDataStaticPtr();
|
||||||
|
static auto* const* FINGERS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gesture_fingers")->getDataStaticPtr();
|
||||||
|
static auto* const* PPOSITIVE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gesture_positive")->getDataStaticPtr();
|
||||||
|
auto e = std::any_cast<IPointer::SSwipeUpdateEvent>(param);
|
||||||
|
|
||||||
|
if (!swipeDirection) {
|
||||||
|
if (std::abs(e.delta.x) > std::abs(e.delta.y))
|
||||||
|
swipeDirection = 'h';
|
||||||
|
else if (std::abs(e.delta.y) > std::abs(e.delta.x))
|
||||||
|
swipeDirection = 'v';
|
||||||
|
else
|
||||||
|
swipeDirection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (swipeActive || g_pOverview)
|
||||||
|
info.cancelled = true;
|
||||||
|
|
||||||
|
if (!**PENABLE || e.fingers != **FINGERS || swipeDirection != 'v')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static auto* const* PPOSITIVE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gesture_positive")->getDataStaticPtr();
|
|
||||||
|
|
||||||
info.cancelled = true;
|
info.cancelled = true;
|
||||||
|
if (!swipeActive) {
|
||||||
auto e = std::any_cast<IPointer::SSwipeUpdateEvent>(param);
|
if (g_pOverview)
|
||||||
|
return;
|
||||||
|
if ((**PPOSITIVE ? 1.0 : -1.0) * e.delta.y <= 0)
|
||||||
|
return;
|
||||||
|
renderingOverview = true;
|
||||||
|
g_pOverview = std::make_unique<COverview>(g_pCompositor->m_pLastMonitor->activeWorkspace, true);
|
||||||
|
renderingOverview = false;
|
||||||
|
gestured = 0;
|
||||||
|
swipeActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
gestured += (**PPOSITIVE ? 1.0 : -1.0) * e.delta.y;
|
gestured += (**PPOSITIVE ? 1.0 : -1.0) * e.delta.y;
|
||||||
|
if (gestured <= 0.01) // plugin will crash if swipe ends at <= 0
|
||||||
|
gestured = 0.01;
|
||||||
g_pOverview->onSwipeUpdate(gestured);
|
g_pOverview->onSwipeUpdate(gestured);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +108,7 @@ static void swipeEnd(void* self, SCallbackInfo& info, std::any param) {
|
||||||
if (!g_pOverview)
|
if (!g_pOverview)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
swipeActive = false;
|
||||||
info.cancelled = true;
|
info.cancelled = true;
|
||||||
|
|
||||||
g_pOverview->onSwipeEnd();
|
g_pOverview->onSwipeEnd();
|
||||||
|
@ -112,6 +116,8 @@ static void swipeEnd(void* self, SCallbackInfo& info, std::any param) {
|
||||||
|
|
||||||
static void onExpoDispatcher(std::string arg) {
|
static void onExpoDispatcher(std::string arg) {
|
||||||
|
|
||||||
|
if (swipeActive)
|
||||||
|
return;
|
||||||
if (arg == "toggle") {
|
if (arg == "toggle") {
|
||||||
if (g_pOverview)
|
if (g_pOverview)
|
||||||
g_pOverview->close();
|
g_pOverview->close();
|
||||||
|
@ -204,6 +210,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:enable_gesture", Hyprlang::INT{1});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:enable_gesture", Hyprlang::INT{1});
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_distance", Hyprlang::INT{200});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_distance", Hyprlang::INT{200});
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_positive", Hyprlang::INT{1});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_positive", Hyprlang::INT{1});
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_fingers", Hyprlang::INT{4});
|
||||||
|
|
||||||
HyprlandAPI::reloadConfig();
|
HyprlandAPI::reloadConfig();
|
||||||
|
|
||||||
|
|
|
@ -439,10 +439,17 @@ void COverview::onSwipeUpdate(double delta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void COverview::onSwipeEnd() {
|
void COverview::onSwipeEnd() {
|
||||||
|
const auto SIZEMIN = pMonitor->vecSize;
|
||||||
|
const auto SIZEMAX = pMonitor->vecSize * pMonitor->vecSize / (pMonitor->vecSize / SIDE_LENGTH);
|
||||||
|
const auto PERC = (size.value() - SIZEMIN).x / (SIZEMAX - SIZEMIN).x;
|
||||||
|
if (PERC > 0.5) {
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
size = pMonitor->vecSize;
|
size = pMonitor->vecSize;
|
||||||
pos = {0, 0};
|
pos = {0, 0};
|
||||||
|
|
||||||
size.setCallbackOnEnd([this](void*) { redrawAll(true); });
|
size.setCallbackOnEnd([this](void*) { redrawAll(true); });
|
||||||
|
|
||||||
swipeWasCommenced = true;
|
swipeWasCommenced = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue