From 7bc4a2c918b8f6eb7685f9fd0dd4b89e79248d8d Mon Sep 17 00:00:00 2001 From: Kat Inskip Date: Sat, 17 Feb 2024 10:37:03 -0800 Subject: [PATCH] feat: hyprland --- konawall/environment.py | 4 ++-- konawall/environments/hyprland.py | 16 ++++++++++++++++ konawall/gui.py | 10 +++++++--- package.nix | 5 ++++- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 konawall/environments/hyprland.py diff --git a/konawall/environment.py b/konawall/environment.py index 8fd6921..fcd7ecb 100644 --- a/konawall/environment.py +++ b/konawall/environment.py @@ -39,7 +39,7 @@ def detect_linux_environment(): elif desktop_session in modified_mapping: return modified_mapping[desktop_session] else: - UnsupportedPlatform(f"Desktop session {desktop_session} is not supported, sorry!") + return os.environ.get("XDG_CURRENT_DESKTOP").lower() def detect_environment(): if sys.platform == "linux": @@ -58,4 +58,4 @@ def set_environment_wallpapers(environment: str, files: list, displays: list): environment_handlers[f"{environment}_setter"](files, displays) logging.debug("Wallpapers set!") else: - UnsupportedPlatform(f"Environment {environment} is not supported, sorry!") \ No newline at end of file + UnsupportedPlatform(f"Environment {environment} is not supported, sorry!") diff --git a/konawall/environments/hyprland.py b/konawall/environments/hyprland.py new file mode 100644 index 0000000..846fadc --- /dev/null +++ b/konawall/environments/hyprland.py @@ -0,0 +1,16 @@ +import subprocess +import dbus +from konawall.module_loader import add_environment + +@add_environment("hyprland_setter") +def set_wallpapers(files: list, displays: list): + #[Monitor(x=0, y=0, width=1920, height=1080, width_mm=280, height_mm=160, name='eDP-1', is_primary=False), Monitor(x=1920, y=0, width=3840, height=2160, width_mm=600, height_mm=340, name='DP-3', is_primary=False)] + try: + subprocess.Popen(["killall", "swaybg"]) + time.sleep(0.005) + except Exception as e: + print(e) + for i in range(len(displays)): + display_name = displays[i].name + command = ["swww", "img", "-o", display_name, files[i]] + subprocess.run(command) diff --git a/konawall/gui.py b/konawall/gui.py index 4df3fef..3764479 100755 --- a/konawall/gui.py +++ b/konawall/gui.py @@ -17,10 +17,11 @@ from humanfriendly import format_timespan class Konawall(wx.adv.TaskBarIcon): def __init__(self, version, file_logger): + super().__init__() # Prevents it from closing before it has done any work on macOS - if wx.Platform == "__WXMAC__" or wx.Platform == "__WXGTK__": - self.hidden_frame = wx.Frame(None) - self.hidden_frame.Hide() + #if wx.Platform == "__WXMAC__" or wx.Platform == "__WXGTK__": + self.hidden_frame = wx.Frame(None) + self.hidden_frame.Hide() self.wallpaper_rotation_counter = 0 self.file_logger = file_logger @@ -29,6 +30,8 @@ class Konawall(wx.adv.TaskBarIcon): self.description_string = "A hopefully cross-platform service for fetching wallpapers and setting them." self.loaded_before = False + print(self.IsAvailable()) + print(self.IsOk()) # Call the super function, make sure that the type is the statusitem for macOS wx.adv.TaskBarIcon.__init__(self, wx.adv.TBI_CUSTOM_STATUSITEM) @@ -58,6 +61,7 @@ class Konawall(wx.adv.TaskBarIcon): # Set up the taskbar icon, menu, bindings, ... icon = self.generate_icon() self.SetIcon(icon, self.title_string) + self.hidden_frame.SetIcon(icon) self.create_menu() self.create_bindings() diff --git a/package.nix b/package.nix index 8e151db..5ce44aa 100644 --- a/package.nix +++ b/package.nix @@ -2,6 +2,7 @@ lib, buildPythonPackage, python311Packages, + psmisc }: let pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); poetryBlock = pyproject.tool.poetry; @@ -21,7 +22,9 @@ in dependencyNames = (lib.attrNames poetryBlock.dependencies) ++ ["dbus-python"]; dependencies = map (name: python311Packages.${name} or dependencyReplacements.${name}) dependencyNames; in - dependencies; + dependencies ++ [ + psmisc + ]; meta = with lib; { description = poetryBlock.description;