Skip to content

Commit 9b9ea6b

Browse files
feat(clipshot): support wl-clipboard
1 parent b461b50 commit 9b9ea6b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2019 ObserverOfTime
1+
Copyright (c) 2019-2020 ObserverOfTime
22

33
Permission to use, copy, modify, and/or distribute this software
44
for any purpose with or without fee is hereby granted.

clipshot.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1-
NAME = 'mpv-screenshot.png'
1+
NAME = 'mpv-screenshot.jpeg'
22

3-
if package.config:sub(1, 1) ~= '/' then -- Windows
3+
if package.config:sub(1, 1) == '\\' then -- Windows
44
SHOT = os.getenv('TEMP')..'\\'..NAME
55
CMD = {
6-
'powershell', '-NoProfile', '-Command',
7-
string.format([[& {
6+
'powershell', '-NoProfile', '-Command', ([[& {
87
Add-Type -Assembly System.Windows.Forms;
98
Add-Type -Assembly System.Drawing;
109
$shot = [Drawing.Image]::FromFile(%q);
1110
[Windows.Forms.Clipboard]::SetImage($shot);
12-
}]], SHOT)
11+
}]]):format(SHOT)
1312
}
1413
else -- Unix
1514
SHOT = '/tmp/'..NAME
1615
-- os.getenv('OSTYPE') doesn't work
1716
local ostype = io.popen('printf "$OSTYPE"', 'r'):read()
1817
if ostype:sub(1, 6) == 'darwin' then -- MacOS
1918
CMD = {
20-
'osascript', '-e', string.format([[¬
19+
'osascript', '-e', ([[¬
2120
set the clipboard to ( ¬
22-
read (POSIX file %q) as «class PNG» ¬
21+
read (POSIX file %q) as JPEG picture ¬
2322
) ¬
24-
]], SHOT)
23+
]]):format(SHOT)
2524
}
2625
else -- Linux/BSD
27-
CMD = {'xclip', '-sel', 'c', '-t', 'image/png', '-i', SHOT}
26+
if os.getenv('XDG_SESSION_TYPE') == 'wayland' then -- Wayland
27+
CMD = {'sh', '-c', ('wl-copy < %q'):format(SHOT)}
28+
else -- Xorg
29+
CMD = {'xclip', '-sel', 'c', '-t', 'image/jpeg', '-i', SHOT}
30+
end
2831
end
2932
end
3033

3134
function clipshot(arg)
3235
return function()
3336
mp.commandv('screenshot-to-file', SHOT, arg)
3437
mp.command_native_async({'run', unpack(CMD)}, function(suc, _, err)
35-
mp.osd_message(suc and 'Copied screenshot to clipboard' or err)
38+
mp.osd_message(suc and 'Copied screenshot to clipboard' or err)
3639
end)
3740
end
3841
end

0 commit comments

Comments
 (0)