Skip to content

Commit

Permalink
Position tray tooltip above the taskbar
Browse files Browse the repository at this point in the history
Use Shell_NotifyGetRect to find the icon location and place the
tip window a fixed distance above/below it.

It appears GUID_NULL used for above is not pulled in by shellapi.h.
Define locally when absent.

Also add TTF_RTLREADING for RTL languages. How to right justify
as well in this case is unclear.

Signed-off-by: Selva Nair <[email protected]>
  • Loading branch information
selvanair committed Feb 13, 2024
1 parent 160754e commit 021cb54
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include "localization.h"
#include "misc.h"

#ifndef GUID_NULL
#include <initguid.h>
DEFINE_GUID(GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#endif

/* Popup Menus */
HMENU hMenu;
HMENU *hMenuConn;
Expand Down Expand Up @@ -438,9 +443,12 @@ OnNotifyTray(LPARAM lParam)
case NIN_POPUPOPEN:
if (traytip)
{
GetCursorPos(&pt);
NOTIFYICONIDENTIFIER nid = {.cbSize = sizeof(nid), .hWnd = o.hWnd,
.uID = HIWORD(lParam), .guidItem = GUID_NULL};
RECT r = {0};
Shell_NotifyIconGetRect(&nid, &r);
SendMessageW(traytip, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM) &ti);
PositionTrayToolTip(pt.x, pt.y); /* taking position from wParam do snot work on Win11! */
PositionTrayToolTip((r.left+r.right)/2, r.top);
}
break;

Expand Down Expand Up @@ -514,6 +522,10 @@ ShowTrayIcon()
ti.cbSize = sizeof(ti);
ti.uId = (UINT_PTR) traytip;
ti.uFlags = TTF_ABSOLUTE|TTF_TRACK|TTF_IDISHWND;
if (LangFlowDirection() != 1)
{
ti.uFlags |= TTF_RTLREADING;
}
ti.hwnd = o.hWnd;
ti.lpszText = _T(PACKAGE_NAME);
SendMessage(traytip, TTM_ADDTOOL, 0, (LPARAM)&ti);
Expand Down

0 comments on commit 021cb54

Please sign in to comment.