Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing osc keyboard control. #8814

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DOCS/man/osc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ Configurable Options

Set to ``yes`` to reduce festivity (i.e. disable santa hat in December.)

``controlkbd``
Default: yes

Deliver control of some keys for the osc to handle, making possible to
eg. disable osd-on-seek and use the osc bar for it.

Script Commands
~~~~~~~~~~~~~~~

Expand Down
10 changes: 5 additions & 5 deletions player/lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ local default_section = "input_dispatch_" .. mp.script_name
-- Note: the bindings are not active by default. Use enable_key_bindings().
--
-- list is an array of key bindings, where each entry is an array as follow:
-- {key, callback_press, callback_down, callback_up}
-- {key, callback_press/callback_repeat, callback_down, callback_up}
-- key is the key string as used in input.conf, like "ctrl+a"
--
-- callback can be a string too, in which case the following will be added like
Expand All @@ -99,10 +99,10 @@ function mp.set_key_bindings(list, section, flags)
local event = state:sub(1, 1)
local is_mouse = state:sub(2, 2) == "m"
local def = (is_mouse and "u") or "d"
if event == "r" then
return
end
if event == "p" and cb then
--if event == "r" then
-- return
--end
if event == "p" or event == "r" and cb then
cb()
elseif event == "d" and cb_down then
cb_down()
Expand Down
34 changes: 34 additions & 0 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ local user_opts = {
windowcontrols = "auto", -- whether to show window controls
windowcontrols_alignment = "right", -- which side to show window controls on
greenandgrumpy = false, -- disable santa hat
controlkbd = true, -- take control of some keyboard keys(eg. seek keys)
}

-- read options from config and command-line
Expand Down Expand Up @@ -2481,6 +2482,25 @@ function process_event(source, what)
end
end

--process events from the keyboard
--generally this is supposed to immitate mpv's own behaviour on the osc
function process_event_key(key)
show_osc()
if key == "right" then
mp.command("seek 5")
end
if key == "left" then
mp.command("seek -5")
end
if key == "up" then
mp.command("seek 60")
end
if key == "down" then
mp.command("seek -60")
end
request_tick()
end


local logo_lines = {
-- White border
Expand Down Expand Up @@ -2664,6 +2684,20 @@ mp.set_key_bindings({
}, "showhide_wc", "force")
do_enable_keybindings()

--keyboard bindings
if user_opts.controlkbd then
mp.set_key_bindings({
{"right", function(e) process_event_key("right") end,
function(e) process_event_key("right") end},
{"left", function(e) process_event_key("left") end,
function(e) process_event_key("left") end},
{"up", function(e) process_event_key("up") end,
function(e) process_event_key("up") end},
{"down", function(e) process_event_key("down") end,
function(e) process_event_key("down") end},
}, "osc-kbd", "force")
mp.enable_key_bindings("osc-kbd")
end
--mouse input bindings
mp.set_key_bindings({
{"mbtn_left", function(e) process_event("mbtn_left", "up") end,
Expand Down