Skip to content

Commit

Permalink
feat: sddm theme setter
Browse files Browse the repository at this point in the history
  • Loading branch information
kRHYME7 committed Aug 28, 2024
1 parent 7d4b027 commit 41c1530
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 245 deletions.
16 changes: 14 additions & 2 deletions Hyde
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,24 @@ sddm() { #? Sddm commands
sddm_install "${@}"
;;
list) #? List all local sddm themes
sddm_list_local
#! sddm_list_local # Deprecatd for simpler approach
sddm_list_theme
;;
set) #? Set Sddm theme from the list
shift
sddm_set_local "${@}"
#! sddm_set_local "${@}"
sddm_set_theme "${@}"
;;
unset) #? Unset a any theme set by 'set' command
sddm_unset
;;
test) #? Test a theme
shift
sddm_test "${@}"
;;
info) #? Check sddm theme status
sddm_info
;;
*) Parameters "${FUNCNAME[0]}" ;;

esac;
Expand Down
126 changes: 77 additions & 49 deletions Scripts/Manage-Sddm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
if ! pkg_installed sddm; then exit 0; fi

sddm_bak=/etc/sddm.conf.d/kde_settings.t2.bkp
export sddm_conf=/etc/sddm.conf.d/kde_settings.conf
export sddm_conf_dir=/etc/sddm.conf.d
export sddm_conf="${sddm_conf_dir}/kde_settings.conf"
sddm_theme_dir="/usr/share/sddm/themes"

