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"])
|
args=["--channel=xfwm4", "--property=/general/button_layout", "--create", "--type=string", "--set=|HMC"])
|
||||||
return true
|
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
|
var
|
||||||
oldConfigDir: Option[string]
|
oldConfigDir: Option[string]
|
||||||
configDirChanged: bool
|
configDirChanged: bool
|
||||||
|
@ -105,6 +87,7 @@ if symlinkExists(getConfigDir() / "gtk-4.0"):
|
||||||
configDirChanged = true
|
configDirChanged = true
|
||||||
|
|
||||||
viewable App:
|
viewable App:
|
||||||
|
loading: bool
|
||||||
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
|
||||||
|
@ -114,6 +97,37 @@ viewable App:
|
||||||
else:
|
else:
|
||||||
putEnv("XDG_CONFIG_HOME", get(oldConfigDir))
|
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 =
|
method view(app: AppState): Widget =
|
||||||
result = gui:
|
result = gui:
|
||||||
Window:
|
Window:
|
||||||
|
@ -121,27 +135,35 @@ method view(app: AppState): Widget =
|
||||||
# Shrink window to the smallest size
|
# Shrink window to the smallest size
|
||||||
defaultSize = (0, 0)
|
defaultSize = (0, 0)
|
||||||
iconName = "tromjaro-layout-switcher"
|
iconName = "tromjaro-layout-switcher"
|
||||||
Box(orient = OrientY, margin = 7, spacing = 5):
|
if app.loading:
|
||||||
Box(orient = OrientX):
|
Box(orient = OrientY, margin = 70):
|
||||||
Label {.hAlign: AlignEnd.}:
|
Spinner(spinning = true)
|
||||||
text = "Please use the"
|
Label(text = "Loading your layout, please wait...") {.expand: false.}
|
||||||
LinkButton {.expand: false.}:
|
else:
|
||||||
text = "Panel Profiles"
|
Box(orient = OrientY, margin = 7, spacing = 5):
|
||||||
proc clicked() =
|
Box(orient = OrientX):
|
||||||
discard runCommand("/usr/bin/setsid", ["-f", "/usr/bin/xfce4-panel-profiles"])
|
Label {.hAlign: AlignEnd.}:
|
||||||
Label {.hAlign: AlignStart.}:
|
text = "Please use the"
|
||||||
text = "to save your current configuration in case you did any manual changes, else you may lose them."
|
LinkButton {.expand: false.}:
|
||||||
Label:
|
text = "Panel Profiles"
|
||||||
text = "Changing to or from any layout that has global menu will require your admin password."
|
proc clicked() =
|
||||||
for row in layoutsGrid:
|
discard runCommand("/usr/bin/setsid", ["-f", "/usr/bin/xfce4-panel-profiles"])
|
||||||
Box(orient = OrientX, spacing = 5):
|
Label {.hAlign: AlignStart.}:
|
||||||
for tooltip in row:
|
text = "to save your current configuration in case you did any manual changes, else you may lose them."
|
||||||
let layoutName = tooltip.split(' ', 1)[0]
|
Label:
|
||||||
Button {.vAlign: AlignCenter, hAlign: AlignCenter.}:
|
text = "Changing to or from any layout that has global menu will require your admin password."
|
||||||
icon = layoutName.toLowerAscii() & "-layout"
|
for row in layoutsGrid:
|
||||||
tooltip = tooltip
|
Box(orient = OrientX, spacing = 5):
|
||||||
style = [ButtonFlat, StyleClass("layout-button")]
|
for tooltip in row:
|
||||||
proc clicked() =
|
let layoutName = tooltip.split(' ', 1)[0]
|
||||||
enableLayout(layoutName)
|
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)])
|
brew(appID, gui(App()), icons=[iconsDir], stylesheets=[newStylesheet(gtkCSS)])
|
||||||
|
|
||||||
|
joinThread(thread)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user