Skip to content
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

Fix drawinTitleBar requirement #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,21 @@ it finds the window, injects a library into the Thunderbird process to hook into
the message queue. TBTray keeps running in the background, in case you want to
restart Thunderbird at some point.

It doesn't work for me!
The close button just closes Thunderbird!
-----------------------

The most likely cause is that you have `mail.tabs.drawInTitlebar` set to `true`
(which is the default value) - setting it to `false` should solve that problem.
(which is the default value).

Note: If you want to get this fixed, consider submitting a pull request - I do
not have the time required to debug and fix a feature I am not using.
TBTray intercepts the close button by intercepting clicks in the non-client area (the title bar). This doesn't work when `drawInTitlebar` is `true`. A workaround for this is to install the [Minimize on Close](https://addons.thunderbird.net/en-us/thunderbird/addon/minimize-on-close/) extension, which uses client-side javascript to intercept the close event and minimize instead.

Halp, how do I quit Thunderbird?
--------------------------------

Through the File menu, or the context menu of the tray icon.

Note that the context menu exit option will not work if you have the Minimize on Close extension installed, in which case you will have to exit through the file menu.

Is there any sort of configuration?
-----------------------------------

Expand Down
83 changes: 56 additions & 27 deletions dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,44 @@
#define dprintf(...)
#endif

/* Our GetMessage hook */
HHOOK hMessageHook;

static HWND mainHwnd = nullptr;
static NOTIFYICONDATA nid = { 0 };
static HWND trayHwnd = nullptr;

enum CommandID
{
ID_RESTORE = 1000,
ID_CLOSE
};

static void ShowTray()
{
// Show tray icon
nid.cbSize = sizeof(nid);
nid.hWnd = trayHwnd;
nid.uID = 1337;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_SHOWTIP | NIF_MESSAGE;
nid.uCallbackMessage = WM_USER + 1337;
nid.hIcon = (HICON)GetClassLongPtr(mainHwnd, GCLP_HICON);
lstrcpy(nid.szTip, _T("Mozilla Thunderbird"));
nid.dwState = 0;
nid.dwStateMask = 0;
lstrcpy(nid.szInfo, _T(""));
nid.uVersion = NOTIFYICON_VERSION_4;
lstrcpy(nid.szInfoTitle, _T(""));
nid.dwInfoFlags = 0;
nid.guidItem = {};
nid.hBalloonIcon = nid.hIcon;
Shell_NotifyIcon(NIM_ADD, &nid);
Shell_NotifyIcon(NIM_SETVERSION, &nid);
}

static LRESULT CALLBACK TrayIconProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if((uMsg == WM_USER + 1337 && LOWORD(lParam) == NIN_SELECT) || uMsg == WM_COMMAND)
{
// Restore main window
ShowWindow(mainHwnd, SW_SHOW);
ShowWindow(mainHwnd, SW_RESTORE);
Shell_NotifyIcon(NIM_DELETE, &nid);
if (uMsg == WM_COMMAND && wParam == ID_CLOSE)
SendMessage(mainHwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
Expand All @@ -78,7 +98,6 @@ static LRESULT CALLBACK TrayIconProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM

LRESULT CALLBACK MessageHook(int nCode, WPARAM wParam, LPARAM lParam)
{
static HWND trayHwnd = nullptr;
MSG &msg = *(MSG *)lParam;

if(mainHwnd == nullptr)
Expand Down Expand Up @@ -125,37 +144,46 @@ LRESULT CALLBACK MessageHook(int nCode, WPARAM wParam, LPARAM lParam)

if(msg.hwnd == mainHwnd &&
(
(msg.message == WM_NCLBUTTONDOWN && (msg.wParam == HTCLOSE || msg.wParam == HTMINBUTTON))
(msg.message == WM_NCLBUTTONDOWN && msg.wParam == HTCLOSE)
||
(msg.message == WM_SYSCOMMAND && (msg.wParam == SC_CLOSE || msg.wParam == SC_MINIMIZE))
(msg.message == WM_SYSCOMMAND && msg.wParam == SC_CLOSE)
))
{
ShowWindow(msg.hwnd, SW_HIDE);
// Show tray icon
nid.cbSize = sizeof(nid);
nid.hWnd = trayHwnd;
nid.uID = 1337;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_SHOWTIP | NIF_MESSAGE;
nid.uCallbackMessage = WM_USER + 1337;
nid.hIcon = (HICON)GetClassLongPtr(mainHwnd, GCLP_HICON);
lstrcpy(nid.szTip, _T("Mozilla Thunderbird"));
nid.dwState = 0;
nid.dwStateMask = 0;
lstrcpy(nid.szInfo, _T(""));
nid.uVersion = NOTIFYICON_VERSION_4;
lstrcpy(nid.szInfoTitle, _T(""));
nid.dwInfoFlags = 0;
nid.guidItem = {};
nid.hBalloonIcon = nid.hIcon;
Shell_NotifyIcon(NIM_ADD, &nid);
Shell_NotifyIcon(NIM_SETVERSION, &nid);
// Ignore this message
ShowTray();

msg.message = WM_NULL;
}

return CallNextHookEx(NULL, nCode, wParam, lParam);
}

LRESULT CALLBACK WindowHook(int nCode, WPARAM wParam, LPARAM lParam)
{
CWPSTRUCT &msg = *(CWPSTRUCT *)lParam;

if (msg.hwnd == mainHwnd)
{
if (msg.message == WM_WINDOWPOSCHANGED)
{
// we won't receive WM_SIZE messages unless we DefWindowProc the WM_WINDOWPOSCHANGED message
DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
}

if (msg.message == WM_SIZE && msg.wParam == SIZE_MINIMIZED)
{
ShowWindow(msg.hwnd, SW_HIDE);
ShowTray();
}

if (msg.message == WM_DESTROY) {
Shell_NotifyIcon(NIM_DELETE, &nid);
}
}

return CallNextHookEx(NULL, nCode, wParam, lParam);
}

HMODULE hDLL;

/*
Expand All @@ -182,7 +210,8 @@ extern "C" __declspec(dllexport) LRESULT CALLBACK EntryHook(int nCode, WPARAM wP
GetModuleFileName(hDLL, dllName, _countof(dllName));
LoadLibrary(dllName);
#endif
hMessageHook = SetWindowsHookEx(WH_GETMESSAGE, MessageHook, NULL, GetCurrentThreadId());
SetWindowsHookEx(WH_GETMESSAGE, MessageHook, NULL, GetCurrentThreadId());
SetWindowsHookEx(WH_CALLWNDPROC, WindowHook, NULL, GetCurrentThreadId());
firstTime = false;
}

Expand Down