This way rofi captures key presses to filter while still loading all the menu items. A user might lose a few keystrokes if typed quickly after hitting Alt before the rofi window appears.
I need to make sure this optimization doesn't steal focus when it shouldn't.
diff --git a/usr/lib/plasma-hud/plasma-hud b/usr/lib/plasma-hud/plasma-hud
index 7b53fa5..3e74812 100755
--- a/usr/lib/plasma-hud/plasma-hud
+++ b/usr/lib/plasma-hud/plasma-hud
@@ -207,19 +207,9 @@ class PlasmaHudConfig(KdeConfig):
### Implementation
-def get_menu(menuKeys):
- """
- Generate menu of available menu items.
- """
+def init_rofi():
global rofi_process, shortcut_fg_color
- if not menuKeys:
- return ''
-
- menu_string, *menu_items = menuKeys
- for menu_item in menu_items:
- menu_string += '\n' + menu_item
-
# Get the currently active font.
font_name = 'Sans 10'
@@ -313,11 +303,30 @@ def get_menu(menuKeys):
'-color-active', bg_color +", " + fg_color + ", " + bg_color + ", " + info_bg_color + ", " + info_fg_color,
'-color-urgent', bg_color +", " + fg_color + ", " + bg_color + ", " + error_bg_color + ", " + error_fg_color],
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
- rofi_process.stdin.write(menu_string.encode('utf-8'))
- menu_result = rofi_process.communicate()[0].decode('utf8').rstrip()
- rofi_process.stdin.close()
- return menu_result
+
+def get_menu(menuKeys):
+ """
+ Generate menu of available menu items.
+ """
+
+ if not menuKeys:
+ if rofi_process and rofi_process.poll() is None:
+ rofi_process.terminate()
+ return ''
+
+ menu_string, *menu_items = menuKeys
+ for menu_item in menu_items:
+ menu_string += '\n' + menu_item
+
+ if rofi_process and rofi_process.poll() is None:
+ rofi_process.stdin.write(menu_string.encode('utf-8'))
+ menu_result = rofi_process.communicate()[0].decode('utf8').rstrip()
+ rofi_process.stdin.close()
+ return menu_result
+ else:
+ return ''
+
"""
try_appmenu_interface
@@ -359,6 +368,8 @@ def try_dbusmenu_interface(dbusmenu_bus, dbusmenu_object_path):
logging.info('Unable to access dbusmenu items.')
return False
+ init_rofi()
+
dbusmenu_root_item = dbusmenu_object_iface.GetLayout(0, 0, ["label", "children-display"])
dbusmenu_item_dict = dict()
This way rofi captures key presses to filter while still loading all the menu items. A user might lose a few keystrokes if typed quickly after hitting
Alt
before the rofi window appears.I need to make sure this optimization doesn't steal focus when it shouldn't.