From b2b865a2cbbe3fc89e54bed4b280e5e1215f4bc3 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Mon, 23 Oct 2023 01:33:14 -0400 Subject: [PATCH] feat: add GOLDENDICT_FORCE_WAYLAND to force wayland --- src/main.cc | 11 +++++++---- src/ui/mainwindow.cc | 6 ++++++ website/docs/topic_wayland.md | 16 ++++++++++++++++ website/mkdocs.yml | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 website/docs/topic_wayland.md diff --git a/src/main.cc b/src/main.cc index 1b97425e..db8a24f6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -311,10 +311,13 @@ int main( int argc, char ** argv ) // GoldenDict use lots of X11 functions and it currently cannot work // natively on Wayland. This workaround will force GoldenDict to use // XWayland. - char * xdg_envc = getenv( "XDG_SESSION_TYPE" ); - QString xdg_session = xdg_envc ? QString::fromLatin1( xdg_envc ) : QString(); - if ( !QString::compare( xdg_session, QString( "wayland" ), Qt::CaseInsensitive ) ) { - setenv( "QT_QPA_PLATFORM", "xcb", 1 ); + + if ( qEnvironmentVariableIsEmpty( "GOLDENDICT_FORCE_WAYLAND" ) ) { + char * xdg_envc = getenv( "XDG_SESSION_TYPE" ); + QString xdg_session = xdg_envc ? QString::fromLatin1( xdg_envc ) : QString(); + if ( !QString::compare( xdg_session, QString( "wayland" ), Qt::CaseInsensitive ) ) { + setenv( "QT_QPA_PLATFORM", "xcb", 1 ); + } } #endif diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index a9d69aa6..771df2bb 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -2856,6 +2856,12 @@ void MainWindow::toggleMainWindow( bool onlyShow ) void MainWindow::installHotKeys() { +#if defined( Q_OS_LINUX ) + if ( !qEnvironmentVariableIsEmpty( "GOLDENDICT_FORCE_WAYLAND" ) ) { + return; + } +#endif + hotkeyWrapper.reset(); // Remove the old one if ( cfg.preferences.enableMainWindowHotkey || cfg.preferences.enableClipboardHotkey ) { diff --git a/website/docs/topic_wayland.md b/website/docs/topic_wayland.md new file mode 100644 index 00000000..dd8808db --- /dev/null +++ b/website/docs/topic_wayland.md @@ -0,0 +1,16 @@ +Environment variable `GOLDENDICT_FORCE_WAYLAND` can be used to force GD to run in Wayland mode, like `env GOLDENDICT_FORCE_WAYLAND=1 goldendict`. + +!!! danger "Don't use unless you know!" + This flag only guarantees GD to run in wayland mode and won't crash, but nothing more. + + Enable this will break scan popup, global hotkeys and probably other things. + +## Current reality + +!!! note "Help wanted" + Need help to redesign scan popup for wayland. + +Scan popup is implemented with `querying mouse cursor's position` and `setting a window's absolute global position`. +Wayland does not support both by design and philosophy. + +Wayland does not support registering global hotkeys until very recently, but a reasonable wayland desktop environment should provide some way to bind keys to commands globally. \ No newline at end of file diff --git a/website/mkdocs.yml b/website/mkdocs.yml index 4dde31fa..5a592294 100644 --- a/website/mkdocs.yml +++ b/website/mkdocs.yml @@ -44,6 +44,7 @@ nav: - Custom transliteration: topic_transliteration.md - Customize Dictionary: custom_dictionary.md - OCR Integration: howto/ocr.md + - Wayland/Linux: topic_wayland.md - Report Bugs & Feedbacks: feedbacks.md - Contributor Guides: - Developer: developer.md