|
1 | | -NAME = 'mpv-screenshot.png' |
| 1 | +NAME = 'mpv-screenshot.jpeg' |
2 | 2 |
|
3 | | -if package.config:sub(1, 1) ~= '/' then -- Windows |
| 3 | +if package.config:sub(1, 1) == '\\' then -- Windows |
4 | 4 | SHOT = os.getenv('TEMP')..'\\'..NAME |
5 | 5 | CMD = { |
6 | | - 'powershell', '-NoProfile', '-Command', |
7 | | - string.format([[& { |
| 6 | + 'powershell', '-NoProfile', '-Command', ([[& { |
8 | 7 | Add-Type -Assembly System.Windows.Forms; |
9 | 8 | Add-Type -Assembly System.Drawing; |
10 | 9 | $shot = [Drawing.Image]::FromFile(%q); |
11 | 10 | [Windows.Forms.Clipboard]::SetImage($shot); |
12 | | - }]], SHOT) |
| 11 | + }]]):format(SHOT) |
13 | 12 | } |
14 | 13 | else -- Unix |
15 | 14 | SHOT = '/tmp/'..NAME |
16 | 15 | -- os.getenv('OSTYPE') doesn't work |
17 | 16 | local ostype = io.popen('printf "$OSTYPE"', 'r'):read() |
18 | 17 | if ostype:sub(1, 6) == 'darwin' then -- MacOS |
19 | 18 | CMD = { |
20 | | - 'osascript', '-e', string.format([[¬ |
| 19 | + 'osascript', '-e', ([[¬ |
21 | 20 | set the clipboard to ( ¬ |
22 | | - read (POSIX file %q) as «class PNG» ¬ |
| 21 | + read (POSIX file %q) as JPEG picture ¬ |
23 | 22 | ) ¬ |
24 | | - ]], SHOT) |
| 23 | + ]]):format(SHOT) |
25 | 24 | } |
26 | 25 | 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 |
28 | 31 | end |
29 | 32 | end |
30 | 33 |
|
31 | 34 | function clipshot(arg) |
32 | 35 | return function() |
33 | 36 | mp.commandv('screenshot-to-file', SHOT, arg) |
34 | 37 | 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) |
36 | 39 | end) |
37 | 40 | end |
38 | 41 | end |
|
0 commit comments