diff options
Diffstat (limited to 'input')
-rw-r--r-- | input/input.c | 72 | ||||
-rw-r--r-- | input/input.h | 2 | ||||
-rw-r--r-- | input/keycodes.c | 9 | ||||
-rw-r--r-- | input/keycodes.h | 77 |
4 files changed, 74 insertions, 86 deletions
diff --git a/input/input.c b/input/input.c index 88527b5974..b3f3d8d93e 100644 --- a/input/input.c +++ b/input/input.c @@ -95,7 +95,7 @@ struct cmd_queue { struct mp_cmd *first; }; -struct axis_state { +struct wheel_state { double dead_zone_accum; double unit_accum; }; @@ -135,11 +135,11 @@ struct input_ctx { bool mouse_mangle, mouse_src_mangle; struct mp_rect mouse_src, mouse_dst; - // Axis state (MP_AXIS_*) - struct axis_state axis_state_y; // MP_AXIS_UP/MP_AXIS_DOWN - struct axis_state axis_state_x; // MP_AXIS_LEFT/MP_AXIS_RIGHT - struct axis_state *axis_current; // Points to axis currently being scrolled - double last_axis_time; // mp_time_sec() of the last axis event + // Wheel state (MP_WHEEL_*) + struct wheel_state wheel_state_y; // MP_WHEEL_UP/MP_WHEEL_DOWN + struct wheel_state wheel_state_x; // MP_WHEEL_LEFT/MP_WHEEL_RIGHT + struct wheel_state *wheel_current; // The direction currently being scrolled + double last_wheel_time; // mp_time_sec() of the last wheel event // List of command binding sections struct cmd_bind_section *cmd_bind_sections; @@ -634,10 +634,10 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale, } } -// Pre-processing for MP_AXIS_* events. If this returns false, the caller +// Pre-processing for MP_WHEEL_* events. If this returns false, the caller // should discard the event. -static bool process_axis(struct input_ctx *ictx, int code, double *scale, - int *scale_units) +static bool process_wheel(struct input_ctx *ictx, int code, double *scale, + int *scale_units) { // Size of the deadzone in scroll units. The user must scroll at least this // much in any direction before their scroll is registered. @@ -650,45 +650,45 @@ static bool process_axis(struct input_ctx *ictx, int code, double *scale, // sent when the user scrolls slowly. static const double UNIT_SCROLL_TIME = 0.5; - // Determine which axis is being scrolled + // Determine which direction is being scrolled double dir; - struct axis_state *state; + struct wheel_state *state; switch (code) { - case MP_AXIS_UP: dir = -1; state = &ictx->axis_state_y; break; - case MP_AXIS_DOWN: dir = +1; state = &ictx->axis_state_y; break; - case MP_AXIS_LEFT: dir = -1; state = &ictx->axis_state_x; break; - case MP_AXIS_RIGHT: dir = +1; state = &ictx->axis_state_x; break; + case MP_WHEEL_UP: dir = -1; state = &ictx->wheel_state_y; break; + case MP_WHEEL_DOWN: dir = +1; state = &ictx->wheel_state_y; break; + case MP_WHEEL_LEFT: dir = -1; state = &ictx->wheel_state_x; break; + case MP_WHEEL_RIGHT: dir = +1; state = &ictx->wheel_state_x; break; default: return true; } // Reset accumulators if it's determined that the user finished scrolling double now = mp_time_sec(); - if (now > ictx->last_axis_time + DEADZONE_SCROLL_TIME) { - ictx->axis_current = NULL; - ictx->axis_state_y.dead_zone_accum = 0; - ictx->axis_state_x.dead_zone_accum = 0; + if (now > ictx->last_wheel_time + DEADZONE_SCROLL_TIME) { + ictx->wheel_current = NULL; + ictx->wheel_state_y.dead_zone_accum = 0; + ictx->wheel_state_x.dead_zone_accum = 0; } - if (now > ictx->last_axis_time + UNIT_SCROLL_TIME) { - ictx->axis_state_y.unit_accum = 0; - ictx->axis_state_x.unit_accum = 0; + if (now > ictx->last_wheel_time + UNIT_SCROLL_TIME) { + ictx->wheel_state_y.unit_accum = 0; + ictx->wheel_state_x.unit_accum = 0; } - ictx->last_axis_time = now; - - // Process axis deadzone. A lot of touchpad drivers don't filter scroll - // input, which makes it difficult for the user to send AXIS_UP/DOWN - // without accidentally triggering AXIS_LEFT/RIGHT. We try to fix this by - // implementing a deadzone. When the value of either axis breaks out of the - // deadzone, events from the other axis will be ignored until the user - // finishes scrolling. - if (ictx->axis_current == NULL) { + ictx->last_wheel_time = now; + + // Process wheel deadzone. A lot of touchpad drivers don't filter scroll + // input, which makes it difficult for the user to send WHEEL_UP/DOWN + // without accidentally triggering WHEEL_LEFT/RIGHT. We try to fix this by + // implementing a deadzone. When the value of either direction breaks out + // of the deadzone, events from the other direction will be ignored until + // the user finishes scrolling. + if (ictx->wheel_current == NULL) { state->dead_zone_accum += *scale * dir; if (state->dead_zone_accum * dir > DEADZONE_DIST) { - ictx->axis_current = state; + ictx->wheel_current = state; *scale = state->dead_zone_accum * dir; } } - if (ictx->axis_current != state) + if (ictx->wheel_current != state) return false; // Determine scale_units. This is incremented every time the accumulated @@ -724,7 +724,7 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale, if (!force_mouse && opts->doubleclick_time && MP_KEY_IS_MOUSE_BTN_DBL(unmod)) return; int units = 1; - if (MP_KEY_IS_AXIS(unmod) && !process_axis(ictx, unmod, &scale, &units)) + if (MP_KEY_IS_WHEEL(unmod) && !process_wheel(ictx, unmod, &scale, &units)) return; interpret_key(ictx, code, scale, units); if (code & MP_KEY_STATE_DOWN) { @@ -733,7 +733,7 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale, now - ictx->last_doubleclick_time < opts->doubleclick_time / 1000.0) { if (code >= MP_MBTN_LEFT && code <= MP_MBTN_RIGHT) { - interpret_key(ictx, code - MP_MOUSE_BASE + MP_MOUSE_DBL_BASE, + interpret_key(ictx, code - MP_MBTN_BASE + MP_MBTN_DBL_BASE, 1, 1); } } @@ -766,7 +766,7 @@ void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t) } } -void mp_input_put_axis(struct input_ctx *ictx, int direction, double value) +void mp_input_put_wheel(struct input_ctx *ictx, int direction, double value) { if (value == 0.0) return; diff --git a/input/input.h b/input/input.h index 0ea054d21b..f00eb9b0e2 100644 --- a/input/input.h +++ b/input/input.h @@ -143,7 +143,7 @@ void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t); // Process scrolling input. Support for precise scrolling. Scales the given // scroll amount add multiplies it with the command (seeking, sub-delay, etc) -void mp_input_put_axis(struct input_ctx *ictx, int direction, double value); +void mp_input_put_wheel(struct input_ctx *ictx, int direction, double value); // Update mouse position (in window coordinates). void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y); diff --git a/input/keycodes.c b/input/keycodes.c index 0832616129..81371e20bf 100644 --- a/input/keycodes.c +++ b/input/keycodes.c @@ -117,11 +117,6 @@ static const struct key_name key_names[] = { { MP_AR_VDOWN, "AR_VDOWN" }, { MP_AR_VDOWN_HOLD, "AR_VDOWN_HOLD" }, - { MP_AXIS_UP, "AXIS_UP" }, - { MP_AXIS_DOWN, "AXIS_DOWN" }, - { MP_AXIS_LEFT, "AXIS_LEFT" }, - { MP_AXIS_RIGHT, "AXIS_RIGHT" }, - { MP_KEY_POWER, "POWER" }, { MP_KEY_MENU, "MENU" }, { MP_KEY_PLAY, "PLAY" }, @@ -176,6 +171,10 @@ static const struct key_name key_names[] = { { MP_MBTN_LEFT_DBL, "MOUSE_BTN0_DBL" }, { MP_MBTN_MID_DBL, "MOUSE_BTN1_DBL" }, { MP_MBTN_RIGHT_DBL, "MOUSE_BTN2_DBL" }, + { MP_WHEEL_UP, "AXIS_UP" }, + { MP_WHEEL_DOWN, "AXIS_DOWN" }, + { MP_WHEEL_LEFT, "AXIS_LEFT" }, + { MP_WHEEL_RIGHT, "AXIS_RIGHT" }, { MP_KEY_CLOSE_WIN, "CLOSE_WIN" }, { MP_KEY_MOUSE_MOVE, "MOUSE_MOVE" }, diff --git a/input/keycodes.h b/input/keycodes.h index 65ff99ddb3..e14ad48f80 100644 --- a/input/keycodes.h +++ b/input/keycodes.h @@ -98,40 +98,42 @@ #define MP_KEY_KPENTER (MP_KEY_KEYPAD+13) // Mouse events from VOs -#define MP_MOUSE_BASE ((MP_KEY_BASE+0xA0)|MP_NO_REPEAT_KEY|MP_KEY_EMIT_ON_UP) -#define MP_MBTN_LEFT (MP_MOUSE_BASE+0) -#define MP_MBTN_MID (MP_MOUSE_BASE+1) -#define MP_MBTN_RIGHT (MP_MOUSE_BASE+2) -#define MP_WHEEL_UP (MP_MOUSE_BASE+3) -#define MP_WHEEL_DOWN (MP_MOUSE_BASE+4) -#define MP_WHEEL_LEFT (MP_MOUSE_BASE+5) -#define MP_WHEEL_RIGHT (MP_MOUSE_BASE+6) -#define MP_MBTN_BACK (MP_MOUSE_BASE+7) -#define MP_MBTN_FORWARD (MP_MOUSE_BASE+8) -#define MP_MBTN9 (MP_MOUSE_BASE+9) -#define MP_MBTN10 (MP_MOUSE_BASE+10) -#define MP_MBTN11 (MP_MOUSE_BASE+11) -#define MP_MBTN12 (MP_MOUSE_BASE+12) -#define MP_MBTN13 (MP_MOUSE_BASE+13) -#define MP_MBTN14 (MP_MOUSE_BASE+14) -#define MP_MBTN15 (MP_MOUSE_BASE+15) -#define MP_MBTN16 (MP_MOUSE_BASE+16) -#define MP_MBTN17 (MP_MOUSE_BASE+17) -#define MP_MBTN18 (MP_MOUSE_BASE+18) -#define MP_MBTN19 (MP_MOUSE_BASE+19) -#define MP_MOUSE_END (MP_MOUSE_BASE+20) +#define MP_MBTN_BASE ((MP_KEY_BASE+0xA0)|MP_NO_REPEAT_KEY|MP_KEY_EMIT_ON_UP) +#define MP_MBTN_LEFT (MP_MBTN_BASE+0) +#define MP_MBTN_MID (MP_MBTN_BASE+1) +#define MP_MBTN_RIGHT (MP_MBTN_BASE+2) +#define MP_WHEEL_UP (MP_MBTN_BASE+3) +#define MP_WHEEL_DOWN (MP_MBTN_BASE+4) +#define MP_WHEEL_LEFT (MP_MBTN_BASE+5) +#define MP_WHEEL_RIGHT (MP_MBTN_BASE+6) +#define MP_MBTN_BACK (MP_MBTN_BASE+7) +#define MP_MBTN_FORWARD (MP_MBTN_BASE+8) +#define MP_MBTN9 (MP_MBTN_BASE+9) +#define MP_MBTN10 (MP_MBTN_BASE+10) +#define MP_MBTN11 (MP_MBTN_BASE+11) +#define MP_MBTN12 (MP_MBTN_BASE+12) +#define MP_MBTN13 (MP_MBTN_BASE+13) +#define MP_MBTN14 (MP_MBTN_BASE+14) +#define MP_MBTN15 (MP_MBTN_BASE+15) +#define MP_MBTN16 (MP_MBTN_BASE+16) +#define MP_MBTN17 (MP_MBTN_BASE+17) +#define MP_MBTN18 (MP_MBTN_BASE+18) +#define MP_MBTN19 (MP_MBTN_BASE+19) +#define MP_MBTN_END (MP_MBTN_BASE+20) #define MP_KEY_IS_MOUSE_BTN_SINGLE(code) \ - ((code) >= MP_MOUSE_BASE && (code) < MP_MOUSE_END) + ((code) >= MP_MBTN_BASE && (code) < MP_MBTN_END) +#define MP_KEY_IS_WHEEL(code) \ + ((code) >= MP_WHEEL_UP && (code) < MP_WHEEL_RIGHT) -#define MP_MOUSE_DBL_BASE ((MP_KEY_BASE+0xC0)|MP_NO_REPEAT_KEY) -#define MP_MBTN_LEFT_DBL (MP_MOUSE_DBL_BASE+0) -#define MP_MBTN_MID_DBL (MP_MOUSE_DBL_BASE+1) -#define MP_MBTN_RIGHT_DBL (MP_MOUSE_DBL_BASE+2) -#define MP_MOUSE_DBL_END (MP_MOUSE_DBL_BASE+20) +#define MP_MBTN_DBL_BASE ((MP_KEY_BASE+0xC0)|MP_NO_REPEAT_KEY) +#define MP_MBTN_LEFT_DBL (MP_MBTN_DBL_BASE+0) +#define MP_MBTN_MID_DBL (MP_MBTN_DBL_BASE+1) +#define MP_MBTN_RIGHT_DBL (MP_MBTN_DBL_BASE+2) +#define MP_MBTN_DBL_END (MP_MBTN_DBL_BASE+20) #define MP_KEY_IS_MOUSE_BTN_DBL(code) \ - ((code) >= MP_MOUSE_DBL_BASE && (code) < MP_MOUSE_DBL_END) + ((code) >= MP_MBTN_DBL_BASE && (code) < MP_MBTN_DBL_END) // Apple Remote input module #define MP_AR_BASE (MP_KEY_BASE+0xE0) @@ -150,17 +152,6 @@ #define MP_AR_VDOWN (MP_AR_BASE + 12) #define MP_AR_VDOWN_HOLD (MP_AR_BASE + 13) -// Mouse wheels or touchpad input -#define MP_AXIS_BASE (MP_KEY_BASE+0x100) -#define MP_AXIS_UP (MP_AXIS_BASE+0) -#define MP_AXIS_DOWN (MP_AXIS_BASE+1) -#define MP_AXIS_LEFT (MP_AXIS_BASE+2) -#define MP_AXIS_RIGHT (MP_AXIS_BASE+3) -#define MP_AXIS_END (MP_AXIS_BASE+4) - -#define MP_KEY_IS_AXIS(code) \ - ((code) >= MP_AXIS_BASE && (code) < MP_AXIS_END) - // Reserved area. Can be used for keys that have no explicit names assigned, // but should be mappable by the user anyway. #define MP_KEY_UNKNOWN_RESERVED_START (MP_KEY_BASE+0x10000) @@ -183,12 +174,10 @@ // Whether to dispatch the key binding by current mouse position. #define MP_KEY_DEPENDS_ON_MOUSE_POS(code) \ - (MP_KEY_IS_MOUSE_CLICK(code) || MP_KEY_IS_AXIS(code) || \ - (code) == MP_KEY_MOUSE_MOVE) + (MP_KEY_IS_MOUSE_CLICK(code) || (code) == MP_KEY_MOUSE_MOVE) #define MP_KEY_IS_MOUSE(code) \ - (MP_KEY_IS_MOUSE_CLICK(code) || MP_KEY_IS_AXIS(code) || \ - MP_KEY_IS_MOUSE_MOVE(code)) + (MP_KEY_IS_MOUSE_CLICK(code) || MP_KEY_IS_MOUSE_MOVE(code)) // No input source should generate this. #define MP_KEY_UNMAPPED (MP_KEY_INTERN+4) |