diff options
Diffstat (limited to 'osc-mod.lua')
| -rw-r--r-- | osc-mod.lua | 314 |
1 files changed, 183 insertions, 131 deletions
diff --git a/osc-mod.lua b/osc-mod.lua index b77fe66..f5af003 100644 --- a/osc-mod.lua +++ b/osc-mod.lua @@ -1073,6 +1073,7 @@ end local function new_element(name, type) elements[name] = {} + elements[name].name = name elements[name].type = type -- add default stuff @@ -2015,8 +2016,10 @@ local function osc_init() local duration = mp.get_property_number("duration") if duration ~= nil and pos ~= nil then local possec = duration * (pos / 100) + mp.set_property_number("user-data/osc/seekbar/possec", possec) return mp.format_time(possec) else + mp.set_property_native("user-data/osc/seekbar/possec", nil) return "" end end @@ -2196,6 +2199,7 @@ end local function osc_visible(visible) if state.osc_visible ~= visible then + mp.set_property_bool("user-data/osc/visible", visible) state.osc_visible = visible update_margins() end @@ -2250,6 +2254,32 @@ local function cache_state(_, st) request_tick() end +local function export_uistate() + mp.set_property_bool("user-data/osc/mouse-in-window", state.mouse_in_window) + if state.mouse_in_window then + active_elem = nil + active_elem_cnt = 0 + for n=1, #elements do + local element = elements[n] + if mouse_hit(element) then + active_elem = element + active_elem_cnt = active_elem_cnt + 1; + end + end + if active_elem ~= nil then + mp.set_property("user-data/osc/active-element", active_elem.name) + mp.set_property_number( + "user-data/osc/active-element-cnt", active_elem_cnt) + else + mp.set_property_native("user-data/osc/active-element", nil) + mp.set_property_number("user-data/osc/active-element-cnt", 0) + end + else + mp.set_property_native("user-data/osc/active-element", nil) + mp.set_property_number("user-data/osc/active-element-cnt", 0) + end +end + local function mouse_leave() if get_hidetimeout() >= 0 and get_touchtimeout() <= 0 then hide_osc() @@ -2257,6 +2287,7 @@ local function mouse_leave() -- reset mouse position state.last_mouseX, state.last_mouseY = nil, nil state.mouse_in_window = false + export_uistate() end local function handle_touch(_, touchpoints) @@ -2434,9 +2465,11 @@ local function render() (state.anistart + (user_opts.fadeduration / 1000)), 0, 255, now) end + mp.set_property_number("user-data/osc/fade", state.animation) else if state.anitype == "out" then + mp.set_property_number("user-data/osc/fade", 255) osc_visible(false) end kill_animation() @@ -2614,6 +2647,8 @@ tick = function() -- render the OSC render() + + export_uistate() else -- Flush OSD render_wipe() @@ -2672,126 +2707,6 @@ local function set_tick_delay(_, display_fps) tick_delay = 1 / display_fps end -mp.register_event("shutdown", shutdown) -mp.register_event("start-file", request_init) -mp.observe_property("track-list", "native", request_init) -mp.observe_property("playlist-count", "native", request_init) -mp.observe_property("playlist-pos", "native", request_init) -mp.observe_property("chapter-list", "native", function(_, list) - list = list or {} -- safety, shouldn't return nil - table.sort(list, function(a, b) return a.time < b.time end) - state.chapter_list = list - update_duration_watch() - request_init() -end) - --- These are for backwards compatibility only. -mp.register_script_message("osc-message", function(message, dur) - if not state.osc_message_warned then - mp.msg.warn("osc-message is deprecated and may be removed in the future.", - "Use the show-text command instead.") - state.osc_message_warned = true - end - mp.osd_message(message, dur) -end) -mp.register_script_message("osc-chapterlist", function(dur) - if not state.osc_chapterlist_warned then - mp.msg.warn("osc-chapterlist is deprecated and may be removed in the future.", - "Use show-text ${chapter-list} instead.") - state.osc_chapterlist_warned = true - end - mp.command("show-text ${chapter-list} " .. (dur and dur * 1000 or "")) -end) -mp.register_script_message("osc-playlist", function(dur) - if not state.osc_playlist_warned then - mp.msg.warn("osc-playlist is deprecated and may be removed in the future.", - "Use show-text ${playlist} instead.") - state.osc_playlist_warned = true - end - mp.command("show-text ${playlist} " .. (dur and dur * 1000 or "")) -end) -mp.register_script_message("osc-tracklist", function(dur) - if not state.osc_tracklist_warned then - mp.msg.warn("osc-tracklist is deprecated and may be removed in the future.", - "Use show-text ${track-list} instead.") - state.osc_tracklist_warned = true - end - mp.command("show-text ${track-list} " .. (dur and dur * 1000 or "")) -end) - -mp.observe_property("fullscreen", "bool", function(_, val) - state.fullscreen = val - state.marginsREQ = true - request_init_resize() -end) -mp.observe_property("border", "bool", function(_, val) - state.border = val - request_init_resize() -end) -mp.observe_property("title-bar", "bool", function(_, val) - state.title_bar = val - request_init_resize() -end) -mp.observe_property("window-maximized", "bool", function(_, val) - state.maximized = val - request_init_resize() -end) -mp.observe_property("idle-active", "bool", function(_, val) - state.idle = val - request_tick() -end) - -mp.observe_property("display-fps", "number", set_tick_delay) -mp.observe_property("pause", "bool", pause_state) -mp.observe_property("volume", "number", request_tick) -mp.observe_property("mute", "bool", request_tick) -mp.observe_property("demuxer-cache-state", "native", cache_state) -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() -end) -mp.observe_property('osd-scale-by-window', 'native', request_init_resize) -mp.observe_property('touch-pos', 'native', handle_touch) - --- mouse show/hide bindings -mp.set_key_bindings({ - {"mouse_move", function() process_event("mouse_move", nil) end}, - {"mouse_leave", mouse_leave}, -}, "showhide", "force") -mp.set_key_bindings({ - {"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() process_event("mbtn_left", "up") end, - function() process_event("mbtn_left", "down") end}, - {"mbtn_mid", function() process_event("mbtn_mid", "up") end, - function() process_event("mbtn_mid", "down") end}, - {"mbtn_right", function() process_event("mbtn_right", "up") end, - function() process_event("mbtn_right", "down") end}, - -- alias shift+mbtn_left to mbtn_mid for touchpads - {"shift+mbtn_left", function() process_event("mbtn_mid", "up") end, - function() process_event("mbtn_mid", "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"}, -}, "input", "force") -mp.enable_key_bindings("input") - -mp.set_key_bindings({ - {"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") - local function always_on(val) if state.enabled then if val then @@ -2872,17 +2787,6 @@ local function idlescreen_visibility(mode, no_osd) request_tick() end -mp.register_script_message("osc-visibility", visibility_mode) -mp.register_script_message("osc-show", show_osc) -mp.register_script_message("osc-hide", function () - if user_opts.visibility == "auto" then - osc_visible(false) - end -end) -mp.add_key_binding(nil, "visibility", function() visibility_mode("cycle") end) - -mp.register_script_message("osc-idlescreen", idlescreen_visibility) - -- Validate string type user options local function validate_user_opts() if layouts[user_opts.layout] == nil then @@ -2951,6 +2855,138 @@ local function validate_user_opts() end end +local function load_plugin() +mp.register_event("shutdown", shutdown) +mp.register_event("start-file", request_init) +mp.observe_property("track-list", "native", request_init) +mp.observe_property("playlist-count", "native", request_init) +mp.observe_property("playlist-pos", "native", request_init) +mp.observe_property("chapter-list", "native", function(_, list) + list = list or {} -- safety, shouldn't return nil + table.sort(list, function(a, b) return a.time < b.time end) + state.chapter_list = list + update_duration_watch() + request_init() +end) + +-- These are for backwards compatibility only. +mp.register_script_message("osc-message", function(message, dur) + if not state.osc_message_warned then + mp.msg.warn("osc-message is deprecated and may be removed in the future.", + "Use the show-text command instead.") + state.osc_message_warned = true + end + mp.osd_message(message, dur) +end) +mp.register_script_message("osc-chapterlist", function(dur) + if not state.osc_chapterlist_warned then + mp.msg.warn("osc-chapterlist is deprecated and may be removed in the future.", + "Use show-text ${chapter-list} instead.") + state.osc_chapterlist_warned = true + end + mp.command("show-text ${chapter-list} " .. (dur and dur * 1000 or "")) +end) +mp.register_script_message("osc-playlist", function(dur) + if not state.osc_playlist_warned then + mp.msg.warn("osc-playlist is deprecated and may be removed in the future.", + "Use show-text ${playlist} instead.") + state.osc_playlist_warned = true + end + mp.command("show-text ${playlist} " .. (dur and dur * 1000 or "")) +end) +mp.register_script_message("osc-tracklist", function(dur) + if not state.osc_tracklist_warned then + mp.msg.warn("osc-tracklist is deprecated and may be removed in the future.", + "Use show-text ${track-list} instead.") + state.osc_tracklist_warned = true + end + mp.command("show-text ${track-list} " .. (dur and dur * 1000 or "")) +end) + +mp.observe_property("fullscreen", "bool", function(_, val) + state.fullscreen = val + state.marginsREQ = true + request_init_resize() +end) +mp.observe_property("border", "bool", function(_, val) + state.border = val + request_init_resize() +end) +mp.observe_property("title-bar", "bool", function(_, val) + state.title_bar = val + request_init_resize() +end) +mp.observe_property("window-maximized", "bool", function(_, val) + state.maximized = val + request_init_resize() +end) +mp.observe_property("idle-active", "bool", function(_, val) + state.idle = val + request_tick() +end) + +mp.observe_property("display-fps", "number", set_tick_delay) +mp.observe_property("pause", "bool", pause_state) +mp.observe_property("volume", "number", request_tick) +mp.observe_property("mute", "bool", request_tick) +mp.observe_property("demuxer-cache-state", "native", cache_state) +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() +end) +mp.observe_property('osd-scale-by-window', 'native', request_init_resize) +mp.observe_property('touch-pos', 'native', handle_touch) + +-- mouse show/hide bindings +mp.set_key_bindings({ + {"mouse_move", function() process_event("mouse_move", nil) end}, + {"mouse_leave", mouse_leave}, +}, "showhide", "force") +mp.set_key_bindings({ + {"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() process_event("mbtn_left", "up") end, + function() process_event("mbtn_left", "down") end}, + {"mbtn_mid", function() process_event("mbtn_mid", "up") end, + function() process_event("mbtn_mid", "down") end}, + {"mbtn_right", function() process_event("mbtn_right", "up") end, + function() process_event("mbtn_right", "down") end}, + -- alias shift+mbtn_left to mbtn_mid for touchpads + {"shift+mbtn_left", function() process_event("mbtn_mid", "up") end, + function() process_event("mbtn_mid", "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"}, +}, "input", "force") +mp.enable_key_bindings("input") + +mp.set_key_bindings({ + {"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") + +mp.register_script_message("osc-visibility", visibility_mode) +mp.register_script_message("osc-show", show_osc) +mp.register_script_message("osc-hide", function () + if user_opts.visibility == "auto" then + osc_visible(false) + end +end) +mp.add_key_binding(nil, "visibility", function() visibility_mode("cycle") end) + +mp.register_script_message("osc-idlescreen", idlescreen_visibility) + -- read options from config and command-line opt.read_options(user_opts, "osc", function(changed) validate_user_opts() @@ -2975,3 +3011,19 @@ update_duration_watch() set_virt_mouse_area(0, 0, 0, 0, "input") set_virt_mouse_area(0, 0, 0, 0, "window-controls") set_virt_mouse_area(0, 0, 0, 0, "window-controls-title") +end -- load_plugin + +-- Disable builtin osc and load self. +local function builtin_unload_observer() + if mp.get_property("user-data/osc/unloading") == nil then + msg.debug("Builtin osc unloaded. Loading self...") + mp.unobserve_property(builtin_unload_observer) + load_plugin() + end +end +if mp.get_property_bool("osc", true) then + msg.debug("Unloading builtin osc") + mp.set_property_bool("user-data/osc/unloading", true) + mp.observe_property("user-data/osc/unloading", nil, builtin_unload_observer) + mp.set_property_bool("osc", false) +end |
