History

osc: rearrange hidetimeout/visibiltiy handling

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.

wm4 committed 6 years ago

Commit db1e28f1 parent 70c54011 file · +19 −19Browse files

Unified · Split

player/lua/osc.lua+19−19
@@ -49,15 +49,8 @@ local user_opts = { · 48 unmodified lines
49 windowcontrols_alignment = "right" -- which side to show window controls on49 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.
54local hidetimeout_def = user_opts.hidetimeout
55-- read options from config and command-line52-- read options from config and command-line
56opt.read_options(user_opts, "osc")53opt.read_options(user_opts, "osc")
57if user_opts.hidetimeout < 0 then
58 user_opts.hidetimeout = hidetimeout_def
59 msg.warn("hidetimeout cannot be negative. Using " .. user_opts.hidetimeout)
60end
61 54
62local osc_param = { -- calculated by osc_init()55local osc_param = { -- calculated by osc_init()
63 playresy = 0, -- canvas size Y56 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 for2073 -- 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) then2075 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 end2077 end
2085 2078
@@ -2167,7 +2160,7 @@ function request_tick() · 81 unmodified lines
2167end2160end
2168 2161
2169function mouse_leave()2162function mouse_leave()
2170 if user_opts.hidetimeout >= 0 then2163 if get_hidetimeout() >= 0 then
2171 hide_osc()2164 hide_osc()
2172 end2165 end
2173 -- reset mouse position2166 -- reset mouse position
@@ -2297,8 +2290,8 @@ function render() · 123 unmodified lines
2297 end2290 end
2298 2291
2299 -- autohide2292 -- autohide
2300 if not (state.showtime == nil) and (user_opts.hidetimeout >= 0) then2293 if not (state.showtime == nil) and (get_hidetimeout() >= 0) then
2301 local timeout = state.showtime + (user_opts.hidetimeout/1000) - now2294 local timeout = state.showtime + (get_hidetimeout()/1000) - now
2302 if timeout <= 0 then2295 if timeout <= 0 then
2303 if (state.active_element == nil) and not (mouse_over_osc) then2296 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")
2589mp.enable_key_bindings("window-controls")2582mp.enable_key_bindings("window-controls")
2590 2583
2591user_opts.hidetimeout_orig = user_opts.hidetimeout2584function get_hidetimeout()
2585 if user_opts.visibility == "always" then
2586 return -1 -- disable autohide
2587 end
2588 return user_opts.hidetimeout
2589end
2592 2590
2593function always_on(val)2591function always_on(val)
2594 if val then2592 if state.enabled then
2595 user_opts.hidetimeout = -1 -- disable autohide2593 if val then
2596 if state.enabled then show_osc() end2594 show_osc()
2597 else2595 else
2598 user_opts.hidetimeout = user_opts.hidetimeout_orig2596 hide_osc()
2599 if state.enabled then hide_osc() end2597 end
2600 end2598 end
2601end2599end
2602 2600
@@ -2606,7 +2604,7 @@ function visibility_mode(mode, no_osd) · 3 unmodified lines
2606 if mode == "cycle" then2604 if mode == "cycle" then
2607 if not state.enabled then2605 if not state.enabled then
2608 mode = "auto"2606 mode = "auto"
2609 elseif user_opts.hidetimeout >= 0 then2607 elseif user_opts.visibility ~= "always" then
2610 mode = "always"2608 mode = "always"
2611 else2609 else
2612 mode = "never"2610 mode = "never"
@@ -2626,6 +2624,8 @@ function visibility_mode(mode, no_osd) · 13 unmodified lines
2626 return2624 return
2627 end2625 end
2628 2626
2627 user_opts.visibility = mode
2628
2629 if not no_osd and tonumber(mp.get_property("osd-level")) >= 1 then2629 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 end2631 end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t