Show loading animation when changing layouts
This commit is contained in:
parent
c020b3626f
commit
1f29b13f85
|
@ -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,6 +135,11 @@ method view(app: AppState): Widget =
|
|||
# Shrink window to the smallest size
|
||||
defaultSize = (0, 0)
|
||||
iconName = "tromjaro-layout-switcher"
|
||||
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.}:
|
||||
|
@ -142,6 +161,9 @@ method view(app: AppState): Widget =
|
|||
tooltip = tooltip
|
||||
style = [ButtonFlat, StyleClass("layout-button")]
|
||||
proc clicked() =
|
||||
enableLayout(layoutName)
|
||||
app.loading = true
|
||||
createThread(thread, enableLayout, (layoutName, app))
|
||||
|
||||
brew(appID, gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])
|
||||
|
||||
joinThread(thread)
|
||||
|
|
Loading…
Reference in New Issue
Block a user