The way how this modifies and backups/restores user option values is a bit of a problem for runtime option changing. Clean this up a little. Now cycling the visibility updates the user option value, but always to "valid" values (unlike hidetimeout used to be used). If the user option value is changed externally (enabled by a later commit), it'll be cleanly overwritten.
Unified · Split
| @@ -49,15 +49,8 @@ local user_opts = { · 48 unmodified lines | |||
| 49 | windowcontrols_alignment = "right" -- which side to show window controls on | 49 | windowcontrols_alignment = "right" -- which side to show window controls on |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -- read_options may modify hidetimeout, so save the original default value in | ||
| 53 | -- case the user set hidetimeout < 0 and we need the default instead. | ||
| 54 | local hidetimeout_def = user_opts.hidetimeout | ||
| 55 | -- read options from config and command-line | 52 | -- read options from config and command-line |
| 56 | opt.read_options(user_opts, "osc") | 53 | opt.read_options(user_opts, "osc") |
| 57 | if user_opts.hidetimeout < 0 then | ||
| 58 | user_opts.hidetimeout = hidetimeout_def | ||
| 59 | msg.warn("hidetimeout cannot be negative. Using " .. user_opts.hidetimeout) | ||
| 60 | end | ||
| 61 | 54 | ||
| 62 | local osc_param = { -- calculated by osc_init() | 55 | local osc_param = { -- calculated by osc_init() |
| 63 | playresy = 0, -- canvas size Y | 56 | playresy = 0, -- canvas size Y |
| @@ -2079,7 +2072,7 @@ function update_margins() · 2015 unmodified lines | |||
| 2079 | 2072 | ||
| 2080 | -- Don't report margins if it's visible only temporarily. At least for | 2073 | -- Don't report margins if it's visible only temporarily. At least for |
| 2081 | -- console.lua this makes no sense. | 2074 | -- console.lua this makes no sense. |
| 2082 | if (not state.osc_visible) or (user_opts.hidetimeout >= 0) then | 2075 | if (not state.osc_visible) or (get_hidetimeout() >= 0) then |
| 2083 | margins = {l = 0, r = 0, t = 0, b = 0} | 2076 | margins = {l = 0, r = 0, t = 0, b = 0} |
| 2084 | end | 2077 | end |
| 2085 | 2078 | ||
| @@ -2167,7 +2160,7 @@ function request_tick() · 81 unmodified lines | |||
| 2167 | end | 2160 | end |
| 2168 | 2161 | ||
| 2169 | function mouse_leave() | 2162 | function mouse_leave() |
| 2170 | if user_opts.hidetimeout >= 0 then | 2163 | if get_hidetimeout() >= 0 then |
| 2171 | hide_osc() | 2164 | hide_osc() |
| 2172 | end | 2165 | end |
| 2173 | -- reset mouse position | 2166 | -- reset mouse position |
| @@ -2297,8 +2290,8 @@ function render() · 123 unmodified lines | |||
| 2297 | end | 2290 | end |
| 2298 | 2291 | ||
| 2299 | -- autohide | 2292 | -- autohide |
| 2300 | if not (state.showtime == nil) and (user_opts.hidetimeout >= 0) then | 2293 | if not (state.showtime == nil) and (get_hidetimeout() >= 0) then |
| 2301 | local timeout = state.showtime + (user_opts.hidetimeout/1000) - now | 2294 | local timeout = state.showtime + (get_hidetimeout()/1000) - now |
| 2302 | if timeout <= 0 then | 2295 | if timeout <= 0 then |
| 2303 | if (state.active_element == nil) and not (mouse_over_osc) then | 2296 | if (state.active_element == nil) and not (mouse_over_osc) then |
| 2304 | hide_osc() | 2297 | hide_osc() |
| @@ -2588,15 +2581,20 @@ mp.set_key_bindings({ · 283 unmodified lines | |||
| 2588 | }, "window-controls", "force") | 2581 | }, "window-controls", "force") |
| 2589 | mp.enable_key_bindings("window-controls") | 2582 | mp.enable_key_bindings("window-controls") |
| 2590 | 2583 | ||
| 2591 | user_opts.hidetimeout_orig = user_opts.hidetimeout | 2584 | function get_hidetimeout() |
| 2585 | if user_opts.visibility == "always" then | ||
| 2586 | return -1 -- disable autohide | ||
| 2587 | end | ||
| 2588 | return user_opts.hidetimeout | ||
| 2589 | end | ||
| 2592 | 2590 | ||
| 2593 | function always_on(val) | 2591 | function always_on(val) |
| 2594 | if val then | 2592 | if state.enabled then |
| 2595 | user_opts.hidetimeout = -1 -- disable autohide | 2593 | if val then |
| 2596 | if state.enabled then show_osc() end | 2594 | show_osc() |
| 2597 | else | 2595 | else |
| 2598 | user_opts.hidetimeout = user_opts.hidetimeout_orig | 2596 | hide_osc() |
| 2599 | if state.enabled then hide_osc() end | 2597 | end |
| 2600 | end | 2598 | end |
| 2601 | end | 2599 | end |
| 2602 | 2600 | ||
| @@ -2606,7 +2604,7 @@ function visibility_mode(mode, no_osd) · 3 unmodified lines | |||
| 2606 | if mode == "cycle" then | 2604 | if mode == "cycle" then |
| 2607 | if not state.enabled then | 2605 | if not state.enabled then |
| 2608 | mode = "auto" | 2606 | mode = "auto" |
| 2609 | elseif user_opts.hidetimeout >= 0 then | 2607 | elseif user_opts.visibility ~= "always" then |
| 2610 | mode = "always" | 2608 | mode = "always" |
| 2611 | else | 2609 | else |
| 2612 | mode = "never" | 2610 | mode = "never" |
| @@ -2626,6 +2624,8 @@ function visibility_mode(mode, no_osd) · 13 unmodified lines | |||
| 2626 | return | 2624 | return |
| 2627 | end | 2625 | end |
| 2628 | 2626 | ||
| 2627 | user_opts.visibility = mode | ||
| 2628 | |||
| 2629 | if not no_osd and tonumber(mp.get_property("osd-level")) >= 1 then | 2629 | if not no_osd and tonumber(mp.get_property("osd-level")) >= 1 then |
| 2630 | mp.osd_message("OSC visibility: " .. mode) | 2630 | mp.osd_message("OSC visibility: " .. mode) |
| 2631 | end | 2631 | end |