diff --git a/cq_editor/__main__.py b/cq_editor/__main__.py index c56f87c8..217de2e4 100644 --- a/cq_editor/__main__.py +++ b/cq_editor/__main__.py @@ -1,3 +1,4 @@ +import os import sys import argparse @@ -5,7 +6,17 @@ NAME = "CQ-editor" -# need to initialize QApp here, otherewise svg icons do not work on windows +# Reorder QT_QPA_PLATFORM so Qt reaches a Wayland plugin only after everything +# else has failed to load, defaulting to xcb. OCCT does not yet support Wayland. +if sys.platform == "linux": + # Desktops such as COSMIC export QT_QPA_PLATFORM="wayland;xcb" session-wide, + # we want to respect this config as far as possible, without using wayland. + plugins = (os.environ.get("QT_QPA_PLATFORM") or "xcb").split(";") + os.environ["QT_QPA_PLATFORM"] = ";".join( + sorted(plugins, key=lambda plugin: plugin.startswith("wayland")) + ) + +# need to initialize QApp here, otherwise svg icons do not work on windows app = QApplication(sys.argv, applicationName=NAME) from .main_window import MainWindow diff --git a/cq_editor/widgets/occt_widget.py b/cq_editor/widgets/occt_widget.py index 195a5a51..2929fe8c 100755 --- a/cq_editor/widgets/occt_widget.py +++ b/cq_editor/widgets/occt_widget.py @@ -220,6 +220,7 @@ def _get_window_win(self, wid): def _get_window_linux(self, wid): + # X11 only as OCCT currently doesn't have wayland support from OCP.Xw import Xw_Window return Xw_Window(self.display_connection, int(wid)) diff --git a/run.py b/run.py index fbcd001e..a8bd2baf 100644 --- a/run.py +++ b/run.py @@ -1,11 +1,6 @@ import sys -import os import faulthandler -# OCP's Xw_Window requires an X11 window ID, so we force XCB so winId() is valid under Wayland/XWayland. -if sys.platform == "linux" and "QT_QPA_PLATFORM" not in os.environ: - os.environ["QT_QPA_PLATFORM"] = "xcb" - # PyInstaller with console=False sets sys.stdout/stderr to None on Windows if sys.stdout is None: sys.stdout = open("nul", "w")