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