Merge pull request #15 from iliayar/main
Scratchpads: Dynamic position and size, depending on monitor
This commit is contained in:
commit
cfe4995e32
4 changed files with 132 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Nix
|
||||
result
|
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
|
@ -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": 1695416179,
|
||||
"narHash": "sha256-610o1+pwbSu+QuF3GE0NU5xQdTHM3t9wyYhB9l94Cd8=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "715d72e967ec1dd5ecc71290ee072bcaf5181ed6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-23.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
|
||||
}
|
27
flake.nix
Normal file
27
flake.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
description = "pyprland";
|
||||
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.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;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
|
@ -407,5 +407,47 @@ class Extension(Plugin): # pylint: disable=missing-class-docstring
|
|||
await fn(monitor, item.client_info, addr, margin)
|
||||
|
||||
await hyprctl(f"focuswindow {addr}")
|
||||
|
||||
size = item.conf.get("size")
|
||||
if size:
|
||||
x_size, y_size = self._convert_coords(size, monitor)
|
||||
await hyprctl(f"resizewindowpixel exact {x_size} {y_size},{addr}")
|
||||
|
||||
position = item.conf.get("position")
|
||||
if 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}")
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
assert coords, "coords must be non null"
|
||||
|
||||
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}")
|
||||
scale = float(monitor["scale"])
|
||||
return int(monitor[dim] / scale * 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}")
|
||||
raise e
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue