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 some support for other desktop environments (mostly XFCE) #56

Merged
merged 7 commits into from
Apr 4, 2022
65 changes: 53 additions & 12 deletions usr/lib/mate-hud/mate-hud
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import Gio, GLib, Gtk, Gdk, GObject
from Xlib import display, protocol, X, Xatom, error

if 'XFCE' in os.environ['XDG_CURRENT_DESKTOP']:
try:
gi.require_version("Xfconf", "0")
from gi.repository import Xfconf
Xfconf.init()
except:
logging.debug('running XFCE, but xfconf gi repository not available')

class EWMH:
"""This class provides the ability to get and set properties defined
by the EWMH spec. It was blanty ripped out of pyewmh
Expand Down Expand Up @@ -131,13 +139,25 @@ def terminate_appmenu_registrar():
# TODO:
# - Use Dbus Quit method.
# - Add checks for other Desktop Environments.
applet = None
if 'MATE' in os.environ['XDG_CURRENT_DESKTOP']:
applet = 'appmenu-mate'

if applet:
if process_running('appmenu-registrar') and not process_running(applet):
if process_running('appmenu-registrar') and not process_running('appmenu-mate'):
kill_process('appmenu-registrar')
elif process_running('xfce4-panel'):
try:
xfc_panel = Xfconf.Channel.new("xfce4-panel")
panels = xfc_panel.get_arrayv("/panels")
plugin_ids = []
for panel in panels:
plugin_ids += xfc_panel.get_arrayv("/panels/panel-" + str(panel) + "/plugin-ids")
appmenu_loaded = False
for plugid in plugin_ids:
if ( xfc_panel.get_string("/plugins/plugin-" + str(plugid), "") == 'appmenu' ):
appmenu_loaded = True
break
if process_running('appmenu-registrar') and not appmenu_loaded:
kill_process('appmenu-registrar')
except:
logging.debug('running XFCE panel, but xfconf gi repository not available')

def rgba_to_hex(color):
"""
Expand Down Expand Up @@ -165,9 +185,6 @@ def get_menu(menuKeys):
for menu_item in menu_items:
menu_string += '\n' + menu_item

# Get the currently active font.
font_name = get_string('org.mate.interface', None, 'font-name')

# Get some colors from the currently selected theme.
window = Gtk.Window()

Expand All @@ -176,6 +193,8 @@ def get_menu(menuKeys):
keyval, modifiers = Gtk.accelerator_parse(shortcut)
shortcut = '' if modifiers else ',' + shortcut

desktop_name = os.environ['XDG_CURRENT_DESKTOP']

# Calculate display DPI value
screen = window.get_screen()
scale = window.get_scale_factor()
Expand All @@ -190,13 +209,20 @@ def get_menu(menuKeys):
height_dpi = get_dpi(screen.height(), screen.height_mm())
dpi = scale * (width_dpi + height_dpi) / 2

theme_options = 'window { location: northwest;'
if 'XFCE' in desktop_name:
xfce_custom_dpi = 0
try:
xfce_custom_dpi = Xfconf.Channel.new_with_property_base("xsettings", "/Xft").get_int("/DPI", 0)
except:
logging.debug('running XFCE, but xfconf gi repository not available')
if xfce_custom_dpi > 0:
dpi = xfce_custom_dpi

rofi_theme = get_rofi_theme()
cmd = ['rofi', '-dmenu', '-i',
'-p', 'HUD',
'-lines', '10',
'-dpi', str(dpi),
'-dpi', str(round(dpi)),
'-separator-style', 'none',
'-hide-scrollbar',
'-click-to-exit',
Expand All @@ -212,6 +238,22 @@ def get_menu(menuKeys):
# If we use the default adaptive theme, we need to pull in some
# color information from the GTK theme
if rofi_theme == 'mate-hud' or rofi_theme == 'mate-hud-rounded' :
# Get the currently active font.
font_name = ''
if 'MATE' in desktop_name:
font_name = get_string('org.mate.interface', None, 'font-name')
elif 'XFCE' in desktop_name:
try:
font_name = Xfconf.Channel.new_with_property_base("xsettings", "/Gtk").get_string("/FontName", "")
except:
logging.debug('running XFCE, but xfconf gi repository not available')
elif 'X-Cinnamon' in desktop_name:
font_name = get_string('org.cinnamon.desktop.interface', None, 'font-name')
elif 'Budgie:GNOME' in desktop_name:
font_name = get_string('org.gnome.desktop.interface', None, 'font-name')
if font_name:
cmd += [ '-theme-str', '* { font: "' + font_name + '"; } ' ]

window = Gtk.Window()
style_context = window.get_style_context()

Expand All @@ -232,8 +274,7 @@ def get_menu(menuKeys):
#text_color = rgba_to_hex(style_context.lookup_color('theme_text_color')[1])

# Overwrite some of the theme options
theme_options = '* { font: "' + font_name + '"; } ' + \
'listview { background-color: ' + bg_color + '; ' + \
theme_options = 'listview { background-color: ' + bg_color + '; ' + \
' border-color: ' + selected_bg_color + '; } ' + \
'element { text-color: ' + fg_color + '; } ' + \
'element selected.normal { background-color: ' + selected_bg_color + '; ' + \
Expand Down