ImageGrab.grabclipboard() screen stealing issue on Wayland
Hey, this is a little out of my scope of understanding but the project maintainer of owocr thinks the issue may lie with Pillow.
What did you do?
I attempted to run owocr, an OCR program that scans images on your clipboard in order to OCR them, and then pastes them through a websocket. It constantly monitors the clipboard for images, and uses pillow to grab images from the clipboard.
I reported this issue here and the maintainer thinks it may be an issue with ImageGrab.grabclipboard() and Wayland. That repository is located below:
https://github.com/AuroraWright/owocr/issues/38
What did you expect to happen?
I expected the images be copied to my clipboard and processed as text, which it does succeed on doing, but not steal focus constantly.
What actually happened?
On X11, the behavior works fine, but on Wayland no key presses will be made but it will behave almost as if you're mashing esc at light speed. For instance, if you open your start menu, it will instantly close it, or if you try to click your URL bar it'll immediately behave as though you hit esc. I ran "show me the keys" to see if it was spamming some sort of input but doesn't seem to be hitting any keys.
It does actually successfully monitor the clipboard and allow owocr to grab images and process them, but just makes the rest of the system mostly unusable until it stops doing so. If I pause the clipboard monitoring in owocr, or remove ImageGrab.grabclipboard() from the program's run.py ( https://github.com/AuroraWright/owocr/blob/master/owocr/run.py#L171 ) it no longer exhibits the behavior.
What are your OS, Python and Pillow versions?
- OS: Arch-64 (KDE Plasma)
- Python: 3.12.3
- Pillow: 12.0.0
Python executable is /home/nw5k/owocr/bin/python3
Environment Python files loaded from /home/nw5k/owocr
System Python files loaded from /home/nw5k/.pyenv/versions/3.12.3
--------------------------------------------------------------------
Python Pillow modules loaded from /home/nw5k/owocr/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /home/nw5k/owocr/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.0.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.14.1
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.3.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1, compiled for zlib-ng 2.2.5
--- LIBTIFF support ok, loaded 4.7.1
--- RAQM (Bidirectional Text) support ok, loaded 0.10.3, fribidi 1.0.16, harfbuzz 12.1.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
https://github.com/AuroraWright/owocr/tree/master is where the program is located, please let me know if a gif or something would be helpful as I'm not sure I've explained the issue sufficiently.