From 6193f47b2313d4b019bf323a3e9d85feafd3b1c2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 16 Jun 2024 20:13:02 -0400 Subject: [PATCH] Additional fixes for WSLg and Ubuntu 20.04 --- README.md | 3 ++- scripts/install.ps1 | 11 ++--------- src/AutoSplit.py | 10 ++++++---- src/region_selection.py | 8 +------- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c040aeaf..ab5cc259 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,8 @@ To understand how to use AutoSplit and how it works in-depth, please read the [t ### Compatibility - Windows 10 and 11. -- Linux (still in early development) +- Linux (still in early development) + - Should work on Ubuntu 20.04+ (Only tested on Ubuntu 22.04) - Wayland is not currently supported - WSL2/WSLg requires an additional Desktop Environment, external X11 server, and/or systemd - Python 3.10+ (Not required for normal use. Refer to the [build instructions](/docs/build%20instructions.md) if you'd like run the application directly in Python). diff --git a/scripts/install.ps1 b/scripts/install.ps1 index f7f9c709..9144f38e 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -34,8 +34,8 @@ $dev = If ($Env:GITHUB_JOB -eq 'Build') { '' } Else { '-dev' } If ($IsLinux) { If (-not $Env:GITHUB_JOB -or $Env:GITHUB_JOB -eq 'Build') { sudo apt-get update - # python3-tk for splash screen the rest for PySide6 - sudo apt-get install -y python3-pip python3-tk libegl1 libxkbcommon0 + # python3-tk for splash screen, libxcb-cursor-dev for QT_QPA_PLATFORM=xcb, the rest for PySide6 + sudo apt-get install -y python3-pip python3-tk libxcb-cursor-dev libegl1 libxkbcommon0 # having issues with npm for pyright, maybe let users take care of it themselves? (pyright from pip) } } @@ -52,13 +52,6 @@ If ($IsLinux) { # Even then, PyPI with Pillow>=7.2.0 will install 0.1.3 instead of 0.1.5 &"$python" -m pip install PyAutoGUI "D3DShot>=0.1.5 ; sys_platform == 'win32'" --no-deps --upgrade -# Because Ubuntu 22.04 is forced to use an older version of PySide6, we do a dirty typing patch -# https://bugreports.qt.io/browse/QTBUG-114635 -If ($IsLinux) { - $libPath = &"$python" -c 'import PySide6 as _; print(_.__path__[0])' - (Get-Content "$libPath/QtWidgets.pyi").replace('-> Tuple:', '-> Tuple[str, ...]:') | - Set-Content "$libPath/QtWidgets.pyi" -} # Uninstall optional dependencies if PyAutoGUI or D3DShot was installed outside this script # PyScreeze -> pyscreenshot -> mss deps call SetProcessDpiAwareness, used to be installed on Windows # Pillow, pygetwindow, pymsgbox, pytweening, MouseInfo are picked up by PySide6 diff --git a/src/AutoSplit.py b/src/AutoSplit.py index 55d596f8..42d66bd0 100644 --- a/src/AutoSplit.py +++ b/src/AutoSplit.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 +import os import sys # Prevent PyAutoGUI and pywinctl from setting Process DPI Awareness, which Qt tries to do then throws warnings about it. @@ -15,14 +16,16 @@ ctypes.windll.shcore.SetProcessDpiAwareness = ( # pyright: ignore[reportAttributeAccessIssue] lambda _: None # pyright: ignore[reportUnknownLambdaType] ) +if sys.platform == "linux": + # Fixes "undefined symbol: wl_proxy_marshal_flags": https://bugreports.qt.io/browse/QTBUG-114635 + os.environ.setdefault("QT_QPA_PLATFORM", "xcb") -import os import signal from collections.abc import Callable from copy import deepcopy from time import time from types import FunctionType -from typing import NoReturn, cast +from typing import NoReturn import cv2 from cv2.typing import MatLike @@ -967,8 +970,7 @@ def set_preview_image(qlabel: QLabel, image: MatLike | None): capture = image qimage = QtGui.QImage( - # Try to update PySide6, see https://bugreports.qt.io/browse/QTBUG-114635 - cast(bytes, capture.data) if sys.platform == "linux" else capture.data, + capture.data, width, height, width * channels, diff --git a/src/region_selection.py b/src/region_selection.py index fc99c553..656f0e35 100644 --- a/src/region_selection.py +++ b/src/region_selection.py @@ -1,4 +1,3 @@ -import os import sys from math import ceil from typing import TYPE_CHECKING @@ -8,6 +7,7 @@ from cv2.typing import MatLike, Point from PySide6 import QtCore, QtGui, QtWidgets from PySide6.QtTest import QTest +from pywinctl import getTopWindowAt from typing_extensions import override import error_messages @@ -33,12 +33,6 @@ if sys.platform == "linux": from Xlib.display import Display - # This variable may be missing in desktopless environment. x11 | wayland - os.environ.setdefault("XDG_SESSION_TYPE", "x11") - -# Must come after the linux XDG_SESSION_TYPE environment variable is set -from pywinctl import getTopWindowAt - if TYPE_CHECKING: from AutoSplit import AutoSplit