Show loading animation when changing layouts

This commit is contained in:
Rokosun 2023-12-25 15:23:03 +00:00
parent c020b3626f
commit 1f29b13f85
1 changed files with 62 additions and 40 deletions

View File

@ -75,24 +75,6 @@ proc disableTopBarIntegration(): bool =
args=["--channel=xfwm4", "--property=/general/button_layout", "--create", "--type=string", "--set=|HMC"])
return true
proc enableLayout(layoutName: string) =
case layoutName
of "Windows-Like", "MX-Like", "Gnome-Like", "TopX-Like":
if not disableTopBarIntegration():
return
of "Unity-Like", "MacOS-Like":
if not enableTopBarIntegration():
return
else:
return
discard runCommand("/usr/bin/xfce4-panel-profiles", ["load", profilesDir / layoutName & ".tar.bz2"])
if runCommand("/usr/bin/killall", ["mate-hud"]) == 0:
discard runCommand("/usr/bin/setsid", ["-f", "/usr/lib/mate-hud/mate-hud"])
sleep(5000)
sendNotification(appID, "Layout Switcher", layoutName & " layout was enabled",
icon = iconsDir / layoutName.toLowerAscii() & "-layout.png")
var
oldConfigDir: Option[string]
configDirChanged: bool
@ -105,6 +87,7 @@ if symlinkExists(getConfigDir() / "gtk-4.0"):
configDirChanged = true
viewable App:
loading: bool
hooks:
build:
# Reset the user's XDG_CONFIG_HOME variable back to what it was before
@ -114,6 +97,37 @@ viewable App:
else:
putEnv("XDG_CONFIG_HOME", get(oldConfigDir))
proc enableLayout(args: tuple[layoutName: string, app: AppState]) {.thread.} =
let
layoutName = args.layoutName
app = args.app
defer:
app.loading = false
app.redrawFromThread()
case layoutName
of "Windows-Like", "MX-Like", "Gnome-Like", "TopX-Like":
if not disableTopBarIntegration():
return
of "Unity-Like", "MacOS-Like":
if not enableTopBarIntegration():
return
else:
return
# Load the layout profile
discard runCommand("/usr/bin/xfce4-panel-profiles", ["load", profilesDir / layoutName & ".tar.bz2"])
# Restart mate-hud
if runCommand("/usr/bin/killall", ["mate-hud"]) == 0:
discard runCommand("/usr/bin/setsid", ["-f", "/usr/lib/mate-hud/mate-hud"])
# Wait 5 seconds for the effects to take place on screen
sleep(5000)
sendNotification(appID, "Layout Switcher", layoutName & " layout was enabled",
icon = iconsDir / layoutName.toLowerAscii() & "-layout.png")
var thread: Thread[(string, AppState)]
method view(app: AppState): Widget =
result = gui:
Window:
@ -121,27 +135,35 @@ method view(app: AppState): Widget =
# Shrink window to the smallest size
defaultSize = (0, 0)
iconName = "tromjaro-layout-switcher"
Box(orient = OrientY, margin = 7, spacing = 5):
Box(orient = OrientX):
Label {.hAlign: AlignEnd.}:
text = "Please use the"
LinkButton {.expand: false.}:
text = "Panel Profiles"
proc clicked() =
discard runCommand("/usr/bin/setsid", ["-f", "/usr/bin/xfce4-panel-profiles"])
Label {.hAlign: AlignStart.}:
text = "to save your current configuration in case you did any manual changes, else you may lose them."
Label:
text = "Changing to or from any layout that has global menu will require your admin password."
for row in layoutsGrid:
Box(orient = OrientX, spacing = 5):
for tooltip in row:
let layoutName = tooltip.split(' ', 1)[0]
Button {.vAlign: AlignCenter, hAlign: AlignCenter.}:
icon = layoutName.toLowerAscii() & "-layout"
tooltip = tooltip
style = [ButtonFlat, StyleClass("layout-button")]
proc clicked() =
enableLayout(layoutName)
if app.loading:
Box(orient = OrientY, margin = 70):
Spinner(spinning = true)
Label(text = "Loading your layout, please wait...") {.expand: false.}
else:
Box(orient = OrientY, margin = 7, spacing = 5):
Box(orient = OrientX):
Label {.hAlign: AlignEnd.}:
text = "Please use the"
LinkButton {.expand: false.}:
text = "Panel Profiles"
proc clicked() =
discard runCommand("/usr/bin/setsid", ["-f", "/usr/bin/xfce4-panel-profiles"])
Label {.hAlign: AlignStart.}:
text = "to save your current configuration in case you did any manual changes, else you may lose them."
Label:
text = "Changing to or from any layout that has global menu will require your admin password."
for row in layoutsGrid:
Box(orient = OrientX, spacing = 5):
for tooltip in row:
let layoutName = tooltip.split(' ', 1)[0]
Button {.vAlign: AlignCenter, hAlign: AlignCenter.}:
icon = layoutName.toLowerAscii() & "-layout"
tooltip = tooltip
style = [ButtonFlat, StyleClass("layout-button")]
proc clicked() =
app.loading = true
createThread(thread, enableLayout, (layoutName, app))
brew(appID, gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])
joinThread(thread)