GTK colors added to color submenu

This commit is contained in:
Daniel Napora 2023-09-09 09:18:19 +02:00
parent f726918df8
commit 51f6143a1b
4 changed files with 151 additions and 32 deletions

View File

@ -268,7 +268,7 @@ if pgrep -u $USER -af "conky.*mbcolor" >/dev/null; then
fi fi
if [[ ${#notstarted[@]} > 0 ]];then if [[ ${#notstarted[@]} > 0 ]];then
out+=("^sep($MORECONKIES)") out+=("^sep($MORECONKIES)")
if [[ "$ALLSUPP" < 15 ]];then if [[ "$ALLSUPP" < 12 ]];then
out+=("^sep(<small><i>$CLICKTOSTART</i></small>)") out+=("^sep(<small><i>$CLICKTOSTART</i></small>)")
for c in ${notstarted[@]};do for c in ${notstarted[@]};do
filename=${c##*/} filename=${c##*/}

View File

@ -333,8 +333,8 @@ out2+=("$TIGHT,jgctl tweak sizing tight;$me")
#### COLOR SCHEMES #### COLOR SCHEMES
out+=("<big><span bgcolor='${MBG}'> <span fgcolor='${TBG}'></span> <span fgcolor='${SFG}'></span> <span fgcolor='${SBG}'></span> </span></big> $SCHEMES,^checkout(schemes)") out+=("<big><span bgcolor='${MBG}'> <span fgcolor='${TBG}'></span> <span fgcolor='${SFG}'></span> <span fgcolor='${SBG}'></span> </span></big> $SCHEMES,^checkout(schemes)")
out2+=("^tag(schemes)") out2+=("^tag(schemes)")
out2+=("^sep($SCHEMES)") out2+=("^sep($SCHEMES)")
out2+=("^sep($SYSTEM_SCHEMES)") out2+=("^sep($SYSTEM_SCHEMES)")

119
bin/gtkcolors.py Executable file
View File

@ -0,0 +1,119 @@
#!/usr/bin/env python3
"""
Based on labwc-gtktheme.py:
Create labwc theme based on the current Gtk theme
SPDX-License-Identifier: GPL-2.0-only
Copyright (C) @Misko_2083 2019
Copyright (C) Johan Malm 2019-2022
"""
import os
import errno
from tokenize import tokenize, NUMBER, NAME, OP
from io import BytesIO
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
def parse(tokens):
"""
Parse css color expression token list and return red/green/blue values
Valid name-tokens include 'rgb' and 'rgba', whereas 'alpha', 'shade' and
'mix' are ignored. @other-color references are still to be implemented.
"""
nr_colors_to_parse = 0
in_label = False
color = []
for toknum, tokval, _, _, _ in tokens:
if '@' in tokval:
in_label = True
continue
if toknum == NAME and in_label:
color.clear()
color.append(f"@{tokval}")
return color
if nr_colors_to_parse > 0:
if toknum == OP and tokval in ')':
print("warn: still parsing numbers; did not expect ')'")
if toknum == NUMBER:
color.append(tokval)
nr_colors_to_parse -= 1
continue
if toknum == NAME and tokval in 'rgb':
nr_colors_to_parse = 3
elif toknum == NAME and tokval in 'rgba':
nr_colors_to_parse = 4
return color
def color_hex(color):
""" return rrggbb color hex from list [r, g, b,...] """
if not color:
return "None"
elif len(color) < 3:
return f"{color[0]}"
return '{:02x}{:02x}{:02x}'.format(*(int(x) for x in color[:3]))
def hex_from_expr(line):
""" parse color expression to return hex style rrggbb """
tokens = tokenize(BytesIO(line.encode('utf-8')).readline)
color = parse(tokens)
return color_hex(color)
def parse_section(lines, name):
theme = {}
inside = False
for line in lines:
if f"{name} {{" in line:
inside = True
continue
if inside:
if "}" in line or "{" in line:
inside = False
break
if 'color' not in line:
continue
key, value = line.strip().split(":", maxsplit=1)
theme[f'{name}.{key.replace(" ", "")}'] = hex_from_expr(value)
return theme
def resolve_labels(theme):
for key, label in theme.items():
if '@' in label:
for tmp, value in theme.items():
if tmp == label[1:]:
theme[key] = value
return resolve_labels(theme)
return theme
def main():
""" main """
gset = Gtk.Settings.get_default()
themename = gset.get_property("gtk-theme-name")
css = Gtk.CssProvider.get_named(themename).to_string()
lines = css.split("\n")
theme = {}
# Parse @define-color lines using syntax "@define-color <key> <value>"
for line in lines:
if "@define-color" not in line:
continue
x = line.split(" ", maxsplit=2)
theme[x[1]] = hex_from_expr(x[2])
# Add the color definitions in the headerbar{} and menu{} sections
theme |= parse_section(lines, "headerbar")
theme |= parse_section(lines, "menu")
theme = resolve_labels(theme)
for key, value in theme.items():
print(f"{key}: {value}")
return
if __name__ == '__main__':
main()

View File

@ -21,7 +21,6 @@
#notify-send.sh "mbclr" "${1}\n${2}\n${3}\n${4}\n${5}\n${6}" #notify-send.sh "mbclr" "${1}\n${2}\n${3}\n${4}\n${5}\n${6}"
case "$LANG" in case "$LANG" in
pl*) pl*)
SELECT_COLOR="Wybierz kolor"
PICK_FROM_SCREEN="Pobierz kolor z ekranu" PICK_FROM_SCREEN="Pobierz kolor z ekranu"
SELECT_OR_PICK="Wybierz kolor z selektora" SELECT_OR_PICK="Wybierz kolor z selektora"
OPACITY="Nieprzezroczystość" OPACITY="Nieprzezroczystość"
@ -30,28 +29,29 @@ case "$LANG" in
LIGHTEN_DARKEN="Jaśniejsze / Ciemniejsze" LIGHTEN_DARKEN="Jaśniejsze / Ciemniejsze"
SATURATION="Nasycenie..." SATURATION="Nasycenie..."
ROTATE_HSL_HUE="Obróć kanał barwy HSL..." ROTATE_HSL_HUE="Obróć kanał barwy HSL..."
CHANGE_COLOR="Zmień na..."
CURRENT="obecny kolor" CURRENT="obecny kolor"
WALLPAPER_COLORS="Kolory z tapety" WALLPAPER_COLORS="...kolory z tapety"
GTKCOLORS="Kolory motywu GTK"
ACCENT_COLORS="Popularne kolory akcentu" ACCENT_COLORS="Popularne kolory akcentu"
LIGHTCOLORS="Jasne kolory..." GRAYS="Odcienie szarości"
DARKCOLORS="Ciemne kolory..."
;; ;;
*) *)
SELECT_COLOR="Select color"
PICK_FROM_SCREEN="Pick color from screen" PICK_FROM_SCREEN="Pick color from screen"
SELECT_OR_PICK="Select or pick from screen" SELECT_OR_PICK="Select or pick from screen"
OPACITY="Opacity" OPACITY="Opacity"
SHADES_OF_CURRENT="Calculate from current" SHADES_OF_CURRENT="Calculate from"
SHADES_OF="Shades of" SHADES_OF="Shades of"
LIGHTEN_DARKEN="Lighten / Darken" LIGHTEN_DARKEN="Lighten / Darken"
SATURATION="Saturation..." SATURATION="Saturation..."
ROTATE_HSL_HUE="Rotate HSL hue channel..." ROTATE_HSL_HUE="Rotate HSL hue channel..."
CHANGE_COLOR="Change to..."
CURRENT="current color" CURRENT="current color"
WALLPAPER_COLORS="Wallpaper colors" WALLPAPER_COLORS="...wallpaper colors"
GTKCOLORS="GTK theme colors"
ACCENT_COLORS="Popular accent colors" ACCENT_COLORS="Popular accent colors"
LIGHTCOLORS="Light colors..." GRAYS="Shades of Gray"
DARKCOLORS="Dark colors..."
;; ;;
esac esac
@ -79,8 +79,7 @@ wallcolors+=("#2e3440" "#4c566a" "#5e81ac" "#bf616b" "#b48ead" "#a3be8c" "#ebcb8
fi fi
dark=("#000000" "#111111" "#222222" "#333333" "#444444" "#555555" "#666666") grays=("#000000" "#0d0d0d" "#1b1b1b" "#282828" "#363636" "#434343" "#515151" "#5e5e5e" "#6b6b6b" "#797979" "#868686" "#949494" "#a1a1a1" "#aeaeae" "#bcbcbc" "#c9c9c9" "#d7d7d7" "#e4e4e4" "#f2f2f2" "#FFFFFF")
light=("#FFFFFF" "#EEEEEE" "#DDDDDD" "#CCCCCC" "#BBBBBB" "#AAAAAA" "#999999")
accents=("#e93d57" "#c7162b" "#e9633a" "#e95620" "#f4a300" "#e8cc2d" "#3cd425" "#0e8420" "#00d3b7" "#18b0b0" "#3dade9" "#686b6f" "#3584e4" "#916ee4" "#b875dc" "#77216e" "#c748ba" "#e93a9a") accents=("#e93d57" "#c7162b" "#e9633a" "#e95620" "#f4a300" "#e8cc2d" "#3cd425" "#0e8420" "#00d3b7" "#18b0b0" "#3dade9" "#686b6f" "#3584e4" "#916ee4" "#b875dc" "#77216e" "#c748ba" "#e93a9a")
out+=("^sep($4)") out+=("^sep($4)")
@ -135,10 +134,6 @@ out2+=("<tt><small> 5</small> <span bgcolor='$1' bgalpha='5%'> </span><
out2+=("<tt><small> 0</small> <span bgcolor='$1' bgalpha='1%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 0 ;${5}") out2+=("<tt><small> 0</small> <span bgcolor='$1' bgalpha='1%'> </span><span bgcolor='$1'> </span></tt>,t2ctl $3 0 ;${5}")
fi fi
#Current
out+=("^sep($SELECT_COLOR)")
out+=(" $PICK_FROM_SCREEN,mbclr pixelcolor $2 $3 ${5} ${6}")
out+=(" $SELECT_OR_PICK,mbclr pick $2 $3 ${5} ${6}")
CUR_FG=$(pastel textcolor $1|pastel format hex) CUR_FG=$(pastel textcolor $1|pastel format hex)
out+=("^sep($SHADES_OF_CURRENT <tt><span bgcolor='$1' fgcolor='$CUR_FG'>$1</span></tt>)") out+=("^sep($SHADES_OF_CURRENT <tt><span bgcolor='$1' fgcolor='$CUR_FG'>$1</span></tt>)")
@ -146,26 +141,31 @@ out+=("$LIGHTEN_DARKEN,^checkout(curshades)")
out+=("$SATURATION,^checkout(saturate)") out+=("$SATURATION,^checkout(saturate)")
out+=("<big>󰑧</big> $ROTATE_HSL_HUE,^checkout(rotate_hsl)") out+=("<big>󰑧</big> $ROTATE_HSL_HUE,^checkout(rotate_hsl)")
#out+=("$SHADES_OF_CURRENT <tt><span bgcolor='$1'> </span></tt> (<small>$1</small>),^checkout(curshades)") #out+=("$SHADES_OF_CURRENT <tt><span bgcolor='$1'> </span></tt> (<small>$1</small>),^checkout(curshades)")
out+=("^sep($CHANGE_COLOR)")
#Current
out+=("<big></big> $PICK_FROM_SCREEN,mbclr pixelcolor $2 $3 ${5} ${6}")
out+=("<big></big> $SELECT_OR_PICK,mbclr pick $2 $3 ${5} ${6}")
out+=("^sep()") out+=("^sep()")
out+=("<big><span bgcolor='#e93d57'> </span> <span bgcolor='#f4a300'> </span> <span bgcolor='#3cd425'> </span> <span bgcolor='#3584e4'> </span> <span bgcolor='#e93a9a'> </span></big> $ACCENT_COLORS,^checkout(accents)") out+=("<big><span bgcolor='#e93d57'> </span> <span bgcolor='#f4a300'> </span> <span bgcolor='#3cd425'> </span> <span bgcolor='#3584e4'> </span> <span bgcolor='#e93a9a'> </span></big> $ACCENT_COLORS,^checkout(accents)")
out2+=("^tag(accents)") out2+=("^tag(accents)")
out2+=("^sep($ACCENT_COLORS)") out2+=("^sep($ACCENT_COLORS)")
for i in ${accents[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}");done for i in ${accents[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}");done
out+=("^sep()")
mapfile -t gtkcolors < <( gtkcolors.py 2>/dev/null| grep -v None|awk '{print "#"$2}'|sort|uniq)
if [ "${#gtkcolors[@]}" -gt 0 ];then
out+=("$GTKCOLORS,^checkout(gtkcols)")
out2+=("^tag(gtkcols)")
out2+=("^sep($GTKCOLORS)")
for i in ${gtkcolors[@]};do out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}");done
out+=("^sep()") out+=("^sep()")
out+=("<tt><span bgcolor='#DDDDDD'> </span></tt> $LIGHTCOLORS,^checkout(light)") fi
out2+=("^tag(light)")
out2+=("^sep($LIGHTCOLORS)")
for i in "${light[@]}" out+=("$GRAYS,^checkout(grayscol)")
do out2+=("^tag(grayscol)")
out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}") out2+=("^sep($GRAYS)")
done for i in "${grays[@]}"
out+=("^sep()")
out+=("<tt><span bgcolor='#222222'> </span></tt> $DARKCOLORS,^checkout(dark)")
out2+=("^tag(dark)")
out2+=("^sep($DARKCOLORS)")
for i in "${dark[@]}"
do do
out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}") out2+=("<tt><small>$i</small> <span bgcolor='$i'> </span></tt>,$2 $3 '${i}' ${6};${5}")
done done