expo: add option for gesture fingers (#174)

This commit is contained in:
Leonel Cortés 2024-05-30 14:58:40 -03:00 committed by GitHub
parent 22e1e1e5b4
commit 83cbe9af3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 39 deletions

View File

@ -15,7 +15,8 @@ plugin {
bg_col = rgb(111111)
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_positive = true # positive = swipe down. Negative = swipe up.
}

View File

@ -14,15 +14,9 @@
inline CFunctionHook* g_pRenderWorkspaceHook = nullptr;
inline CFunctionHook* g_pAddDamageHookA = nullptr;
inline CFunctionHook* g_pAddDamageHookB = nullptr;
inline CFunctionHook* g_pSwipeBeginHook = nullptr;
inline CFunctionHook* g_pSwipeEndHook = nullptr;
inline CFunctionHook* g_pSwipeUpdateHook = nullptr;
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*);
typedef void (*origRenderWorkspace)(void*, CMonitor*, PHLWORKSPACE, timespec*, const CBox&);
typedef void (*origAddDamageA)(void*, const CBox*);
typedef void (*origAddDamageB)(void*, const pixman_region32_t*);
// Do NOT change this function.
APICALL EXPORT std::string PLUGIN_API_VERSION() {
@ -61,43 +55,52 @@ static void hkAddDamageB(void* thisptr, const pixman_region32_t* rg) {
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 auto* const* PENABLE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:enable_gesture")->getDataStaticPtr();
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 swipeBegin(void* self, SCallbackInfo& info, std::any param) {
swipeActive = false;
swipeDirection = 0;
}
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;
static auto* const* PPOSITIVE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprexpo:gesture_positive")->getDataStaticPtr();
info.cancelled = true;
auto e = std::any_cast<IPointer::SSwipeUpdateEvent>(param);
if (!swipeActive) {
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;
if (gestured <= 0.01) // plugin will crash if swipe ends at <= 0
gestured = 0.01;
g_pOverview->onSwipeUpdate(gestured);
}
@ -105,6 +108,7 @@ static void swipeEnd(void* self, SCallbackInfo& info, std::any param) {
if (!g_pOverview)
return;
swipeActive = false;
info.cancelled = true;
g_pOverview->onSwipeEnd();
@ -112,6 +116,8 @@ static void swipeEnd(void* self, SCallbackInfo& info, std::any param) {
static void onExpoDispatcher(std::string arg) {
if (swipeActive)
return;
if (arg == "toggle") {
if (g_pOverview)
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:gesture_distance", Hyprlang::INT{200});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_positive", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprexpo:gesture_fingers", Hyprlang::INT{4});
HyprlandAPI::reloadConfig();

View File

@ -439,10 +439,17 @@ void COverview::onSwipeUpdate(double delta) {
}
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;
pos = {0, 0};
size.setCallbackOnEnd([this](void*) { redrawAll(true); });
swipeWasCommenced = true;
}
}