From 3c79b26d42390352fac15c9d0165127df5156d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pankowski?= Date: Sat, 9 Oct 2021 15:07:04 +0200 Subject: [PATCH] qtile: scale down bar on HD monitors --- qtile/.config/qtile/config.py | 26 +++++++++++++++++++------- qtile/.config/qtile/monitors.py | 13 +++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 qtile/.config/qtile/monitors.py diff --git a/qtile/.config/qtile/config.py b/qtile/.config/qtile/config.py index 03af106..ef042f7 100644 --- a/qtile/.config/qtile/config.py +++ b/qtile/.config/qtile/config.py @@ -2,14 +2,22 @@ from libqtile import bar, layout, qtile, widget from libqtile.config import Group, Key, KeyChord, Screen from libqtile.lazy import lazy +from monitors import list_monitors from themes import apply_theme, subtheme, theme, toggle_theme mod = "mod4" terminal = "alacritty" +hdpi_sizes = dict(size=46, fontsize=26) +hd_sizes = dict(size=32, fontsize=18) + +def sizes(monitor): + hdpi = monitor is None or max(monitor.width, monitor.height) > 2000 + return hdpi_sizes if hdpi else hd_sizes + widget_defaults = dict( font="Iosevka Slab Light", - fontsize=26, + fontsize=hdpi_sizes["fontsize"], padding=5, foreground=theme["foreground"], ) @@ -26,24 +34,28 @@ layouts = [ layout.Columns(border_width=4, margin=4, **subtheme("border_focus", "border_normal")), ] -def createBar(): +monitors = {i: m for i, m in enumerate(list_monitors())} + +def createBar(monitor=None): + s = sizes(monitor) return bar.Bar([ widget.Spacer(10), - widget.CurrentLayout(fmt="[{:3.3}]"), + widget.CurrentLayout(fmt="[{:3.3}]", fontsize=s["fontsize"]), widget.Spacer(10), widget.GroupBox(highlight_method='block', + fontsize=s["fontsize"], padding_y=10, active=theme["foreground"], **subtheme("inactive", "this_current_screen_border", "this_screen_border", "other_current_screen_border", "other_screen_border")), widget.Spacer(15), - widget.WindowName(), + widget.WindowName(fontsize=s["fontsize"]), widget.Spacer(), - widget.Clock(), + widget.Clock(fontsize=s["fontsize"]), widget.Spacer(10), - ], 48, background=theme["background"]) + ], s["size"], background=theme["background"]) -screens = [Screen(top=createBar()) for i in range(4)] +screens = [Screen(top=createBar(monitors.get(i))) for i in range(4)] #fake_screens = [Screen(top=createBar(), x=x, y=y, width=1920, height=1080) for x, y in [(0, 0), (1920, 0), (0, 1080), (1920, 1080)]] diff --git a/qtile/.config/qtile/monitors.py b/qtile/.config/qtile/monitors.py new file mode 100644 index 0000000..595cac0 --- /dev/null +++ b/qtile/.config/qtile/monitors.py @@ -0,0 +1,13 @@ +import re +import subprocess +from collections import namedtuple + +Monitor = namedtuple('Monitor', ["name", "width", "height"]) + +monitor_line = re.compile(r"^ *[0-9]+: +[+*]*([-A-Za-z0-9]+) +([0-9]+)/([0-9]+)x([0-9]+)/([0-9]+)\+([0-9]+)\+([0-9]+) +([-A-Za-z0-9]+)") + +def list_monitors(): + p = subprocess.run(["xrandr", "--listmonitors"], capture_output=True, encoding='UTF-8') + return [Monitor(name=m.group(1), width=int(m.group(2)), height=int(m.group(4))) + for m in map(monitor_line.match, p.stdout.split('\n')) + if m is not None]