From c9c271f7950f85f98e5b4a8a8ff0cb011dc62a27 Mon Sep 17 00:00:00 2001 From: mpeter50 <83356418+mpeter50@users.noreply.github.com> Date: Wed, 19 Mar 2025 00:54:28 +0000 Subject: [PATCH] select copy tool by session type the former code selected xclip on wayland, and so copying was not working. keep former code too for compatibility --- copyStuff.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/copyStuff.lua b/copyStuff.lua index 44f93ac..4ef8378 100644 --- a/copyStuff.lua +++ b/copyStuff.lua @@ -30,6 +30,24 @@ local function command_exists(cmd) end local function get_clipboard_cmd() + -- attempt to decide by current session's type + -- The environment variable is not a Freedesktop standard, but a Systemd one. For possible values see `man 8 pam_systemd` + local session_type = os.getenv("XDG_SESSION_TYPE") + if session_type == "wayland" then + if command_exists("wl-copy") then + return "wl-copy" + else + mp.msg.error("MPV is running in a wayland environment, but suitable command was not found") + end + elseif session_type == "x11" then + if command_exists("xclip") then + return "xclip -silent -in -selection clipboard" + else + mp.msg.error("MPV is running in an X11 environment, but suitable command was not found") + end + end + + -- fallback to whatever is available if command_exists("xclip") then return "xclip -silent -in -selection clipboard" elseif command_exists("wl-copy") then