Skip to content

Commit baa9844

Browse files
authored
Enhance GPU state management and tray icon setup
Refactor GPU detection and tray icon initialization.
1 parent ae033d8 commit baa9844

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

src/main.cpp

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,54 @@ extern "C" {
1515
__declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1;
1616
}
1717

18-
// Global GPU state (used by win_helpers.cpp)
18+
// Global GPU states
1919
GpuState g_displayGpuState;
2020
GpuState g_renderGpuState;
2121

22+
bool g_forceRenderGpu = true; // User toggle
2223
HINSTANCE g_hInst = nullptr;
2324

25+
void RefreshGpuState(HWND hwnd)
26+
{
27+
DetectDisplayGPU(g_displayGpuState);
28+
29+
if (g_forceRenderGpu)
30+
DetectRenderGPU(g_renderGpuState);
31+
else
32+
g_renderGpuState = {}; // Clear render GPU
33+
34+
// Choose active GPU
35+
UINT activeVendor = (g_renderGpuState.vendor != 0)
36+
? g_renderGpuState.vendor
37+
: g_displayGpuState.vendor;
38+
39+
HICON icon = LoadDisplayIcon(activeVendor, g_hInst);
40+
41+
NOTIFYICONDATAW nid = {};
42+
nid.cbSize = sizeof(nid);
43+
nid.hWnd = hwnd;
44+
nid.uID = TRAY_ID;
45+
nid.uFlags = NIF_ICON | NIF_TIP | NIF_SHOWTIP;
46+
nid.hIcon = icon;
47+
48+
std::wstring tip = BuildGpuTooltip(g_displayGpuState, g_renderGpuState);
49+
wcsncpy_s(nid.szTip, tip.c_str(), _TRUNCATE);
50+
51+
Shell_NotifyIconW(NIM_MODIFY, &nid);
52+
}
53+
2454
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
2555
{
2656
g_hInst = hInst;
2757

28-
// Prevent multiple instances
2958
HANDLE hMutex = CreateMutexW(nullptr, TRUE, L"GPUSwitcherMutex");
3059
if (GetLastError() == ERROR_ALREADY_EXISTS)
3160
{
3261
CloseHandle(hMutex);
3362
return 0;
3463
}
3564

36-
// Register hidden window class
65+
// Register hidden window
3766
WNDCLASSW wc = {};
3867
wc.lpfnWndProc = WndProc;
3968
wc.hInstance = hInst;
@@ -49,33 +78,20 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
4978
nullptr, nullptr, hInst, nullptr
5079
);
5180

52-
// Detect GPUs
53-
DetectDisplayGPU(g_displayGpuState);
54-
DetectRenderGPU(g_renderGpuState);
55-
56-
// Choose active GPU for icon: prefer render GPU, fallback to display GPU
57-
UINT activeVendor = (g_renderGpuState.vendor != 0)
58-
? g_renderGpuState.vendor
59-
: g_displayGpuState.vendor;
60-
61-
HICON icon = LoadDisplayIcon(activeVendor, g_hInst);
62-
63-
// Build tooltip with both GPUs
64-
std::wstring tip = BuildGpuTooltip(g_displayGpuState, g_renderGpuState);
65-
66-
// Add tray icon
81+
// Add tray icon (temporary)
6782
NOTIFYICONDATAW nid = {};
6883
nid.cbSize = sizeof(nid);
6984
nid.hWnd = hwnd;
7085
nid.uID = TRAY_ID;
7186
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP;
7287
nid.uCallbackMessage = WM_TRAY;
73-
nid.hIcon = icon;
74-
75-
wcsncpy_s(nid.szTip, tip.c_str(), _TRUNCATE);
76-
88+
nid.hIcon = LoadIconW(nullptr, IDI_APPLICATION);
89+
wcscpy_s(nid.szTip, L"Initializing GPU detection...");
7790
Shell_NotifyIconW(NIM_ADD, &nid);
7891

92+
// Delay detection by 1 second
93+
SetTimer(hwnd, 1, 1000, nullptr);
94+
7995
// Message loop
8096
MSG msg;
8197
while (GetMessageW(&msg, nullptr, 0, 0))

0 commit comments

Comments
 (0)