MCPcopy Create free account
hub / github.com/WayfireWM/wayfire / vswipe_process_delta

Function vswipe_process_delta

plugins/single_plugins/vswipe-processing.hpp:4–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <cmath>
3
4static inline double vswipe_process_delta(const double delta,
5 const double accumulated_dx,
6 const int vx, const int vw,
7 const double speed_cap = 0.5,
8 const bool free_movement = false)
9{
10 // The slowdown below must be applied differently for going out of bounds.
11 double sdx_offset = free_movement ?
12 std::copysign(0, accumulated_dx) : accumulated_dx;
13 if (vx - accumulated_dx < 0.0)
14 {
15 sdx_offset = (accumulated_dx - std::floor(accumulated_dx)) + 1.0;
16 }
17
18 if (vx - accumulated_dx > vw - 1.0)
19 {
20 sdx_offset = (accumulated_dx - std::ceil(accumulated_dx)) - 1.0;
21 }
22
23 // To achieve a "rubberband" resistance effect when going too far, ease-in
24 // of the whole swiped distance is used as a slowdown factor for the current
25 // delta.
26 const double ease = 1.0 - std::pow(std::abs(sdx_offset) - 0.025, 4.0);
27
28 // If we're moving further in the limit direction, slow down all the way
29 // to extremely slow, but reversing the direction should be easier.
30 const double slowdown = wf::clamp(ease,
31 std::signbit(delta) == std::signbit(sdx_offset) ? 0.005 : 0.2, 1.0);
32
33 return wf::clamp(delta, -speed_cap, speed_cap) * slowdown;
34}
35
36static inline int vswipe_finish_target(const double accumulated_dx,
37 const int vx, const int vw,

Callers 1

vswipeClass · 0.85

Calls 2

absFunction · 0.85
clampFunction · 0.85

Tested by

no test coverage detected