From bca516bd2c282670aa2c92663329e7d5ddf978e0 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 27 Nov 2022 17:10:45 -0600 Subject: [PATCH] osc: don't spam window-controls bindings on every render Not sure when this actually started happening, but it's probably been like this for years. Currently, the logic for the window-controls works by simply checking if the osc is visible and then either enabling or disabling the associated keybindings. The problem is that this can just constantly spam mp.enable_keybindings/disable_key_bindings on every single render call if the user disables the border at any point in time. This does a lot of pointless work and also results in the logs being spammed with lines like "disable-section". Clearly, this should just work like the code for checking the input keybindings just above it. Keep track of an internal state variable and check when it doesn't match the osc visibility. In that case, we can then either enable or disable the key bindings and just update the variable. --- player/lua/osc.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 67b6621256..a244280a35 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -122,6 +122,7 @@ local state = { enabled = true, input_enabled = true, showhide_enabled = false, + windowcontrols_buttons = false, dmx_cache = 0, using_video_margins = false, border = true, @@ -2409,9 +2410,14 @@ function render() for _,cords in ipairs(osc_param.areas["window-controls"]) do if state.osc_visible then -- activate only when OSC is actually visible set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "window-controls") - mp.enable_key_bindings("window-controls") - else - mp.disable_key_bindings("window-controls") + end + if state.osc_visible ~= state.windowcontrols_buttons then + if state.osc_visible then + mp.enable_key_bindings("window-controls") + else + mp.disable_key_bindings("window-controls") + end + state.windowcontrols_buttons = state.osc_visible end if (mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2)) then