Add Qt theme detection + Option
This commit is contained in:
parent
6dd85d67fc
commit
4f49053c8f
1 changed files with 151 additions and 28 deletions
179
neofetch
179
neofetch
|
@ -389,6 +389,16 @@ gtk2="on"
|
||||||
# off: 'Numix [GTK2]'
|
# off: 'Numix [GTK2]'
|
||||||
gtk3="on"
|
gtk3="on"
|
||||||
|
|
||||||
|
# Enable/Disable Qt Theme / Icons / Font
|
||||||
|
#
|
||||||
|
# Default: 'on'
|
||||||
|
# Values: 'on', 'off'
|
||||||
|
# Flag: --qt
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# on: 'Breeze [Qt], Arc [GTK3]'
|
||||||
|
# off: 'Arc [GTK3]'
|
||||||
|
qt="on"
|
||||||
|
|
||||||
# IP Address
|
# IP Address
|
||||||
|
|
||||||
|
@ -1773,6 +1783,7 @@ get_de() {
|
||||||
|
|
||||||
elif [[ $DESKTOP_SESSION ]]; then
|
elif [[ $DESKTOP_SESSION ]]; then
|
||||||
de=${DESKTOP_SESSION##*/}
|
de=${DESKTOP_SESSION##*/}
|
||||||
|
de=${de/trinity/Trinity}
|
||||||
|
|
||||||
elif [[ $GNOME_DESKTOP_SESSION_ID ]]; then
|
elif [[ $GNOME_DESKTOP_SESSION_ID ]]; then
|
||||||
de=GNOME
|
de=GNOME
|
||||||
|
@ -2039,9 +2050,9 @@ get_wm_theme() {
|
||||||
|
|
||||||
Openbox)
|
Openbox)
|
||||||
case $de in
|
case $de in
|
||||||
LXDE*) ob_file=lxde-rc ;;
|
LXDE*) ob_file="lxde-rc" ;;
|
||||||
LXQt*) ob_file=lxqt-rc ;;
|
LXQt*) ob_file="lxqt-rc" ;;
|
||||||
*) ob_file=rc ;;
|
*) ob_file="rc" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
ob_file=$XDG_CONFIG_HOME/openbox/$ob_file.xml
|
ob_file=$XDG_CONFIG_HOME/openbox/$ob_file.xml
|
||||||
|
@ -3025,7 +3036,7 @@ get_resolution() {
|
||||||
|
|
||||||
get_style() {
|
get_style() {
|
||||||
# Fix weird output when the function is run multiple times.
|
# Fix weird output when the function is run multiple times.
|
||||||
unset gtk2_theme gtk3_theme theme path
|
unset qt_theme gtk2_theme gtk3_theme theme path
|
||||||
|
|
||||||
if [[ "$DISPLAY" && $os != "Mac OS X" && $os != "macOS" ]]; then
|
if [[ "$DISPLAY" && $os != "Mac OS X" && $os != "macOS" ]]; then
|
||||||
# Get DE if user has disabled the function.
|
# Get DE if user has disabled the function.
|
||||||
|
@ -3041,15 +3052,9 @@ get_style() {
|
||||||
|
|
||||||
if [[ -f "${kde_config_dir}/kdeglobals" ]]; then
|
if [[ -f "${kde_config_dir}/kdeglobals" ]]; then
|
||||||
kde_config_file="${kde_config_dir}/kdeglobals"
|
kde_config_file="${kde_config_dir}/kdeglobals"
|
||||||
|
qt_theme="$(grep "^${kde}" "$kde_config_file")"
|
||||||
kde_theme="$(grep "^${kde}" "$kde_config_file")"
|
qt_theme="${qt_theme/*=}"
|
||||||
kde_theme="${kde_theme/*=}"
|
|
||||||
if [[ "$kde" == "font" ]]; then
|
|
||||||
kde_font_size="${kde_theme#*,}"
|
|
||||||
kde_font_size="${kde_font_size/,*}"
|
|
||||||
kde_theme="${kde_theme/,*} ${kde_theme/*,} ${kde_font_size}"
|
|
||||||
fi
|
|
||||||
kde_theme="$kde_theme [$de], "
|
|
||||||
else
|
else
|
||||||
err "Theme: KDE config files not found, skipping."
|
err "Theme: KDE config files not found, skipping."
|
||||||
fi
|
fi
|
||||||
|
@ -3081,6 +3086,32 @@ get_style() {
|
||||||
type -p xfconf-query >/dev/null && \
|
type -p xfconf-query >/dev/null && \
|
||||||
gtk2_theme="$(xfconf-query -c xsettings -p "$xfconf")"
|
gtk2_theme="$(xfconf-query -c xsettings -p "$xfconf")"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"Trinity")
|
||||||
|
tde_config_dir
|
||||||
|
|
||||||
|
if [[ -f "${tde_config_dir}/kdeglobals" ]]; then
|
||||||
|
tde_config_file="${tde_config_dir}/kdeglobals"
|
||||||
|
qt_theme="$(grep "^${kde}" "$tde_config_file")"
|
||||||
|
qt_theme="${qt_theme/*=}"
|
||||||
|
|
||||||
|
else
|
||||||
|
err "Theme: TDE config files not found, skipping."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
"LXQt"*)
|
||||||
|
shopt -s nullglob
|
||||||
|
if ! qt_theme=$(awk -F "=" -v r="^$lxqt" '
|
||||||
|
$1~r { theme=$2 }
|
||||||
|
END { print theme }
|
||||||
|
' {/etc/xdg,/etc/xdg/*,"$XDG_CONFIG_HOME"}/lxqt/lxqt.con?); then
|
||||||
|
err "Theme: Can't read LXQt config files. Unsetting Qt theme."
|
||||||
|
unset qt_theme
|
||||||
|
fi
|
||||||
|
shopt -u nullglob
|
||||||
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check for general GTK2 Theme.
|
# Check for general GTK2 Theme.
|
||||||
|
@ -3120,34 +3151,101 @@ get_style() {
|
||||||
gtk3_theme="${gtk3_theme/${name}*=}"
|
gtk3_theme="${gtk3_theme/${name}*=}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle Qt5ct platform theme
|
||||||
|
if [[ "$QT_QPA_PLATFORMTHEME" == 'qt5ct' && -f "${XDG_CONFIG_HOME}/qt5ct/qt5ct.conf" ]]; then
|
||||||
|
qt_theme="$(grep "^${qt5ct}" "${XDG_CONFIG_HOME}/qt5ct/qt5ct.conf")"
|
||||||
|
qt_theme="${qt_theme/*=}"
|
||||||
|
# Reformat font, since qt5ct stores fonts in binary format
|
||||||
|
if [[ "$qt5ct" == "general" ]]; then
|
||||||
|
# Trim quotes and parentheses
|
||||||
|
qt_theme="${qt_theme#'"'}"
|
||||||
|
qt_theme="${qt_theme%'"'}"
|
||||||
|
qt_theme="${qt_theme#@Variant(}"
|
||||||
|
qt_theme="${qt_theme%)}"
|
||||||
|
|
||||||
|
# Read font name
|
||||||
|
qt5ct_font_name="${qt_theme#*@}"
|
||||||
|
qt5ct_font_name="${qt5ct_font_name%%@*}"
|
||||||
|
# Interpret backslashes
|
||||||
|
qt5ct_font_name="$(printf "%b" "$qt5ct_font_name")"
|
||||||
|
qt5ct_font_name="${qt5ct_font_name//[[:cntrl:]]}" # trim control characters
|
||||||
|
|
||||||
|
# Get font size
|
||||||
|
# Tread carefully, Qt sometimes uses @ in binary data
|
||||||
|
local pre_size="${qt_theme#*@}"
|
||||||
|
local pre_size="${pre_size#*@}"
|
||||||
|
# Need to declare array and manually handle the second byte
|
||||||
|
# (workaround for `od` without --endian)
|
||||||
|
IFS=' ' local raw_size=( $(printf "%b" "${pre_size}" | od -An -tu1 -N2) )
|
||||||
|
# Split the upper 4 bits (exponent) the lower 12.
|
||||||
|
local lowers=$(( ((raw_size[0]%16)<<8) + (raw_size[1]) ))
|
||||||
|
local upper4=$((raw_size[0]>>4 ))
|
||||||
|
qt5ct_font_size=$(( (2**(upper4+1)) + (lowers>>(11-upper4)) ))
|
||||||
|
|
||||||
|
qt_theme="$qt5ct_font_name, $qt5ct_font_size"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Forced Qt theme through environment variables - Apply only if handling widget style!
|
||||||
|
[[ "$kde" == "widgetStyle" && "$qt_theme" ]] && qt_theme="${QT_STYLE_OVERRIDE:-"$qt_theme"}"
|
||||||
|
|
||||||
|
# Reformat Qt fonts
|
||||||
|
if [[ "$kde" == "font" && "$qt_theme" ]]; then
|
||||||
|
qt_font_size="${qt_theme#*,}"
|
||||||
|
qt_font_size="${qt_font_size/,*}"
|
||||||
|
qt_theme="${qt_theme/,*}, ${qt_font_size}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Trim whitespace.
|
# Trim whitespace.
|
||||||
gtk2_theme="$(trim "$gtk2_theme")"
|
gtk2_theme="$(trim "$gtk2_theme")"
|
||||||
gtk3_theme="$(trim "$gtk3_theme")"
|
gtk3_theme="$(trim "$gtk3_theme")"
|
||||||
|
qt_theme="$(trim "$qt_theme")"
|
||||||
|
|
||||||
# Remove quotes.
|
# Remove quotes.
|
||||||
gtk2_theme="$(trim_quotes "$gtk2_theme")"
|
gtk2_theme="$(trim_quotes "$gtk2_theme")"
|
||||||
gtk3_theme="$(trim_quotes "$gtk3_theme")"
|
gtk3_theme="$(trim_quotes "$gtk3_theme")"
|
||||||
|
qt_theme="$(trim_quotes "$qt_theme")"
|
||||||
|
|
||||||
# Toggle visibility of GTK themes.
|
# Toggle visibility of GTK themes.
|
||||||
[[ "$gtk2" == "off" ]] && unset gtk2_theme
|
[[ "$gtk2" == "off" ]] && unset gtk2_theme
|
||||||
[[ "$gtk3" == "off" ]] && unset gtk3_theme
|
[[ "$gtk3" == "off" ]] && unset gtk3_theme
|
||||||
|
[[ "$qt" == "off" ]] && unset qt_theme
|
||||||
|
|
||||||
|
# Handle Qt theme engines that load external themes
|
||||||
|
case "$qt_theme" in
|
||||||
|
'Kvantum')
|
||||||
|
if kvantum_theme="$(grep '^theme' "${XDG_CONFIG_HOME}/Kvantum/kvantum.kvconfig")"; then
|
||||||
|
qt_theme="$kvantum_theme"
|
||||||
|
qt_theme="${qt_theme/*=}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*'gtk2')
|
||||||
|
qt_theme="$gtk2_theme"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Format the string based on which themes exist.
|
# Format the string based on which themes exist.
|
||||||
if [[ "$gtk2_theme" && "$gtk2_theme" == "$gtk3_theme" ]]; then
|
# append_theme theme toolkit
|
||||||
gtk3_theme+=" [GTK2/3]"
|
append_theme() {
|
||||||
unset gtk2_theme
|
if [[ "$1" ]]; then
|
||||||
|
if [[ "$1" == "$cur_theme" ]]; then
|
||||||
elif [[ "$gtk2_theme" && "$gtk3_theme" ]]; then
|
theme+="/$2"
|
||||||
gtk2_theme+=" [GTK2], "
|
else
|
||||||
gtk3_theme+=" [GTK3] "
|
theme+="], $1 [$2"
|
||||||
|
cur_theme="$1"
|
||||||
else
|
fi
|
||||||
[[ "$gtk2_theme" ]] && gtk2_theme+=" [GTK2] "
|
fi
|
||||||
[[ "$gtk3_theme" ]] && gtk3_theme+=" [GTK3] "
|
}
|
||||||
fi
|
theme=''
|
||||||
|
local cur_theme=''
|
||||||
|
append_theme "$qt_theme" 'Qt'
|
||||||
|
append_theme "$gtk2_theme" 'GTK2'
|
||||||
|
append_theme "$gtk3_theme" 'GTK3'
|
||||||
|
|
||||||
# Final string.
|
# Final string.
|
||||||
theme="${kde_theme}${gtk2_theme}${gtk3_theme}"
|
theme+=']'
|
||||||
|
theme="${theme#'], '}"
|
||||||
|
theme="${theme/'GTK2/GTK3'/'GTK2/3'}"
|
||||||
theme="${theme%, }"
|
theme="${theme%, }"
|
||||||
|
|
||||||
# Make the output shorter by removing "[GTKX]" from the string.
|
# Make the output shorter by removing "[GTKX]" from the string.
|
||||||
|
@ -3156,6 +3254,7 @@ get_style() {
|
||||||
theme="${theme/ '[GTK2/3]'}"
|
theme="${theme/ '[GTK2/3]'}"
|
||||||
theme="${theme/ '[KDE]'}"
|
theme="${theme/ '[KDE]'}"
|
||||||
theme="${theme/ '[Plasma]'}"
|
theme="${theme/ '[Plasma]'}"
|
||||||
|
theme="${theme/ '[Qt]'}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -3165,7 +3264,10 @@ get_theme() {
|
||||||
gsettings="gtk-theme"
|
gsettings="gtk-theme"
|
||||||
gconf="gtk_theme"
|
gconf="gtk_theme"
|
||||||
xfconf="/Net/ThemeName"
|
xfconf="/Net/ThemeName"
|
||||||
kde="Name"
|
kde="widgetStyle"
|
||||||
|
lxqt="style"
|
||||||
|
qt5ct="style=" # There is a property called 'stylesheets'.
|
||||||
|
|
||||||
|
|
||||||
get_style
|
get_style
|
||||||
}
|
}
|
||||||
|
@ -3176,6 +3278,9 @@ get_icons() {
|
||||||
gconf="icon_theme"
|
gconf="icon_theme"
|
||||||
xfconf="/Net/IconThemeName"
|
xfconf="/Net/IconThemeName"
|
||||||
kde="Theme"
|
kde="Theme"
|
||||||
|
lxqt="icon_theme"
|
||||||
|
qt5ct="icon_theme"
|
||||||
|
|
||||||
|
|
||||||
get_style
|
get_style
|
||||||
icons="$theme"
|
icons="$theme"
|
||||||
|
@ -3187,6 +3292,8 @@ get_font() {
|
||||||
gconf="font_theme"
|
gconf="font_theme"
|
||||||
xfconf="/Gtk/FontName"
|
xfconf="/Gtk/FontName"
|
||||||
kde="font"
|
kde="font"
|
||||||
|
lxqt="font"
|
||||||
|
qt5ct="general"
|
||||||
|
|
||||||
get_style
|
get_style
|
||||||
font="$theme"
|
font="$theme"
|
||||||
|
@ -4745,7 +4852,7 @@ kde_config_dir() {
|
||||||
|
|
||||||
elif type -p kde-config &>/dev/null; then
|
elif type -p kde-config &>/dev/null; then
|
||||||
kde_config_dir="$(kde-config --path config)"
|
kde_config_dir="$(kde-config --path config)"
|
||||||
|
|
||||||
elif [[ -d "${HOME}/.kde4" ]]; then
|
elif [[ -d "${HOME}/.kde4" ]]; then
|
||||||
kde_config_dir="${HOME}/.kde4/share/config"
|
kde_config_dir="${HOME}/.kde4/share/config"
|
||||||
|
|
||||||
|
@ -4756,6 +4863,21 @@ kde_config_dir() {
|
||||||
kde_config_dir="${kde_config_dir/$'/:'*}"
|
kde_config_dir="${kde_config_dir/$'/:'*}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tde_config_dir() {
|
||||||
|
if [[ "$tde_config_dir" ]]; then
|
||||||
|
return
|
||||||
|
|
||||||
|
elif type -p tde-config &>/dev/null; then
|
||||||
|
tde_config_dir="$(tde-config --path config)"
|
||||||
|
|
||||||
|
elif [[ -d "${HOME}/.configtde" ]]; then
|
||||||
|
tde_config_dir="${HOME}/.configtde"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
tde_config_dir="${tde_config_dir/$'/:'*}"
|
||||||
|
}
|
||||||
|
|
||||||
term_padding() {
|
term_padding() {
|
||||||
# Get terminal padding to properly align cursor.
|
# Get terminal padding to properly align cursor.
|
||||||
[[ -z "$term" ]] && get_term
|
[[ -z "$term" ]] && get_term
|
||||||
|
@ -5163,6 +5285,7 @@ get_args() {
|
||||||
"--gtk_shorthand") gtk_shorthand="$2" ;;
|
"--gtk_shorthand") gtk_shorthand="$2" ;;
|
||||||
"--gtk2") gtk2="$2" ;;
|
"--gtk2") gtk2="$2" ;;
|
||||||
"--gtk3") gtk3="$2" ;;
|
"--gtk3") gtk3="$2" ;;
|
||||||
|
"--qt") qt="$2" ;;
|
||||||
"--shell_path") shell_path="$2" ;;
|
"--shell_path") shell_path="$2" ;;
|
||||||
"--shell_version") shell_version="$2" ;;
|
"--shell_version") shell_version="$2" ;;
|
||||||
"--ip_host") public_ip_host="$2" ;;
|
"--ip_host") public_ip_host="$2" ;;
|
||||||
|
|
Loading…
Reference in a new issue