sddm_set() {
[ -z "${sddm_theme}" ] && print_prompt -r "Operation Cancelled" && return 1
print_prompt -y "Setting into '${sddm_theme} theme'..."
ask_confirm "${USER}"
[ -f "${sddm_bak}" ] && SUPER rm "${sddm_bak}"
[[ -d "$(dirname ${sddm_conf})" ]] || SUPER mkdir -p "$(dirname ${sddm_conf})"
[[ -d "${sddm_conf_dir}" ]] || SUPER mkdir -p "${sddm_conf_dir}"
SUPER tar -xzf ${CloneDir}/Source/arcs/Sddm_${sddm_theme}.tar.gz -C "${sddm_theme_dir}/${theme}"
SUPER touch "${sddm_conf}"
SUPER cp "${sddm_conf}" "${sddm_bak}"
SUPER cp ${sddm_theme_dir}/${sddm_theme}/kde_settings.conf "$(dirname ${sddm_conf})"
SUPER touch "${sddm_conf_dir}/kde_settings.conf"
SUPER cp "${sddm_conf_dir}/kde_settings.conf" "${sddm_bak}"
SUPER cp ${sddm_theme_dir}/${sddm_theme}/kde_settings.conf "${sddm_conf_dir}"
enable_service sddm

}
Expand All @@ -30,46 +31,44 @@ sddm_list_arcs() {

sddm_exec_seleted() {
sddm_theme_conf=$1
[[ -d "$(dirname ${sddm_conf})" ]] || SUPER mkdir -p "$(dirname ${sddm_conf})"
[[ -f "${sddm_conf}" ]] && cp -fr "${sddm_conf}" "$(dirname "${sddm_conf}")/kde_settings.t2.bkp"
# cp "${sddm_theme_conf}" "$(dirname "${sddm_conf}")"
cp -fr "${sddm_theme_conf}" "${sddm_conf}" && echo "[ok] Sddm theme set"
[[ -d "${sddm_conf_dir}" ]] || SUPER mkdir -p "${sddm_conf_dir}"
[[ -f "${sddm_conf_dir}/kde_settings.conf" ]] && cp -fr "${sddm_conf_dir}/kde_settings.conf" "${sddm_conf_dir}/kde_settings.hyde.bkp"
# cp "${sddm_theme_conf}" "$(dirname "${sddm_conf_dir}")"
cp -fr "${sddm_theme_conf}" "${sddm_conf_dir}/kde_settings.conf" && echo "[ok] Sddm theme set"
}

sddm_list_local() {
declare -A sddm_themes
output=$(find "${sddm_theme_dir}" -name "kde_settings.conf" -exec grep -H "Current" {} \;)
[[ -z "${output}" ]] && print_prompt -crit "[error] " "No settings detected.Do themes have 'kde_settings.conf' declared? " && exit 1

# Populate the associative array
while IFS=':' read -r path theme_name; do
# Remove "Current=" from the theme_name
theme_name="${theme_name#Current=}"
sddm_themes["$theme_name"]="$path"
# echo "Theme Name: $theme_name, Path: $path"
done <<<"$output"
# Print the associative array to verify
for theme_name in "${!sddm_themes[@]}"; do
# echo "Theme Name: $theme_name, Path: ${sddm_themes[$theme_name]}"
echo "${theme_name}"
done
sddm_set_selected() {

set_theme="${1}"
cat <<THEME >"${sddm_conf_dir}/user-hyde-theme.conf" && print_prompt -g "[ok] " "$set_theme" || { print_prompt -crit "[err]" "Can't set the theme" && exit 1; }
# This setting is autogenerated by Hyde-cli
# to unset this theme run ' ${CLI_PATH}/Hyde sddm unset '
# This is positioned almost at the bottom of the sddm.conf.d so this should be executed last
[Theme]
Current=${set_theme}
THEME

bottom_conf=$(find /etc/sddm.conf.d/ -maxdepth 1 | tail -n 1)
[ "${bottom_conf}" != "${sddm_conf_dir}/user-hyde-theme.conf" ] && print_prompt -y "[warning] " "${bottom_conf} is overriding the config\nSddm theme might not be setted"

}

sddm_set_local() {
sddm_list_theme() {
find "${sddm_theme_dir}" -maxdepth 2 -name "theme.conf" -exec dirname {} \; | awk -F "${sddm_theme_dir}/" '{print $2}'
}

sddm_set_theme() {

declare -A sddm_themes
output=$(find "${sddm_theme_dir}" -name "kde_settings.conf" -exec grep -H "Current" {} \;)
[[ -z "${output}" ]] && print_prompt -crit "[error] " "No settings detected.Do themes have 'kde_settings.conf' declared? " && exit 1
# Populate the associative array
while IFS=':' read -r path theme_name; do
# Remove "Current=" from the theme_name
theme_name="${theme_name#Current=}"
sddm_themes["$theme_name"]="$path"
# echo "Theme Name: $theme_name, Path: $path"
done <<<"$output"
mapfile -t themes < <(find "${sddm_theme_dir}" -maxdepth 2 -name "theme.conf" -exec dirname {} \; | awk -F "${sddm_theme_dir}/" '{print $2}')

for theme in "${themes[@]}"; do
sddm_themes["$theme"]="$theme"
done

if [[ -z "${1}" ]]; then
sddm_theme=$(
selected_theme=$(
# Print the associative array to verify
for theme_name in "${!sddm_themes[@]}"; do
# echo "Theme Name: $theme_name, Path: ${sddm_themes[$theme_name]}"
Expand All @@ -81,30 +80,59 @@ sddm_set_local() {
# Proceed with the theme if it exists in the array
print_prompt -y "[sddm] " "Setting '${1}' theme"
# Perform actions with the selected theme
sddm_theme=${1}
selected_theme=${1}
else
print_prompt -r "[error] " "sddm '${1}' theme not found."
print_prompt -r "[error] " "sddm '${1}' theme not found."
# Handle the case where the theme does not exist
exit 1
fi
fi

[ -z "${sddm_theme}" ] && print_prompt -r "Operation Cancelled" && return 1
export sddm_theme_conf="${sddm_themes[$sddm_theme]}"

print_prompt -y "[sddm] " "Setting into '${sddm_theme}' theme from path ${sddm_theme_conf}"

if [ ! -w "$(dirname ${sddm_conf})" ] || [ ! -w "${sddm_conf}" ]; then
NOTIFY -a " HyDE-cli " "Run 'sudo chmod -R a+wr $(dirname ${sddm_conf})' to set the permissions one time" -t 10000
print_prompt -c "[note] " "Run 'sudo chmod -R a+wr $(dirname ${sddm_conf})' to set the permissions one time"
pkexec bash -c ". ${CLI_PATH}/lib/hyde-cli/Package-Manager ;. ${CLI_PATH}/lib/hyde-cli/Manage-Sddm;sddm_exec_seleted ${sddm_theme_conf}" || exit 1
[ -z "${selected_theme}" ] && print_prompt -r "Operation Cancelled" && return 1
print_prompt -y "[sddm] " "Setting '${selected_theme}' theme "

if [ ! -w "${sddm_conf_dir}" ]; then
NOTIFY -a " HyDE-cli " "Run 'sudo chmod -R a+wr ${sddm_conf_dir}' to set the permissions one time" -t 10000
print_prompt -c "[note] " "Run 'sudo chmod -R a+wr ${sddm_conf_dir}' to set the permissions one time"
pkexec bash -c ". ${CLI_PATH}/lib/hyde-cli/Package-Manager ;. ${CLI_PATH}/lib/hyde-cli/Manage-Sddm;sddm_set_selected ${selected_theme}" || exit 1
else
sddm_exec_seleted "${sddm_theme_conf}"
:
sddm_set_selected "${selected_theme}"
fi
enable_service sddm
print_prompt -y "Restart sddm?"
ask_confirm && systemctl restart --now display-manager
}

sddm_install() {
sddm_list_arcs
sddm_set
}

sddm_test() {

if [[ -z "${1}" ]]; then
test_theme="$(find "${sddm_theme_dir}" -maxdepth 2 -name "theme.conf" -exec dirname {} \; | awk -F "${sddm_theme_dir}/" '{print $2}' | fzf)"
else
test_theme=${1}
fi
print_prompt -g "[try] " "${test_theme} theme"
sddm-greeter --test-mode --theme "${sddm_theme_dir}/${test_theme}"
}
sddm_unset() {

if [ -f "${sddm_conf_dir}/user-hyde-theme.conf" ]; then
rm "${sddm_conf_dir}/user-hyde-theme.conf"
else
print_prompt -y "[warn] " "hyde sddm theme not set"
fi

}

sddm_info() {
output=$(find /etc/sddm.conf.d/ -type f -name "*.conf" -exec grep -H "Current" {} \; | tail -n 1)
cat << STAT
Current theme: $( awk -F ':Current=' '{print $2}' <<< ${output} )
theme directory: $( awk -F ':Current=' '{print $1}' <<< ${output})
STAT
}
10 changes: 8 additions & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ Usage: Hyde [Function] [options]
[list] ↪️ List all local sddm themes
[set] ↪️ Set Sddm theme from the list
[unset] ↪️ Unset a any theme set by 'set' command
[test] ↪️ Test a theme
[info] ↪️ Check sddm theme status
[shell] ↪️ Shell commands
Expand Down Expand Up @@ -270,7 +276,7 @@ Usage: Hyde [Function] [options]
[flatpak] ↪️ Flatpak setup for HyDE
[reload] ↪️ Just reload
=====================================================================================================================================================================================
============================================================================================================================================================================
Descriptions with [*] can be expanded to show more information. Append [--help]
Expand All @@ -293,7 +299,7 @@ Usage: Hyde-tool [Function] [options]
[out] ↪️ Zoom out
[reset] ↪️ Reset Zoom
=====================================================================================================================================================================================
============================================================================================================================================================================
Descriptions with [*] can be expanded to show more information. Append [--help]
```
66 changes: 33 additions & 33 deletions shell-completions/Hyde.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,45 @@ _Hyde () {
local words cword
_get_comp_words_by_ref -n "$COMP_WORDBREAKS" words cword

local -a literals=("revert" "--uninstall" "wallbash" "--copy" "--opacity" "-j" "theme" "save" "unset" "3" "--stop" "--animations" "backup" "BackUp" "list" "cursor" "--freeze" "-p" "--no-custom" "Config" "--install" "--scan" "--record-focus" "theme" "bookmarks" "0" "--reset" "toggle" "pastebin" "1" "systeminfo" "--all" "theme" "--delete" "upgrade" "toggle" "waybar" "reload" "update" "all" "glyph" "--wipe" "--print-monitor" "game" "shell" "Config" "info" "--style" "set" "reload" "reset" "on" "--animations" "code" "search" "version" "--site" "select" "--blur" "off" "variety" "clean" "calc" "airplane_mode" "reload" "--browser" "--print-snip" "--reset" "reload" "--rasi" "Clone" "--all" "check" "--all" "::=" "--mismatch" "prev" "--borderangle" "wallpaper" "--borderangle" "show" "-f" "inject" "power" "--persist" "binds" "rebuild" "screencap" "man" "asus_patch" "events" "override" "--rebuild" "--rasi" "--blur" "restore" "install" "-d" "--browser" "sddm" "run" "set" "--option" "cache" "list" "control" "prev" "chaotic_aur" "--less" "mode" "--opacity" "--reset" "Link" "audio_idle" "--print-all" "next" "-h" "select" "--preserve" "size" "next" "branch" "next" "size" "flatpak" "Config" "screencap" "emoji" "--record-snip" "prev" "2" "--revert" "set" "patch" "select" "Package" "control")
local -a literals=("revert" "--uninstall" "wallbash" "--copy" "--opacity" "-j" "theme" "save" "unset" "3" "--stop" "--animations" "backup" "BackUp" "list" "cursor" "--freeze" "-p" "--no-custom" "Config" "--install" "--scan" "--record-focus" "theme" "bookmarks" "0" "--reset" "toggle" "pastebin" "1" "systeminfo" "--all" "theme" "--delete" "upgrade" "toggle" "waybar" "reload" "update" "all" "glyph" "--wipe" "--print-monitor" "game" "shell" "Config" "info" "--style" "set" "reload" "reset" "on" "--animations" "code" "search" "version" "--site" "select" "--blur" "off" "variety" "clean" "calc" "airplane_mode" "reload" "--browser" "--print-snip" "--reset" "reload" "--rasi" "Clone" "--all" "check" "--all" "::=" "--mismatch" "prev" "--borderangle" "wallpaper" "--borderangle" "show" "-f" "inject" "power" "--persist" "binds" "rebuild" "screencap" "man" "asus_patch" "unset" "override" "events" "--rebuild" "--rasi" "--blur" "restore" "install" "-d" "info" "--browser" "sddm" "run" "set" "--option" "cache" "list" "control" "prev" "chaotic_aur" "--less" "mode" "--opacity" "--reset" "Link" "audio_idle" "--print-all" "next" "-h" "select" "--preserve" "size" "next" "branch" "next" "size" "test" "flatpak" "Config" "screencap" "emoji" "--record-snip" "prev" "2" "--revert" "set" "patch" "select" "Package" "control")

declare -A literal_transitions
literal_transitions[0]="([83]=6 [72]=2 [38]=3 [55]=4 [2]=5 [34]=25 [23]=7 [99]=9 [100]=10 [121]=12 [103]=11 [36]=26 [44]=13 [105]=14 [88]=15 [30]=16 [12]=17 [78]=18 [15]=19 [80]=20 [82]=21 [91]=22 [53]=24 [95]=8 [37]=1)"
literal_transitions[2]="([135]=27 [45]=28)"
literal_transitions[5]="([35]=27 [109]=36)"
literal_transitions[6]="([27]=27 [43]=27 [7]=40 [50]=27 [8]=41)"
literal_transitions[7]="([57]=27 [115]=27 [133]=27 [106]=27 [132]=27)"
literal_transitions[8]="([112]=27 [19]=27 [13]=27 [70]=27)"
literal_transitions[9]="([101]=27 [96]=27 [104]=27)"
literal_transitions[10]="([63]=27 [113]=27 [90]=27 [126]=34)"
literal_transitions[0]="([83]=6 [72]=2 [38]=3 [55]=4 [2]=5 [34]=25 [23]=7 [101]=9 [102]=10 [123]=12 [105]=11 [36]=26 [44]=13 [107]=14 [88]=15 [30]=16 [12]=17 [78]=18 [15]=19 [80]=20 [82]=21 [91]=22 [53]=24 [96]=8 [37]=1)"
literal_transitions[2]="([138]=27 [45]=30)"
literal_transitions[5]="([35]=27 [111]=34)"
literal_transitions[6]="([27]=27 [43]=27 [7]=33 [50]=27 [8]=44)"
literal_transitions[7]="([57]=27 [117]=27 [136]=27 [108]=27 [135]=27)"
literal_transitions[8]="([114]=27 [19]=27 [13]=27 [70]=27)"
literal_transitions[9]="([103]=27 [99]=27 [106]=27 [90]=27 [126]=27 [97]=27)"
literal_transitions[10]="([63]=27 [115]=27 [92]=27 [129]=42)"
literal_transitions[11]="([86]=27 [68]=27)"
literal_transitions[13]="([134]=27)"
literal_transitions[14]="([125]=27)"
literal_transitions[13]="([137]=27)"
literal_transitions[14]="([128]=27)"
literal_transitions[17]="([14]=27 [39]=27 [61]=27 [0]=27)"
literal_transitions[18]="([60]=44 [117]=27 [48]=27 [120]=27 [76]=27)"
literal_transitions[19]="([64]=27 [46]=27 [119]=27 [32]=27)"
literal_transitions[20]="([127]=33 [62]=29 [40]=27 [85]=32 [24]=37 [87]=27 [54]=38 [28]=31)"
literal_transitions[21]="([89]=27 [124]=27 [107]=43)"
literal_transitions[18]="([60]=40 [119]=27 [48]=27 [122]=27 [76]=27)"
literal_transitions[19]="([64]=27 [46]=27 [121]=27 [32]=27)"
literal_transitions[20]="([130]=28 [62]=31 [40]=27 [85]=36 [24]=37 [87]=27 [54]=35 [28]=38)"
literal_transitions[21]="([89]=27 [127]=27 [109]=43)"
literal_transitions[24]="([6]=27)"
literal_transitions[26]="([123]=42 [129]=27 [49]=27 [122]=27 [136]=27)"
literal_transitions[28]="([118]=27 [108]=27 [75]=27)"
literal_transitions[29]="([26]=27 [93]=30)"
literal_transitions[31]="([102]=27 [33]=27 [41]=27 [3]=27)"
literal_transitions[32]="([5]=27 [116]=27 [17]=27 [81]=30 [97]=27)"
literal_transitions[33]="([47]=27 [69]=30)"
literal_transitions[34]="([10]=27 [128]=27 [22]=27 [42]=27 [16]=27 [111]=27 [66]=27 [114]=27 [21]=27)"
literal_transitions[35]="([74]=27)"
literal_transitions[36]="([25]=27 [29]=27 [130]=27 [9]=27)"
literal_transitions[37]="([92]=27 [18]=27 [84]=27 [69]=30 [65]=39)"
literal_transitions[38]="([56]=27 [98]=27 [93]=30 [26]=27)"
literal_transitions[40]="([51]=27 [11]=27 [58]=27 [59]=27 [77]=27 [110]=27 [71]=27)"
literal_transitions[41]="([4]=27 [52]=27 [79]=27 [94]=27 [73]=27)"
literal_transitions[42]="([31]=27)"
literal_transitions[43]="([1]=27 [20]=27 [131]=27)"
literal_transitions[44]="([67]=27)"
literal_transitions[26]="([125]=32 [132]=27 [49]=27 [124]=27 [139]=27)"
literal_transitions[28]="([47]=27 [69]=29)"
literal_transitions[30]="([120]=27 [110]=27 [75]=27)"
literal_transitions[31]="([26]=27 [94]=29)"
literal_transitions[32]="([31]=27)"
literal_transitions[33]="([51]=27 [11]=27 [58]=27 [59]=27 [77]=27 [112]=27 [71]=27)"
literal_transitions[34]="([25]=27 [29]=27 [133]=27 [9]=27)"
literal_transitions[35]="([56]=27 [100]=27 [94]=29 [26]=27)"
literal_transitions[36]="([5]=27 [118]=27 [17]=27 [81]=29 [98]=27)"
literal_transitions[37]="([93]=27 [18]=27 [84]=27 [69]=29 [65]=41)"
literal_transitions[38]="([104]=27 [33]=27 [41]=27 [3]=27)"
literal_transitions[39]="([74]=27)"
literal_transitions[40]="([67]=27)"
literal_transitions[42]="([10]=27 [131]=27 [22]=27 [42]=27 [16]=27 [113]=27 [66]=27 [116]=27 [21]=27)"
literal_transitions[43]="([1]=27 [20]=27 [134]=27)"
literal_transitions[44]="([4]=27 [52]=27 [79]=27 [95]=27 [73]=27)"

declare -A match_anything_transitions
match_anything_transitions=([1]=27 [39]=27 [3]=27 [30]=27 [12]=27 [16]=27 [0]=23 [15]=27 [4]=27 [22]=27 [25]=27 [23]=35)
match_anything_transitions=([25]=27 [1]=27 [3]=27 [41]=27 [12]=27 [16]=27 [0]=23 [15]=27 [4]=27 [22]=27 [29]=27 [23]=39)
declare -A subword_transitions

local state=0
Expand Down Expand Up @@ -117,7 +117,7 @@ _Hyde () {
fi

declare -A specialized_commands
specialized_commands=([30]=0)
specialized_commands=([29]=0)
if [[ -v "specialized_commands[$state]" ]]; then
local command_id=${specialized_commands[$state]}
local completions=()
Expand Down
Loading

0 comments on commit 41c1530

Please sign in to comment.