summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-10-11 14:04:52 -0500
committerDudemanguy <random342@airmail.cc>2023-10-16 15:38:59 +0000
commit0fd8f0b3c10f20c8026d3ade5d2b075fa67ef90c (patch)
treedbfe43b35bbba29f7ea6463e8bd3b15c0eb5a793
parent635674a4a0844191f7f2142dd3d07b3edffca9d5 (diff)
downloadmpv-0fd8f0b3c10f20c8026d3ade5d2b075fa67ef90c.tar.bz2
mpv-0fd8f0b3c10f20c8026d3ade5d2b075fa67ef90c.tar.xz
input: convert autorepeat timing to nanoseconds
-rw-r--r--input/input.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/input/input.c b/input/input.c
index 32803f653e..9d50abb50d 100644
--- a/input/input.c
+++ b/input/input.c
@@ -590,7 +590,7 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale,
ictx->current_down_cmd = mp_cmd_clone(cmd);
}
ictx->last_key_down = code;
- ictx->last_key_down_time = mp_time_us();
+ ictx->last_key_down_time = mp_time_ns();
ictx->ar_state = 0;
mp_input_wakeup(ictx); // possibly start timer for autorepeat
} else if (state == MP_KEY_STATE_UP) {
@@ -915,19 +915,19 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx)
ictx->ar_state = -1; // disable
if (ictx->ar_state >= 0) {
- int64_t t = mp_time_us();
- if (ictx->last_ar + 2000000 < t)
+ int64_t t = mp_time_ns();
+ if (ictx->last_ar + MP_TIME_S_TO_NS(2) < t)
ictx->last_ar = t;
// First time : wait delay
if (ictx->ar_state == 0
- && (t - ictx->last_key_down_time) >= opts->ar_delay * 1000)
+ && (t - ictx->last_key_down_time) >= MP_TIME_MS_TO_NS(opts->ar_delay))
{
ictx->ar_state = 1;
- ictx->last_ar = ictx->last_key_down_time + opts->ar_delay * 1000;
+ ictx->last_ar = ictx->last_key_down_time + MP_TIME_MS_TO_NS(opts->ar_delay);
// Then send rate / sec event
} else if (ictx->ar_state == 1
- && (t - ictx->last_ar) >= 1000000 / opts->ar_rate) {
- ictx->last_ar += 1000000 / opts->ar_rate;
+ && (t - ictx->last_ar) >= 1e9 / opts->ar_rate) {
+ ictx->last_ar += 1e9 / opts->ar_rate;
} else {
return NULL;
}