diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 4718be44c1..31db711f25 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -75,7 +75,7 @@ local user_opts = { } -- read options from config and command-line -opt.read_options(user_opts, "osc", function(list) update_options(list) end) +opt.read_options(user_opts, "osc", function() update_options() end) local osc_param = { -- calculated by osc_init() playresy = 0, -- canvas size Y @@ -92,6 +92,8 @@ function osc_color_convert(color) return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3) end +-- luacheck: push ignore +-- luacheck: max line length local osc_styles = { bigButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs50\\fnmpv-osd-symbols}", smallButtonsL = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsL_color) .. "\\3c&HFFFFFF\\fs19\\fnmpv-osd-symbols}", @@ -114,26 +116,27 @@ local osc_styles = { wcTitle = "{\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\fs24\\q2}", wcBar = "{\\1c&H" .. osc_color_convert(user_opts.background_color) .. "}", } +-- luacheck: pop -- internal states, do not touch local state = { - showtime, -- time of last invocation (last mouse move) + showtime = nil, -- time of last invocation (last mouse move) osc_visible = false, - anistart, -- time when the animation started - anitype, -- current type of animation - animation, -- current animation alpha + anistart = nil, -- time when the animation started + anitype = nil, -- current type of animation + animation = nil, -- current animation alpha mouse_down_counter = 0, -- used for softrepeat active_element = nil, -- nil = none, 0 = background, 1+ = see elements[] active_event_source = nil, -- the "button" that issued the current event rightTC_trem = not user_opts.timetotal, -- if the right timecode should display total or remaining time tc_ms = user_opts.timems, -- Should the timecodes display their time with milliseconds - mp_screen_sizeX, mp_screen_sizeY, -- last screen-resolution, to detect resolution changes to issue reINITs + screen_sizeX = nil, screen_sizeY = nil, -- last screen-resolution, to detect resolution changes to issue reINITs initREQ = false, -- is a re-init request pending? marginsREQ = false, -- is a margins update pending? - last_mouseX, last_mouseY, -- last mouse position, to detect significant mouse movement + last_mouseX = nil, last_mouseY = nil, -- last mouse position, to detect significant mouse movement mouse_in_window = false, - message_text, - message_hide_timer, + message_text = nil, + message_hide_timer = nil, fullscreen = false, tick_timer = nil, tick_last_time = 0, -- when the last tick() was run @@ -392,9 +395,9 @@ end -- return a nice list of tracks of the given type (video, audio, sub) function get_tracklist(type) - local msg = "Available " .. nicetypes[type] .. " Tracks: " + local message = "Available " .. nicetypes[type] .. " Tracks: " if not tracks_osc or #tracks_osc[type] == 0 then - msg = msg .. "none" + message = message .. "none" else for n = 1, #tracks_osc[type] do local track = tracks_osc[type][n] @@ -404,10 +407,10 @@ function get_tracklist(type) if track.id == tonumber(mp.get_property(type)) then selected = "●" end - msg = msg.."\n"..selected.." "..n..": ["..lang.."] "..title + message = message.."\n"..selected.." "..n..": ["..lang.."] "..title end end - return msg + return message end -- relatively change the track of given by tracks @@ -476,7 +479,7 @@ function prepare_elements() -- remove elements without layout or invisible local elements2 = {} - for n, element in pairs(elements) do + for _, element in pairs(elements) do if element.layout ~= nil and element.visible then table.insert(elements2, element) end @@ -742,7 +745,8 @@ function render_elements(master_ass) if pos > range["end"] then pend = get_slider_ele_pos_for(element, range["end"]) end - elem_ass:rect_ccw(pstart, elem_geo.h - foV - seekRangeLineHeight, pend, elem_geo.h - foV) + elem_ass:rect_ccw(pstart, elem_geo.h - foV - seekRangeLineHeight, + pend, elem_geo.h - foV) end end end @@ -876,8 +880,6 @@ function render_elements(master_ass) end buttontext = buttontext .. "..." end - local _, nchars2 = buttontext:gsub(".[\128-\191]*", "") - local stretch = (maxchars/#buttontext)*100 buttontext = string.format("{\\fscx%f}", (maxchars/#buttontext)*100) .. buttontext end @@ -927,7 +929,7 @@ function get_playlist() end local message = string.format('Playlist [%d/%d]:\n', pos, count) - for i, v in ipairs(limlist) do + for _, v in ipairs(limlist) do local title = v.title local _, filename = utils.split_path(v.filename) if not user_opts.playlist_media_title or title == nil then @@ -964,7 +966,7 @@ function show_message(text, duration) --print("text: "..text.." duration: " .. duration) if duration == nil then duration = tonumber(mp.get_property("options/osd-duration")) / 1000 - elseif not type(duration) == "number" then + elseif type(duration) ~= "number" then print("duration: " .. duration) end @@ -1248,8 +1250,7 @@ layouts["box"] = function () add_area("showhide", 0, sh_area_y0, osc_param.playresx, sh_area_y1) -- fetch values - local osc_w, osc_h, osc_r, osc_p = - osc_geo.w, osc_geo.h, osc_geo.r, osc_geo.p + local osc_w, osc_h, osc_r = osc_geo.w, osc_geo.h, osc_geo.r local lo @@ -1425,8 +1426,10 @@ layouts["slimbox"] = function () -- styles local styles = { box = "{\\rDefault\\blur0\\bord1\\1c&H" .. osc_color_convert(user_opts.background_color) .. "\\3c&HFFFFFF}", - timecodes = "{\\1c&H" .. osc_color_convert(user_opts.timecode_color) .. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs20\\bord2\\blur1}", - tooltip = "{\\1c&H" .. osc_color_convert(user_opts.time_pos_color).. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs12\\bord1\\blur0.5}", + timecodes = "{\\1c&H" .. osc_color_convert(user_opts.timecode_color) .. "\\3c&H" .. + osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs20\\bord2\\blur1}", + tooltip = "{\\1c&H" .. osc_color_convert(user_opts.time_pos_color).. "\\3c&H" .. + osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs12\\bord1\\blur0.5}", } @@ -1488,9 +1491,9 @@ end function bar_layout(direction) local osc_geo = { x = -2, - y, + y = nil, an = (direction < 0) and 7 or 1, - w, + w = nil, h = 56, } @@ -1758,7 +1761,7 @@ function validate_user_opts() end end -function update_options(list) +function update_options() validate_user_opts() request_tick() visibility_mode(user_opts.visibility, true) @@ -1774,8 +1777,8 @@ function osc_init() -- set canvas resolution according to display aspect and scaling setting local baseResY = 720 - local display_w, display_h, display_aspect = mp.get_osd_size() - local scale = 1 + local _, display_h, display_aspect = mp.get_osd_size() + local scale if mp.get_property("video") == "no" then -- dummy/forced window scale = user_opts.scaleforcedwindow @@ -2205,8 +2208,8 @@ end function reset_margins() if state.using_video_margins then - for _, opt in ipairs(margins_opts) do - mp.set_property_number(opt[2], 0.0) + for _, mopt in ipairs(margins_opts) do + mp.set_property_number(mopt[2], 0.0) end state.using_video_margins = false end @@ -2228,18 +2231,18 @@ function update_margins() local margins_used = false if not state.using_video_margins then - for _, opt in ipairs(margins_opts) do - if mp.get_property_number(opt[2], 0.0) ~= 0.0 then + for _, mopt in ipairs(margins_opts) do + if mp.get_property_number(mopt[2], 0.0) ~= 0.0 then margins_used = true end end end if not margins_used then - for _, opt in ipairs(margins_opts) do - local v = margins[opt[1]] + for _, mopt in ipairs(margins_opts) do + local v = margins[mopt[1]] if v ~= 0 or state.using_video_margins then - mp.set_property_number(opt[2], v) + mp.set_property_number(mopt[2], v) state.using_video_margins = true end end @@ -2301,12 +2304,12 @@ function osc_visible(visible) request_tick() end -function pause_state(name, enabled) +function pause_state(_, enabled) state.paused = enabled request_tick() end -function cache_state(name, st) +function cache_state(_, st) state.cache_state = st request_tick() end @@ -2361,18 +2364,18 @@ end function render() msg.trace("rendering") - local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_osd_size() + local current_screen_sizeX, current_screen_sizeY = mp.get_osd_size() local mouseX, mouseY = get_virt_mouse_pos() local now = mp.get_time() -- check if display changed, if so request reinit - if state.mp_screen_sizeX ~= current_screen_sizeX - or state.mp_screen_sizeY ~= current_screen_sizeY then + if state.screen_sizeX ~= current_screen_sizeX + or state.screen_sizeY ~= current_screen_sizeY then request_init_resize() - state.mp_screen_sizeX = current_screen_sizeX - state.mp_screen_sizeY = current_screen_sizeY + state.screen_sizeX = current_screen_sizeX + state.screen_sizeY = current_screen_sizeY end -- init management @@ -2427,11 +2430,11 @@ function render() end --mouse show/hide area - for k,cords in pairs(osc_param.areas["showhide"]) do + for _, cords in pairs(osc_param.areas["showhide"]) do set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide") end if osc_param.areas["showhide_wc"] then - for k,cords in pairs(osc_param.areas["showhide_wc"]) do + for _, cords in pairs(osc_param.areas["showhide_wc"]) do set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide_wc") end else @@ -2576,7 +2579,7 @@ function process_event(source, what) if elements[state.active_element] then local n = state.active_element - if n == 0 then + if n == 0 then --luacheck: ignore 542 --click on background (does not work) elseif element_has_action(elements[n], action) and mouse_hit(elements[n]) then @@ -2618,7 +2621,8 @@ function process_event(source, what) request_tick() end - +-- luacheck: push ignore +-- luacheck: max line length local logo_lines = { -- White border "{\\c&HE5E5E5&\\p6}m 895 10 b 401 10 0 410 0 905 0 1399 401 1800 895 1800 1390 1800 1790 1399 1790 905 1790 410 1390 10 895 10 {\\p0}", @@ -2643,6 +2647,7 @@ local santa_hat_lines = { -- Brim and tip pompom "{\\c&HF8F8F8&\\p6}m 626 -191 b 565 -155 486 -196 428 -151 387 -115 327 -101 304 -47 273 2 267 59 249 113 219 157 217 213 215 265 217 309 260 302 285 283 373 264 465 264 555 257 608 252 655 292 709 287 759 294 816 276 863 298 903 340 972 324 1012 367 1061 394 1125 382 1167 424 1213 462 1268 482 1322 506 1385 546 1427 610 1479 662 1510 690 1534 725 1566 752 1611 796 1664 830 1703 880 1740 918 1747 986 1805 1005 1863 991 1897 932 1916 880 1914 823 1945 777 1961 725 1979 673 1957 622 1938 575 1912 534 1862 515 1836 473 1790 417 1755 351 1697 305 1658 266 1633 216 1593 176 1574 138 1539 116 1497 110 1448 101 1402 77 1371 37 1346 -16 1295 15 1254 6 1211 -27 1170 -62 1121 -86 1072 -104 1027 -128 976 -133 914 -130 851 -137 794 -162 740 -181 679 -168 626 -191 m 2051 917 b 1971 932 1929 1017 1919 1091 1912 1149 1923 1214 1970 1254 2000 1279 2027 1314 2066 1325 2139 1338 2212 1295 2254 1238 2281 1203 2287 1158 2282 1116 2292 1061 2273 1006 2229 970 2206 941 2167 938 2138 918{\\p0}", } +-- luacheck: pop -- called by mpv on every frame function tick() @@ -2670,7 +2675,7 @@ function tick() local ass = assdraw.ass_new() -- mpv logo if user_opts.idlescreen then - for i, line in ipairs(logo_lines) do + for _, line in ipairs(logo_lines) do ass:new_event() ass:append(line_prefix .. line) end @@ -2678,7 +2683,7 @@ function tick() -- Santa hat if is_december and user_opts.idlescreen and not user_opts.greenandgrumpy then - for i, line in ipairs(santa_hat_lines) do + for _, line in ipairs(santa_hat_lines) do ass:new_event() ass:append(line_prefix .. line) end @@ -2795,53 +2800,49 @@ mp.register_script_message("osc-playlist", function(dur) show_message(get_playlist(), dur) end) mp.register_script_message("osc-tracklist", function(dur) - local msg = {} - for k,v in pairs(nicetypes) do - table.insert(msg, get_tracklist(k)) + local message = {} + for k in pairs(nicetypes) do + table.insert(message, get_tracklist(k)) end - show_message(table.concat(msg, '\n\n'), dur) + show_message(table.concat(message, '\n\n'), dur) end) mp.observe_property("fullscreen", "bool", - function(name, val) + function(_, val) state.fullscreen = val state.marginsREQ = true request_init_resize() end ) mp.observe_property("border", "bool", - function(name, val) + function(_, val) state.border = val request_init_resize() end ) mp.observe_property("title-bar", "bool", - function(name, val) + function(_, val) state.title_bar = val request_init_resize() end ) mp.observe_property("window-maximized", "bool", - function(name, val) + function(_, val) state.maximized = val request_init_resize() end ) mp.observe_property("idle-active", "bool", - function(name, val) + function(_, val) state.idle = val request_tick() end ) mp.observe_property("pause", "bool", pause_state) mp.observe_property("demuxer-cache-state", "native", cache_state) -mp.observe_property("vo-configured", "bool", function(name, val) - request_tick() -end) -mp.observe_property("playback-time", "number", function(name, val) - request_tick() -end) -mp.observe_property("osd-dimensions", "native", function(name, val) +mp.observe_property("vo-configured", "bool", request_tick) +mp.observe_property("playback-time", "number", request_tick) +mp.observe_property("osd-dimensions", "native", function() -- (we could use the value instead of re-querying it all the time, but then -- we might have to worry about property update ordering) request_init_resize() @@ -2849,28 +2850,28 @@ end) -- mouse show/hide bindings mp.set_key_bindings({ - {"mouse_move", function(e) process_event("mouse_move", nil) end}, + {"mouse_move", function() process_event("mouse_move", nil) end}, {"mouse_leave", mouse_leave}, }, "showhide", "force") mp.set_key_bindings({ - {"mouse_move", function(e) process_event("mouse_move", nil) end}, + {"mouse_move", function() process_event("mouse_move", nil) end}, {"mouse_leave", mouse_leave}, }, "showhide_wc", "force") do_enable_keybindings() --mouse input bindings mp.set_key_bindings({ - {"mbtn_left", function(e) process_event("mbtn_left", "up") end, - function(e) process_event("mbtn_left", "down") end}, - {"shift+mbtn_left", function(e) process_event("shift+mbtn_left", "up") end, - function(e) process_event("shift+mbtn_left", "down") end}, - {"mbtn_right", function(e) process_event("mbtn_right", "up") end, - function(e) process_event("mbtn_right", "down") end}, + {"mbtn_left", function() process_event("mbtn_left", "up") end, + function() process_event("mbtn_left", "down") end}, + {"shift+mbtn_left", function() process_event("shift+mbtn_left", "up") end, + function() process_event("shift+mbtn_left", "down") end}, + {"mbtn_right", function() process_event("mbtn_right", "up") end, + function() process_event("mbtn_right", "down") end}, -- alias to shift_mbtn_left for single-handed mouse use - {"mbtn_mid", function(e) process_event("shift+mbtn_left", "up") end, - function(e) process_event("shift+mbtn_left", "down") end}, - {"wheel_up", function(e) process_event("wheel_up", "press") end}, - {"wheel_down", function(e) process_event("wheel_down", "press") end}, + {"mbtn_mid", function() process_event("shift+mbtn_left", "up") end, + function() process_event("shift+mbtn_left", "down") end}, + {"wheel_up", function() process_event("wheel_up", "press") end}, + {"wheel_down", function() process_event("wheel_down", "press") end}, {"mbtn_left_dbl", "ignore"}, {"shift+mbtn_left_dbl", "ignore"}, {"mbtn_right_dbl", "ignore"}, @@ -2878,8 +2879,8 @@ mp.set_key_bindings({ mp.enable_key_bindings("input") mp.set_key_bindings({ - {"mbtn_left", function(e) process_event("mbtn_left", "up") end, - function(e) process_event("mbtn_left", "down") end}, + {"mbtn_left", function() process_event("mbtn_left", "up") end, + function() process_event("mbtn_left", "down") end}, }, "window-controls", "force") mp.enable_key_bindings("window-controls")