Compare commits

..

No commits in common. "4c5a39a77cee61a0998efeb1a45848aae2cc9205" and "9056b40bc4911018e036dfa0bf372dc9e2e5d4b5" have entirely different histories.

View File

@ -1,6 +1,7 @@
from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close from std/osproc import execProcess, ProcessOption, startProcess, waitForExit, close
from std/os import symlinkExists, getConfigDir, putEnv, `/` from std/os import symlinkExists, getConfigDir, putEnv, `/`
from std/strutils import split, endsWith from std/strutils import split, endsWith, strip
from std/algorithm import fill
from std/strformat import fmt from std/strformat import fmt
import owlkettle import owlkettle
@ -57,25 +58,37 @@ proc setTheme(themeName: string) =
if symlinkExists(getConfigDir() / "gtk-4.0"): if symlinkExists(getConfigDir() / "gtk-4.0"):
putEnv("XDG_CONFIG_HOME", "/dev/null") putEnv("XDG_CONFIG_HOME", "/dev/null")
var
lastClickedButton: array[2, int]
# Display the GTK-4 GUI using owlkettle # Display the GTK-4 GUI using owlkettle
viewable App: viewable App:
highlightButton: array[2, string] # 2D array storing the style for each button
buttonStyles: array[themeStyles.len(),array[themeColors.len(), StyleClass]]
hooks: hooks:
build: build:
# Make all buttons flat by default
for index in 0..state.buttonStyles.high():
fill(state.buttonStyles[index], ButtonFlat)
let currentTheme: string = execProcess("/usr/bin/xfconf-query", let currentTheme: string = execProcess("/usr/bin/xfconf-query",
args=["--channel=xsettings", "--property=/Net/ThemeName"], args=["--channel=xsettings", "--property=/Net/ThemeName"],
options={})[0 .. ^2] options={}).strip(leading=false, trailing=true, chars={'\n'})
let currentThemeSplit: seq[string] = currentTheme.split('-', 2) let currentThemeSplit: seq[string] = currentTheme.split('-', 2)
if currentThemeSplit.len() < 3 or currentThemeSplit[0] != "Colloid": if currentThemeSplit.len() < 3 or currentThemeSplit[0] != "Colloid":
return return
let currentThemeColor = currentThemeSplit[1] let currentThemeColorIndex = find(themeColors, currentThemeSplit[1])
let currentThemeStyle = currentThemeSplit[2] let currentThemeStyleIndex = find(themeStyles, currentThemeSplit[2])
if -1 in [currentThemeColorIndex, currentThemeStyleIndex]:
return
# Highlight current theme button # Highlight current theme button
state.highlightButton = [currentThemeColor, currentThemeStyle] state.buttonStyles[currentThemeStyleIndex][currentThemeColorIndex] = ButtonSuggested
lastClickedButton = [currentThemeStyleIndex, currentThemeColorIndex]
method view(app: AppState): Widget = method view(app: AppState): Widget =
result = gui: result = gui:
@ -90,10 +103,10 @@ method view(app: AppState): Widget =
Label {.vAlign: AlignStart.}: Label {.vAlign: AlignStart.}:
useMarkup = true useMarkup = true
text="<span size='small'>NOTE: Some apps need to be reopened for the theme to be applied.</span>" text="<span size='small'>NOTE: Some apps need to be reopened for the theme to be applied.</span>"
for themeStyle in themeStyles: for y, themeStyle in themeStyles:
# Horizontal box # Horizontal box
Box(orient = OrientX, spacing = 5): Box(orient = OrientX, spacing = 5):
for themeColor in themeColors: for x, themeColor in themeColors:
Button {.vAlign: AlignCenter, hAlign: AlignCenter.}: Button {.vAlign: AlignCenter, hAlign: AlignCenter.}:
icon = fmt"Colloid-{themeColor}-{themeStyle}" icon = fmt"Colloid-{themeColor}-{themeStyle}"
# Teal-Dark-Nord theme will have "(default)" added to its tooltip # Teal-Dark-Nord theme will have "(default)" added to its tooltip
@ -101,13 +114,15 @@ method view(app: AppState): Widget =
fmt"{themeColor}-{themeStyle} (default)" fmt"{themeColor}-{themeStyle} (default)"
else: else:
fmt"{themeColor}-{themeStyle}" fmt"{themeColor}-{themeStyle}"
style = if [themeColor, themeStyle] == app.highlightButton: style = app.buttonStyles[y][x]
ButtonSuggested
else:
ButtonFlat
proc clicked() = proc clicked() =
var thisButton = [y, x]
setTheme(fmt"Colloid-{themeColor}-{themeStyle}") setTheme(fmt"Colloid-{themeColor}-{themeStyle}")
# Highlight this button # Highlight this button
app.highlightButton = [themeColor, themeStyle] app.buttonStyles[y][x] = ButtonSuggested
if lastClickedButton != thisButton:
# Remove highlight from lastClickedButton
app.buttonStyles[lastClickedButton[0]][lastClickedButton[1]] = ButtonFlat
lastClickedButton = thisButton
brew("com.tromjaro.ThemeSwitcher", gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)]) brew("com.tromjaro.ThemeSwitcher", gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])