From 564752e7c581e0db269caa031f5d8196ec326085 Mon Sep 17 00:00:00 2001 From: Ted Alff Date: Fri, 1 Apr 2022 07:34:49 -0400 Subject: [PATCH 1/7] Check for the interface font in desktop specific locations. If not found, don't override the font, but just use the default from the rasi theme. Adds an optional dependency on gir1.2-xfconf-0 to query properties when running XFCE. --- usr/lib/mate-hud/mate-hud | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index 6fa7296..6068e35 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -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.getenv('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 @@ -165,9 +173,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() @@ -176,6 +181,8 @@ def get_menu(menuKeys): keyval, modifiers = Gtk.accelerator_parse(shortcut) shortcut = '' if modifiers else ',' + shortcut + desktop_name = os.getenv('XDG_CURRENT_DESKTOP') + # Calculate display DPI value screen = window.get_screen() scale = window.get_scale_factor() @@ -190,8 +197,6 @@ 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;' - rofi_theme = get_rofi_theme() cmd = ['rofi', '-dmenu', '-i', '-p', 'HUD', @@ -212,6 +217,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() @@ -232,8 +253,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 + '; ' + \ From 2a808102829b40965cb6bfaa84b59cd2c99af33e Mon Sep 17 00:00:00 2001 From: Ted Alff Date: Fri, 1 Apr 2022 07:36:56 -0400 Subject: [PATCH 2/7] Use xfce's custom dpi property to pass to rofi if running XFCE and available. --- usr/lib/mate-hud/mate-hud | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index 6068e35..7e6912c 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -197,6 +197,15 @@ def get_menu(menuKeys): height_dpi = get_dpi(screen.height(), screen.height_mm()) dpi = scale * (width_dpi + height_dpi) / 2 + 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', From f7cc8ce7c02b07433678f0eda5951d3b49983503 Mon Sep 17 00:00:00 2001 From: Ted Alff Date: Fri, 1 Apr 2022 07:41:30 -0400 Subject: [PATCH 3/7] Round the dpi before passing to rofi to avoid warning: 'Option: dpi needs to be set with a number not a Double.' --- usr/lib/mate-hud/mate-hud | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index 7e6912c..82b1484 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -210,7 +210,7 @@ def get_menu(menuKeys): cmd = ['rofi', '-dmenu', '-i', '-p', 'HUD', '-lines', '10', - '-dpi', str(dpi), + '-dpi', str(round(dpi)), '-separator-style', 'none', '-hide-scrollbar', '-click-to-exit', From 248fc9d18bfb25e68149c44103ef02e7c8130cbb Mon Sep 17 00:00:00 2001 From: Ted Alff Date: Fri, 1 Apr 2022 08:52:52 -0400 Subject: [PATCH 4/7] Add XFCE logic to terminate_appmenu_registrar function --- usr/lib/mate-hud/mate-hud | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index 82b1484..3afbd13 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -139,13 +139,26 @@ 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): + desktop_name = os.environ['XDG_CURRENT_DESKTOP'] + if 'MATE' in desktop_name: + if process_running('appmenu-registrar') and not process_running('applet-mate'): kill_process('appmenu-registrar') + elif 'XFCE' in desktop_name: + 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, but xfconf gi repository not available') def rgba_to_hex(color): """ From 0e0020fa72771686140367dff0160778ba9f05e6 Mon Sep 17 00:00:00 2001 From: Ted Alff Date: Fri, 1 Apr 2022 08:56:33 -0400 Subject: [PATCH 5/7] Check os.environ for desktop rather than calling os.getenv --- usr/lib/mate-hud/mate-hud | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index 3afbd13..d542f46 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -16,7 +16,7 @@ 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.getenv('XDG_CURRENT_DESKTOP'): +if 'XFCE' in os.environ['XDG_CURRENT_DESKTOP']: try: gi.require_version("Xfconf", "0") from gi.repository import Xfconf @@ -194,7 +194,7 @@ def get_menu(menuKeys): keyval, modifiers = Gtk.accelerator_parse(shortcut) shortcut = '' if modifiers else ',' + shortcut - desktop_name = os.getenv('XDG_CURRENT_DESKTOP') + desktop_name = os.environ['XDG_CURRENT_DESKTOP'] # Calculate display DPI value screen = window.get_screen() From caa97f3739b959ac18b28c85aaab65a144d53240 Mon Sep 17 00:00:00 2001 From: Ted Alff Date: Fri, 1 Apr 2022 22:22:32 -0400 Subject: [PATCH 6/7] Check if xfce4-panel running rather than if current desktop is XFCE when checking if the xfce4-panel appmenu plugin is loaded. --- usr/lib/mate-hud/mate-hud | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index d542f46..d04fd86 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -139,11 +139,10 @@ def terminate_appmenu_registrar(): # TODO: # - Use Dbus Quit method. # - Add checks for other Desktop Environments. - desktop_name = os.environ['XDG_CURRENT_DESKTOP'] - if 'MATE' in desktop_name: + if 'MATE' in os.environ['XDG_CURRENT_DESKTOP']: if process_running('appmenu-registrar') and not process_running('applet-mate'): kill_process('appmenu-registrar') - elif 'XFCE' in desktop_name: + elif process_running('xfce4-panel'): try: xfc_panel = Xfconf.Channel.new("xfce4-panel") panels = xfc_panel.get_arrayv("/panels") @@ -158,7 +157,7 @@ def terminate_appmenu_registrar(): if process_running('appmenu-registrar') and not appmenu_loaded: kill_process('appmenu-registrar') except: - logging.debug('running XFCE, but xfconf gi repository not available') + logging.debug('running XFCE panel, but xfconf gi repository not available') def rgba_to_hex(color): """ From 3607635d797feaba7f7d21f04f61af6c81f2ef7e Mon Sep 17 00:00:00 2001 From: twa022 Date: Mon, 4 Apr 2022 11:11:52 -0400 Subject: [PATCH 7/7] Fix typo. The process name for the appmenu plug-in in mate is appmenu-mate, not applet-mate (whoops) --- usr/lib/mate-hud/mate-hud | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/lib/mate-hud/mate-hud b/usr/lib/mate-hud/mate-hud index d04fd86..0543e96 100755 --- a/usr/lib/mate-hud/mate-hud +++ b/usr/lib/mate-hud/mate-hud @@ -140,7 +140,7 @@ def terminate_appmenu_registrar(): # - Use Dbus Quit method. # - Add checks for other Desktop Environments. if 'MATE' in os.environ['XDG_CURRENT_DESKTOP']: - if process_running('appmenu-registrar') and not process_running('applet-mate'): + if process_running('appmenu-registrar') and not process_running('appmenu-mate'): kill_process('appmenu-registrar') elif process_running('xfce4-panel'): try: