Skip to content

Commit dcd0400

Browse files
committed
Added logic for window tray, app runs, cannot be modified yet.
1 parent a39629d commit dcd0400

File tree

3 files changed

+112
-9
lines changed

3 files changed

+112
-9
lines changed

src/app/main.cpp

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,73 @@
1-
#include "../core/Platform.h"
2-
#include <stdio.h>
1+
#include <windows.h>
2+
#include "win/WinTray.h"
3+
#include "core/Platform.h"
34

4-
int main() {
5-
printf("Split Loaf daemon running...\n");
6-
printf("F8 = Set target window\n");
7-
printf("F6 = Lock keyboard\n");
8-
printf("F7 = Unlock keyboard\n");
5+
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
6+
switch (uMsg) {
7+
case WM_DESTROY:
8+
RemoveTrayIcon();
9+
PostQuitMessage(0);
10+
return 0;
911

12+
case WM_USER + 1: // tray icon callback
13+
if (lParam == WM_RBUTTONUP) {
14+
ShowTrayMenu(hwnd);
15+
}
16+
return 0;
17+
18+
case WM_COMMAND: // menu selection
19+
switch(LOWORD(wParam)) {
20+
case 1: // Settings
21+
MessageBox(hwnd, "Settings dialog would appear here.", "Settings", MB_OK);
22+
break;
23+
case 2: // Exit
24+
DestroyWindow(hwnd);
25+
break;
26+
}
27+
return 0;
28+
}
29+
return DefWindowProc(hwnd, uMsg, wParam, lParam);
30+
}
31+
32+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
33+
const char CLASS_NAME[] = "SplitLoafTray";
34+
35+
WNDCLASS wc = {};
36+
wc.lpfnWndProc = WindowProc;
37+
wc.hInstance = hInstance;
38+
wc.lpszClassName = CLASS_NAME;
39+
40+
RegisterClass(&wc);
41+
42+
HWND hwnd = CreateWindowEx(
43+
0,
44+
CLASS_NAME,
45+
"Split Loaf",
46+
0, 0, 0, 0, 0,
47+
NULL, NULL, hInstance, NULL
48+
);
49+
50+
InitTrayIcon(hwnd);
51+
52+
// --- Core Platform initialization ---
1053
Platform::init();
11-
Platform::processEvents();
12-
Platform::shutdown();
1354

55+
MSG msg = {};
56+
while (true) {
57+
// Process Windows messages
58+
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
59+
TranslateMessage(&msg);
60+
DispatchMessage(&msg);
61+
62+
if (msg.message == WM_QUIT)
63+
goto quit;
64+
}
65+
66+
// Process your platform-specific events
67+
Platform::processEvents();
68+
}
69+
70+
quit:
71+
Platform::shutdown();
1472
return 0;
1573
}

src/win/WinTray.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "WinTray.h"
2+
#include <shellapi.h>
3+
#include "../res/resource.h"
4+
5+
NOTIFYICONDATA nid;
6+
HMENU hMenu = NULL;
7+
8+
void InitTrayIcon(HWND hwnd) {
9+
ZeroMemory(&nid, sizeof(nid));
10+
nid.cbSize = sizeof(NOTIFYICONDATA);
11+
nid.hWnd = hwnd;
12+
nid.uID = 1;
13+
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
14+
nid.uCallbackMessage = WM_USER + 1;
15+
16+
// Load a custom icon from resource (IDI_MYICON)
17+
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APP_ICON));
18+
strcpy_s(nid.szTip, "Split Loaf - Idle");
19+
20+
Shell_NotifyIcon(NIM_ADD, &nid);
21+
22+
// Create context menu
23+
hMenu = CreatePopupMenu();
24+
AppendMenu(hMenu, MF_STRING, 1, "Settings");
25+
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
26+
AppendMenu(hMenu, MF_STRING, 2, "Exit");
27+
}
28+
29+
void RemoveTrayIcon() {
30+
Shell_NotifyIcon(NIM_DELETE, &nid);
31+
if(hMenu) DestroyMenu(hMenu);
32+
}
33+
34+
void ShowTrayMenu(HWND hwnd) {
35+
POINT pt;
36+
GetCursorPos(&pt);
37+
SetForegroundWindow(hwnd); // required for menu to disappear correctly
38+
TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);
39+
}

src/win/WinTray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
#include <windows.h>
3+
4+
void InitTrayIcon(HWND hwnd);
5+
void RemoveTrayIcon();
6+
void ShowTrayMenu(HWND hwnd);

0 commit comments

Comments
 (0)