Remove Python launcher and use the Rusty

This commit is contained in:
Victor Timofei 2023-06-14 16:32:15 +03:00
parent b3b3793fdf
commit 39bbf3529a
Signed by: vtimofei
GPG Key ID: B790DCEBE281403A
2 changed files with 1 additions and 129 deletions

View File

@ -1,128 +0,0 @@
#!/usr/bin/env python3
import subprocess
import json
from string import Template
import os
def panic(err):
import traceback
print(traceback.format_exc())
print(f"error {err}")
os._exit(1)
class Monitor:
id: int
name: str
width: int
height: int
def __init__(self, id: int, name: str, width: int, height: int):
self.id = id
self.name = name
self.width = width
self.height = height
def get_monitors() -> list[Monitor]:
ws = subprocess.run(
["hyprctl", "monitors", "-j"],
capture_output=True
)
_monitors = json.loads(ws.stdout)
ret = []
for m in _monitors:
ret.append(Monitor(
id=m["id"],
name=m["name"],
width=m["width"],
height=m["height"],
))
return ret
def temlate(source: str, monitor: Monitor, bar_name: str, home: str, base_dir: str) -> str:
height = int(monitor.height * .02)
return Template(source) \
.safe_substitute({
"monitor": monitor.id,
"monitor_name": monitor.name,
"bar_name": bar_name,
"home": home,
"base_dir": base_dir,
"height": height,
})
def generate_bar_config(monitor: Monitor, bar_name: str, home: str, base_dir: str, source_dir: str, dest_dir: str):
items = os.listdir(source_dir)
for item in items:
if os.path.isdir(f"{source_dir}/{item}"):
os.makedirs(f"{dest_dir}/{item}")
generate_bar_config(monitor, bar_name, home, base_dir, f"{source_dir}/{item}", f"{dest_dir}/{item}")
elif os.path.isfile(f"{source_dir}/{item}"):
data = ""
try:
with open(f"{source_dir}/{item}", "r") as fp:
data = fp.read()
except Exception as e:
panic(e)
data = temlate(
data,
monitor,
bar_name,
home,
base_dir
)
try:
with open(f"{dest_dir}/{item}", "w") as fp:
fp.write(data)
except Exception as e:
panic(e)
def launch_bar(monitor: Monitor, wayland_display: str):
bar_name = f"bar-{wayland_display}-{monitor.id}"
dir = f"/tmp/vbar/{wayland_display}/{monitor.id}"
home = os.getenv("HOME", default=None)
if home == None:
panic("HOME environment variable is unset")
try:
os.makedirs(dir)
except FileExistsError:
try:
subprocess.run(["rm", "-rf", dir])
os.makedirs(dir)
except Exception as e:
panic(e)
config = generate_bar_config(monitor, bar_name, home, dir, f"{home}/.config/eww/templates/bar", dir)
try:
subprocess.run(["eww", "-c", dir, "reload"])
subprocess.run(["eww", "-c", dir, "open", bar_name])
except Exception as e:
panic(e)
def main():
wayland_display = os.getenv("WAYLAND_DISPLAY", default=None)
if wayland_display is None:
os.exit(1)
monitors = get_monitors()
for monitor in monitors:
launch_bar(
monitor=monitor,
wayland_display=wayland_display,
)
if __name__ == '__main__':
main()

View File

@ -21,7 +21,7 @@ monitor=eDP-1,1366x768@60,3840x1392,1
# See https://wiki.hyprland.org/Configuring/Keywords/ for more # See https://wiki.hyprland.org/Configuring/Keywords/ for more
# Execute your favorite apps at launch # Execute your favorite apps at launch
exec-once = ~/.config/eww/scripts/launch.py exec-once = ~/.config/eww/scripts/launch.rs
exec-once = wl-paste --watch cliphist store exec-once = wl-paste --watch cliphist store
exec-once = hyprpaper exec-once = hyprpaper