From 4b7a373b7127fad52ee2b10a6b5f1b4b48b35ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Luca=20Lagm=C3=B6ller?= Date: Sat, 14 May 2022 19:02:40 +0200 Subject: [PATCH] Fixed several KDE specific scaling issues --- VERSION | 2 +- .../environment/desktop_environment/kde.py | 40 +++++++++++-------- rescreen/lib/utils/paths.py | 14 +++++-- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index e6d5cb8..e4c0d46 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 \ No newline at end of file +1.0.3 \ No newline at end of file diff --git a/rescreen/lib/environment/desktop_environment/kde.py b/rescreen/lib/environment/desktop_environment/kde.py index 24af339..c557c49 100644 --- a/rescreen/lib/environment/desktop_environment/kde.py +++ b/rescreen/lib/environment/desktop_environment/kde.py @@ -53,13 +53,15 @@ def pre_xrandr_hook(cls, scaling: float) -> bool: return True if not cls.get_user_confirmation( - "To apply the display configuration, a session restart is required. " - "All currently open applications will be closed. Continue?" + "To apply the display configuration, a session restart is required. " + "All currently open applications will be closed. Continue?" ): return False config_dir = cls.CONFIG_DIR.expanduser() + scaling = int(scaling) + subprocess.call( [ "kwriteconfig5", @@ -87,8 +89,8 @@ def pre_xrandr_hook(cls, scaling: float) -> bool: "", ] ) - .decode("utf-8") - .strip() + .decode("utf-8") + .strip() ) new_screen_scale_factors = "" @@ -127,28 +129,32 @@ def pre_xrandr_hook(cls, scaling: float) -> bool: ] ) - process = subprocess.Popen( - ["xrdb", "-quiet", "-merge", "-nocpp"], stdout=PIPE, stdin=PIPE, stderr=STDOUT - ) - process.communicate(input=f"Xft.dpi: {font_dpi}\n".encode("utf-8")) - if scaling == 2: cls.set_cursor_size(36) else: cls.set_cursor_size(24) + process = subprocess.Popen( + ["xrdb", "-quiet", "-merge", "-nocpp"], stdout=PIPE, stdin=PIPE, stderr=STDOUT + ) + + process.communicate(input=f"Xft.dpi: {font_dpi}\n".encode("utf-8")) + cls.logout() return False @classmethod def post_xrandr_hook(cls, scaling: float) -> None: - subprocess.call(["killall", "plasmashell"]) - - env = os.environ - env["PLASMA_USE_QT_SCALING"] = "1" + try: + subprocess.run("killall plasmashell", check=True, shell=True) + except subprocess.CalledProcessError as e: + if e.returncode == 1: + pass # No plasmashell found + else: + raise e - subprocess.call(["kstart5", "plasmashell"], env=env) + subprocess.run("PLASMA_USE_QT_SCALING=1 kstart5 plasmashell", check=True, shell=True) @classmethod def get_ui_scale(cls) -> float: @@ -166,11 +172,11 @@ def get_ui_scale(cls) -> float: "1", ] ) - .decode("utf-8") - .strip() + .decode("utf-8") + .strip() ) return float(scale_factor) @classmethod def get_available_ui_scales(cls) -> List[float]: - return [1, 1.25, 1.5, 1.75, 2] + return [1, 2] diff --git a/rescreen/lib/utils/paths.py b/rescreen/lib/utils/paths.py index 2d477dd..238f215 100644 --- a/rescreen/lib/utils/paths.py +++ b/rescreen/lib/utils/paths.py @@ -4,16 +4,24 @@ def get_config_paths(suffix: Optional[Path] = None) -> Tuple[Path, List[Path]]: + config_home = "~/.config" + if "XDG_CONFIG_HOME" in os.environ: + config_home = os.environ["XDG_CONFIG_HOME"] + + config_dirs = "/etc/xdg" + if "XDG_CONFIG_DIRS" in os.environ: + config_dirs = os.environ["XDG_CONFIG_DIRS"] + config_home_path = ( - Path(os.environ.setdefault("XDG_CONFIG_HOME", "~/.config")).expanduser().absolute() - / "rescreen" + Path(config_home).expanduser().absolute() + / "rescreen" ) if suffix: config_home_path /= suffix config_paths = [] - for path_str in os.environ.setdefault("XDG_CONFIG_DIRS", "/etc/xdg").split(":"): + for path_str in config_dirs.split(":"): path = Path(path_str).expanduser().absolute() / "rescreen" if suffix: path /= suffix