69 lines
2.1 KiB
Lua
69 lines
2.1 KiB
Lua
require "mp"
|
|
require "mp.msg"
|
|
|
|
-- Default settings
|
|
-- Can be overriden on the command line or via the config. file ~/.config/mpv/script-opts/delayed_quit.conf
|
|
-- delayed_quit_cpt=2
|
|
-- delayed_quit_activating_when_modifying=no
|
|
local settings = {
|
|
delayed_quit_cpt = 0,
|
|
delayed_quit_activating_when_modifying = true
|
|
}
|
|
(require "mp.options").read_options(settings, "delayed_quit")
|
|
local delayed_quit = false
|
|
local delayed_quit_cpt = settings.delayed_quit_cpt
|
|
|
|
-- Functions for the key bindings
|
|
function delayed_quit_decrease()
|
|
-- Decrease (minimum is 0)
|
|
delayed_quit_cpt = math.max(delayed_quit_cpt - 1, 0)
|
|
|
|
-- Eventually activate the delayed_quit
|
|
delayed_quit = delayed_quit or settings.delayed_quit_activating_when_modifying
|
|
|
|
delayed_quit_little_debug()
|
|
end
|
|
|
|
function delayed_quit_increase()
|
|
-- Increment the delayed counter
|
|
delayed_quit_cpt = delayed_quit_cpt + 1
|
|
|
|
-- Eventually activate the delayed_quit
|
|
delayed_quit = delayed_quit or settings.delayed_quit_activating_when_modifying
|
|
|
|
delayed_quit_little_debug()
|
|
end
|
|
|
|
function delayed_quit_switch()
|
|
delayed_quit = not delayed_quit
|
|
delayed_quit_little_debug()
|
|
end
|
|
|
|
-- Little debug
|
|
function delayed_quit_little_debug()
|
|
mp.osd_message((delayed_quit and "" or "(disabled) ") .. "Quitting after " .. delayed_quit_cpt .. " file(s).")
|
|
end
|
|
|
|
-- Hooks
|
|
function hook_should_we_quit()
|
|
if delayed_quit then
|
|
if delayed_quit_cpt <= 0 then
|
|
mp.command("quit")
|
|
|
|
-- Little debug
|
|
mp.msg.log("info", "As requested, quitting now.")
|
|
else
|
|
delayed_quit_cpt = delayed_quit_cpt - 1
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Register our little hook
|
|
mp.add_hook("on_after_end_file", 50, hook_should_we_quit)
|
|
|
|
-- Add the key binding
|
|
-- We add a name so a user can remap it in its input.conf like this :
|
|
-- y script-binding delayed_quit_switch
|
|
mp.add_key_binding("alt+q", "delayed_quit_switch", delayed_quit_switch)
|
|
mp.add_key_binding("alt+shift+q", "delayed_quit_increase", delayed_quit_increase)
|
|
mp.add_key_binding("alt+a", "delayed_quit_decrease", delayed_quit_decrease)
|