From 2a419f594a2edc2655699c2049fc4ff5652697fe Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 15 Aug 2023 20:31:28 +0100 Subject: [PATCH 1/2] Add link to gtk3/css-overview --- labwc-gtktheme.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/labwc-gtktheme.py b/labwc-gtktheme.py index 8f075e8..95c8d14 100755 --- a/labwc-gtktheme.py +++ b/labwc-gtktheme.py @@ -7,6 +7,9 @@ Copyright (C) @Misko_2083 2019 Copyright (C) Johan Malm 2019-2022 + +https://docs.gtk.org/gtk3/css-overview.html + """ import os From c9ec65cec0907244f817fd6a3fae4c94bf44185d Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 15 Aug 2023 20:31:54 +0100 Subject: [PATCH 2/2] Parse png icons for close/max/iconfiy --- labwc-gtktheme.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/labwc-gtktheme.py b/labwc-gtktheme.py index 95c8d14..f685621 100755 --- a/labwc-gtktheme.py +++ b/labwc-gtktheme.py @@ -20,6 +20,7 @@ import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk +from base64 import b64decode def parse(tokens): """ @@ -115,6 +116,39 @@ def resolve_labels(theme): return resolve_labels(theme) return theme +def create_one_icon(lines, nodename, filename): + """ + The data contains entries like the one below (base64 strings truncated). + We merely split the string at 'base64,' and '\"' to get the x1 size icons. + TODO: Parse this better, maybe with a recursive descendant approach. + + button.close.titlebutton { + background-image: -gtk-scaled(url("data:image/png;base64,iVBORw0..."),url("data:image/png;base64,iVBORw0...")); + } + """ + theme = {} + inside = False + for line in lines: + if f"{nodename} {{" in line: + inside = True + continue + if inside: + if "}" in line or "{" in line: + inside = False + continue + key, value = line.strip().split(":", maxsplit=1) + key = key.replace(" ", ""); + if key == "background-image": + value = value.split("base64,", maxsplit=1)[1] + value = value.split('\"', maxsplit=1)[0] + with open(filename, 'wb') as f: + f.write(b64decode(value)) + +def create_icons(lines, themedir): + create_one_icon(lines, "button.close.titlebutton", themedir + "/close-active.png") + create_one_icon(lines, "button.maximize.titlebutton", themedir + "/max-active.png") + create_one_icon(lines, "button.minimize.titlebutton", themedir + "/iconify-active.png") + def main(): """ main """ parser = argparse.ArgumentParser(prog="labwc-gtktheme") @@ -194,5 +228,7 @@ def main(): # window.label.text.justify: center # osd.border.width: 1 + create_icons(lines, themedir); + if __name__ == '__main__': main()