-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreathing.cpp
More file actions
639 lines (542 loc) · 20.5 KB
/
breathing.cpp
File metadata and controls
639 lines (542 loc) · 20.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
#define _WIN32_WINNT 0x0A00 // Windows 10
#include <windows.h>
#include <shellapi.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <d2d1_1.h>
#include <dcomp.h>
#include <mmsystem.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "gdi32.lib")
#pragma comment (lib, "shell32.lib")
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "dxgi.lib")
#pragma comment (lib, "d2d1.lib")
#pragma comment (lib, "dcomp.lib")
#pragma comment (lib, "winmm.lib")
// Safe Release helper
template<class Interface>
inline void SafeRelease(Interface** ppInterfaceToRelease) {
if (*ppInterfaceToRelease != NULL) {
(*ppInterfaceToRelease)->Release();
(*ppInterfaceToRelease) = NULL;
}
}
#define WM_TRAYICON (WM_USER + 1)
#define ID_TRAY_EXIT 9001
#define ID_TRAY_RELOAD 9002
#define ID_PRESET_NORMAL 9003
#define ID_PRESET_FOCUS 9004
#define ID_PRESET_QUICK 9005
#define ID_TOGGLE_BORDER 9006 // Added new ID
// Global variables
NOTIFYICONDATA nid = { 0 };
HICON hAppIcon = NULL; // Global Icon Handle
// DirectX / DComp Objects
ID3D11Device* pD3DDevice = nullptr;
IDXGIDevice* pDXGIDevice = nullptr;
ID2D1Factory1* pD2DFactory = nullptr;
ID2D1Device* pD2DDevice = nullptr;
ID2D1DeviceContext* pD2DContext = nullptr;
IDXGISwapChain1* pSwapChain = nullptr;
IDCompositionDevice* pDCompDevice = nullptr;
IDCompositionTarget* pDCompTarget = nullptr;
IDCompositionVisual* pDCompVisual = nullptr;
// 1. Config Structure
struct Timing {
float inhale = 4.0f;
float holdIn = 4.0f;
float exhale = 4.0f;
float holdEx = 4.0f;
};
struct Visuals {
float minRadius = 20.0f;
float maxRadius = 380.0f;
int r = 26;
int g = 115;
int b = 232;
int alpha = 100;
bool showBorder = true;
};
struct AppConfig {
char activePreset[64] = "Normal";
Timing currentTiming;
Visuals visuals;
} g_Config;
// Animation State
enum BreathingState { INHALE, HOLD_IN, EXHALE, HOLD_EX };
BreathingState g_State = INHALE;
float g_StateTimer = 0.0f;
LARGE_INTEGER g_LastFrameTime;
LARGE_INTEGER g_Frequency;
// Forward declarations
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void LoadConfig();
void CreateDefaultConfigIfMissing(const char* path);
void SavePreset(const char* presetName);
void SaveSetting(const char* key, int value); // Added forward declaration
bool InitDirectX(HWND hwnd);
void Render();
void CleanupDirectX();
void ResetAnimation();
float GetIniFloat(const char* section, const char* key, float defaultValue, const char* path);
HICON CreateProceduralIcon(int size);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
timeBeginPeriod(1);
// Generate Soft Burst Icon (32x32)
hAppIcon = CreateProceduralIcon(32);
// Initialize Timer
QueryPerformanceFrequency(&g_Frequency);
QueryPerformanceCounter(&g_LastFrameTime);
LoadConfig();
const char* className = "BreathingOverlayClass";
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = className;
// Set Class Icon
wc.hIcon = hAppIcon;
wc.hIconSm = hAppIcon;
RegisterClassEx(&wc);
int width = 800;
int height = 800;
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int xPos = (screenWidth - width) / 2;
int yPos = (screenHeight - height) / 2;
HWND hwnd = CreateWindowEx(
WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOREDIRECTIONBITMAP,
className,
"Breathing Overlay",
WS_POPUP | WS_VISIBLE,
xPos, yPos, width, height,
NULL, NULL, hInstance, NULL
);
if (!hwnd) return 0;
if (!InitDirectX(hwnd)) {
CleanupDirectX();
return 0;
}
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd;
nid.uID = 1001;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYICON;
// Set Tray Icon
nid.hIcon = hAppIcon;
lstrcpy(nid.szTip, "Breathing Overlay");
Shell_NotifyIcon(NIM_ADD, &nid);
MSG msg = { 0 };
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
Render();
}
}
timeEndPeriod(1);
CleanupDirectX();
return (int)msg.wParam;
}
// 1. Procedural Icon Generator (Raw C++ Math)
HICON CreateProceduralIcon(int size) {
// 32-bit RGBA (4 bytes per pixel)
std::vector<uint32_t> pixels(size * size);
float centerX = size / 2.0f;
float centerY = size / 2.0f;
float maxRadius = (size / 2.0f) - 1.0f;
float amplitude = maxRadius * 0.20f;
float baseRadius = maxRadius - amplitude;
// Iterate pixels
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
float dx = x - centerX;
float dy = y - centerY;
float dist = sqrtf(dx*dx + dy*dy);
float theta = atan2f(dy, dx);
// Soft Burst Shape: r = base + amp * cos(8 * theta)
float burstRadius = baseRadius + amplitude * cosf(8.0f * theta);
// Anti-aliasing / Soft Edge
// If dist < burstRadius, alpha = 255.
// If dist > burstRadius + 1, alpha = 0.
// In between, interpolate.
float edgeDist = dist - burstRadius;
float alphaFactor = 0.0f;
if (edgeDist < -0.5f) alphaFactor = 1.0f;
else if (edgeDist > 0.5f) alphaFactor = 0.0f;
else alphaFactor = 0.5f - edgeDist; // Linear fade
uint8_t a = (uint8_t)(alphaFactor * 255.0f);
uint8_t r = 26;
uint8_t g = 115;
uint8_t b = 232;
// Pre-multiplied Alpha is often safer, but for CreateIcon cursor mask logic, raw values usually work.
// Windows Icon format: BGRA
// We'll write 0xAARRGGBB
if (a > 0) {
pixels[y * size + x] = (a << 24) | (r << 16) | (g << 8) | b;
} else {
pixels[y * size + x] = 0;
}
}
}
// Create Bitmaps for the Icon
HBITMAP hColorObj = CreateBitmap(size, size, 1, 32, pixels.data());
// Mask is required. For 32-bit icons with alpha, checking the alpha channel handles transparency.
// But CreateIconIndirect still needs a valid mask bitmap handle.
// We can use a mono bitmap that is all white (transparent) or black (opaque) logic,
// but since we supply an Alpha channel in hbmColor, the mask is largely ignored for composition
// EXCEPT for legacy hit-testing. Let's make a simple empty mask.
std::vector<uint8_t> maskPixels((size * size) / 8, 0xFF); // All 1s
HBITMAP hMaskObj = CreateBitmap(size, size, 1, 1, maskPixels.data());
ICONINFO ii = { 0 };
ii.fIcon = TRUE;
ii.xHotspot = 0;
ii.yHotspot = 0;
ii.hbmMask = hMaskObj;
ii.hbmColor = hColorObj;
HICON hIcon = CreateIconIndirect(&ii);
DeleteObject(hColorObj);
DeleteObject(hMaskObj);
return hIcon;
}
bool InitDirectX(HWND hwnd) {
HRESULT hr;
hr = D3D11CreateDevice(
nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
nullptr, 0, D3D11_SDK_VERSION,
&pD3DDevice, nullptr, nullptr
);
if (FAILED(hr)) return false;
hr = pD3DDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&pDXGIDevice);
if (FAILED(hr)) return false;
D2D1_FACTORY_OPTIONS options = { D2D1_DEBUG_LEVEL_NONE };
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory1), &options, (void**)&pD2DFactory);
if (FAILED(hr)) return false;
hr = pD2DFactory->CreateDevice(pDXGIDevice, &pD2DDevice);
if (FAILED(hr)) return false;
hr = pD2DDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &pD2DContext);
if (FAILED(hr)) return false;
IDXGIAdapter* pAdapter = nullptr;
pDXGIDevice->GetAdapter(&pAdapter);
IDXGIFactory2* pDXGIFactory = nullptr;
pAdapter->GetParent(__uuidof(IDXGIFactory2), (void**)&pDXGIFactory);
DXGI_SWAP_CHAIN_DESC1 scDesc = { 0 };
scDesc.Width = 800;
scDesc.Height = 800;
scDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
scDesc.Stereo = FALSE;
scDesc.SampleDesc.Count = 1;
scDesc.SampleDesc.Quality = 0;
scDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scDesc.BufferCount = 2;
scDesc.Scaling = DXGI_SCALING_STRETCH;
scDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
scDesc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
hr = pDXGIFactory->CreateSwapChainForComposition(pD3DDevice, &scDesc, nullptr, &pSwapChain);
SafeRelease(&pAdapter);
SafeRelease(&pDXGIFactory);
if (FAILED(hr)) return false;
IDXGISurface* pSurface = nullptr;
hr = pSwapChain->GetBuffer(0, __uuidof(IDXGISurface), (void**)&pSurface);
if (FAILED(hr)) return false;
D2D1_BITMAP_PROPERTIES1 bp = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)
);
ID2D1Bitmap1* pBitmap = nullptr;
hr = pD2DContext->CreateBitmapFromDxgiSurface(pSurface, &bp, &pBitmap);
pD2DContext->SetTarget(pBitmap);
SafeRelease(&pSurface);
SafeRelease(&pBitmap);
if (FAILED(hr)) return false;
hr = DCompositionCreateDevice(pDXGIDevice, __uuidof(IDCompositionDevice), (void**)&pDCompDevice);
if (FAILED(hr)) return false;
hr = pDCompDevice->CreateTargetForHwnd(hwnd, TRUE, &pDCompTarget);
if (FAILED(hr)) return false;
hr = pDCompDevice->CreateVisual(&pDCompVisual);
if (FAILED(hr)) return false;
hr = pDCompVisual->SetContent(pSwapChain);
if (FAILED(hr)) return false;
hr = pDCompTarget->SetRoot(pDCompVisual);
if (FAILED(hr)) return false;
hr = pDCompDevice->Commit();
if (FAILED(hr)) return false;
return true;
}
// Helper to read floats from INI
float GetIniFloat(const char* section, const char* key, float defaultValue, const char* path) {
char defaultStr[32];
sprintf_s(defaultStr, "%.2f", defaultValue);
char buffer[64];
GetPrivateProfileStringA(section, key, defaultStr, buffer, 64, path);
return (float)atof(buffer);
}
void CreateDefaultConfigIfMissing(const char* path) {
if (GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES) {
FILE* pFile;
// fopen_s returns 0 on success
if (fopen_s(&pFile, path, "w") == 0) {
fputs("[Settings]\n"
"ActivePreset=Normal\n"
"MaxRadius=360\n"
"MinRadius=40\n"
"ShowBorder=1\n"
"\n"
"Alpha=50\n"
"ColorR=26\n"
"ColorG=115\n"
"ColorB=232\n"
"\n\n"
"[Normal]\n"
"Inhale=4.0\n"
"HoldIn=1.0\n"
"Exhale=4.0\n"
"HoldEx=1.0\n"
"\n"
"[Focus]\n"
"Inhale=4.0\n"
"HoldIn=7.0\n"
"Exhale=8.0\n"
"HoldEx=0.0\n"
"\n"
"[Quick]\n"
"Inhale=2.0\n"
"HoldIn=0.0\n"
"Exhale=2.0\n"
"HoldEx=0.0\n", pFile);
fclose(pFile);
}
}
}
void LoadConfig() {
char path[MAX_PATH];
if (GetModuleFileNameA(NULL, path, MAX_PATH) == 0) return;
char* lastSlash = strrchr(path, '\\');
if (lastSlash) *(lastSlash + 1) = '\0';
lstrcatA(path, "breathing-config.ini");
// Auto-create defaults if missing
CreateDefaultConfigIfMissing(path);
// Read Active Preset
GetPrivateProfileStringA("Settings", "ActivePreset", "Normal", g_Config.activePreset, 64, path);
// Read Timings from the Active Preset Section
g_Config.currentTiming.inhale = GetIniFloat(g_Config.activePreset, "Inhale", 4.0f, path);
g_Config.currentTiming.holdIn = GetIniFloat(g_Config.activePreset, "HoldIn", 4.0f, path);
g_Config.currentTiming.exhale = GetIniFloat(g_Config.activePreset, "Exhale", 4.0f, path);
g_Config.currentTiming.holdEx = GetIniFloat(g_Config.activePreset, "HoldEx", 4.0f, path);
// Read Visuals from Settings
g_Config.visuals.minRadius = GetIniFloat("Settings", "MinRadius", 20.0f, path);
g_Config.visuals.maxRadius = GetIniFloat("Settings", "MaxRadius", 380.0f, path);
g_Config.visuals.r = GetPrivateProfileIntA("Settings", "ColorR", 26, path);
g_Config.visuals.g = GetPrivateProfileIntA("Settings", "ColorG", 115, path);
g_Config.visuals.b = GetPrivateProfileIntA("Settings", "ColorB", 232, path);
g_Config.visuals.alpha = GetPrivateProfileIntA("Settings", "Alpha", 100, path);
g_Config.visuals.showBorder = GetPrivateProfileIntA("Settings", "ShowBorder", 1, path) != 0;
}
void SavePreset(const char* presetName) {
char path[MAX_PATH];
if (GetModuleFileNameA(NULL, path, MAX_PATH) == 0) return;
char* lastSlash = strrchr(path, '\\');
if (lastSlash) *(lastSlash + 1) = '\0';
lstrcatA(path, "breathing-config.ini");
WritePrivateProfileStringA("Settings", "ActivePreset", presetName, path);
}
// Added Save Helper
void SaveSetting(const char* key, int value) {
char path[MAX_PATH];
if (GetModuleFileNameA(NULL, path, MAX_PATH) == 0) return;
char* lastSlash = strrchr(path, '\\');
if (lastSlash) *(lastSlash + 1) = '\0';
lstrcatA(path, "breathing-config.ini");
char buffer[32];
sprintf_s(buffer, "%d", value);
WritePrivateProfileStringA("Settings", key, buffer, path);
}
void ResetAnimation() {
g_State = INHALE;
g_StateTimer = 0.0f;
}
void Render() {
if (!pD2DContext) return;
// Time Calc
LARGE_INTEGER currentTime;
QueryPerformanceCounter(¤tTime);
double deltaTime = (double)(currentTime.QuadPart - g_LastFrameTime.QuadPart) / g_Frequency.QuadPart;
g_LastFrameTime = currentTime;
// Direct2D Start
pD2DContext->BeginDraw();
pD2DContext->Clear(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.0f));
// --- 3. Animation State Machine ---
g_StateTimer += (float)deltaTime;
float currentRadius = g_Config.visuals.minRadius;
float minR = g_Config.visuals.minRadius;
float maxR = g_Config.visuals.maxRadius;
if (g_State == INHALE) {
if (g_StateTimer >= g_Config.currentTiming.inhale) {
g_State = HOLD_IN;
g_StateTimer = 0.0f; // Exact Reset
currentRadius = maxR;
} else {
float t = g_StateTimer / g_Config.currentTiming.inhale;
currentRadius = minR + (maxR - minR) * t; // Linear Lerp
}
}
else if (g_State == HOLD_IN) {
currentRadius = maxR;
if (g_StateTimer >= g_Config.currentTiming.holdIn) {
g_State = EXHALE;
g_StateTimer = 0.0f; // Exact Reset
}
}
else if (g_State == EXHALE) {
if (g_StateTimer >= g_Config.currentTiming.exhale) {
g_State = HOLD_EX;
g_StateTimer = 0.0f; // Exact Reset
currentRadius = minR;
} else {
float t = g_StateTimer / g_Config.currentTiming.exhale;
currentRadius = maxR - (maxR - minR) * t; // Linear Lerp
}
}
else if (g_State == HOLD_EX) {
currentRadius = minR;
if (g_StateTimer >= g_Config.currentTiming.holdEx) {
g_State = INHALE;
g_StateTimer = 0.0f; // Exact Reset
}
}
// --------------------------------
float centerX = 400.0f;
float centerY = 400.0f;
// Draw
float r = g_Config.visuals.r / 255.0f;
float g = g_Config.visuals.g / 255.0f;
float b = g_Config.visuals.b / 255.0f;
float a = g_Config.visuals.alpha / 255.0f;
ID2D1SolidColorBrush* pFillBrush = nullptr;
pD2DContext->CreateSolidColorBrush(D2D1::ColorF(r, g, b, a), &pFillBrush);
if (pFillBrush) {
D2D1_ELLIPSE ellipse = D2D1::Ellipse(D2D1::Point2F(centerX, centerY), currentRadius, currentRadius);
pD2DContext->FillEllipse(ellipse, pFillBrush);
SafeRelease(&pFillBrush);
}
if (g_Config.visuals.showBorder) {
ID2D1SolidColorBrush* pBorderBrush = nullptr;
pD2DContext->CreateSolidColorBrush(D2D1::ColorF(r, g, b, 40.0f / 255.0f), &pBorderBrush);
if (pBorderBrush) {
D2D1_ELLIPSE borderEllipse = D2D1::Ellipse(D2D1::Point2F(centerX, centerY), maxR, maxR);
pD2DContext->DrawEllipse(borderEllipse, pBorderBrush, 2.0f);
SafeRelease(&pBorderBrush);
}
}
HRESULT hr = pD2DContext->EndDraw();
if (pSwapChain) {
pSwapChain->Present(1, 0);
}
}
void CleanupDirectX() {
if (hAppIcon) DestroyIcon(hAppIcon);
SafeRelease(&pDCompVisual);
SafeRelease(&pDCompTarget);
SafeRelease(&pDCompDevice);
SafeRelease(&pD2DContext);
SafeRelease(&pD2DDevice);
SafeRelease(&pD2DFactory);
SafeRelease(&pSwapChain);
SafeRelease(&pDXGIDevice);
SafeRelease(&pD3DDevice);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_NCHITTEST:
return HTTRANSPARENT;
case WM_TRAYICON:
if (lParam == WM_RBUTTONUP) {
POINT curPoint;
GetCursorPos(&curPoint);
HMENU hMenu = CreatePopupMenu();
// 2. Context Menu (Flat & Checkmarks)
// Presets List
const char* presets[] = { "Normal", "Focus", "Quick" };
int ids[] = { ID_PRESET_NORMAL, ID_PRESET_FOCUS, ID_PRESET_QUICK };
char path[MAX_PATH];
if (GetModuleFileNameA(NULL, path, MAX_PATH) != 0) {
char* lastSlash = strrchr(path, '\\');
if (lastSlash) *(lastSlash + 1) = '\0';
lstrcatA(path, "breathing-config.ini");
}
for (int i = 0; i < 3; i++) {
float inh = GetIniFloat(presets[i], "Inhale", 4.0f, path);
float hIn = GetIniFloat(presets[i], "HoldIn", 4.0f, path);
float exh = GetIniFloat(presets[i], "Exhale", 4.0f, path);
float hEx = GetIniFloat(presets[i], "HoldEx", 4.0f, path);
char label[128];
sprintf_s(label, "%s (%.0f-%.0f-%.0f-%.0f)", presets[i], inh, hIn, exh, hEx);
UINT flags = MF_STRING;
if (strcmp(g_Config.activePreset, presets[i]) == 0) {
flags |= MF_CHECKED;
}
AppendMenu(hMenu, flags, ids[i], label);
}
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
// Toggle Border Item
UINT borderFlags = MF_STRING;
if (g_Config.visuals.showBorder) borderFlags |= MF_CHECKED;
AppendMenu(hMenu, borderFlags, ID_TOGGLE_BORDER, "Show Border Ring");
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, ID_TRAY_RELOAD, "Reload Config");
AppendMenu(hMenu, MF_STRING, ID_TRAY_EXIT, "Exit");
SetForegroundWindow(hwnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, curPoint.x, curPoint.y, 0, hwnd, NULL);
DestroyMenu(hMenu);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case ID_TRAY_EXIT:
DestroyWindow(hwnd);
break;
case ID_TRAY_RELOAD:
LoadConfig(); // Presets define new values
ResetAnimation();
MessageBeep(MB_OK);
break;
case ID_PRESET_NORMAL:
SavePreset("Normal");
LoadConfig();
ResetAnimation();
break;
case ID_PRESET_FOCUS:
SavePreset("Focus");
LoadConfig();
ResetAnimation();
break;
case ID_PRESET_QUICK:
SavePreset("Quick");
LoadConfig();
ResetAnimation();
break;
case ID_TOGGLE_BORDER:
g_Config.visuals.showBorder = !g_Config.visuals.showBorder;
SaveSetting("ShowBorder", g_Config.visuals.showBorder ? 1 : 0);
// No need for ResetAnimation, just redraw next frame
break;
}
break;
case WM_DESTROY:
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}