diff options
Diffstat (limited to 'rt.lua')
| -rw-r--r-- | rt.lua | 105 |
1 files changed, 97 insertions, 8 deletions
@@ -7,11 +7,13 @@ local rt = {} local state local osd +local input local ctx -function rt.init(_state, _osd, _ctx) +function rt.init(_state, _osd, _input, _ctx) state = _state osd = _osd + input = _input ctx = _ctx end @@ -28,10 +30,6 @@ local function cache_miss_status_msg(str) } end -local function set_key_mapping(m) - ctx.binding_state.active = ctx.binding_state.mappings[m] -end - function rt.load_data(force) local arr = { {id = 'live', name = 'Live TV', type = 'live'}, @@ -913,7 +911,7 @@ function rt.start_search() end osd:dirty() - set_key_mapping('SEARCH') + input.set_key_mapping('SEARCH') end function rt.end_search() @@ -922,7 +920,7 @@ function rt.end_search() menu.title = 'Search results: <text>' .. ' <colour.info>(<num_matches>/<num_total>)' osd:dirty() - set_key_mapping('MENU') + input.set_key_mapping('MENU') end function rt.cancel_search() @@ -940,7 +938,7 @@ function rt.cancel_search() menu.search_active = false state.depth = state.depth - 1 osd:dirty() - set_key_mapping('MENU') + input.set_key_mapping('MENU') end function rt.toggle_menu_sort() @@ -953,6 +951,82 @@ function rt.toggle_menu_sort() osd:dirty() end +local function mouse_click_left_menu(dbl, line) + if line == 0 then + return + end + + -- title + if line < 0 then + if not dbl then + return + end + + if line == -1 then + rt.set_cursor(1) + else + state.depth = state.depth + line + 1 + osd:dirty() + end + return + end + + local menu = state:menu() + local pos = menu.view_top + line - 1 + if dbl then + if pos ~= menu.cursor then + return + end + + rt.select_option() + else + if pos > #menu.options then + return + end + + rt.set_cursor(pos) + end +end + +local function mouse_click_left_scrollbar(dbl, ratio) + if not dbl then + return + end + + -- set_cursor handles out-of-bounds moves (when ratio == 1) + rt.set_cursor( + math.floor(ratio * #state:menu().options) + 1, + {centre = true}) +end + +local function mouse_click_right_menu(dbl, line) + if not dbl or line < 1 then + return + end + + local menu = state:menu() + local pos = menu.view_top + line - 1 + if pos > #menu.options then + return + end + + rt.open_option_info(menu.options[pos]) +end + +function rt.mouse_click_left(dbl, area, val) + if area == 'menu' then + return mouse_click_left_menu(dbl, val) + elseif area == 'scrollbar' then + return mouse_click_left_scrollbar(dbl, val) + end +end + +function rt.mouse_click_right(dbl, area, val) + if area == 'menu' then + return mouse_click_right_menu(dbl, val) + end +end + function rt.reload_data() if state.depth > 1 then osd:flash_error('Can only reload data from root menu') @@ -965,4 +1039,19 @@ function rt.reload_data() rt.push_group_menu(ctx.catalogue:get('root')) end +function rt.set_osc_visibility() + local v = osd:is_hidden() and state.saved_osc_visibility or 'never' + mp.command_native({'script-message', 'osc-visibility', v, ''}) +end + +function rt.toggle_menu() + osd:toggle_hidden() + + if state.saved_osc_visibility ~= 'never' then + rt.set_osc_visibility() + end + + input.set_key_bindings() +end + return rt |
