Skip to content

Commit

Permalink
tray: add a way to call the menus AboutToShow
Browse files Browse the repository at this point in the history
  • Loading branch information
kotontrion committed Jan 10, 2025
1 parent c5b2191 commit ef4f956
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/tray/trayItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ public class TrayItem : Object {

private DBusMenu.Importer menu_importer;

public MenuModel menu_model {
public MenuModel? menu_model {
owned get {
if (menu_importer == null) return null;
return menu_importer.model;
}
}

public ActionGroup action_group {
public ActionGroup? action_group {
owned get {
if (menu_importer == null) return null;
return menu_importer.action_group;
Expand Down Expand Up @@ -298,6 +298,31 @@ public class TrayItem : Object {
);
}

/**
* tells the tray app that its menu is about to be opened,
* so it can update the menu if needed. You should call this method
* before openening the menu.
*/
public void about_to_show() {
if(proxy.Menu == null) return;
try {
Bus.get_sync(BusType.SESSION).call_sync(
this.proxy.g_name_owner,
this.proxy.Menu,
"com.canonical.dbusmenu",
"AboutToShow",
new Variant("(i)", 0),
null,
DBusCallFlags.NONE,
-1,
null
);
}
catch (Error r) {
//silently ignore
}
}

/**
* Send an activate request to the tray app.
*/
Expand Down

0 comments on commit ef4f956

Please sign in to comment.