Skip to content

add wayland autodetection. #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions script-opts/SmartCopyPaste.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 37 additions & 8 deletions scripts/SmartCopyPaste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down