#include "win.h"
#include <shellapi.h>
#include "winprefs.h"
void
winInitNotifyIcon (winPrivScreenPtr pScreenPriv)
{
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
NOTIFYICONDATA nid = {0};
nid.cbSize = sizeof (NOTIFYICONDATA);
nid.hWnd = pScreenPriv->hwndScreen;
nid.uID = pScreenInfo->dwScreen;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYICON;
nid.hIcon = LoadImage (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN),
IMAGE_ICON,
GetSystemMetrics (SM_CXSMICON),
GetSystemMetrics (SM_CYSMICON),
0);
pScreenPriv->hiconNotifyIcon = nid.hIcon;
snprintf (nid.szTip,
sizeof (nid.szTip),
"Cygwin/XFree86 Server - %s:%d",
display,
(int) pScreenInfo->dwScreen);
if (!Shell_NotifyIcon (NIM_ADD, &nid))
ErrorF ("winInitNotifyIcon - Shell_NotifyIcon Failed\n");
}
void
winDeleteNotifyIcon (winPrivScreenPtr pScreenPriv)
{
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
NOTIFYICONDATA nid = {0};
#if 0
ErrorF ("winDeleteNotifyIcon\n");
#endif
nid.cbSize = sizeof (NOTIFYICONDATA);
nid.hWnd = pScreenPriv->hwndScreen;
nid.uID = pScreenInfo->dwScreen;
if (!Shell_NotifyIcon (NIM_DELETE, &nid))
{
ErrorF ("winDeleteNotifyIcon - Shell_NotifyIcon failed\n");
return;
}
if (pScreenPriv->hiconNotifyIcon != NULL
&& DestroyIcon (pScreenPriv->hiconNotifyIcon) == 0)
{
ErrorF ("winDeleteNotifyIcon - DestroyIcon failed\n");
}
pScreenPriv->hiconNotifyIcon = NULL;
}
LRESULT
winHandleIconMessage (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam,
winPrivScreenPtr pScreenPriv)
{
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
switch (lParam)
{
case WM_LBUTTONDBLCLK:
winDisplayExitDialog (pScreenPriv);
break;
case WM_RBUTTONUP:
{
POINT ptCursor;
HMENU hmenuPopup;
HMENU hmenuTray;
GetCursorPos (&ptCursor);
hmenuPopup = LoadMenu (g_hInstance,
MAKEINTRESOURCE(IDM_TRAYICON_MENU));
if (!hmenuPopup)
ErrorF ("winHandleIconMessage - LoadMenu failed\n");
hmenuTray = GetSubMenu (hmenuPopup, 0);
if (pScreenInfo->fMultiWindow)
{
if (pScreenPriv->fRootWindowShown)
{
RemoveMenu (hmenuTray,
ID_APP_SHOW_ROOT,
MF_BYCOMMAND);
}
else
{
RemoveMenu (hmenuTray,
ID_APP_HIDE_ROOT,
MF_BYCOMMAND);
}
}
else
{
RemoveMenu (hmenuTray,
ID_APP_SHOW_ROOT,
MF_BYCOMMAND);
RemoveMenu (hmenuTray,
ID_APP_HIDE_ROOT,
MF_BYCOMMAND);
RemoveMenu (hmenuTray,
0,
MF_BYPOSITION);
}
SetupRootMenu ((unsigned long)hmenuTray);
SetForegroundWindow (hwnd);
TrackPopupMenuEx (hmenuTray,
TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
ptCursor.x, ptCursor.y,
hwnd,
NULL);
PostMessage (hwnd, WM_NULL, 0, 0);
DestroyMenu (hmenuPopup);
}
break;
}
return 0;
}