Compare commits

..

15 Commits

4 changed files with 270 additions and 110 deletions

View File

@@ -9,4 +9,4 @@ remove:
pamac-installer --remove tromjaro-theme-switcher pamac-installer --remove tromjaro-theme-switcher
clean: clean:
$(RM) -rf src/ pkg/ icons.zip *.tar.zst $(RM) -rf src/ pkg/ icons.tar.gz *.tar.zst

View File

@@ -1,7 +1,7 @@
# Maintainer: TROM <contact@tromsite.com> # Maintainer: TROM <contact@tromsite.com>
pkgname=tromjaro-theme-switcher pkgname=tromjaro-theme-switcher
pkgver=2.1 pkgver=3
pkgrel=1 pkgrel=4
pkgdesc="TROMjaro Theme switcher application" pkgdesc="TROMjaro Theme switcher application"
arch=('x86_64') arch=('x86_64')
url="https://git.trom.tf/TROMjaro/theme-switcher-package" url="https://git.trom.tf/TROMjaro/theme-switcher-package"
@@ -10,6 +10,11 @@ depends=('tromjaro-fixes'
'xfconf' 'xfconf'
'gtk4' 'gtk4'
'colloid-gtk-theme-git' 'colloid-gtk-theme-git'
'colloid-dracula-gtk-theme-git'
'colloid-gruvbox-gtk-theme-git'
'colloid-nord-gtk-theme-git'
'colloid-everforest-gtk-theme-git'
'colloid-catppuccin-gtk-theme-git'
'zafiro-icon-theme') 'zafiro-icon-theme')
makedepends=('choosenim') makedepends=('choosenim')
provides=('tromjaro-theme-switcher') provides=('tromjaro-theme-switcher')
@@ -18,7 +23,7 @@ options=(!strip)
source=("themeSwitcher.nim" source=("themeSwitcher.nim"
"tromjaro-theme-switcher.desktop" "tromjaro-theme-switcher.desktop"
"tromjaro-theme-switcher.svg" "tromjaro-theme-switcher.svg"
"icons.zip::https://www.drive.tromsite.com/s/zFtCp3SkZ4NpKix/download") "icons.tar.gz::https://www.drive.tromsite.com/s/ysM33nJAkpro85b/download/icons.tar.gz")
sha256sums=('SKIP' sha256sums=('SKIP'
'SKIP' 'SKIP'
'SKIP' 'SKIP'
@@ -29,29 +34,35 @@ prepare() {
mkdir -p "$HOME"/.choosenim mkdir -p "$HOME"/.choosenim
touch "$HOME"/.choosenim/analytics touch "$HOME"/.choosenim/analytics
} }
echo 'Install Nim if not already installed:' echo 'Install Nim if not already installed:'
choosenim stable choosenim stable
echo 'Update Nim to the latest stable release:' echo 'Update Nim to the latest stable release:'
choosenim update stable choosenim update stable
echo 'Refresh nimble package list:' echo 'Refresh nimble package list:'
"$HOME"/.nimble/bin/nimble --nim:"$HOME"/.nimble/bin/nim refresh "$HOME"/.nimble/bin/nimble --nim:"$HOME"/.nimble/bin/nim refresh
echo 'Install owlkettle from the latest git commit:' echo 'Install owlkettle from the latest git commit:'
"$HOME"/.nimble/bin/nimble --nim:"$HOME"/.nimble/bin/nim install owlkettle "$HOME"/.nimble/bin/nimble --nim:"$HOME"/.nimble/bin/nim install owlkettle
} }
build(){ build(){
echo 'Compile themeSwitcher.nim for release build:' echo 'Compile themeSwitcher.nim for release build:'
"$HOME"/.nimble/bin/nim c -d:release --out:${srcdir}/themeSwitcher ${srcdir}/themeSwitcher.nim "$HOME"/.nimble/bin/nim c -d:release --out:${srcdir}/themeSwitcher ${srcdir}/themeSwitcher.nim
} }
package() { package() {
# copy icons # copy icons
install -d ${pkgdir}/usr/share/tromjaro-theme-switcher/icons install -d ${pkgdir}/usr/share/tromjaro-theme-switcher/icons/Styles
install -Dm644 ${srcdir}/icons/* ${pkgdir}/usr/share/tromjaro-theme-switcher/icons install -Dm644 ${srcdir}/icons/Styles/* ${pkgdir}/usr/share/tromjaro-theme-switcher/icons/Styles
# copy executables for source_dir in "${srcdir}/icons/Accent Colors"/*; do
install -Dm644 ${srcdir}/tromjaro-theme-switcher.desktop ${pkgdir}/usr/share/applications/tromjaro-theme-switcher.desktop dest_dir="${pkgdir}/usr/share/tromjaro-theme-switcher/icons/Accent Colors/${source_dir##*/}"
install -Dm755 ${srcdir}/themeSwitcher ${pkgdir}/usr/bin/tromjaro-theme-switcher install -d "$dest_dir"
install -Dm644 "$source_dir"/* "$dest_dir"
done
# copy the icon # copy executables
install -d ${pkgdir}/usr/share/icons/hicolor/scalable/apps install -Dm644 ${srcdir}/tromjaro-theme-switcher.desktop ${pkgdir}/usr/share/applications/tromjaro-theme-switcher.desktop
install -Dm644 ${srcdir}/tromjaro-theme-switcher.svg ${pkgdir}/usr/share/icons/hicolor/scalable/apps install -Dm755 ${srcdir}/themeSwitcher ${pkgdir}/usr/bin/tromjaro-theme-switcher
# copy the icon
install -d ${pkgdir}/usr/share/icons/hicolor/scalable/apps
install -Dm644 ${srcdir}/tromjaro-theme-switcher.svg ${pkgdir}/usr/share/icons/hicolor/scalable/apps
} }

View File

@@ -1,60 +1,45 @@
from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close from std/os import symlinkExists, getConfigDir, walkDirs, `/`
from std/envvars import existsEnv, getEnv, delEnv, putEnv from std/envvars import existsEnv, getEnv, delEnv, putEnv
from std/os import symlinkExists, getConfigDir, `/`
from std/options import Option, some, get, isNone from std/options import Option, some, get, isNone
from std/strutils import split, endsWith
from std/strformat import fmt from std/strformat import fmt
import owlkettle import pkg/owlkettle
import ./themes
const const
# Set the directory path where icons are stored # Set the directory path where icons are stored
iconsDir = "/usr/share/tromjaro-theme-switcher/icons" iconsDir = "/usr/share/tromjaro-theme-switcher/icons"
styleIconsDir = iconsDir / "Styles"
accentIconsDir = iconsDir / "Accent Colors"
# GTK CSS for overriding the default icon size of buttons # GTK CSS for overriding the default icon size of buttons
gtkCSS = "button { -gtk-icon-size: 85px; }" gtkCSS = """
applicationID = "com.tromjaro.ThemeSwitcher" .style-button {
themeColors = ["Grey", "Pink", "Green", "Orange", "Purple", "Yellow", "Teal"] min-width: 5.5em;
themeStyles = ["Light", "Nord", "Dark", "Dark-Nord"] min-height: 5em;
padding: 0.3em;
border-radius: 14%;
}
proc runCommand(command: string, args: openArray[string]): bool = .accent-button {
## This will run a command with the given args and return true upon success -gtk-icon-size: 1.65em;
let process = startProcess(command, args=args, options={poParentStreams}) padding: 0.4em;
result = process.waitForExit() == 0 border-radius: 50%;
process.close() }
"""
proc setIconTheme(iconName: string) = var iconsDirs: seq[string]
# Change icon theme in XFCE
discard runCommand("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/IconThemeName", "--create", "--type=string", "--set", iconName])
proc enableDarkPanels(): bool = for dir in walkDirs(accentIconsDir / "*"):
# Return if dark panels is already enabled iconsDirs.add(dir)
if execProcess("/usr/bin/xfconf-query",
args=["--channel=xfce4-panel", "--property=/panels/dark-mode"], options={}) == "true\n":
return
# Try to enable it and return true upon success
result = runCommand("/usr/bin/xfconf-query",
args=["--channel=xfce4-panel", "--property=/panels/dark-mode", "--create", "--type=bool", "--set=true"])
proc setTheme(themeName: string) = # Function prototypes
proc makeThemeButton(shadeName: string, styleName: string): Widget
var panelNotification: string proc makeAccentButton(accentColor: string): Widget
proc accentButtons(): Widget
# Set the icon theme and panel color according to the chosen theme proc themeButtons(): Widget
if themeName.endsWith("-Dark") or themeName.endsWith("-Dark-Nord"): proc mainGUI(): Widget
setIconTheme("zafiro-dark")
else:
setIconTheme("zafiro")
if enableDarkPanels():
panelNotification = " with dark panels"
# Change the main theme to the chosen one
discard runCommand("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName", "--create", "--type=string", "--set", themeName])
# Send notification about the theme change
sendNotification(applicationID, "Theme Switcher", fmt"{themeName} theme{panelNotification} is enabled",
icon=fmt"{iconsDir}/{themeName}.svg")
# Keep track of current theme button
var currentTheme = getCurrentTheme()
var var
oldConfigDir: Option[string] oldConfigDir: Option[string]
@@ -68,8 +53,8 @@ if symlinkExists(getConfigDir() / "gtk-4.0"):
configDirChanged = true configDirChanged = true
# Display the GTK-4 GUI using owlkettle # Display the GTK-4 GUI using owlkettle
viewable App: viewable App:
highlightButton: array[2, string]
hooks: hooks:
build: build:
# Reset the user's XDG_CONFIG_HOME variable back to what it was before # Reset the user's XDG_CONFIG_HOME variable back to what it was before
@@ -79,53 +64,106 @@ viewable App:
else: else:
putEnv("XDG_CONFIG_HOME", get(oldConfigDir)) putEnv("XDG_CONFIG_HOME", get(oldConfigDir))
let currentTheme: string = execProcess("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName"],
options={})[0 .. ^2]
let currentThemeSplit: seq[string] = currentTheme.split('-', 2)
if currentThemeSplit.len() < 3 or currentThemeSplit[0] != "Colloid":
return
let currentThemeColor = currentThemeSplit[1]
let currentThemeStyle = currentThemeSplit[2]
# Highlight current theme button
state.highlightButton = [currentThemeColor, currentThemeStyle]
method view(app: AppState): Widget = method view(app: AppState): Widget =
result = mainGUI()
brew(appID, gui(App()), icons=iconsDirs, stylesheets=[newStylesheet(gtkCSS)])
# Function declarations
proc makeThemeButton(shadeName: string, styleName: string): Widget =
let
shade = if shadeName == "": "" else: fmt"-{shadeName}"
style = if styleName == "Default": "" else: fmt"-{styleName}"
color = if currentTheme.color in ["Blue", ""]: "" else: fmt"-{currentTheme.color}"
themeString = fmt"Colloid{color}{shade}{style}"
result = gui: result = gui:
Button:
Picture:
pixbuf = loadPixbuf(fmt"{styleIconsDir}/Colloid{shade}{style}.svg")
tooltip = if shadeName == "": styleName else: fmt"{shadeName}-{styleName}"
style = if (shadeName, styleName) == (currentTheme.shade, currentTheme.style):
[StyleClass("style-button"), ButtonSuggested]
else:
[StyleClass("style-button"), ButtonFlat]
proc clicked() =
setTheme(themeString)
# Highlight this button
currentTheme.shade = shadeName
currentTheme.style = styleName
if currentTheme.color == "":
currentTheme.color = "Blue"
proc makeAccentButton(accentColor: string): Widget =
let
shade = if currentTheme.shade == "": "" else: fmt"-{currentTheme.shade}"
style = if currentTheme.style in ["Default", ""]: "" else: fmt"-{currentTheme.style}"
color = if accentColor == "Blue": "" else: fmt"-{accentColor}"
themeString = fmt"Colloid{color}{shade}{style}"
result = gui:
Button:
icon = fmt"{accentColor}{style}{shade}"
tooltip = accentColor
style = if accentColor == currentTheme.color:
[StyleClass("accent-button"), ButtonSuggested]
else:
[StyleClass("accent-button"), ButtonFlat]
proc clicked() =
setTheme(themeString)
# Highlight this button
currentTheme.color = accentColor
if currentTheme.style == "":
currentTheme.style = "Default"
proc themeButtons(): Widget =
gui:
# Vertical box
Box(orient = OrientY, spacing = 5):
for shadeName in themeShades:
# Horizontal box
Box(orient = OrientX, spacing = 5):
for styleName in themeStyles:
let themeButton = makeThemeButton(shadeName, styleName)
insert(themeButton) {.vAlign: AlignCenter, hAlign: AlignCenter.}
proc accentButtons(): Widget =
gui:
# Horizontal box
Box(orient = OrientX, spacing = 3):
for accentColor in accentColors:
let accentButton = makeAccentButton(accentColor)
insert(accentButton) {.vAlign: AlignCenter, hAlign: AlignCenter.}
proc mainGUI(): Widget =
gui:
Window: Window:
title = "TROMjaro Theme Switcher" title = "TROMjaro Theme Switcher"
# Shrink window to the smallest size # Shrink window to the smallest size
defaultSize = (0, 0) defaultSize = (1, 1)
iconName = "tromjaro-theme-switcher" iconName = appLogo
# Vertical box # Vertical box
Box(orient = OrientY, margin = 7, spacing = 5): Box(orient = OrientY, margin = 13, spacing = 10):
Label: Label:
text="A Theme Switcher for TROMjaro's default theme-set (Colloid) and icon-set (Zafiro)." useMarkup=true
Label {.vAlign: AlignStart.}: text="<span size='large'>STYLE</span>"
useMarkup = true # Theme buttons
text="<span size='small'>NOTE: Some apps need to be reopened for the theme to be applied.</span>" insert(themeButtons())
for themeStyle in themeStyles: Separator(margin = Margin(top: 5)) {.vAlign: AlignCenter.}
# Horizontal box Label:
Box(orient = OrientX, spacing = 5): useMarkup=true
for themeColor in themeColors: text="<span size='large'>ACCENT COLOR</span>"
Button {.vAlign: AlignCenter, hAlign: AlignCenter.}: # Accent buttons
icon = fmt"Colloid-{themeColor}-{themeStyle}" insert(accentButtons())
# Teal-Dark-Nord theme will have "(default)" added to its tooltip Separator(margin = Margin(top: 12)) {.vAlign: AlignCenter.}
tooltip = if (themeColor, themeStyle) == ("Teal", "Dark-Nord"): # Vertical box
fmt"{themeColor}-{themeStyle} (default)" Box(orient = OrientY):
else: Label:
fmt"{themeColor}-{themeStyle}" text="A Theme Switcher for TROMjaro's default theme-set (Colloid) and icon-set (Zafiro)."
style = if [themeColor, themeStyle] == app.highlightButton: Label {.vAlign: AlignStart.}:
ButtonSuggested useMarkup = true
else: text="<span size='small'>NOTE: Some apps need to be reopened for the theme to be applied.</span>"
ButtonFlat
proc clicked() =
setTheme(fmt"Colloid-{themeColor}-{themeStyle}")
# Highlight this button
app.highlightButton = [themeColor, themeStyle]
brew(applicationID, gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])

111
themes.nim Normal file
View File

@@ -0,0 +1,111 @@
from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close
from std/strutils import split, endsWith, contains
from std/strformat import fmt
import pkg/owlkettle
type Theme = tuple[color, shade, style: string]
const
themeShades* = ["Light", "", "Dark"]
themeStyles* = ["Default", "Nord", "Dracula", "Catppuccin", "Everforest", "Gruvbox"]
accentColors* = ["Blue", "Red", "Purple", "Pink", "Teal", "Green", "Yellow", "Orange", "Grey"]
appID* = "com.tromjaro.ThemeSwitcher"
appLogo* = "tromjaro-theme-switcher"
proc getCurrentTheme*(): Theme =
let currentThemeString = execProcess("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName"],
options={})[0 .. ^2]
# Split the theme string into words
let words = currentThemeString.split('-')
if words[0] != "Colloid":
return
var currentTheme: Theme = (color: "Blue", shade: "", style: "Default")
case len(words):
of 1: discard
# Match against Colloid-Color, Colloid-Shade, Colloid-Style
of 2:
let word1 = words[1]
if word1 in accentColors:
currentTheme.color = word1
elif word1 in themeShades:
currentTheme.shade = word1
elif word1 in themeStyles:
currentTheme.style = word1
else:
return
# Match against Colloid-Color-Shade, Colloid-Shade-Style
of 3:
let
word1 = words[1]
word2 = words[2]
if (word1 in accentColors) and (word2 in themeShades):
currentTheme.color = word1
currentTheme.shade = word2
elif (word1 in themeShades) and (word2 in themeStyles):
currentTheme.shade = word1
currentTheme.style = word2
else:
return
# Match against Colloid-Color-Shade-Style
of 4:
let
word1 = words[1]
word2 = words[2]
word3 = words[3]
if (word1 in accentColors) and (word2 in themeShades) and (word3 in themeStyles):
currentTheme.color = word1
currentTheme.shade = word2
currentTheme.style = word3
else:
return
else:
return
return currentTheme
proc runCommand(command: string, args: openArray[string]): bool =
## This will run a command with the given args and return true upon success
let process = startProcess(command, args=args, options={poParentStreams})
result = process.waitForExit() == 0
process.close()
proc setIconTheme(iconName: string) =
# Change icon theme in XFCE
discard runCommand("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/IconThemeName", "--create", "--type=string", "--set", iconName])
proc enableDarkPanels(): bool =
# Return if dark panels is already enabled
if execProcess("/usr/bin/xfconf-query",
args=["--channel=xfce4-panel", "--property=/panels/dark-mode"], options={}) == "true\n":
return
# Try to enable it and return true upon success
result = runCommand("/usr/bin/xfconf-query",
args=["--channel=xfce4-panel", "--property=/panels/dark-mode", "--create", "--type=bool", "--set=true"])
proc setTheme*(themeName: string) =
var panelNotification: string
# Set the icon theme and panel color according to the chosen theme
if themeName.endsWith("-Dark") or themeName.contains("-Dark-"):
setIconTheme("zafiro-dark")
else:
setIconTheme("zafiro")
if enableDarkPanels():
panelNotification = " with dark panels"
# Change the main theme to the chosen one
discard runCommand("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName", "--create", "--type=string", "--set", themeName])
# Send notification about the theme change
sendNotification(appID, "Theme Switcher", fmt"{themeName} theme{panelNotification} is enabled",
icon=appLogo)