kamui-fin / gazou

Japanese and Chinese OCR for Linux & Windows
GNU General Public License v3.0
85 stars 13 forks source link

Wayland support #6

Closed xrishox closed 2 years ago

xrishox commented 3 years ago

With wayland being the future and all major desktops shipping wayland by default now it seems like wayland support would be a pretty important feature to support. I'm not sure if you are interested in supporting this or if the tools exist for wayland to properly support this tool, but it would be really nice if possible.

kamui-fin commented 3 years ago

Thanks for the suggestion. I'll start looking into this

kamui-fin commented 3 years ago

It looks like Wayland does not support applications registering their own global hotkeys as a security measure. Only the Wayland compositor is able to do this. I assume this is to guard against key-loggers. So, a workaround would be to have the users manually register the hotkeys in the compositor configuration and have it operate the gazou CLI. I'll make the hotkey listener and GUI a compile-time option for gazou to compile on Wayland systems.

xrishox commented 3 years ago

nice. thanks a lot! i'm not sure if you are going to need to implement something for being able to select/draw and use clipboard on wayland or if the libraries you are already using for this sort of thing already support it. stuff like xdotool and xclip are probably going to be broken. though i'm not exactly sure which libraries you are using. maybe it's all already managed by tesseract or something.

kamui-fin commented 2 years ago

Hey, sorry for the delay. Wayland support should be up now, so check out the readme for instructions on setting it up. Essentially, I made X11Extras an optional dependency and added additional features to the CLI, so it has all the functionality of the GUI now. Let me know if anything doesn't work properly.

xrishox commented 2 years ago

when I try to install it with DGUI=OFF I get this output

[anonymous@toolbox build]$ sudo make install [ 9%] Automatic MOC and UIC for target gazou [ 9%] Built target gazou_autogen [ 18%] Building CXX object CMakeFiles/gazou.dir/src/main.cpp.o /var/home/anonymous/Downloads/Save/gazou/src/main.cpp:13:10: fatal error: QHotkey: No such file or directory 13 | #include | ^~~~~ compilation terminated. make[2]: [CMakeFiles/gazou.dir/build.make:97: CMakeFiles/gazou.dir/src/main.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:111: CMakeFiles/gazou.dir/all] Error 2 make: *** [Makefile:136: all] Error 2

compiling in the traditional way appears to work fine. (with dgui=on)

kamui-fin commented 2 years ago

Ah right, forgot to get rid of the #include. Please try again with the latest source.

xrishox commented 2 years ago

on arch using kde I get this output: requestActivate() called for QWidgetWindow(0x562c83be19e0, name="SelectorWidgetClassWindow") which has Qt::WindowDoesNotAcceptFocus set.

and the transparent selection window comes up. I can highlight an area just fine. it doesn't appear to grab anything though. it doesn't output anything anywhere and i don't see anything in my clipboard.

When I tried to run it on arch running gnome on wayland it gave me a generic qt gnome wayland complaint that can supposedly be be solved by modifying an environment variable. Exporting that variable doesn't fix anything. It still outputs an error. I had the same issue on Ubuntu 21.10 running gnome. On fedora running gnome on wayland it gave me a different error, but I'm pretty sure that was a fedora issue.

I'm not sure if I'm missing a dependency or something. I will say that everything worked fine under x11 so if it is a missing dependency it would have to be something related to wayland I'm assuming. I have wl-clipboard installed if that matters.

edit: this is the error I get on gnome on ubuntu and arch:

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
requestActivate() called for  QWidgetWindow(0x561881c1e1c0, name="SelectorWidgetClassWindow")  which has Qt::WindowDoesNotAcceptFocus set.

anonymous@anonymous-ubuntu-desktop:~$ QT_QPA_PLATFORM=wayland gazou -h
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
QSocketNotifier: Can only be used with threads started with QThread
requestActivate() called for  QWidgetWindow(0x5611fb523580, name="SelectorWidgetClassWindow")  which has Qt::WindowDoesNotAcceptFocus set.
kamui-fin commented 2 years ago

