From 8826cd3dbc87f9778ee0f4cdeec6ec17fa76592b Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 14 Sep 2026 10:47:30 +0200 Subject: [PATCH] stats.lua: make ESC also exit oneshot stats If oneshot stats close automatically, don't respond to ESC for 1 second so users don't unintentionally exit fullscreen or whatever they bound to ESC. Fixes https://github.com/mpv-player/mpv/issues/18479 --- DOCS/man/stats.rst | 5 ----- player/lua/stats.lua | 31 +++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index 3d057a453c709..97c5285e43871 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -28,11 +28,6 @@ stats: 4 Active key bindings (scroll) 5 Selected Tracks Info (scroll) 0 Internal stuff (scroll) -==== ================== - -If stats were displayed by toggling, these key bindings are also active: - -==== ================== ESC Close the stats ==== ================== diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 6796515f72717..e0c56dffb4002 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -1630,14 +1630,15 @@ local function unbind_search() end local function bind_exit() - -- Don't bind in oneshot mode because if ESC is pressed right when the stats - -- stop being displayed, it would unintentionally trigger any user-defined - -- ESC binding. - if not display_timer.oneshot then - mp.add_forced_key_binding(o.key_exit, "__forced_" .. o.key_exit, function () + mp.add_forced_key_binding(o.key_exit, "__forced_" .. o.key_exit, function () + if display_timer.oneshot then + display_timer:kill() + clear_screen() + remove_page_bindings() + else process_key_binding(false) - end) - end + end + end) end local function unbind_exit() @@ -1678,13 +1679,23 @@ end -- Remove keybindings for every page -remove_page_bindings = function() +remove_page_bindings = function(delay_unbinding_exit) for k, _ in pairs(pages) do mp.remove_key_binding("__forced_"..k) end unbind_scroll() unbind_search() - unbind_exit() + -- If ESC is pressed right after oneshot stats stop being displayed, don't + -- unintentionally trigger any user-defined ESC binding. + if delay_unbinding_exit then + mp.add_timeout(1, function () + if not display_timer:is_enabled() then + unbind_exit() + end + end) + else + unbind_exit() + end end @@ -1746,7 +1757,7 @@ end display_timer = mp.add_periodic_timer(o.duration, function() if display_timer.oneshot then - display_timer:kill() ; clear_screen() ; remove_page_bindings() + display_timer:kill() ; clear_screen() ; remove_page_bindings(true) -- Close the console only if it was opened for searching bindings. if searched_text then input.terminate()