diff --git a/v2/internal/ffenestri/menu_darwin.c b/v2/internal/ffenestri/menu_darwin.c index 1b6f7060a..6f384d3a8 100644 --- a/v2/internal/ffenestri/menu_darwin.c +++ b/v2/internal/ffenestri/menu_darwin.c @@ -767,7 +767,7 @@ void processMenuItem(Menu *menu, id parentMenu, JsonNode *item) { bool templateImage = false; getJSONBool(item, "MacTemplateImage", &templateImage); - int fontSize = 13; + int fontSize = 0; getJSONInt(item, "FontSize", &fontSize); // If we have an accelerator diff --git a/v2/internal/ffenestri/traymenu_darwin.c b/v2/internal/ffenestri/traymenu_darwin.c index f926c1b43..343b8ed28 100644 --- a/v2/internal/ffenestri/traymenu_darwin.c +++ b/v2/internal/ffenestri/traymenu_darwin.c @@ -35,8 +35,12 @@ TrayMenu* NewTrayMenu(const char* menuJSON) { result->fontName = getJSONString(processedJSON, "FontName"); result->RGBA = getJSONString(processedJSON, "RGBA"); getJSONBool(processedJSON, "MacTemplateImage", &result->templateImage); - result->fontSize = 13; + result->fontSize = 0; getJSONInt(processedJSON, "FontSize", &result->fontSize); + result->tooltip = NULL; + result->tooltip = getJSONString(processedJSON, "Tooltip"); + result->disabled = false; + getJSONBool(processedJSON, "Disabled", &result->disabled); // Create the menu JsonNode* processedMenu = mustJSONObject(processedJSON, "ProcessedMenu"); @@ -59,7 +63,7 @@ void DumpTrayMenu(TrayMenu* trayMenu) { } -void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName, int fontSize, const char *RGBA) { +void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName, int fontSize, const char *RGBA, const char *tooltip, bool disabled) { // Exit early if NULL if( trayMenu->label == NULL ) { @@ -68,6 +72,13 @@ void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName // Update button label id statusBarButton = msg(trayMenu->statusbaritem, s("button")); id attributedString = createAttributedString(label, fontName, fontSize, RGBA); + + if( tooltip != NULL ) { + msg(statusBarButton, s("setToolTip:"), str(tooltip)); + } + + msg(statusBarButton, s("setEnabled:"), !disabled); + msg(statusBarButton, s("setAttributedTitle:"), attributedString); } @@ -122,7 +133,7 @@ void ShowTrayMenu(TrayMenu* trayMenu) { UpdateTrayIcon(trayMenu); // Update the label if needed - UpdateTrayLabel(trayMenu, trayMenu->label, trayMenu->fontName, trayMenu->fontSize, trayMenu->RGBA); + UpdateTrayLabel(trayMenu, trayMenu->label, trayMenu->fontName, trayMenu->fontSize, trayMenu->RGBA, trayMenu->tooltip, trayMenu->disabled); // Update the menu id menu = GetMenu(trayMenu->menu); diff --git a/v2/internal/ffenestri/traymenu_darwin.h b/v2/internal/ffenestri/traymenu_darwin.h index a619a00cb..331ad4551 100644 --- a/v2/internal/ffenestri/traymenu_darwin.h +++ b/v2/internal/ffenestri/traymenu_darwin.h @@ -13,12 +13,15 @@ typedef struct { const char *label; const char *icon; const char *ID; + const char *tooltip; bool templateImage; const char *fontName; int fontSize; const char *RGBA; + bool disabled; + Menu* menu; id statusbaritem; @@ -35,7 +38,7 @@ void DumpTrayMenu(TrayMenu* trayMenu); void ShowTrayMenu(TrayMenu* trayMenu); void UpdateTrayMenuInPlace(TrayMenu* currentMenu, TrayMenu* newMenu); void UpdateTrayIcon(TrayMenu *trayMenu); -void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName, int fontSize, const char *RGBA); +void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName, int fontSize, const char *RGBA, const char *tooltip, bool disabled); void LoadTrayIcons(); void UnloadTrayIcons(); diff --git a/v2/internal/ffenestri/traymenustore_darwin.c b/v2/internal/ffenestri/traymenustore_darwin.c index 1338532ea..c6a30a894 100644 --- a/v2/internal/ffenestri/traymenustore_darwin.c +++ b/v2/internal/ffenestri/traymenustore_darwin.c @@ -121,10 +121,14 @@ void UpdateTrayMenuLabelInStore(TrayMenuStore* store, const char* JSON) { const char *fontName = getJSONString(parsedUpdate, "FontName"); const char *RGBA = getJSONString(parsedUpdate, "RGBA"); - int fontSize = 13; + int fontSize = 0; getJSONInt(parsedUpdate, "FontSize", &fontSize); + const char *tooltip = getJSONString(parsedUpdate, "Tooltip"); + bool disabled = false; + getJSONBool(parsedUpdate, "Disabled", &disabled); + + UpdateTrayLabel(menu, Label, fontName, fontSize, RGBA, tooltip, disabled); - UpdateTrayLabel(menu, Label, fontName, fontSize, RGBA); } diff --git a/v2/internal/menumanager/traymenu.go b/v2/internal/menumanager/traymenu.go index 5e79258e5..d6901c264 100644 --- a/v2/internal/menumanager/traymenu.go +++ b/v2/internal/menumanager/traymenu.go @@ -27,6 +27,8 @@ type TrayMenu struct { Label string FontSize int FontName string + Disabled bool + Tooltip string `json:",omitempty"` Image string MacTemplateImage bool RGBA string @@ -50,6 +52,8 @@ func NewTrayMenu(trayMenu *menu.TrayMenu) *TrayMenu { Label: trayMenu.Label, FontName: trayMenu.FontName, FontSize: trayMenu.FontSize, + Disabled: trayMenu.Disabled, + Tooltip: trayMenu.Tooltip, Image: trayMenu.Image, MacTemplateImage: trayMenu.MacTemplateImage, menu: trayMenu.Menu, @@ -145,13 +149,27 @@ func (m *Manager) UpdateTrayMenuLabel(trayMenu *menu.TrayMenu) (string, error) { } type LabelUpdate struct { - ID string - Label string + ID string + Label string + FontName string + FontSize int + RGBA string + Disabled bool + Tooltip string + Image string + MacTemplateImage bool } update := &LabelUpdate{ - ID: trayID, - Label: trayMenu.Label, + ID: trayID, + Label: trayMenu.Label, + FontName: trayMenu.FontName, + FontSize: trayMenu.FontSize, + Disabled: trayMenu.Disabled, + Tooltip: trayMenu.Tooltip, + Image: trayMenu.Image, + MacTemplateImage: trayMenu.MacTemplateImage, + RGBA: trayMenu.RGBA, } data, err := json.Marshal(update) diff --git a/v2/pkg/menu/tray.go b/v2/pkg/menu/tray.go index 2e9253b48..7554795ad 100644 --- a/v2/pkg/menu/tray.go +++ b/v2/pkg/menu/tray.go @@ -23,6 +23,15 @@ type TrayMenu struct { FontSize int FontName string + // Tooltip + Tooltip string + + // Callback function when menu clicked + //Click Callback `json:"-"` + + // Disabled makes the item unselectable + Disabled bool + // Menu is the initial menu we wish to use for the tray Menu *Menu