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
4949 windowcontrols_alignment = "right" -- which side to show window controls on
5050 }
5151
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
5552 -- read options from config and command-line
5653 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
6154
6255 local osc_param = { -- calculated by osc_init()
6356 playresy = 0, -- canvas size Y
@@ -2079,7 +2072,7 @@ function update_margins() · 2015 unmodified lines
20792072
20802073 -- Don't report margins if it's visible only temporarily. At least for
20812074 -- 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
20832076 margins = {l = 0, r = 0, t = 0, b = 0}
20842077 end
20852078
@@ -2167,7 +2160,7 @@ function request_tick() · 81 unmodified lines
21672160 end
21682161
21692162 function mouse_leave()
2170− if user_opts.hidetimeout >= 0 then
2163+ if get_hidetimeout() >= 0 then
21712164 hide_osc()
21722165 end
21732166 -- reset mouse position
@@ -2297,8 +2290,8 @@ function render() · 123 unmodified lines
22972290 end
22982291
22992292 -- autohide
2300− if not (state.showtime == nil) and (user_opts.hidetimeout >= 0) then
2301− local timeout = state.showtime + (user_opts.hidetimeout/1000) - now
2293+ if not (state.showtime == nil) and (get_hidetimeout() >= 0) then
2294+ local timeout = state.showtime + (get_hidetimeout()/1000) - now
23022295 if timeout <= 0 then
23032296 if (state.active_element == nil) and not (mouse_over_osc) then
23042297 hide_osc()
@@ -2588,15 +2581,20 @@ mp.set_key_bindings({ · 283 unmodified lines
25882581 }, "window-controls", "force")
25892582 mp.enable_key_bindings("window-controls")
25902583
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
25922590
25932591 function always_on(val)
2594− if val then
2595− user_opts.hidetimeout = -1 -- disable autohide
2596− if state.enabled then show_osc() end
2597− else
2598− user_opts.hidetimeout = user_opts.hidetimeout_orig
2599− if state.enabled then hide_osc() end
2592+ if state.enabled then
2593+ if val then
2594+ show_osc()
2595+ else
2596+ hide_osc()
2597+ end
26002598 end
26012599 end
26022600
@@ -2606,7 +2604,7 @@ function visibility_mode(mode, no_osd) · 3 unmodified lines
26062604 if mode == "cycle" then
26072605 if not state.enabled then
26082606 mode = "auto"
2609− elseif user_opts.hidetimeout >= 0 then
2607+ elseif user_opts.visibility ~= "always" then
26102608 mode = "always"
26112609 else
26122610 mode = "never"
@@ -2626,6 +2624,8 @@ function visibility_mode(mode, no_osd) · 13 unmodified lines
26262624 return
26272625 end
26282626
2627+ user_opts.visibility = mode
2628+
26292629 if not no_osd and tonumber(mp.get_property("osd-level")) >= 1 then
26302630 mp.osd_message("OSC visibility: " .. mode)
26312631 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