mirror of
https://github.com/wizbright/waybox.git
synced 2025-10-29 05:40:20 -04:00
Expandable submenus; better support for other menu systems
This commit is contained in:
parent
77652741b5
commit
7a679988ac
4 changed files with 52 additions and 27 deletions
65
data/menu
65
data/menu
|
|
@ -10,35 +10,50 @@ def get_waybox_pid(name='waybox'):
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_menu_items(menu, indent):
|
def get_menu_items(menu, indent, expand):
|
||||||
print("%s⇢ %s\0nonselectable\x1ftrue\x1ficon\x1fgo-next-symbolic" % (indent, menu.getAttribute('label').replace('_', '') or menu.getAttribute('id')))
|
menu_id = menu.getAttribute('id')
|
||||||
|
nonselectable = str(bool(menu_id == '')).lower()
|
||||||
|
print("%s%s ⇢\0info\x1f{\"menu\": \"%s\"}\x1fnonselectable\x1f%s" % (indent, menu.getAttribute('label').replace('_', '') or menu_id, menu_id, nonselectable))
|
||||||
indent = indent + " "
|
indent = indent + " "
|
||||||
children = menu.childNodes
|
children = menu.childNodes
|
||||||
for i in range(0, children.length):
|
for i in range(0, children.length):
|
||||||
if children[i].nodeType == dom.Node.ELEMENT_NODE and children[i].tagName == 'item':
|
if expand:
|
||||||
action = children[i].getElementsByTagName('action')[0].getAttribute('name')
|
if children[i].nodeType == dom.Node.ELEMENT_NODE and children[i].tagName == 'item':
|
||||||
cmd = ""
|
action = children[i].getElementsByTagName('action')[0].getAttribute('name')
|
||||||
icon = children[i].getAttribute('icon')
|
cmd = ""
|
||||||
label = children[i].getAttribute('label').replace('_', '')
|
icon = children[i].getAttribute('icon')
|
||||||
if action == 'Execute':
|
label = children[i].getAttribute('label').replace('_', '')
|
||||||
cmd = children[i].getElementsByTagName('execute')[0].firstChild.nodeValue
|
if action == 'Execute':
|
||||||
elif action == 'Exit':
|
cmd = children[i].getElementsByTagName('execute')[0].firstChild.nodeValue
|
||||||
cmd = "kill -s SIGTERM %d" % get_waybox_pid()
|
elif action == 'Exit':
|
||||||
elif action == 'Reconfigure':
|
cmd = "kill -s SIGTERM %d" % get_waybox_pid()
|
||||||
cmd = "kill -s SIGUSR2 %d" % get_waybox_pid()
|
elif action == 'Reconfigure':
|
||||||
print("%s %s\0info\x1f%s\x1ficon\x1f%s" % (indent, label, cmd, icon))
|
cmd = "kill -s SIGUSR2 %d" % get_waybox_pid()
|
||||||
elif children[i].nodeType == dom.Node.ELEMENT_NODE and children[i].tagName == 'menu':
|
print("%s\0info\x1f{\"exec\": \"%s\"}\x1ficon\x1f%s\x1fdisplay\x1f%s %s" % (cmd, cmd.replace('"', '\\"'), icon, indent, label))
|
||||||
get_menu_items(children[i], indent)
|
elif children[i].nodeType == dom.Node.ELEMENT_NODE and children[i].tagName == 'menu':
|
||||||
|
get_menu_items(children[i], indent, os.getenv('ROFI_RETV') is None)
|
||||||
|
|
||||||
menu_xml = os.getenv("WB_MENU_XML") or "menu.xml"
|
menu_xml = os.getenv("WB_MENU_XML") or "menu.xml"
|
||||||
# If ran as a rofi script (not possible with wofi)
|
|
||||||
if not os.getenv('ROFI_RETV') is None:
|
|
||||||
import shlex
|
|
||||||
print("\0message\x1f%s" % os.path.abspath(menu_xml))
|
|
||||||
if not (info := os.getenv('ROFI_INFO')) is None:
|
|
||||||
subprocess.Popen(shlex.split(info), stdout=subprocess.PIPE)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
document = dom.parse(menu_xml)
|
document = dom.parse(menu_xml)
|
||||||
|
|
||||||
|
print("\0message\x1f%s" % os.path.abspath(menu_xml))
|
||||||
|
if not (info := os.getenv('ROFI_INFO')) is None:
|
||||||
|
import json
|
||||||
|
obj = json.JSONDecoder().decode(s=info)
|
||||||
|
if 'exec' in info:
|
||||||
|
import shlex
|
||||||
|
subprocess.Popen(shlex.split(obj['exec']), stdout=subprocess.PIPE)
|
||||||
|
sys.exit(0)
|
||||||
|
elif 'menu' in obj:
|
||||||
|
# Eh document.getElementById() seems not to work
|
||||||
|
menus = document.getElementsByTagName('menu')
|
||||||
|
for i in range(0, menus.length):
|
||||||
|
if menus[i].getAttribute('id') == obj['menu']:
|
||||||
|
menu = menus[i]
|
||||||
|
break
|
||||||
|
if not menu is None:
|
||||||
|
get_menu_items(menu, "", True)
|
||||||
|
print("---\0nonselectable\x1ftrue")
|
||||||
|
|
||||||
root_menu = document.getElementsByTagName('menu')[0]
|
root_menu = document.getElementsByTagName('menu')[0]
|
||||||
get_menu_items(root_menu, "")
|
get_menu_items(root_menu, "", True)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
cfdata = configuration_data()
|
cfdata = configuration_data()
|
||||||
|
cfdata.set('bindir', get_option('prefix') / get_option('bindir'))
|
||||||
cfdata.set('libexecdir', get_option('prefix') / get_option('libexecdir'))
|
cfdata.set('libexecdir', get_option('prefix') / get_option('libexecdir'))
|
||||||
cfdata.set('localedir', get_option('prefix') / get_option('localedir'))
|
cfdata.set('localedir', get_option('prefix') / get_option('localedir'))
|
||||||
cfdata.set('sysconfdir', get_option('prefix') / get_option('sysconfdir'))
|
cfdata.set('sysconfdir', get_option('prefix') / get_option('sysconfdir'))
|
||||||
|
|
@ -16,7 +17,6 @@ configure_file(
|
||||||
scripts = files(
|
scripts = files(
|
||||||
'autostart',
|
'autostart',
|
||||||
'environment',
|
'environment',
|
||||||
'menu',
|
|
||||||
'xdg-autostart',
|
'xdg-autostart',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -45,3 +45,10 @@ install_data(
|
||||||
install_dir: get_option('prefix') / get_option('datadir') + '/wayland-sessions',
|
install_dir: get_option('prefix') / get_option('datadir') + '/wayland-sessions',
|
||||||
install_mode: 'rw-r--r--',
|
install_mode: 'rw-r--r--',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
install_data(
|
||||||
|
'menu',
|
||||||
|
install_dir: get_option('prefix') / get_option('bindir'),
|
||||||
|
install_mode: 'rwxr-xr-x',
|
||||||
|
rename: ['waybox-menu']
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,8 @@
|
||||||
</keybind>
|
</keybind>
|
||||||
<keybind key="A-r">
|
<keybind key="A-r">
|
||||||
<action name="Execute">
|
<action name="Execute">
|
||||||
<execute>rofi -show menu:$WB_CONF_DIR/menu</execute>
|
<!-- If you'd prefer to use something like wmenu: `waybox-menu | wmenu | xargs env` -->
|
||||||
|
<execute>rofi -show waybox-menu</execute>
|
||||||
</action>
|
</action>
|
||||||
</keybind>
|
</keybind>
|
||||||
<keybind key="A-F2">
|
<keybind key="A-F2">
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,8 @@ then
|
||||||
DBUS_LAUNCH="dbus-launch --exit-with-session"
|
DBUS_LAUNCH="dbus-launch --exit-with-session"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export PATH=@bindir@:$PATH
|
||||||
|
|
||||||
# No need to export these to Waybox
|
# No need to export these to Waybox
|
||||||
unset TEXTDOMAIN TEXTDOMAINDIR
|
unset TEXTDOMAIN TEXTDOMAINDIR
|
||||||
$DBUS_LAUNCH @libexecdir@/waybox --startup "${WB_AUTOSTART:-true}; ${WB_XDG_AUTOSTART:-true}" "$@"
|
$DBUS_LAUNCH @libexecdir@/waybox --startup "${WB_AUTOSTART:-true}; ${WB_XDG_AUTOSTART:-true}" "$@"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue