From 6d3fe8997bd3dd284a4815b736f10a29a43b8cf0 Mon Sep 17 00:00:00 2001 From: amix3 <112207774+amix3@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:28:43 +0330 Subject: [PATCH] add wayland autodetection. --- script-opts/SmartCopyPaste.conf | 6 +++++ scripts/SmartCopyPaste.lua | 45 +++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/script-opts/SmartCopyPaste.conf b/script-opts/SmartCopyPaste.conf index 1a1eb30..1e24247 100644 --- a/script-opts/SmartCopyPaste.conf +++ b/script-opts/SmartCopyPaste.conf @@ -10,6 +10,12 @@ linux_copy=xclip -silent -selection clipboard -in #--paste command that will be used in Linux. OR write a different command linux_paste=xclip -selection clipboard -o +#--copy command that will be used in Linux wayland. OR write a different command +wayland_copy=wl-copy + +#--paste command that will be used in Linux wayland. OR write a different command +wayland_paste=wl-paste + #--copy command that will be used in MAC. OR write a different command mac_copy=pbcopy diff --git a/scripts/SmartCopyPaste.lua b/scripts/SmartCopyPaste.lua index 41af740..1adb0d9 100644 --- a/scripts/SmartCopyPaste.lua +++ b/scripts/SmartCopyPaste.lua @@ -13,6 +13,8 @@ local o = { device = 'auto', --'auto' is for automatic device detection, or manually change to: 'windows' or 'mac' or 'linux' linux_copy = 'xclip -silent -selection clipboard -in', --copy command that will be used in Linux. OR write a different command linux_paste = 'xclip -selection clipboard -o', --paste command that will be used in Linux. OR write a different command + wayland_copy = 'wl-copy', --copy command that will be used in Linux Wayland. OR write a different command + wayland_paste = 'wl-paste', --paste command that will be used in Linux Wayland. OR write a different command mac_copy = 'pbcopy', --copy command that will be used in MAC. OR write a different command mac_paste = 'pbpaste', --paste command that will be used in MAC. OR write a different command windows_copy = 'powershell', --'powershell' is for using windows powershell to copy. OR write the copy command, e.g: ' clip' @@ -110,15 +112,35 @@ for i = 1, #o.specific_time_attributes do end end -if not o.device or o.device == 'auto' then - if os.getenv('windir') ~= nil then - o.device = 'windows' - elseif os.execute '[ -d "/Applications" ]' == 0 and os.execute '[ -d "/Library" ]' == 0 or os.execute '[ -d "/Applications" ]' == true and os.execute '[ -d "/Library" ]' == true then - o.device = 'mac' - else - o.device = 'linux' - end +function detect_device() + local gpu_context = mp.get_property_native("current-gpu-context") + +-- msg.info("GPU Context: " .. tostring(gpu_context)) + + if not o.device or o.device == 'auto' then + if os.getenv('windir') ~= nil then + o.device = 'windows' + elseif gpu_context == "wayland" or gpu_context == "waylandvk" then + o.device = 'wayland' + elseif (os.execute '[ -d "/Applications" ]' == 0 and os.execute '[ -d "/Library" ]' == 0) or + (os.execute '[ -d "/Applications" ]' == true and os.execute '[ -d "/Library" ]' == true) then + o.device = 'mac' + else + o.device = 'linux' + end + end +-- msg.info("Detected Device: " .. tostring(o.device)) +end + +function check_gpu_context() + local gpu_context = mp.get_property_native("current-gpu-context") + if gpu_context then + detect_device() + end end +-- Observe changes to the "current-gpu-context" property +mp.observe_property("current-gpu-context", "string", check_gpu_context) + function starts_protocol(tab, val) for index, value in ipairs(tab) do @@ -292,6 +314,9 @@ function get_clipboard() if o.device == 'linux' then clipboard = os.capture(o.linux_paste) return clipboard + elseif o.device == 'wayland' then + clipboard = os.capture(o.wayland_paste) + return clipboard elseif o.device == 'windows' then if o.windows_paste == 'powershell' then local args = { @@ -327,6 +352,10 @@ function set_clipboard(text) pipe = io.popen(o.linux_copy, 'w') pipe:write(text) pipe:close() + elseif o.device == 'wayland' then + pipe = io.popen(o.wayland_copy, 'w') + pipe:write(text) + pipe:close() elseif o.device == 'windows' then if o.windows_copy == 'powershell' then local res = utils.subprocess({ args = {