[Core] Mouse key kinetic mode fix (#17176)
Co-authored-by: Drashna Jaelre <drashna@live.com>
This commit is contained in:
		
							parent
							
								
									d6eff188e9
								
							
						
					
					
						commit
						c725b6bf89
					
				
					 3 changed files with 21 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -66,11 +66,18 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
 | 
			
		|||
/* milliseconds between the initial key press and first repeated motion event (0-2550) */
 | 
			
		||||
uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
 | 
			
		||||
/* milliseconds between repeated motion events (0-255) */
 | 
			
		||||
uint8_t mk_wheel_interval    = MOUSEKEY_WHEEL_INTERVAL;
 | 
			
		||||
#    ifdef MK_KINETIC_SPEED
 | 
			
		||||
float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
 | 
			
		||||
#    else
 | 
			
		||||
uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
 | 
			
		||||
#    endif
 | 
			
		||||
uint8_t mk_wheel_max_speed   = MOUSEKEY_WHEEL_MAX_SPEED;
 | 
			
		||||
uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
 | 
			
		||||
 | 
			
		||||
#    ifndef MK_COMBINED
 | 
			
		||||
#        ifndef MK_KINETIC_SPEED
 | 
			
		||||
 | 
			
		||||
/* Default accelerated mode */
 | 
			
		||||
 | 
			
		||||
static uint8_t move_unit(void) {
 | 
			
		||||
    uint16_t unit;
 | 
			
		||||
| 
						 | 
				
			
			@ -108,8 +115,7 @@ static uint8_t wheel_unit(void) {
 | 
			
		|||
    return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#    else /* #ifndef MK_COMBINED */
 | 
			
		||||
#        ifdef MK_KINETIC_SPEED
 | 
			
		||||
#        else /* #ifndef MK_KINETIC_SPEED */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Kinetic movement  acceleration algorithm
 | 
			
		||||
| 
						 | 
				
			
			@ -147,27 +153,27 @@ static uint8_t move_unit(void) {
 | 
			
		|||
    return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
 | 
			
		||||
 | 
			
		||||
static uint8_t wheel_unit(void) {
 | 
			
		||||
    float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
 | 
			
		||||
 | 
			
		||||
    if (mousekey_accel & ((1 << 0) | (1 << 2))) {
 | 
			
		||||
        speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
 | 
			
		||||
    } else if (mousekey_repeat && mouse_timer) {
 | 
			
		||||
    } else if (mousekey_wheel_repeat && mouse_timer) {
 | 
			
		||||
        if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
 | 
			
		||||
            const float time_elapsed = timer_elapsed(mouse_timer) / 50;
 | 
			
		||||
            speed                    = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
 | 
			
		||||
        }
 | 
			
		||||
        speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mk_wheel_interval = 1000.0f / speed;
 | 
			
		||||
 | 
			
		||||
    return 1;
 | 
			
		||||
    return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#        else /* #ifndef MK_KINETIC_SPEED */
 | 
			
		||||
#        endif /* #ifndef MK_KINETIC_SPEED */
 | 
			
		||||
#    else      /* #ifndef MK_COMBINED */
 | 
			
		||||
 | 
			
		||||
/* Combined mode */
 | 
			
		||||
 | 
			
		||||
static uint8_t move_unit(void) {
 | 
			
		||||
    uint16_t unit;
 | 
			
		||||
| 
						 | 
				
			
			@ -205,8 +211,7 @@ static uint8_t wheel_unit(void) {
 | 
			
		|||
    return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#        endif /* #ifndef MK_KINETIC_SPEED */
 | 
			
		||||
#    endif     /* #ifndef MK_COMBINED */
 | 
			
		||||
#    endif /* #ifndef MK_COMBINED */
 | 
			
		||||
 | 
			
		||||
void mousekey_task(void) {
 | 
			
		||||
    // report cursor and scroll movement independently
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,7 +39,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		|||
#        ifndef MK_KINETIC_SPEED
 | 
			
		||||
#            define MOUSEKEY_MOVE_DELTA 8
 | 
			
		||||
#        else
 | 
			
		||||
#            define MOUSEKEY_MOVE_DELTA 5
 | 
			
		||||
#            define MOUSEKEY_MOVE_DELTA 16
 | 
			
		||||
#        endif
 | 
			
		||||
#    endif
 | 
			
		||||
#    ifndef MOUSEKEY_WHEEL_DELTA
 | 
			
		||||
| 
						 | 
				
			
			@ -82,7 +82,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		|||
#        define MOUSEKEY_INITIAL_SPEED 100
 | 
			
		||||
#    endif
 | 
			
		||||
#    ifndef MOUSEKEY_BASE_SPEED
 | 
			
		||||
#        define MOUSEKEY_BASE_SPEED 1000
 | 
			
		||||
#        define MOUSEKEY_BASE_SPEED 5000
 | 
			
		||||
#    endif
 | 
			
		||||
#    ifndef MOUSEKEY_DECELERATED_SPEED
 | 
			
		||||
#        define MOUSEKEY_DECELERATED_SPEED 400
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue