flathub / io.mpv.Mpv

Home Page:https://flathub.org/apps/details/io.mpv.Mpv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use kscreen-doctor in the Flatpak

fighuass opened this issue · comments

I use this script to automatically adjust my refresh rate in mpv, but it doesn't work in the Flatpak: https://gitlab.com/smaniottonicola/mpv-kscreen-doctor

Terminal output:

[mpv_kscreen_doctor] 
[mpv_kscreen_doctor] stack traceback:
[mpv_kscreen_doctor]    ...me/.var/app/io.mpv.Mpv/config/mpv/mpv-kscreen-doctor.lua:37: in function 'get_available'
[mpv_kscreen_doctor]    ...me/.var/app/io.mpv.Mpv/config/mpv/mpv-kscreen-doctor.lua:154: in function 'prop'
[mpv_kscreen_doctor]    mp.defaults:409: in function 'handler'
[mpv_kscreen_doctor]    mp.defaults:512: in function 'call_event_handlers'
[mpv_kscreen_doctor]    mp.defaults:554: in function 'dispatch_events'
[mpv_kscreen_doctor]    mp.defaults:505: in function <mp.defaults:504>
[mpv_kscreen_doctor]    [C]: at 0x559011e3b640
[mpv_kscreen_doctor]    [C]: at 0x559011e3c2c0
[mpv_kscreen_doctor] Lua error: ...me/.var/app/io.mpv.Mpv/config/mpv/mpv-kscreen-doctor.lua:37: Could not detect display config

it needs kscreen-doctor access in the system. as it is sandboxed, the lua script needs to access the kscreen-doctor command on the host, this can be achieved using flatpak-spawn --host kcreen-doctor. Wherever host's kscreen-doctor is required, change that to flatpak-spawn --host kscreen-doctor in the lua script.

before that make sure to run mpv flaptak with host access and filesystem access.
flatpak run --filesystem=host --talk-name=org.freedesktop.Flatpak --command=bash io.mpv.Mpv

A sandbox application should not access the host system, but since you require it. you may override the permissions:

flatpak override --user --filesystem=host --talk-name=org.freedesktop.Flatpak io.mpv.Mpv

you can reset it (undo the above access) with flatpak override --reset io.mpv.Mpv

Thanks, that worked!

To anyone else reading this, I changed the .lua as follows:

  1. Within the get_available function, change:
local command = {
	name = "subprocess",
	playback_only = false,
	capture_stdout = true,
	args = {
		"kscreen-doctor",
		"-j",
	},
}

to

local command = {
	name = "subprocess",
	playback_only = false,
	capture_stdout = true,
	args = {
		"flatpak-spawn",
		"--host",
		"kscreen-doctor",
		"-j",
	},
}
  1. Within the kscreen_doctor_set_mode function, change:
local command = {
	name = "subprocess",
	playback_only = false,
	capture_stderr = true, -- prints here, don't want to log that
	args = {
		"kscreen-doctor",
	},
}

to


local command = {
	name = "subprocess",
	playback_only = false,
	capture_stderr = true, -- prints here, don't want to log that
	args = {
		"flatpak-spawn",
		"--host",
		"kscreen-doctor",
	},
}