Skip to content

Commit

Permalink
Fix GlobalMenu callback bug
Browse files Browse the repository at this point in the history
Previous menus still had callbacks attached to layout changes. These
callbacks need to be removed when finalising the widget.
  • Loading branch information
elParaguayo committed May 31, 2024
1 parent 04e3d6d commit c6c33e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2024-05-31: [BUGFIX] Fix `GlobalMenu` crash after reloading config
2024-05-29: [BUGFIX] Fix bug with border decorations when using both standard and decorated borders
2024-05-22: [RELEASE] v0.26.0 release - compatible with qtile 0.26.0
2024-05-19: [FEATURE] Add modified `Plasma` layout to include border highlighting
Expand Down
14 changes: 12 additions & 2 deletions qtile_extras/resources/dbusmenu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(

def __repr__(self):
"""Custom repr to help debugging."""
txt = f"'{self.label.replace('_','')}'" if self.label else self.item_type
txt = f"'{self.label.replace('_', '')}'" if self.label else self.item_type
if self.children_display == "submenu":
txt += "*"
return f"<DBusMenuItem ({self.id}:{txt})>"
Expand Down Expand Up @@ -119,6 +119,7 @@ def __init__(
self.path = path
self.bus = bus
self._menus: dict[int, dict[str, int | list[DBusMenuItem]]] = {}
self._interface = None
self.no_cache_menus = no_cache_menus
self.layout_callbacks = []
self.display_menu_callback = display_menu_callback
Expand Down Expand Up @@ -186,6 +187,9 @@ async def _get_menu(self, root):
Method to retrieve the menu layout from the DBus interface.
"""

if self._interface is None:
return None, None

needs_update = True

# Alert the app that we're about to draw a menu
Expand Down Expand Up @@ -237,7 +241,10 @@ def parse_menu(self, root, callback, task):
update_needed, returned_menu = task.result()
menu = []

if update_needed == self.MENU_UPDATED:
if update_needed is None:
return

elif update_needed == self.MENU_UPDATED:
# Remember the menu revision ID so we know whether to update or not
revision, layout = returned_menu

Expand Down Expand Up @@ -285,3 +292,6 @@ async def click(self, id):
# Ugly hack: delete all stored menus if the menu has been clicked
# This will force a reload when the menu is next generated.
self._menus = {}

def stop(self):
self._interface.off_layout_updated(self._layout_updated)
14 changes: 11 additions & 3 deletions qtile_extras/widget/globalmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
# SOFTWARE.
from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING

from libqtile import hook
from libqtile.backend.base.window import Internal
from libqtile.utils import create_task
from libqtile.widget import base

from qtile_extras.resources.dbusmenu import DBusMenu
Expand Down Expand Up @@ -85,20 +85,24 @@ def client_updated(self, wid):
del self.app_menus[wid]

if wid == self.current_wid:
asyncio.create_task(self.get_window_menu(wid))
create_task(self.get_window_menu(wid))

def set_hooks(self):
hook.subscribe.focus_change(self.hook_response)
hook.subscribe.client_killed(self.client_killed)

def clear_hooks(self):
hook.unsubscribe.focus_change(self.hook_response)
hook.unsubscribe.client_killed(self.client_killed)

def hook_response(self, *args, startup=False):
if not startup and self.bar.screen != self.qtile.current_screen:
self.clear()
return

self.current_wid = self.qtile.current_window.wid if self.qtile.current_window else None
if self.current_wid:
asyncio.create_task(self.get_window_menu(self.current_wid))
create_task(self.get_window_menu(self.current_wid))
elif not startup:
self.clear()

Expand Down Expand Up @@ -228,4 +232,8 @@ def finalize(self):
registrar.finalize()
for item in self.items:
item.finalize()
for menu in self.app_menus.values():
menu.stop()
self.app_menus.clear()
self.clear_hooks()
base._TextBox.finalize(self)

0 comments on commit c6c33e3

Please sign in to comment.