diff options
| -rw-r--r-- | input.lua | 36 | ||||
| -rw-r--r-- | main.lua | 5 | ||||
| -rw-r--r-- | osd.lua | 3 |
3 files changed, 33 insertions, 11 deletions
@@ -6,6 +6,7 @@ local input = {} local mappings = {} local active_mapping = {} +local persistent_mapping = {} local mapping_bound = false local clicks = {} @@ -78,6 +79,13 @@ local function process_mbtn(ev, id) end end +local btn_timer; btn_timer = mp.add_periodic_timer(0.1, function() + if osd.mpos and mp.get_time() - osd.mpos_time > config.btn_timeout then + osd:show_menu_btn(false) + btn_timer:kill() + end +end, true) -- disabled + -- mpv does not process key-binding changes requested by script functions until -- those functions return. in the meantime, while the function is running, mpv -- discards any key presses for keys that were not already bound prior to the @@ -112,8 +120,8 @@ local function handle_key(ev) local target_mapping = osd.mstate.target and active_mapping._targets and active_mapping._targets[osd.mstate.target] - local t = target_mapping and - (target_mapping[k] or + local t = persistent_mapping[k] or + target_mapping and (target_mapping[k] or ev.key_text and target_mapping['ANY_UNICODE']) or (active_mapping[k] or ev.key_text and active_mapping['ANY_UNICODE']) @@ -126,6 +134,12 @@ local function handle_key(ev) elseif osd.mactive then osd:set_mactive(false) clicks.k = nil + + if not osd.menu_btn.hidden and + osd.mstate.target ~= 'menu_btn' then + osd:show_menu_btn(false) + btn_timer:kill() + end end local f = t and t[1] @@ -147,6 +161,18 @@ local function handle_key(ev) osd:flush(state) end +function input.set_persistent_mapping(m) + for k, _ in pairs(persistent_mapping) do + mp.remove_key_binding('persistent-' .. k) + end + + persistent_mapping = m + for k, _ in pairs(m) do + mp.add_forced_key_binding( + k, 'persistent-' .. k, handle_key, {complex = true}) + end +end + -- uses enable-section and disable-section to disable builtin key bindings -- while the OSD is visible. these commands are technically deprecated for -- non-internal use, but they still work, and there doesn't appear to be @@ -195,12 +221,6 @@ local function unbind_click() mp.command_native({'disable-section', 'click-nodrag'}) end -local btn_timer; btn_timer = mp.add_periodic_timer(0.1, function() - if osd.mpos and mp.get_time() - osd.mpos_time > config.btn_timeout then - osd:show_menu_btn(false) - btn_timer:kill() - end -end, true) -- disabled function input.update_mpos(mpos) if not mpos then return @@ -114,9 +114,10 @@ state.saved_osc_visibility = mp.get_property_native( 'user-data/osc/visibility', 'auto') rt.set_osc_visibility(false) -mp.add_forced_key_binding('TAB', 'toggle-menu', rt.toggle_menu) - input.init(state, osd, rt.toggle_menu) +input.set_persistent_mapping({ + ['TAB'] = {rt.toggle_menu}, +}) input.define_mapping('MENU', { ['BS'] = {rt.prev_menu}, ['/'] = {rt.start_search}, @@ -727,7 +727,8 @@ end function mt:mouse_over_btn_area(mpos) local y = mpos.y / self.scale - return y < self.padding + (2 * config.font_size) + return mpos.x < self.width / 2 and + y < self.padding + (2 * config.font_size) end function mt:mouse_over_menu_btn(mpos) |
