From 5197977a26f03a5fe72c98f47078d4171723bc57 Mon Sep 17 00:00:00 2001 From: iliayar Date: Fri, 4 Aug 2023 02:32:14 +0300 Subject: [PATCH 1/7] feat nix: Add nix flake --- .gitignore | 2 ++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 27 ++++++++++++++++++++++++ poetry.lock | 8 +++++++ 4 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 poetry.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e8862c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Nix +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8d25f52 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1685573264, + "narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "380be19fbd2d9079f677978361792cb25e8a3635", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-22.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ee0ead0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,27 @@ +{ + description = "pyprland"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + { + packages = rec { + pyprland = pkgs.poetry2nix.mkPoetryApplication { + projectDir = ./.; + python = pkgs.python310; + }; + default = pyprland; + }; + } + ); +} diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..2ddd539 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,8 @@ +package = [] + +[metadata] +lock-version = "1.1" +python-versions = "^3.10" +content-hash = "53f2eabc9c26446fbcc00d348c47878e118afc2054778c3c803a0a8028af27d9" + +[metadata.files] From ecfade18ab0e94a85b554f06536f833057d2b777 Mon Sep 17 00:00:00 2001 From: iliayar Date: Fri, 4 Aug 2023 20:17:47 +0300 Subject: [PATCH 2/7] feat scratchpads: adjust size, position for monitor --- pyprland/plugins/scratchpads.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pyprland/plugins/scratchpads.py b/pyprland/plugins/scratchpads.py index e7b37f3..65242a8 100644 --- a/pyprland/plugins/scratchpads.py +++ b/pyprland/plugins/scratchpads.py @@ -381,6 +381,9 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring wrkspc = monitor["activeWorkspace"]["id"] + size = item.conf.get("size") + position = item.conf.get("position") + self.transitioning_scratches.add(uid) await hyprctl(f"moveworkspacetomonitor special:scratch_{uid} {monitor['name']}") await hyprctl(f"movetoworkspacesilent {wrkspc},{addr}") @@ -390,5 +393,23 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring await fn(monitor, item.client_info, addr, margin) await hyprctl(f"focuswindow {addr}") + + if size: + # NOTE: Format for size is "X_SIZE Y_SIZE" + # X_SIZE, Y_SIZE is percentage of monitor size + x_size_p, y_size_p = map(int, size.split()) + x_size, y_size = int(monitor["width"] * x_size_p / 100), int(monitor["height"] * y_size_p / 100) + + await hyprctl(f"resizewindowpixel exact {x_size} {y_size},{addr}") + + if position: + # NOTE: Format for position is "X_POS Y_POS" + # X_POS, Y_POS is percentage of monitor size from top left corner + x_pos_p, y_pos_p = map(int, position.split()) + x_pos, y_pos = int(monitor["width"] * x_pos_p / 100), int(monitor["height"] * y_pos_p / 100) + x_pos_abs, y_pos_abs = x_pos + monitor["x"], y_pos + monitor["y"] + + await hyprctl(f"movewindowpixel exact {x_pos_abs} {y_pos_abs},{addr}") + await asyncio.sleep(0.2) # ensure some time for events to propagate self.transitioning_scratches.discard(uid) From d0fcbf123fd0ce40f995bebde7108300a5fe38c8 Mon Sep 17 00:00:00 2001 From: iliayar Date: Sun, 6 Aug 2023 17:09:50 +0300 Subject: [PATCH 3/7] refactor scratchpads: size, position percentage --- pyprland/plugins/scratchpads.py | 47 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/pyprland/plugins/scratchpads.py b/pyprland/plugins/scratchpads.py index 65242a8..c203b4b 100644 --- a/pyprland/plugins/scratchpads.py +++ b/pyprland/plugins/scratchpads.py @@ -381,9 +381,6 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring wrkspc = monitor["activeWorkspace"]["id"] - size = item.conf.get("size") - position = item.conf.get("position") - self.transitioning_scratches.add(uid) await hyprctl(f"moveworkspacetomonitor special:scratch_{uid} {monitor['name']}") await hyprctl(f"movetoworkspacesilent {wrkspc},{addr}") @@ -394,22 +391,46 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring await hyprctl(f"focuswindow {addr}") + size = self._convert_coords(item.conf.get("size"), monitor) if size: - # NOTE: Format for size is "X_SIZE Y_SIZE" - # X_SIZE, Y_SIZE is percentage of monitor size - x_size_p, y_size_p = map(int, size.split()) - x_size, y_size = int(monitor["width"] * x_size_p / 100), int(monitor["height"] * y_size_p / 100) - + x_size, y_size = size await hyprctl(f"resizewindowpixel exact {x_size} {y_size},{addr}") + position = self._convert_coords(item.conf.get("position"), monitor) if position: - # NOTE: Format for position is "X_POS Y_POS" - # X_POS, Y_POS is percentage of monitor size from top left corner - x_pos_p, y_pos_p = map(int, position.split()) - x_pos, y_pos = int(monitor["width"] * x_pos_p / 100), int(monitor["height"] * y_pos_p / 100) + x_pos, y_pos = position x_pos_abs, y_pos_abs = x_pos + monitor["x"], y_pos + monitor["y"] - await hyprctl(f"movewindowpixel exact {x_pos_abs} {y_pos_abs},{addr}") await asyncio.sleep(0.2) # ensure some time for events to propagate self.transitioning_scratches.discard(uid) + + def _convert_coords(self, coords, monitor): + """ + Converts a string like "X Y" to coordinates relative to monitor + Supported formats for X, Y: + - Percentage: "V%". V in [0; 100] + + Example: + "10% 20%", monitor 800x600 => 80, 120 + """ + + if not coords: + return None + + def convert(s, dim): + if s[-1] == "%": + p = int(s[:-1]) + if p < 0 or p > 100: + raise Exception(f"Percentage must be in range [0; 100], got {p}") + return int(monitor[dim] * p / 100) + else: + raise Exception(f"Unsupported format for dimension {dim} size, got {s}") + + try: + x_str, y_str = coords.split() + + return convert(x_str, "width"), convert(y_str, "height") + except Exception as e: + self.log.error(f"Failed to read coordinates: {e}") + return None From 121c11c26bf6e5dba97711049c3e32fcff42ab21 Mon Sep 17 00:00:00 2001 From: iliayar Date: Sun, 24 Sep 2023 14:44:10 +0300 Subject: [PATCH 4/7] feat scratchpads: Support monitor scale --- pyprland/plugins/scratchpads.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyprland/plugins/scratchpads.py b/pyprland/plugins/scratchpads.py index c203b4b..ddcb6f1 100644 --- a/pyprland/plugins/scratchpads.py +++ b/pyprland/plugins/scratchpads.py @@ -423,7 +423,8 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring p = int(s[:-1]) if p < 0 or p > 100: raise Exception(f"Percentage must be in range [0; 100], got {p}") - return int(monitor[dim] * p / 100) + scale = float(monitor["scale"]) + return int(monitor[dim] / scale * p / 100) else: raise Exception(f"Unsupported format for dimension {dim} size, got {s}") From 2b722a39b098c99180c4e99031cc2aae459c7ec6 Mon Sep 17 00:00:00 2001 From: iliayar Date: Sun, 24 Sep 2023 14:48:06 +0300 Subject: [PATCH 5/7] feat nix: Update nixpkgs to 23.05 --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index 8d25f52..6067f6e 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1685573264, - "narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=", + "lastModified": 1695416179, + "narHash": "sha256-610o1+pwbSu+QuF3GE0NU5xQdTHM3t9wyYhB9l94Cd8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "380be19fbd2d9079f677978361792cb25e8a3635", + "rev": "715d72e967ec1dd5ecc71290ee072bcaf5181ed6", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-22.05", + "ref": "nixos-23.05", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index ee0ead0..b60c2b8 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; - nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; }; outputs = { self, nixpkgs, flake-utils, ... }: From 8c7ad933ab112729a3334db96249551ed2d8387b Mon Sep 17 00:00:00 2001 From: iliayar Date: Tue, 17 Oct 2023 03:50:03 +0300 Subject: [PATCH 6/7] fix scratchapds: rework _convert_coords --- pyprland/plugins/scratchpads.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyprland/plugins/scratchpads.py b/pyprland/plugins/scratchpads.py index ddcb6f1..5c8ba0b 100644 --- a/pyprland/plugins/scratchpads.py +++ b/pyprland/plugins/scratchpads.py @@ -391,14 +391,14 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring await hyprctl(f"focuswindow {addr}") - size = self._convert_coords(item.conf.get("size"), monitor) + size = item.conf.get("size") if size: - x_size, y_size = size + x_size, y_size = self._convert_coords(size, monitor) await hyprctl(f"resizewindowpixel exact {x_size} {y_size},{addr}") - position = self._convert_coords(item.conf.get("position"), monitor) + position = item.conf.get("position") if position: - x_pos, y_pos = position + x_pos, y_pos = self._convert_coords(position, monitor) x_pos_abs, y_pos_abs = x_pos + monitor["x"], y_pos + monitor["y"] await hyprctl(f"movewindowpixel exact {x_pos_abs} {y_pos_abs},{addr}") @@ -415,8 +415,7 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring "10% 20%", monitor 800x600 => 80, 120 """ - if not coords: - return None + assert coords, "coords must be non null" def convert(s, dim): if s[-1] == "%": @@ -434,4 +433,4 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring return convert(x_str, "width"), convert(y_str, "height") except Exception as e: self.log.error(f"Failed to read coordinates: {e}") - return None + raise e From 2074554268098f951359fbba9075b9a10771a741 Mon Sep 17 00:00:00 2001 From: iliayar Date: Tue, 17 Oct 2023 03:53:46 +0300 Subject: [PATCH 7/7] fix: remove poetry.lock --- poetry.lock | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 poetry.lock diff --git a/poetry.lock b/poetry.lock deleted file mode 100644 index 2ddd539..0000000 --- a/poetry.lock +++ /dev/null @@ -1,8 +0,0 @@ -package = [] - -[metadata] -lock-version = "1.1" -python-versions = "^3.10" -content-hash = "53f2eabc9c26446fbcc00d348c47878e118afc2054778c3c803a0a8028af27d9" - -[metadata.files]