forked from Plippo/twofing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easing.c
130 lines (112 loc) · 3.47 KB
/
easing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Copyright (C) 2010, 2011 Philipp Merkel <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <math.h>
#include <X11/Xlib.h>
#include "twofingemu.h"
#include "easing.h"
#include "gestures.h"
#include <unistd.h>
/* Variables for easing: */
/* 1 if there is currently easing going on */
int easingActive = 0;
/* Start Interval between two easing steps */
int easingInterval = 0;
/* 1 if easing shall move to the right, -1 if it shall move to the left. */
int easingDirectionX = 0;
/* 1 if easing shall move down, -1 if it shall move up. */
int easingDirectionY = 0;
/* The profile for the easing */
Profile* easingProfile;
TimeVal easingStepTimeVal;
TimeVal nonEasingTimeVal = { 5, 0 };
/* Starts the easing; profile, interval and directions have to be set before. */
void startEasing(Profile * profile, int directionX, int directionY, int interval) {
easingDirectionX = directionX;
easingDirectionY = directionY;
easingProfile = profile;
easingInterval = interval;
easingStepTimeVal.tv_sec = interval / 1000;
easingStepTimeVal.tv_usec = (interval % 1000) * 1000;
easingActive = 1;
}
/* Stops the easing. */
void stopEasing() {
if(easingActive) {
easingActive = 0;
}
}
void checkEasingStep()
{
if(easingActive && easingStepTimeVal.tv_sec <= 0 && easingStepTimeVal.tv_usec <= 0)
{
if(inDebugMode()) printf("Easing step\n");
if (easingProfile->scrollInherit) {
if(easingDirectionY == -1) {
executeAction(&(getDefaultProfile()->scrollUpAction),
EXECUTEACTION_BOTH);
}
if(easingDirectionY == 1) {
executeAction(&(getDefaultProfile()->scrollDownAction),
EXECUTEACTION_BOTH);
}
if(easingDirectionX == -1) {
executeAction(&(getDefaultProfile()->scrollLeftAction),
EXECUTEACTION_BOTH);
}
if(easingDirectionX == 1) {
executeAction(&(getDefaultProfile()->scrollRightAction),
EXECUTEACTION_BOTH);
}
} else {
if(easingDirectionY == -1) {
executeAction(&(easingProfile->scrollUpAction),
EXECUTEACTION_BOTH);
}
if(easingDirectionY == 1) {
executeAction(&(easingProfile->scrollDownAction),
EXECUTEACTION_BOTH);
}
if(easingDirectionX == -1) {
executeAction(&(easingProfile->scrollLeftAction),
EXECUTEACTION_BOTH);
}
if(easingDirectionX == 1) {
executeAction(&(easingProfile->scrollRightAction),
EXECUTEACTION_BOTH);
}
}
easingInterval = (int) (((float) easingInterval) * 1.15);
easingStepTimeVal.tv_sec = easingInterval / 1000;
easingStepTimeVal.tv_usec = (easingInterval % 1000) * 1000;
if(easingInterval > MAX_EASING_INTERVAL) {
easingActive = 0;
}
}
}
TimeVal* getEasingStepTimeVal()
{
if(easingActive) {
return &easingStepTimeVal;
} else {
return &nonEasingTimeVal;
}
}
int isEasingActive()
{
return easingActive;
}