From 090b8526ab1f9a8f3f6836e4d0cd7898be7a5c7f Mon Sep 17 00:00:00 2001 From: Christopher Schramm Date: Wed, 27 Jul 2022 16:49:51 +0200 Subject: [PATCH] Avoid rapid LayoutUpdated signals libdbusmenu gets things wrong when signals arrive too frequently (but still with some gap). The interval is completely random - 10 ms turned out too fast as the issue still shows up (probably the gap between the signals is actually lower in those cases), 1 s sounds a lot too long to delay things (just to make broken receiver happy). Closes #1791 --- blueman/main/indicators/StatusNotifierItem.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/blueman/main/indicators/StatusNotifierItem.py b/blueman/main/indicators/StatusNotifierItem.py index 53a224c70..ee5dbba8b 100644 --- a/blueman/main/indicators/StatusNotifierItem.py +++ b/blueman/main/indicators/StatusNotifierItem.py @@ -15,6 +15,7 @@ def __init__(self, on_activate_menu_item: "MenuItemActivator") -> None: super().__init__(None, "com.canonical.dbusmenu", "/org/blueman/sni/menu", Gio.BusType.SESSION) self._items: List["MenuItemDict"] = [] self._revision = 0 + self._revision_advertised = -1 self._on_activate = on_activate_menu_item self.add_method("GetLayout", ("i", "i", "as"), ("u", "(ia{sv}av)"), self._get_layout) @@ -26,10 +27,17 @@ def __init__(self, on_activate_menu_item: "MenuItemActivator") -> None: self.add_signal("LayoutUpdated", ("u", "i")) + GLib.timeout_add(100, self._advertise_revision) + def set_items(self, items: Iterable["MenuItemDict"]) -> None: self._items = list(items) self._revision += 1 - self.emit_signal("LayoutUpdated", self._revision, 0) + + def _advertise_revision(self) -> bool: + if self._revision != self._revision_advertised: + self.emit_signal("LayoutUpdated", self._revision, 0) + self._revision_advertised = self._revision + return True def _get_layout(self, parent_id: int, _recursion_depth: int, _property_names: List[str] ) -> Tuple[int, Tuple[int, Dict[str, GLib.Variant], List[GLib.Variant]]]: