Skip to content

Add support for setting tooltip text for TrayIcons on MacOS #12948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions native/Avalonia.Native/src/OSX/trayicon.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class AvnTrayIcon : public ComSingleObject<IAvnTrayIcon, &IID_IAvnTrayIcon>
virtual HRESULT SetMenu (IAvnMenu* menu) override;

virtual HRESULT SetIsVisible (bool isVisible) override;

virtual HRESULT SetToolTipText (char* text) override;
};

#endif /* trayicon_h */
15 changes: 15 additions & 0 deletions native/Avalonia.Native/src/OSX/trayicon.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@

return S_OK;
}

HRESULT AvnTrayIcon::SetToolTipText(char* text)
{
START_COM_CALL;

@autoreleasepool
{
if (text != nullptr)
{
[[_native button] setToolTip:[NSString stringWithUTF8String:(const char*)text]];
}
}

return S_OK;
}
2 changes: 1 addition & 1 deletion src/Avalonia.Native/TrayIconImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public unsafe void SetIcon(IWindowIconImpl? icon)

public void SetToolTipText(string? text)
{
// NOP
_native.SetToolTipText(text);
}

public void SetIsVisible(bool visible)
Expand Down
1 change: 1 addition & 0 deletions src/Avalonia.Native/avn.idl
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ interface IAvnTrayIcon : IUnknown
HRESULT SetIcon(void* data, size_t length);
HRESULT SetMenu(IAvnMenu* menu);
HRESULT SetIsVisible(bool isVisible);
HRESULT SetToolTipText(char* text);
}

[uuid(a7724dc1-cf6b-4fa8-9d23-228bf2593edc)]
Expand Down