1 /* 2 * Copyright 2008-2011, Clemens Zeidler <haiku@clemens-zeidler.de> 3 * Copyright 2022, Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef MOVEMENT_MAKER_H 7 #define MOVEMENT_MAKER_H 8 9 #include <OS.h> 10 11 #include <keyboard_mouse_driver.h> 12 #include <touchpad_settings.h> 13 14 15 class MovementMaker { 16 public: 17 void SetSpecs(const touchpad_specs& specs); 18 void SetSettings(const touchpad_settings& settings); 19 20 float xDelta; 21 float yDelta; 22 23 float scrolling_x; 24 float scrolling_y; 25 26 protected: 27 void StartNewMovment(); 28 void GetMovement(uint32 posX, uint32 posY); 29 void GetScrolling(uint32 posX, uint32 posY); 30 31 touchpad_specs fSpecs; 32 touchpad_settings fSettings; 33 34 int8 fSpeed; 35 int16 fAreaWidth; 36 int16 fAreaHeight; 37 38 private: 39 void _GetRawMovement(uint32 posX, uint32 posY); 40 void _ComputeAcceleration(int8 accel_factor); 41 42 43 bool fMovementMakerStarted; 44 45 uint32 fPreviousX; 46 uint32 fPreviousY; 47 float fDeltaSumX; 48 float fDeltaSumY; 49 50 int8 fSmallMovement; 51 }; 52 53 54 enum button_ids 55 { 56 kNoButton = 0x00, 57 kLeftButton = 0x01, 58 kRightButton = 0x02, 59 kMiddleButton = 0x04 60 }; 61 62 63 class TouchpadMovement : public MovementMaker { 64 public: 65 TouchpadMovement(); 66 67 status_t EventToMovement(const touchpad_movement *event, 68 mouse_movement *movement, bigtime_t &repeatTimeout); 69 70 bigtime_t click_speed; 71 private: 72 void _UpdateButtons(mouse_movement *movement); 73 bool _EdgeMotion(const touchpad_movement *event, 74 mouse_movement *movement, bool validStart); 75 inline void _NoTouchToMovement(const touchpad_movement *event, 76 mouse_movement *movement); 77 inline void _MoveToMovement(const touchpad_movement *event, 78 mouse_movement *movement); 79 inline bool _CheckScrollingToMovement(const touchpad_movement *event, 80 mouse_movement *movement); 81 82 83 bool fMovementStarted; 84 bool fScrollingStarted; 85 bool fTapStarted; 86 bigtime_t fTapTime; 87 int32 fTapDeltaX; 88 int32 fTapDeltaY; 89 int32 fTapClicks; 90 bool fTapdragStarted; 91 92 bool fValidEdgeMotion; 93 bigtime_t fLastEdgeMotion; 94 float fRestEdgeMotion; 95 96 bool fDoubleClick; 97 98 bigtime_t fClickLastTime; 99 int32 fClickCount; 100 uint32 fButtonsState; 101 }; 102 103 104 #endif 105