Skip to content

Commit

Permalink
gestures: add gesture_workspace_switch_*
Browse files Browse the repository at this point in the history
  • Loading branch information
dawsers committed Dec 20, 2024
1 parent b782168 commit af08f46
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ The default for scrolling is swiping with three fingers to scroll left, right,
up or down. Four fingers up enables the *overview* mode, down disables it.
To change workspace, swipe right or left, also with four fingers.

You can enable/disable any of the three gestures. But if you want to have the
three enabled, note that scrolling needs the two axes, horizontal and
vertical, while overview only uses the vertical, and workspace switching the
horizontal axis. That means, you will want to share `_fingers` (see
**Options**) for overview and workspace switching, while leaving scrolling on
its own `_fingers` value. The default accounts for that, so leave it as it is
unless your touchpad supports gestures with more fingers and you want to use
that.

*hyprscroller* touchpad gestures respect the global option
`input:touchpad:natural_scroll` and provide several others specific to the
plugin to tweak gestures behavior. You can find them in the **Options** section
Expand Down Expand Up @@ -818,20 +827,48 @@ scrolling will be to swipes.
### `gesture_overview_enable`

`true` (default) or `false`. Enables or disables touchpad gestures to call
*overview* mode and workspace switching.
*overview* mode.

### `gesture_overview_fingers`

Integer value, default is `4`. Number of fingers used to swipe for overview
or changing workspace.
Integer value, default is `4`. Number of fingers used to swipe for overview.

If you want to use gestures for both overview and workspace switch, you should
set the same `_fingers` value for both. *overview* will use the vertical axis
and workspace switch the horizontal one. If you set a different number of
fingers for each, make sure your touchpad accepts gestures with that number
of fingers.

### `gesture_overview_distance`

Integer value, default is `5`. Delta generated by swiping to call *overview*
mode or change workspace. It is like a sensitivity value; the smaller, the
mode. It is like a sensitivity value; the smaller, the
easier it will be to trigger the command. Each swipe triggers it only once,
regardless of the length or the swipe.

### `gesture_workspace_switch_enable`

`true` (default) or `false`. Enables or disables touchpad gestures for
workspace switching.

### `gesture_workspace_switch_fingers`

Integer value, default is `4`. Number of fingers used to swipe for a workspace
change.

If you want to use gestures for both overview and workspace switch, you should
set the same `_fingers` value for both. *overview* will use the vertical axis
and workspace switch the horizontal one. If you set a different number of
fingers for each, make sure your touchpad accepts gestures with that number
of fingers.

### `gesture_workspace_switch_distance`

Integer value, default is `5`. Delta generated by swiping to change workspace.
It is like a sensitivity value; the smaller, the easier it will be to trigger
the command. Each swipe triggers it only once, regardless of the length or the
swipe.

### `gesture_workspace_switch_prefix`

String value (one character). The default is "". It is the prefix used when
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_scroll_enable", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_scroll_distance", Hyprlang::INT{60});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_scroll_fingers", Hyprlang::INT{3});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_enable", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_distance", Hyprlang::INT{5});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_fingers", Hyprlang::INT{4});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_prefix", Hyprlang::STRING{""});

HyprlandAPI::addConfigValue(PHANDLE, "plugin:scroller:col.selection_border", Hyprlang::INT{0xff9e1515});
Expand Down
50 changes: 31 additions & 19 deletions src/scroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ void ScrollerLayout::swipe_update(SCallbackInfo &info, IPointer::SSwipeUpdateEve
static auto *const *OENABLE = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_overview_enable")->getDataStaticPtr();
static auto *const *OFINGERS = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_overview_fingers")->getDataStaticPtr();
static auto *const *ODISTANCE = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_overview_distance")->getDataStaticPtr();
static auto *const *WENABLE = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_enable")->getDataStaticPtr();
static auto *const *WFINGERS = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_fingers")->getDataStaticPtr();
static auto *const *WDISTANCE = (Hyprlang::INT *const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_distance")->getDataStaticPtr();
static auto const *WPREFIX = (Hyprlang::STRING const *)HyprlandAPI::getConfigValue(PHANDLE, "plugin:scroller:gesture_workspace_switch_prefix")->getDataStaticPtr();

if (**HS &&
Expand All @@ -1321,7 +1324,8 @@ void ScrollerLayout::swipe_update(SCallbackInfo &info, IPointer::SSwipeUpdateEve
}

if (!(**SENABLE && swipe_event.fingers == **SFINGERS) &&
!(**OENABLE && swipe_event.fingers == **OFINGERS)) {
!(**OENABLE && swipe_event.fingers == **OFINGERS) &&
!(**WENABLE && swipe_event.fingers == **WFINGERS)) {
return;
}

Expand Down Expand Up @@ -1368,30 +1372,38 @@ void ScrollerLayout::swipe_update(SCallbackInfo &info, IPointer::SSwipeUpdateEve
}
}
s->recalculate_row_geometry();
} else if (**OENABLE && swipe_event.fingers == **OFINGERS) {
// Only accept the first update: one swipe, one trigger.
if (swipe_active)
return;
} else {
// Undo natural
const Vector2D delta = gesture_delta * (**NATURAL ? -1.0 : 1.0);
if (delta.y <= -**ODISTANCE) {
if (s == nullptr)
if (**OENABLE && swipe_event.fingers == **OFINGERS) {
// Only accept the first update: one swipe, one trigger.
if (swipe_active)
return;
if (!s->is_overview()) {
s->toggle_overview();
if (delta.y <= -**ODISTANCE) {
if (s == nullptr)
return;
if (!s->is_overview()) {
s->toggle_overview();
}
} else if (delta.y >= **ODISTANCE) {
if (s == nullptr)
return;
if (s->is_overview()) {
s->toggle_overview();
}
}
} else if (delta.y >= **ODISTANCE) {
if (s == nullptr)
}
if (**WENABLE && swipe_event.fingers == **WFINGERS) {
// Only accept the first update: one swipe, one trigger.
if (swipe_active)
return;
if (s->is_overview()) {
s->toggle_overview();
if (delta.x <= -**WDISTANCE) {
std::string offset(*WPREFIX);
g_pKeybindManager->m_mDispatchers["workspace"](**HSINVERT ? offset + "+1" : offset + "-1");
} else if (delta.x >= **WDISTANCE) {
std::string offset(*WPREFIX);
g_pKeybindManager->m_mDispatchers["workspace"](**HSINVERT ? offset + "-1" : offset + "+1");
}
} else if (delta.x <= -**ODISTANCE) {
std::string offset(*WPREFIX);
g_pKeybindManager->m_mDispatchers["workspace"](**HSINVERT ? offset + "+1" : offset + "-1");
} else if (delta.x >= **ODISTANCE) {
std::string offset(*WPREFIX);
g_pKeybindManager->m_mDispatchers["workspace"](**HSINVERT ? offset + "-1" : offset + "+1");
}
}
swipe_active = true;
Expand Down

0 comments on commit af08f46

Please sign in to comment.