Moved mpv sockets to the user runtime folder defined in `XDG_RUNTIME_DIR` with a fallback to `/tmp`, also added a lua script to properly handle env variables in the mpv config for the `input-ipc-server` property

master
Meliurwen 3 years ago
parent 7f31ce2d43
commit 60e3bca73c
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 2
      i3/.config/i3/scripts/webcam-toggle.sh
  2. 3
      mpv/.config/mpv/mpv.conf
  3. 40
      mpv/.config/mpv/scripts/set_input-ipc-server.lua
  4. 2
      polybar/.config/polybar/config
  5. 6
      polybar/.config/polybar/scripts/mpv.sh

@ -2,7 +2,7 @@
pkill -f /dev/video || \
mpv --title="mpv-floating-window" \
--input-ipc-server="$HOME/.cache/mpvsocket-webcam" \
--no-config \
--no-osc \
--no-input-default-bindings \
--input-conf=/dev/null \

@ -15,7 +15,8 @@ hwdec=vaapi
[default]
# In order to communicate to the Polybar's mpv module
input-ipc-server=~/.cache/mpvsocket
#input-ipc-server=${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/mpv/main.sock
script-opts=input-ipc-server="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/mpv/main.sock"
save-position-on-quit

@ -0,0 +1,40 @@
--[[--
@script input-ipc-server-plus
@author Meliurwen
@license GPLv3
This script makes possible the use of environment variables for the
`input-ipc-server` property in the config file.
The script triggers if and only if no `input-ipc-server` is set and the
homonymous `input-ipc-server` option in `script-opts` is set in its place.
A typical use case is to set the path with the env variable XDG_RUNTIME_DIR
and a respective fallback path like this:
@usage script-opts=input-ipc-server="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/mpv/main.sock"
It's worth to note that it's possible to include subshells in order to compute
part (or the whole) path. A typical use case, like in the just showed example
is to stick to POSIX standards, using `$(id -u)` instead of `$USER`.
]]
local function isempty(s)
return s == nil or s == ""
end
local function os_cmd_return(command)
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
return string.format(result:match("^%s*(.+)"))
end
local ipc_opt_par = mp.get_property("input-ipc-server")
local ipc_opt_raw = mp.get_opt("input-ipc-server")
if isempty(ipc_opt_par) and not isempty(ipc_opt_raw) then
local ipc_opt_fullpath = os_cmd_return('printf "%s" ' .. ipc_opt_raw)
local ipc_opt_dirpath = os_cmd_return("dirname " .. ipc_opt_fullpath)
os.execute("mkdir -p " .. ipc_opt_dirpath)
mp.set_property("input-ipc-server", ipc_opt_fullpath)
end

@ -264,7 +264,7 @@ interval = 1
format = <label>
label = %output%
click-left = printf "%s\n" "cycle pause" | socat - ~/.cache/mpvsocket
click-left = printf "%s\n" "cycle pause" | socat - $XDG_RUNTIME_DIR/mpv/main.sock
[module/bluetooth]

@ -3,9 +3,9 @@
# Note: In order to use this script you have to tell to mpv to enable a socket.
# Two ways are possible to achieve this:
# 1) Use the argument --input-ipc-server when you launch it. For example:
# `mpv --input-ipc-server=~/.cache/mpvsocket Your.Video.File.mkv`
# `mpv --input-ipc-server=mpvsocket Your.Video.File.mkv`
# 2) Add the line below when in the `mpv.conf` file:
# `input-ipc-server=~/.cache/mpvsocket`
# `input-ipc-server=mpvsocket`
time_to_human(){
if [ "$API_OUTPUT" -gt 3600 ]; then
@ -19,7 +19,7 @@ time_to_human(){
fi
}
MPV_SOCKET_PATH="$HOME/.cache/mpvsocket"
MPV_SOCKET_PATH="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/mpv/main.sock"
OUTPUT=""

Loading…
Cancel
Save