WIP frobar 4

This commit is contained in:
Geoffrey Frogeye 2025-05-30 00:41:09 +02:00
parent dc0048d8dc
commit f15e407240
4 changed files with 209 additions and 139 deletions

View file

@ -12,7 +12,7 @@
# is called pyton-mpd2 on PyPi but mpd2 in nixpkgs.
pkgs.python3Packages.buildPythonPackage rec {
pname = "frobar";
version = "3.1";
version = "4.0";
dependencies = with pkgs.python3Packages; [
i3ipc
@ -29,6 +29,7 @@ pkgs.python3Packages.buildPythonPackage rec {
buildInputs = with pkgs; [
playerctl
gtk4-layer-shell
];
preFixup = ''
@ -50,6 +51,7 @@ pkgs.python3Packages.buildPythonPackage rec {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.glib.out
pkgs.playerctl
pkgs.gtk4-layer-shell
];
src = ./.;

View file

@ -0,0 +1,149 @@
import rich.color
import rich.logging
import rich.terminal_theme
import frobar.common
import frobar.providers
from frobar.common import Alignment
def main() -> None:
# TODO Configurable
frogarized = (
"#092c0e",
"#143718",
"#5a7058",
"#677d64",
"#89947f",
"#99a08d",
"#fae2e3",
"#fff0f1",
"#e0332e",
"#cf4b15",
"#bb8801",
"#8d9800",
"#1fa198",
"#008dd1",
"#5c73c4",
"#d43982",
)
# TODO Not super happy with the color management,
# while using an existing library is great, it's limited to ANSI colors
def base16_color(color: int) -> tuple[int, int, int]:
hexa = frogarized[color]
return tuple(rich.color.parse_rgb_hex(hexa[1:]))
theme = rich.terminal_theme.TerminalTheme(
base16_color(0x0),
base16_color(0x0), # TODO Should be 0x7 but otherwise spacer is white
[
base16_color(0x0), # black
base16_color(0x8), # red
base16_color(0xB), # green
base16_color(0xA), # yellow
base16_color(0xD), # blue
base16_color(0xE), # magenta
base16_color(0xC), # cyan
base16_color(0x5), # white
],
[
base16_color(0x3), # bright black
base16_color(0x8), # bright red
base16_color(0xB), # bright green
base16_color(0xA), # bright yellow
base16_color(0xD), # bright blue
base16_color(0xE), # bright magenta
base16_color(0xC), # bright cyan
base16_color(0x7), # bright white
],
)
bar = frobar.common.Bar(theme=theme)
dual_screen = len(bar.children) > 1
left_preferred = 0 if dual_screen else None
right_preferred = 1 if dual_screen else None
workspaces_suffixes = "▲■"
workspaces_names = {
str(i + 1): f"{i + 1} {c}" for i, c in enumerate(workspaces_suffixes)
}
color = rich.color.Color.parse
bar.add_provider(
frobar.providers.I3ModeProvider(color=color("red")),
alignment=Alignment.LEFT,
)
bar.add_provider(
frobar.providers.I3WorkspacesProvider(custom_names=workspaces_names),
alignment=Alignment.LEFT,
)
if dual_screen:
bar.add_provider(
frobar.providers.I3WindowTitleProvider(color=color("white")),
screen_num=0,
alignment=Alignment.CENTER,
)
bar.add_provider(
frobar.providers.MprisProvider(color=color("bright_white")),
screen_num=right_preferred,
alignment=Alignment.CENTER,
)
else:
bar.add_provider(
frobar.common.SpacerProvider(),
alignment=Alignment.LEFT,
)
bar.add_provider(
frobar.providers.MprisProvider(color=color("bright_white")),
alignment=Alignment.LEFT,
)
bar.add_provider(
frobar.providers.CpuProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.LoadProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.RamProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.TemperatureProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.BatteryProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.PulseaudioProvider(color=color("magenta")),
screen_num=right_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.NetworkProvider(color=color("blue")),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.TimeProvider(color=color("cyan")),
alignment=Alignment.RIGHT,
)
bar.launch()
if __name__ == "__main__":
main()

View file

@ -1,149 +1,68 @@
import rich.color
import rich.logging
import rich.terminal_theme
from ctypes import CDLL
import frobar.common
import frobar.providers
from frobar.common import Alignment
CDLL("libgtk4-layer-shell.so")
import gi
gi.require_version("Gtk", "4.0")
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk4LayerShell", "1.0")
from gi.repository import Gtk, Gdk
from gi.repository import Gtk4LayerShell as LayerShell
WIDTH = 1920
HEIGHT = 20
BLOCK = 8
def main() -> None:
# TODO Configurable
frogarized = (
"#092c0e",
"#143718",
"#5a7058",
"#677d64",
"#89947f",
"#99a08d",
"#fae2e3",
"#fff0f1",
"#e0332e",
"#cf4b15",
"#bb8801",
"#8d9800",
"#1fa198",
"#008dd1",
"#5c73c4",
"#d43982",
)
# TODO Not super happy with the color management,
# while using an existing library is great, it's limited to ANSI colors
def draw_event(widget, ctx, w, h, data):
text = "   Nyan Cat  Nyan cat "
# Not tailored for surrounding spaces
def base16_color(color: int) -> tuple[int, int, int]:
hexa = frogarized[color]
return tuple(rich.color.parse_rgb_hex(hexa[1:]))
ctx.select_font_face("DejaVuSansM Nerd Font")
ctx.set_font_size(14)
(x, y, width, height, dx, dy) = ctx.text_extents(text)
theme = rich.terminal_theme.TerminalTheme(
base16_color(0x0),
base16_color(0x0), # TODO Should be 0x7 but otherwise spacer is white
[
base16_color(0x0), # black
base16_color(0x8), # red
base16_color(0xB), # green
base16_color(0xA), # yellow
base16_color(0xD), # blue
base16_color(0xE), # magenta
base16_color(0xC), # cyan
base16_color(0x5), # white
],
[
base16_color(0x3), # bright black
base16_color(0x8), # bright red
base16_color(0xB), # bright green
base16_color(0xA), # bright yellow
base16_color(0xD), # bright blue
base16_color(0xE), # bright magenta
base16_color(0xC), # bright cyan
base16_color(0x7), # bright white
],
)
ctx.translate(100, 0) # → ↓
print(x, y, width, height, dx, dy)
bar = frobar.common.Bar(theme=theme)
dual_screen = len(bar.children) > 1
left_preferred = 0 if dual_screen else None
right_preferred = 1 if dual_screen else None
ctx.new_path()
ctx.move_to(0, 0)
ctx.rel_line_to(width, 0)
ctx.rel_line_to(BLOCK, HEIGHT/2)
ctx.rel_line_to(-BLOCK, HEIGHT/2)
ctx.rel_line_to(-width, 0)
ctx.close_path()
ctx.set_source_rgb(1, 1, 1)
ctx.fill()
workspaces_suffixes = "▲■"
workspaces_names = {
str(i + 1): f"{i + 1} {c}" for i, c in enumerate(workspaces_suffixes)
}
color = rich.color.Color.parse
bar.add_provider(
frobar.providers.I3ModeProvider(color=color("red")),
alignment=Alignment.LEFT,
)
bar.add_provider(
frobar.providers.I3WorkspacesProvider(custom_names=workspaces_names),
alignment=Alignment.LEFT,
)
ctx.move_to(0, height)
ctx.set_source_rgb(0, 0, 0)
ctx.show_text(text)
if dual_screen:
bar.add_provider(
frobar.providers.I3WindowTitleProvider(color=color("white")),
screen_num=0,
alignment=Alignment.CENTER,
)
bar.add_provider(
frobar.providers.MprisProvider(color=color("bright_white")),
screen_num=right_preferred,
alignment=Alignment.CENTER,
)
else:
bar.add_provider(
frobar.common.SpacerProvider(),
alignment=Alignment.LEFT,
)
bar.add_provider(
frobar.providers.MprisProvider(color=color("bright_white")),
alignment=Alignment.LEFT,
)
def on_activate(app):
bar.add_provider(
frobar.providers.CpuProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.LoadProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.RamProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.TemperatureProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.BatteryProvider(),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.PulseaudioProvider(color=color("magenta")),
screen_num=right_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.NetworkProvider(color=color("blue")),
screen_num=left_preferred,
alignment=Alignment.RIGHT,
)
bar.add_provider(
frobar.providers.TimeProvider(color=color("cyan")),
alignment=Alignment.RIGHT,
)
bar.launch()
# monitors = Gdk.get_monitors()
if __name__ == "__main__":
main()
window = Gtk.Window(application=app, title="frobar")
window.set_default_size(WIDTH, HEIGHT)
LayerShell.init_for_window(window)
LayerShell.set_layer(window, LayerShell.Layer.TOP)
LayerShell.set_anchor(window, LayerShell.Edge.BOTTOM, True)
LayerShell.auto_exclusive_zone_enable(window)
drawingarea = Gtk.DrawingArea()
drawingarea.set_draw_func(draw_event, None)
window.set_child(drawingarea)
window.present()
def main():
app = Gtk.Application(application_id="fr.frogeye.frobar")
app.connect("activate", on_activate)
app.run(None)

View file

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="frobar",
version="3.1",
version="4.0",
install_requires=[
"i3ipc",
"psutil",