Skip to content

Commit

Permalink
Add minimize_to_tray feature to chrome47 branch.
Browse files Browse the repository at this point in the history
Patch from commit e9e1b07.
  • Loading branch information
cztomczak committed Feb 7, 2016
1 parent d38c32a commit c2bd8a4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions phpdesktop-chrome47/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
#define _WIN32_WINNT 0x0501
#define _WIN32_IE _WIN32_IE_IE60SP2
#define _RICHEDIT_VER 0x0200

// Win messages
#define WM_TRAY_MESSAGE (WM_USER + 1)
41 changes: 41 additions & 0 deletions phpdesktop-chrome47/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
HWND childHandle = 0;
HWND shellBrowserHandle = 0;

json_value* appSettings = GetApplicationSettings();
std::string main_window_title = (*appSettings)["main_window"]["title"];

// Minimize to system tray
bool minimize_to_tray = (*appSettings)["main_window"]["minimize_to_tray"];
std::string minimize_to_tray_message = (*appSettings)["main_window"]["minimize_to_tray_message"];
NOTIFYICONDATA tray = {0};
tray.cbSize = sizeof(tray);
tray.hWnd = hwnd;
tray.uID = 1;
tray.uCallbackMessage = WM_TRAY_MESSAGE;
tray.hIcon = (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDR_MAINWINDOW), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);
wcscpy_s(tray.szInfo, 256, Utf8ToWide(minimize_to_tray_message).c_str());
wcscpy_s(tray.szInfoTitle, 64, Utf8ToWide(main_window_title).c_str());
tray.uFlags = NIF_ICON | NIF_INFO | NIF_MESSAGE;
tray.dwInfoFlags = NIIF_NONE;

switch (uMsg) {
case WM_SIZE:
browser = GetBrowserWindow(hwnd);
Expand Down Expand Up @@ -70,6 +89,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
// Debugging mongoose, see InitializeLogging().
printf("----------------------------------------");
printf("----------------------------------------\n");

Shell_NotifyIcon(NIM_DELETE, &tray);
#endif
// Cannot call PostQuitMessage as cookies won't be flushed to disk
// if application is closed immediately. See comment #2:
Expand Down Expand Up @@ -116,6 +137,26 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
}
}
break;
case WM_SYSCOMMAND:
if (wParam == SC_MINIMIZE && minimize_to_tray && !GetBrowserWindow(hwnd)->IsPopup()) {
LOG_DEBUG << "Minimize to tray";
ShowWindow(hwnd, SW_MINIMIZE);
Sleep(200);
ShowWindow(hwnd, SW_HIDE);
Shell_NotifyIcon(NIM_ADD, &tray);
break;
}
break;
case WM_TRAY_MESSAGE:
if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN) {
LOG_DEBUG << "Restore from tray";
ShowWindow(hwnd, SW_SHOW);
ShowWindow(hwnd, SW_RESTORE);
SetForegroundWindow(hwnd);
Shell_NotifyIcon(NIM_DELETE, &tray);
break;
}
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Expand Down
4 changes: 3 additions & 1 deletion phpdesktop-chrome47/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"center_on_screen": true,
"start_maximized": false,
"start_fullscreen": false,
"always_on_top": false
"always_on_top": false,
"minimize_to_tray": false,
"minimize_to_tray_message": "Minimized to tray"
},
"popup_window": {
"icon": "",
Expand Down

0 comments on commit c2bd8a4

Please sign in to comment.