From f87ef86275d077cb45ee546fb53efd2334f43318 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 1 Mar 2024 15:30:53 -0800 Subject: automatically detect monitor width --- panel.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/panel.py b/panel.py index 0248838..17c41ca 100755 --- a/panel.py +++ b/panel.py @@ -181,7 +181,8 @@ class HLWMClient(): else: self.listeners[hook] = [d] - def exec(self, *args): + @staticmethod + def exec(*args): res = subprocess.run( ('herbstclient', *args), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) @@ -394,7 +395,7 @@ class ModMem(ModInterval): self.out = Fmt.labelled('MEM', f'{percent:.0f}%%') class Panel: - def __init__(self, *mods, max_paint_delay=0): + def __init__(self, *mods, max_paint_delay=0, width=1920, height=22): self.e_repaint = threading.Event() self.e_flush = threading.Event() self.mods = mods @@ -403,6 +404,8 @@ class Panel: m.e_flush = self.e_flush self.mod_by_id = {id(m): m for m in self.mods} self.max_paint_delay = max_paint_delay + self.width = width + self.height = height def process_cmds(self, pipe): while True: @@ -421,7 +424,8 @@ class Panel: ('/home/david/lemonbar-xft/lemonbar', '-bf', 'Monospace:size=10:dpi=96', '-f', 'Monospace:size=10:dpi=96:bold', - '-u', '2', '-g', '1920x22', '-a', '100'), + '-g', f'{self.width}x{self.height}', + '-u', '2', '-a', '100'), stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) @@ -461,5 +465,7 @@ Panel( fmts=('%Y-%m-%d %H:%M:%S', '%H:%M'), tzs=({'id': None}, {'id': 'UTC'}, {'id': 'Asia/Yerevan', 'label': 'AMT'})), - max_paint_delay=0.01 + max_paint_delay=0.01, + width=(re.match('[0-9]+', HLWMClient.exec('attr', 'monitors.0.geometry')) + .group()) ).run() -- cgit v1.2.3-70-g09d2