vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / bus_managers / ps2 / movement_maker.h
blob5375f78dd984889154c4df65d7f33d4ea6b94e3f
1 #ifndef MOVEMENT_MAKER_H
2 #define MOVEMENT_MAKER_H
4 #include <OS.h>
6 #include <keyboard_mouse_driver.h>
7 #include <touchpad_settings.h>
10 float floorf(float x);
11 float ceilf(float x);
12 float sqrtf(float x);
15 struct touch_event {
16 uint8 buttons;
17 uint32 xPosition;
18 uint32 yPosition;
19 uint8 zPressure;
20 // absolut mode (unused)
21 bool finger;
22 bool gesture;
23 // absolut w mode
24 uint8 wValue;
28 struct hardware_specs {
29 uint16 edgeMotionWidth;
31 uint16 areaStartX;
32 uint16 areaEndX;
33 uint16 areaStartY;
34 uint16 areaEndY;
36 uint16 minPressure;
37 // the value you reach when you hammer really hard on the touchpad
38 uint16 realMaxPressure;
39 uint16 maxPressure;
43 /*! The raw movement calculation is calibrated on ths synaptics touchpad. */
44 // increase the touchpad size a little bit
45 #define SYN_AREA_TOP_LEFT_OFFSET 40
46 #define SYN_AREA_BOTTOM_RIGHT_OFFSET 60
47 #define SYN_AREA_START_X (1472 - SYN_AREA_TOP_LEFT_OFFSET)
48 #define SYN_AREA_END_X (5472 + SYN_AREA_BOTTOM_RIGHT_OFFSET)
49 #define SYN_WIDTH (SYN_AREA_END_X - SYN_AREA_START_X)
50 #define SYN_AREA_START_Y (1408 - SYN_AREA_TOP_LEFT_OFFSET)
51 #define SYN_AREA_END_Y (4448 + SYN_AREA_BOTTOM_RIGHT_OFFSET)
52 #define SYN_HEIGHT (SYN_AREA_END_Y - SYN_AREA_START_Y)
55 class MovementMaker {
56 public:
57 void SetSettings(touchpad_settings* settings);
58 void SetSpecs(hardware_specs* specs);
60 float xDelta;
61 float yDelta;
63 float scrolling_x;
64 float scrolling_y;
66 protected:
67 void StartNewMovment();
68 void GetMovement(uint32 posX, uint32 posY);
69 void GetScrolling(uint32 posX, uint32 posY);
71 touchpad_settings* fSettings;
72 hardware_specs* fSpecs;
74 int8 fSpeed;
75 int16 fAreaWidth;
76 int16 fAreaHeight;
78 private:
79 void _GetRawMovement(uint32 posX, uint32 posY);
80 void _ComputeAcceleration(int8 accel_factor);
83 bool fMovementMakerStarted;
85 uint32 fPreviousX;
86 uint32 fPreviousY;
87 float fDeltaSumX;
88 float fDeltaSumY;
90 int8 fSmallMovement;
94 enum button_ids
96 kNoButton = 0x00,
97 kLeftButton = 0x01,
98 kRightButton = 0x02,
99 kMiddleButton = 0x04
103 class TouchpadMovement : public MovementMaker {
104 public:
105 void Init();
107 status_t EventToMovement(touch_event *event,
108 mouse_movement *movement);
110 bool TapDragStarted() { return fTapdragStarted; }
111 bool WasEdgeMotion() { return fValidEdgeMotion; }
113 void UpdateButtons(mouse_movement *movement);
115 bigtime_t click_speed;
116 private:
117 bool _EdgeMotion(mouse_movement *movement,
118 touch_event *event, bool validStart);
119 inline void _NoTouchToMovement(touch_event *event,
120 mouse_movement *movement);
121 inline void _MoveToMovement(touch_event *event,
122 mouse_movement *movement);
123 inline bool _CheckScrollingToMovement(touch_event *event,
124 mouse_movement *movement);
126 bool fMovementStarted;
127 bool fScrollingStarted;
128 bool fTapStarted;
129 bigtime_t fTapTime;
130 int32 fTapDeltaX;
131 int32 fTapDeltaY;
132 int32 fTapClicks;
133 bool fTapdragStarted;
135 bool fValidEdgeMotion;
136 bigtime_t fLastEdgeMotion;
137 float fRestEdgeMotion;
139 bool fDoubleClick;
141 bigtime_t fClickLastTime;
142 int32 fClickCount;
143 uint32 fButtonsState;
147 #endif