On arch, do you have qt5-wayland installed?

xrishox commented 2 years ago

yes i do. i actually daily drive kde so I imagine all of my qt dependencies should be okay. for the most part i live in fedora kinoite (kde's silverblue) but alternatively i have a kde arch install for situations where silverblue is problematic. i just happened to test gnome as well since i wasn't sure if it was an issue with kwin or something since gnome is farther along in their wayland journey. x11 gazou works just fine under both kinoite and arch.

it's worth noting that when i have gazou process an image under wayland it works fine.

[anonymous@anonymous-arch-desktop ~]$ gazou -h /home/anonymous/Pictures/Screenshot_20211114_125049.png 
: 昨日 す:
[anonymous@anonymous-arch-desktop ~]$ QT_QPA_PLATFORM=wayland gazou -h
requestActivate() called for  QWidgetWindow(0x5575310aa000, name="SelectorWidgetClassWindow")  which has Qt::WindowDoesNotAcceptFocus set.
[anonymous@anonymous-arch-desktop ~]$ gazou -h
requestActivate() called for  QWidgetWindow(0x55d6dfa69d90, name="SelectorWidgetClassWindow")  which has Qt::WindowDoesNotAcceptFocus set.

list of all of my qt packages (you can go to q to see the ones that are explicitly named qt

[anonymous@anonymous-arch-desktop ~]$ pacman -Qs qt
local/appstream-qt 0.14.6-1
    Qt5 interface for AppStream
local/attica 5.88.0-1 (kf5)
    Qt library that implements the Open Collaboration Services API
local/avahi 0.8+22+gfd482a7-1
    Service Discovery for Linux using mDNS/DNS-SD -- compatible with Bonjour
local/bluez-qt 5.88.0-1 (kf5)
    Qt wrapper for Bluez 5 DBus API
local/karchive 5.88.0-1 (kf5)
    Qt 5 addon providing access to numerous types of archives
local/kcolorpicker 0.1.6-1
    Qt based Color Picker with popup menu
local/kcoreaddons 5.88.0-1 (kf5)
    Addons to QtCore
local/kdbusaddons 5.88.0-1 (kf5)
    Addons to QtDBus
local/kdsoap 2.0.0-1
    Qt-based client-side and server-side SOAP component
local/kguiaddons 5.88.0-1 (kf5)
    Addons to QtGui
local/kirigami2 5.88.0-1 (kf5)
    A QtQuick based components set
local/kitemmodels 5.88.0-1 (kf5)
    Models for Qt Model/View system
local/kitemviews 5.88.0-1 (kf5)
    Widget addons for Qt Model/View
local/kquickcharts 5.88.0-1 (kf5)
    A QtQuick plugin providing high-performance charts
local/kwayland 5.88.0-1 (kf5)
    Qt-style Client and Server library wrapper for the Wayland libraries
local/kwidgetsaddons 5.88.0-1 (kf5)
    Addons to QtWidgets
local/layer-shell-qt 5.23.3-1 (plasma)
    Qt component to allow applications to make use of the Wayland wl-layer-shell protocol
local/libaccounts-qt 1.16-3
    Qt-based client library for accessing the online accounts database
local/libdbusmenu-qt5 0.9.3+16.04.20160218-6
    A library that provides a Qt implementation of the DBusMenu spec
local/modemmanager-qt 5.88.0-1 (kf5)
    Qt wrapper for ModemManager DBus API
local/networkmanager-qt 5.88.0-1 (kf5)
    Qt wrapper for NetworkManager API
local/phonon-qt5 4.11.1-2
    The multimedia framework by KDE
local/phonon-qt5-gstreamer 4.10.0-2
    Phonon GStreamer backend for Qt5
local/plasma-framework 5.88.0-1 (kf5)
    Plasma library and runtime components based upon KF5 and Qt5
local/plasma-integration 5.23.3-1 (plasma)
    Qt Platform Theme integration plugins for the Plasma workspaces
local/polkit-qt5 0.114.0-1
    A library that allows developers to access PolicyKit API with a nice Qt-style API
local/poppler-qt5 21.11.0-1
    Poppler Qt5 bindings
local/pulseaudio-qt 1.3-1
    Qt bindings for libpulse
local/pyside2 5.15.2-3 (qt qt5)
    Enables the use of Qt5 APIs in Python applications
local/python-pyqt5 5.15.6-2 (pyqt5)
    A set of Python bindings for the Qt5 toolkit
local/python-pyqt5-sip 12.9.0-1
    The sip module support for PyQt5
local/python-pyqt5-webengine 5.15.5-1 (pyqt5)
    Python bindings for QtWebEngine
local/qbittorrent 4.3.9-1
    An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar.
local/qca-qt5 2.3.4-1
    Qt Cryptographic Architecture
local/qqc2-desktop-style 5.88.0-1 (kf5)
    A style for Qt Quick Controls 2 to make it follow your desktop theme
local/qt5-3d 5.15.2+kde+r33-1 (qt qt5)
    C++ and QML APIs for easy inclusion of 3D graphics
local/qt5-base 5.15.2+kde+r254-1 (qt qt5)
    A cross-platform application and UI framework
local/qt5-charts 5.15.2-1 (qt qt5)
    Provides a set of easy to use chart components
local/qt5-connectivity 5.15.2-1 (qt qt5)
    Provides access to Bluetooth hardware
local/qt5-datavis3d 5.15.2-1 (qt qt5)
    Qt Data Visualization module
local/qt5-declarative 5.15.2+kde+r39-1 (qt qt5)
    Classes for QML and JavaScript languages
local/qt5-doc 5.15.2-2 (qt qt5)
    A cross-platform application and UI framework (Documentation)
local/qt5-examples 5.15.2-2 (qt qt5)
    Examples and demos from qt5 documentation
local/qt5-gamepad 5.15.2-1 (qt qt5)
    Adds support for getting events from gamepad devices
local/qt5-graphicaleffects 5.15.2-1 (qt qt5)
    Graphical effects for use with Qt Quick 2
local/qt5-imageformats 5.15.2-1 (qt qt5)
    Plugins for additional image formats: TIFF, MNG, TGA, WBMP
local/qt5-location 5.15.2-3 (qt qt5)
    Provides access to position, satellite and area monitoring classes
local/qt5-lottie 5.15.2-1 (qt qt5)
    A family of player software for a certain json-based file format for describing 2d vector graphics animations
local/qt5-multimedia 5.15.2-1 (qt qt5)
    Classes for audio, video, radio and camera functionality
local/qt5-networkauth 5.15.2-1 (qt qt5)
    Network authentication module
local/qt5-purchasing 5.15.2-1 (qt qt5)
    Qt In-App Purchasing API
local/qt5-quick3d 5.15.2+kde+r19-1 (qt qt5)
    Qt module and API for defining 3D content in Qt Quick
local/qt5-quickcontrols 5.15.2-1 (qt qt5)
    Reusable Qt Quick based UI controls to create classic desktop-style user interfaces
local/qt5-quickcontrols2 5.15.2+kde+r8-1 (qt qt5)
    Next generation user interface controls based on Qt Quick
local/qt5-quicktimeline 5.15.2-1 (qt qt5)
    Qt module for keyframe-based timeline construction
local/qt5-remoteobjects 5.15.2-1 (qt qt5)
    Inter-process communication (IPC) module developed for Qt
local/qt5-script 5.15.7-1 (qt qt5)
    Classes for making Qt applications scriptable. Provided for Qt 4.x compatibility
local/qt5-scxml 5.15.2-1 (qt qt5)
    Static and runtime integration of SCXML models into Qt code
local/qt5-sensors 5.15.2-1 (qt qt5)
    Provides access to sensor hardware and motion gesture recognition
local/qt5-serialbus 5.15.2-1 (qt qt5)
    Qt module for general purpose serial bus access
local/qt5-serialport 5.15.2-1 (qt qt5)
    Provides access to hardware and virtual serial ports
local/qt5-speech 5.15.2-1 (qt qt5)
    Qt module to make text to speech and speech recognition easy
local/qt5-svg 5.15.2+kde+r13-1 (qt qt5)
    Classes for displaying the contents of SVG files
local/qt5-tools 5.15.2+kde+r17-4 (qt qt5)
    A cross-platform application and UI framework (Development Tools, QtHelp)
local/qt5-translations 5.15.2+kde+r20-1 (qt qt5)
    A cross-platform application and UI framework (Translations)
local/qt5-virtualkeyboard 5.15.2+kde+r4-1 (qt qt5)
    Virtual keyboard framework
local/qt5-wayland 5.15.2+kde+r36-1 (qt qt5)
    Provides APIs for Wayland
local/qt5-webchannel 5.15.2-1 (qt qt5)
    Provides access to QObject or QML objects from HTML clients for seamless integration of Qt applications with HTML/JavaScript clients
local/qt5-webengine 5.15.7-1 (qt qt5)
    Provides support for web applications using the Chromium browser project
local/qt5-webglplugin 5.15.2-1 (qt qt5)
    QPA plugin for running an application via a browser using streamed WebGL commands
local/qt5-websockets 5.15.2+kde+r4-1 (qt qt5)
    Provides WebSocket communication compliant with RFC 6455
local/qt5-webview 5.15.2-1 (qt qt5)
    Provides a way to display web content in a QML application
local/qt5-x11extras 5.15.2-1 (qt qt5)
    Provides platform-specific APIs for X11
local/qt5-xmlpatterns 5.15.2-1 (qt qt5)
    Support for XPath, XQuery, XSLT and XML schema validation
local/qt5ct 1.5-1
    Qt5 Configuration Utility
local/signond 8.60-3
    A D-Bus service which performs user authentication on behalf of its clients
local/sonnet 5.88.0-1 (kf5)
    Spelling framework for Qt5
local/xdg-desktop-portal-kde 5.23.3-1 (plasma)
    A backend implementation for xdg-desktop-portal using Qt/KF5
local/zbar 0.23.1-7
    Application and library for reading bar codes from various sources

output on arch kde x11:

[anonymous@anonymous-arch-desktop ~]$ gazou -h
requestActivate() called for  QWidgetWindow(0x55d56d4184e0, name="SelectorWidgetClassWindow")  which has Qt::WindowDoesNotAcceptFocus set.
昨日
kamui-fin commented 2 years ago

Hmm, It may actually be because Wayland does not allow applications to run QScreen::grabWindow on areas that they do not actually own. Instead, it seems that I should be pulling the desktop pixmap from a compositor-specific API (eg. dbus for gnome and sway). I will look into implementing this, so in the meanwhile you can use something like grim to handle the screenshot part and run gazou on the resulting image.

xrishox commented 2 years ago

so in the meanwhile you can use something like grim to handle the screenshot part and run gazou on the resulting image.

Wow I'm almost ashamed that I never came up with this totally obvious solution on my own. What a great idea. Thanks a lot! For anyone wanting an easy to use command for doing this on kde under wayland you can do this:

spectacle  -rbo /tmp/ocr.png && gazou -h /tmp/ocr.png | wl-copy

this will basically do exactly what gazou is already doing, including the region select stuff.

there's probably a gnome equivalent. I've come up with my own rube goldberg machine for making this work with silverblue and toolbox, but it seems like that wouldn't be particularly useful to anyone else.

grim probably works with sway, but appears to be incompatible with both kde and gnome as best i can tell.

kamui-fin commented 2 years ago

Somewhat late but finally got around to implementing native Wayland screenshots, so I'm going to go ahead and close this issue. Let me know if any issue pops up.

mobedoor commented 2 years ago

Hello. Gazou's screenshot functionality is not working for me on wayland. I'm on Arch and using sway.

Yuri-K7 commented 8 months ago

Oh so you've actually already implemented xdg portals here, would you consider to also implement the xdg global shortcuts portal here or in QHotkey ? It's been supported on kde plasma since 5.27.