2024-01-01 15:38:54 +00:00
|
|
|
from std/osproc import execProcess
|
2023-12-25 07:54:45 +00:00
|
|
|
from std/strformat import fmt
|
2024-01-01 15:38:54 +00:00
|
|
|
import sharedModule, std/os
|
2023-12-25 07:54:45 +00:00
|
|
|
|
|
|
|
proc enableGlobalMenus(): int =
|
2024-01-01 15:38:54 +00:00
|
|
|
try:
|
|
|
|
moveFile("/usr/lib/vala-panel/appmenu-registrar.disabled", "/usr/lib/vala-panel/appmenu-registrar")
|
|
|
|
removeFile("/usr/share/libalpm/hooks/disable-global-menu.hook")
|
|
|
|
except:
|
|
|
|
return 1
|
2023-12-25 07:54:45 +00:00
|
|
|
|
|
|
|
proc disableGlobalMenus(): int =
|
2024-01-01 15:38:54 +00:00
|
|
|
try:
|
|
|
|
moveFile("/usr/lib/vala-panel/appmenu-registrar", "/usr/lib/vala-panel/appmenu-registrar.disabled")
|
|
|
|
if not fileExists("/usr/share/libalpm/hooks/disable-global-menu.hook"):
|
|
|
|
createDir("/usr/share/libalpm/hooks")
|
|
|
|
copyFileWithPermissions("/usr/share/tromjaro-layout-switcher/disable-global-menu.hook",
|
|
|
|
"/usr/share/libalpm/hooks/disable-global-menu.hook")
|
2023-12-25 07:54:45 +00:00
|
|
|
discard runCommand("/usr/bin/killall", ["appmenu-registrar"])
|
2024-01-01 15:38:54 +00:00
|
|
|
except:
|
|
|
|
return 1
|
2023-12-25 07:54:45 +00:00
|
|
|
|
|
|
|
proc showHelp() =
|
|
|
|
let executableName = paramStr(0).extractFilename()
|
|
|
|
echo fmt"""
|
|
|
|
Usage: {executableName} <option>
|
|
|
|
Options:
|
2024-01-01 15:38:54 +00:00
|
|
|
enable enable global menus
|
|
|
|
disable disable global menus"""
|
|
|
|
|
|
|
|
if execProcess("/usr/bin/id", args=["--user"], options={}) != "0\n":
|
|
|
|
echo "Run this program as root."
|
|
|
|
quit(1)
|
2023-12-25 07:54:45 +00:00
|
|
|
|
|
|
|
var exitCode: int
|
|
|
|
if paramCount() < 1:
|
|
|
|
if isGlobalMenuEnabled():
|
|
|
|
exitCode = disableGlobalMenus()
|
|
|
|
else:
|
|
|
|
exitCode = enableGlobalMenus()
|
|
|
|
else:
|
|
|
|
case paramStr(1)
|
|
|
|
of "enable":
|
|
|
|
if isGlobalMenuEnabled():
|
|
|
|
echo "Global menus are already enabled."
|
|
|
|
exitCode = 0
|
|
|
|
else:
|
|
|
|
exitCode = enableGlobalMenus()
|
|
|
|
of "disable":
|
|
|
|
if not isGlobalMenuEnabled():
|
|
|
|
echo "Global menus are already disabled."
|
|
|
|
exitCode = 0
|
|
|
|
else:
|
|
|
|
exitCode = disableGlobalMenus()
|
|
|
|
else:
|
|
|
|
showHelp()
|
|
|
|
|
|
|
|
quit(exitCode)
|