hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.56k stars 439 forks source link

extremely lag when handle screenshot captured by spectacle and call hasClipboardFormat('image/png') #2377

Open LXYan2333 opened 1 year ago

LXYan2333 commented 1 year ago

Before creating a new issue, see list of known issues.

Describe the bug when I write a script to handle screenshot captured by KDE spectacle, I found it is extremely lag once I called hasClipboardFormat('image/png').

To Reproduce Steps to reproduce the behavior:

  1. write a automatic script like serverLog(hasClipboardFormat('image/png'))
  2. make a screenshot using spectacle. It is more noticeable if the screenshot resolution is high.
  3. press the buttom copy to clipboard
  4. notice the huge lag.

another minor problem

It is also kinda weired if I call

var format = dataFormats()
for (var i in format){
    serverLog(format[i])
}

with spectacle screenshot, it only print out 4 types (3 copyq and one ''image/png"), however if I call hasClipboardFormat('image/avif') it returns true.

code:

copyq:
if (isClipboard()) {
    var format = dataFormats()
    for (var i in format) {
        serverLog(format[i])
    }
    serverLog(format.length)
    serverLog(currentWindowTitle())
    serverLog('haspng')
    serverLog(hasClipboardFormat('image/png'))
    serverLog('hasavif')
    serverLog(hasClipboardFormat('image/avif'))
}

result:

Note: application/x-copyq-current-tab
Note: application/x-copyq-output-tab
Note: application/x-copyq-owner-window-title
Note: image/png
Note: 4   // there are more than 4 types. see screenshot below
Note: 
Note: haspng
Note: true
Note: hasavif
Note: true

Expected behavior

there should't be that huge lag.

and since it has image/avif format it should include in the dataFormats().

the existance of image/avif content can be verified with qdbus org.kde.KWin /KWin org.kde.KWin.showDebugConsole:

图片

Screenshots If applicable, add screenshots to help explain your problem.

Version, OS and Environment CopyQ Clipboard Manager 6.4.0 Qt: 5.15.8 KNotifications: 5.101.0 Compiler: GCC Arch: x86_64-little_endian-lp64 OS: Debian GNU/Linux 12 (bookworm)

Additional context KDE with wayland

LXYan2333 commented 1 year ago

It seems that, in the 'image/png' mimetype, spectacle append a lot of data after IEND i.e. the end of the png file. Is it possible to truncate it using copyq? I tried to use QByteArray::indexOf and QByteArray::truncate but they are not avaliable in copyq.

hluk commented 1 year ago

Call dataFormats() only returns the formats already fetched from the clipboard (available using data() function), i.e. the data that are used by commands and will be stored in a new item.

To get full format list in the clipboard, you can use:

formats = str(clipboard('?')).split('\n');

Not sure what causes the lag though. Even fetching larger amount of data from clipboard (specifically from the source app - Spectacle in this case) is usually fast without any noticeable lag.