Skip to content

Commit

Permalink
Avoid rapid LayoutUpdated signals
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cschramm committed Jul 27, 2022
1 parent 0bc5460 commit 090b852
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion blueman/main/indicators/StatusNotifierItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]]]:
Expand Down

0 comments on commit 090b852

Please sign in to comment.