aboutsummaryrefslogtreecommitdiff
path: root/programs/cwal/components/qt.sh
blob: e6a8011f809041f8da728a2934c745567328bf4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
# Copyright (C) 2026 deltegui
# SPDX-License-Identifier: GPL-3.0-or-later

set -euo pipefail

component_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
source "$component_dir/common.sh"

CWAL_COMPONENT=qt
export CWAL_COMPONENT

template="$CWAL_TEMPLATES_DIR/kde.colors"
color_scheme_directory="${XDG_DATA_HOME:-$HOME/.local/share}/color-schemes"
color_destination="$color_scheme_directory/Cwal.colors"
config="$HOME/.config/kdeglobals"
environment_directory="$HOME/.config/environment.d"
environment_destination="$environment_directory/cwal-qt.conf"

prepare_environment()
{
    local temporary

    temporary=$(component_temp environment "$environment_destination")
    printf '# Generated by cwal; applies to new Qt Wayland applications.\n' \
        > "$temporary"
    printf 'QT_QPA_PLATFORMTHEME=KDE\n' >> "$temporary"
    printf 'QT_WAYLAND_DISABLE_WINDOWDECORATION=1\n' >> "$temporary"
    chmod 0644 "$temporary"
}

case ${1:-} in
detect)
    command -v kwriteconfig6 >/dev/null 2>&1 &&
        [[ -d ${HOME:?HOME is not set}/.config ]]
    ;;
prepare)
    require_readable 'Qt color scheme template' "$template"
    mkdir -p -- "$color_scheme_directory" "$environment_directory"
    prepare_environment
    ;;
generate)
    component_render colors "$color_destination" "$template"
    ;;
validate)
    ;;
install)
    component_install colors "$color_destination"
    component_install environment "$environment_destination"
    ;;
reload)
    if command -v plasma-apply-colorscheme >/dev/null 2>&1; then
        if command -v kreadconfig6 >/dev/null 2>&1 &&
           [[ $(kreadconfig6 --file "$config" --group General \
               --key ColorScheme 2>/dev/null || true) == Cwal ]]; then
            plasma-apply-colorscheme BreezeDark >/dev/null 2>&1 || true
        fi
        if ! plasma-apply-colorscheme Cwal >/dev/null 2>&1; then
            printf 'apply-theme: could not apply the live Qt color scheme\n' >&2
        fi
    else
        kwriteconfig6 --file "$config" --group General \
            --key ColorScheme Cwal
    fi
    if [[ ${CWAL_ICON_THEME_INSTALLED:-0} == 1 ]]; then
        kwriteconfig6 --file "$config" --group Icons \
            --key Theme "${CWAL_ICON_THEME:-}"
    fi
    kwriteconfig6 --file "$config" --group KDE --key widgetStyle Breeze
    ;;
summary)
    printf '  Qt:     %s (color scheme Cwal)\n' "$color_destination"
    if [[ ${CWAL_ICON_THEME_INSTALLED:-0} == 1 ]]; then
        printf '           icon theme: %s\n' "$CWAL_ICON_THEME"
    elif [[ ${CWAL_ICON_THEME:-} != '' ]]; then
        printf '           icon theme: default (requested theme is not installed)\n'
    else
        printf '           icon theme: unchanged (system default)\n'
    fi
    printf '           decorations disabled for new Qt Wayland apps\n'
    ;;
*)
    printf 'Usage: %s {detect|prepare|generate|validate|install|reload|summary}\n' \
        "${0##*/}" >&2
    exit 2
    ;;
esac