Skip to content

Commit

Permalink
Merge pull request #1255 from shenlebantongying/force-wayland
Browse files Browse the repository at this point in the history
feat: add GOLDENDICT_FORCE_WAYLAND to force wayland (and get things broken)
  • Loading branch information
xiaoyifang authored Oct 23, 2023
2 parents 7823280 + b2b865a commit 919e948
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/ui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
16 changes: 16 additions & 0 deletions website/docs/topic_wayland.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions website/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 919e948

Please sign in to comment.