mirror of
https://github.com/Derisis13/dotfiles.git
synced 2025-12-06 19:32:50 +01:00
feat: mpv config from various scripts
This commit is contained in:
131
mpv/scripts/mpv-gnome-inhibit.lua
Executable file
131
mpv/scripts/mpv-gnome-inhibit.lua
Executable file
@@ -0,0 +1,131 @@
|
||||
--[[
|
||||
|
||||
Prevent the screen from blanking while a video is playing.
|
||||
|
||||
This script is a workaround for the GNOME+Wayland issue documented in the
|
||||
[Disabling Screensaver] section of the mpv manual, and depends on
|
||||
gnome-session-inhibit (usually provided by the gnome-session package) to set up
|
||||
the inhibitors.
|
||||
|
||||
|
||||
# CAVEATS
|
||||
|
||||
This is not (yet?) a foolproof solution.
|
||||
|
||||
At this time GNOME's implementation of the Inhibit protocol does not support the
|
||||
SimluateUserActivity method:
|
||||
|
||||
dbus-send --print-reply --session \
|
||||
--dest=org.gnome.ScreenSaver --type=method_call \
|
||||
/org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity
|
||||
|
||||
So there seems to be no way to "poke" the system with a heartbeat to extend to
|
||||
idle timeout for a bit and prevent blanking.
|
||||
|
||||
This means that inhibitors have to be installed, then removed when mpv exits.
|
||||
|
||||
The current implementation handles this via another application, which should
|
||||
alwasy be available on GNOME+Wayland desktops (because provided by gnome-session
|
||||
itself): gnome-session-inhibit.
|
||||
|
||||
Executing gnome-session-inhibit to handle this is not ideal because if mpv does
|
||||
not exit cleanly, gnome-session-inhibit is not necessarily killed (it can get
|
||||
ophaned, and gets adopted by the init process), leaving the inhibitors intact
|
||||
with no easy way for the user to figure it out.
|
||||
|
||||
Ideally this script should open a DBus session directly to handle the
|
||||
inhibitors, as they would be removed if the DBus session gets disconnected (cf.
|
||||
[Inhibit's documentation][Inhibit]):
|
||||
|
||||
> Applications should invoke [Inhibit ()] when they begin an operation that
|
||||
> should not be interrupted [...] When the application completes the operation
|
||||
> it should call Uninhibit() or disconnect from the session bus.
|
||||
|
||||
This is how [other applications] do it.
|
||||
|
||||
But really, the only secure way to handle this would be with a heartbeat to
|
||||
regularly reset the idle timer, i.e. what SimulateUserActivity is supposed to
|
||||
provide. Especially for a core security feature such as screen locking (cf.
|
||||
xscreensaver's author [rant][jwz]).
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
- Do not inhibit for audio-only playback, only for video
|
||||
- Fix inhibitors not removed when mpv does not terminate gracefully, e.g. with
|
||||
`kill -9 <pid>`, either by having a wrapper around gnome-session-inhibit
|
||||
checking the parent PID (see https://stackoverflow.com/a/2035683), or by
|
||||
interfacing with dbus to open a session that gets disconnected if mpv
|
||||
terminates uncleanly (hopefully), or ...
|
||||
- Investigate whether the 'playback-abort' event should be handled
|
||||
- Only inhibit when the player is visible
|
||||
|
||||
|
||||
[Disabling Screensaver]: https://mpv.io/manual/master/#disabling-screensaver
|
||||
[Inhibit]: https://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html#org.gnome.SessionManager.Inhibit
|
||||
[jwz]: https://www.jwz.org/blog/2021/01/i-told-you-so-2021-edition/
|
||||
[other applications]: https://unix.stackexchange.com/a/438335
|
||||
|
||||
]]
|
||||
|
||||
|
||||
local mp = require 'mp'
|
||||
local msg = require 'mp.msg'
|
||||
|
||||
local cookie
|
||||
|
||||
local function handle_inhibit(_, paused)
|
||||
if paused and cookie then
|
||||
mp.abort_async_command(cookie)
|
||||
cookie = nil
|
||||
msg.debug('inhibit off')
|
||||
elseif not paused and not cookie then
|
||||
cookie = mp.command_native_async(
|
||||
{
|
||||
name = 'subprocess',
|
||||
args = {
|
||||
'gnome-session-inhibit',
|
||||
'--inhibit-only',
|
||||
'--inhibit', 'idle',
|
||||
'--app-id', 'mpv',
|
||||
'--reason', 'video-playing',
|
||||
},
|
||||
|
||||
-- `playback_only = true` does not kill the command when
|
||||
-- playback is paused (i.e. "pause" is still "playback == true")
|
||||
-- but also kills it immediately the first time.
|
||||
-- So we need to handle the paused state ourselves.
|
||||
playback_only = false,
|
||||
|
||||
-- If not captured, mpv will just forward everything to stdout
|
||||
-- and stderr. Setting capture_stdXXX with capture_size = 0 will
|
||||
-- ensure that the command's output is discarded.
|
||||
capture_stdout = true,
|
||||
capture_stderr = true,
|
||||
capture_size = 0,
|
||||
},
|
||||
|
||||
-- Should be optional according to the doc, but I get an error if I
|
||||
-- don't provide a function: attempt to call local 'cb' (a nil value)
|
||||
function() end
|
||||
)
|
||||
|
||||
msg.debug('inhibit on')
|
||||
end
|
||||
end
|
||||
|
||||
mp.observe_property('stop-screensaver', 'bool', function(_, enable)
|
||||
if enable then
|
||||
mp.observe_property('pause', 'bool', handle_inhibit)
|
||||
msg.debug('inhibit handling on')
|
||||
else
|
||||
mp.unobserve_property('pause', 'bool', handle_inhibit)
|
||||
msg.debug('inhibit handling off')
|
||||
|
||||
if cookie then
|
||||
mp.abort_async_command(cookie)
|
||||
cookie = nil
|
||||
msg.debug('inhibit off')
|
||||
end
|
||||
end
|
||||
end)
|
||||
123
mpv/scripts/playlistmanager.conf
Executable file
123
mpv/scripts/playlistmanager.conf
Executable file
@@ -0,0 +1,123 @@
|
||||
#### ------- Mpv-Playlistmanager configuration ------- ####
|
||||
|
||||
#### ------- FUNCTIONAL ------- ####
|
||||
|
||||
#navigation keybindings force override only while playlist is visible
|
||||
#if "no" then you can display the playlist by any of the navigation keys
|
||||
dynamic_binds=yes
|
||||
|
||||
#dynamic keybind keys, they should not be re-bound in input.conf
|
||||
#to bind multiple keys separate them by a space
|
||||
key_moveup=UP
|
||||
key_movedown=DOWN
|
||||
key_movepageup=PGUP
|
||||
key_movepagedown=PGDWN
|
||||
key_movebegin=HOME
|
||||
key_moveend=END
|
||||
key_selectfile=RIGHT LEFT
|
||||
key_unselectfile=
|
||||
key_playfile=ENTER
|
||||
key_removefile=BS
|
||||
key_closeplaylist=ESC
|
||||
|
||||
#json format for replacing, check .lua for explanation
|
||||
#example json=[{"ext":{"all":true},"rules":[{"_":" "}]},{"ext":{"mp4":true,"mkv":true},"rules":[{"^(.+)%..+$":"%1"},{"%s*[%[%(].-[%]%)]%s*":""},{"(%w)%.(%w)":"%1 %2"}]},{"protocol":{"http":true,"https":true},"rules":[{"^%a+://w*%.?":""}]}]
|
||||
#empty for no replace
|
||||
filename_replace=
|
||||
|
||||
#filetypes to search from directory
|
||||
loadfiles_filetypes=["jpg","jpeg","png","tif","tiff","gif","webp","svg","bmp","mp3","wav","ogm","flac","m4a","wma","ogg","opus","mkv","avi","mp4","ogv","webm","rmvb","flv","wmv","mpeg","mpg","m4v","3gp"]
|
||||
|
||||
#loadfiles at startup if there is 0 or 1 items in playlist, if 0 uses worḱing dir for files
|
||||
#requires --idle=yes or --idle=once if 0 files in playlist
|
||||
loadfiles_on_start=no
|
||||
|
||||
#sort playlist on mpv start
|
||||
sortplaylist_on_start=no
|
||||
|
||||
#sort playlist when any files are added to playlist after initial load
|
||||
sortplaylist_on_file_add=no
|
||||
|
||||
#yes: use alphanumerical sort comparison(nonpadded numbers in order), no: use normal lua string comparison
|
||||
alphanumsort=yes
|
||||
|
||||
#linux | windows | auto
|
||||
system=auto
|
||||
|
||||
#Use ~ for home directory. Leave as empty to use mpv/playlists
|
||||
playlist_savepath=
|
||||
|
||||
#save playlist automatically after current file was unloaded
|
||||
save_playlist_on_file_end=no
|
||||
|
||||
#2 shows playlist, 1 shows current file(filename strip applied), 0 shows nothing
|
||||
show_playlist_on_fileload=0
|
||||
|
||||
#sync cursor when file is loaded from outside reasons(file-ending, playlist-next shortcut etc.)
|
||||
sync_cursor_on_load=yes
|
||||
|
||||
#playlist open key will toggle visibility instead of refresh
|
||||
open_toggles=yes
|
||||
|
||||
#allow the playlist cursor to loop from end to start and vice versa
|
||||
loop_cursor=yes
|
||||
|
||||
#### ------- VISUAL ------- ####
|
||||
|
||||
#prefer to display titles for following files: "all", "url", "none". Sorting still uses filename
|
||||
prefer_titles=url
|
||||
|
||||
#call youtube-dl to resolve the titles of urls in the playlist
|
||||
resolve_titles=no
|
||||
|
||||
#playlist timeout on inactivity, with high value on this open_toggles is good to be yes
|
||||
playlist_display_timeout=5
|
||||
|
||||
#amount of entries to show before slicing. Optimal value depends on font/video size etc.
|
||||
showamount=16
|
||||
|
||||
#font size scales by window, if no then needs larger font and padding sizes
|
||||
scale_playlist_by_window=yes
|
||||
#playlist ass style overrides
|
||||
#example {\fnUbuntu\fs10\b0\bord1} equals: font=Ubuntu, size=10, bold=no, border=1
|
||||
#read http://docs.aegisub.org/3.2/ASS_Tags/ for reference of tags
|
||||
#no values defaults to OSD settings in mpv.conf
|
||||
style_ass_tags=
|
||||
#paddings for top left corner
|
||||
text_padding_x=10
|
||||
text_padding_y=30
|
||||
|
||||
#set title of window with stripped name
|
||||
set_title_stripped=no
|
||||
title_prefix=
|
||||
title_suffix= - mpv
|
||||
|
||||
#slice long filenames, and how many chars to show
|
||||
slice_longfilenames=no
|
||||
slice_longfilenames_amount=70
|
||||
|
||||
#Playing header. One newline will be added after the string.
|
||||
#%mediatitle or %filename = title or name of playing file
|
||||
#%pos = position of playing file
|
||||
#%cursor = position of navigation
|
||||
#%plen = playlist lenght
|
||||
#%N = newline
|
||||
playlist_header=[%cursor/%plen]
|
||||
|
||||
#Playlist file templates
|
||||
#%pos = position of file with leading zeros
|
||||
#%name = title or name of file
|
||||
#%N = newline
|
||||
#you can also use the ass tags mentioned above. For example:
|
||||
# selected_file={\c&HFF00FF&}➔ %name | to add a color for selected file. However, if you
|
||||
# use ass tags you need to reset them for every line (see https://github.com/jonniek/mpv-playlistmanager/issues/20)
|
||||
normal_file=○ %name
|
||||
hovered_file=● %name
|
||||
selected_file=➔ %name
|
||||
playing_file=▷ %name
|
||||
playing_hovered_file=▶ %name
|
||||
playing_selected_file=➤ %name
|
||||
|
||||
#what to show when playlist is truncated
|
||||
playlist_sliced_prefix=...
|
||||
playlist_sliced_suffix=...
|
||||
1040
mpv/scripts/playlistmanager.lua
Executable file
1040
mpv/scripts/playlistmanager.lua
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user