Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a root menu for the desktop #654

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 67 additions & 25 deletions src/bridges/labwc/labwc_bridge.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# This file is part of budgie-desktop
#
# Copyright Budgie Desktop Developers
Expand All @@ -16,6 +17,7 @@
from systemd.journal import JournalHandler
import psutil
import sys
import gettext

import gi
from gi.repository import Gio, GLib
Expand All @@ -28,6 +30,7 @@ class Bridge:

# element tree to read/write
et = None
menuet = None

# gsettings connections
panel_settings = None
Expand Down Expand Up @@ -71,28 +74,35 @@ def write_config(self):
# reload config for labwc
subprocess.call("labwc -r", shell=True)

# starting point for the bridge
def __init__(self):

self.log = logging.getLogger('labwc_bridge')
self.log.addHandler(JournalHandler())

# Check if a local labwc environment file exists - if doesn't
def search_for_config(self, config_file):
# Check if a local labwc config_file exists - if doesn't
# use the budgie-desktop shared file - or the distro variant if it exists
# to populate the local labwc environment file
# to populate the local labwc config folder

search_path = [self.user_config("environment")]
search_path = [self.user_config(config_file)]
for system_dir in GLib.get_system_data_dirs():
search_path.append(os.path.join(system_dir, "budgie-desktop", "distro-environment"))
search_path.append(os.path.join(system_dir, "budgie-desktop", "environment"))
search_path.append(os.path.join(system_dir, "budgie-desktop", "distro-"+config_file))
search_path.append(os.path.join(system_dir, "budgie-desktop", config_file))

path = ""
for path in search_path:
if os.path.isfile(path):
break

if path == "":
self.log.critical("Could not find an existing environment or a shipped budgie equivalent")
self.log.critical("Could not find an existing "+config_file+" or a shipped budgie equivalent")
return None, None

return path, search_path

# starting point for the bridge
def __init__(self):

self.log = logging.getLogger('labwc_bridge')
self.log.addHandler(JournalHandler())

path,search_path = self.search_for_config("environment")
if path == None:
return

try:
Expand All @@ -105,23 +115,29 @@ def __init__(self):
self.log.critical(e)
return

# Check if a local labwc config file exists - if so use it
# otherwise use the budgie-desktop shared file - or the distro variant if it exists
# to populate the local labwc config
path, search_path = self.search_for_config("menu.xml")
if path == None:
return

search_path = [self.user_config()]
try:
if path != search_path[0]:
shutil.copy(path, search_path[0])
except Exception as e:
self.log.critical("Failed to copy " + path + " to " + search_path[0])
self.log.critical(e)
return

for system_dir in GLib.get_system_data_dirs():
search_path.append(os.path.join(system_dir, "budgie-desktop", "distro-rc.xml"))
search_path.append(os.path.join(system_dir, "budgie-desktop", "rc.xml"))
try:
self.menuet = Et.parse(source=path)
except Exception as e:
self.log.warning("Cannot parse " + path + ":\n")
self.log.warning(e)
return

path = ""
for path in search_path:
if os.path.isfile(path):
break
self.translate_menu_labels(path)

if path == "":
self.log.critical("Could not find an existing rc.xml or a shipped budgie equivalent")
path,search_path = self.search_for_config("rc.xml")
if path == None:
return

try:
Expand Down Expand Up @@ -173,6 +189,32 @@ def __init__(self):

self.bridge_config()

# this translate all menu labels if not already done
def translate_menu_labels(self, path):
root = self.menuet.getroot()

# first scan the config file to find any custom entries.
matches = self.menuet.findall('./menu/item[@label]')

gettext.bindtextdomain("budgie-desktop", "/usr/share/locale")
gettext.textdomain("budgie-desktop")

# look for labels and translate them
# we save the original translation string with the menu and use that
# so we can retranslate if the locale changes
for matched in matches:
if "original" in matched.attrib:
label = matched.attrib["original"]
else:
label = matched.attrib["label"]
matched.attrib["original"] = label

translated = gettext.gettext(label)
matched.attrib["label"] = translated

Et.indent(self.menuet, space="\t", level=0)
self.menuet.write(path)

# this manages the default terminal updates
def default_terminal_changed(self, settings, key):
if key != "exec":
Expand Down
10 changes: 10 additions & 0 deletions src/bridges/labwc/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<openbox_menu>
<menu id="root-menu">
<item label="Budgie Desktop Settings" original="Budgie Desktop Settings">
<action name="Execute" command="budgie-desktop-settings" />
</item>
<item label="System Settings" original="System Settings">
<action name="Execute" command="budgie-control-center" />
</item>
</menu>
</openbox_menu>
5 changes: 5 additions & 0 deletions src/bridges/labwc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ install_data(
'environment',
install_dir: join_paths(datadir, 'budgie-desktop')
)

install_data(
'menu.xml',
install_dir: join_paths(datadir, 'budgie-desktop')
)
Loading