Skip to content

Commit 5f06ec1

Browse files
committed
Show tray icon
1 parent 998f415 commit 5f06ec1

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ quickjs:
1919
@echo 'OK.'
2020

2121
clean:
22-
rm -rf $(PROJ).exe quickjs
22+
rm -rf $(PROJ).exe wblocks.res quickjs
2323

2424
run: $(PROJ).exe
2525
./$(PROJ).exe

src/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ INCTXT(wblocksLibMJS, "src/lib.mjs");
2020

2121
JSClassID jsBlockClassId;
2222
UINT_PTR createWindowTimer;
23+
HINSTANCE hInst;
2324

2425
#define WBLOCKS_MAX_LEN 1024
2526

@@ -190,6 +191,7 @@ void createWindow()
190191
err("failed to find taskbar");
191192
return;
192193
}
194+
193195
// Create window
194196
assert(CreateWindowEx(
195197
WS_EX_LAYERED, WBLOCKS_BAR_CLASS, "wblocks2_bar",
@@ -211,6 +213,16 @@ void initWnd(HWND wnd)
211213
wb.hdc = CreateCompatibleDC(wb.screenHDC);
212214
SetParent(wnd, wb.bar);
213215
updateBlocks(wnd);
216+
217+
// Show tray icon
218+
NOTIFYICONDATA notifData = {
219+
.cbSize = sizeof(notifData),
220+
.hWnd = wnd,
221+
.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(100)),
222+
.uFlags = NIF_ICON | NIF_TIP,
223+
.szTip = "wblocks",
224+
};
225+
Shell_NotifyIcon(NIM_ADD, &notifData);
214226
}
215227

216228
void cleanupWnd()
@@ -220,6 +232,8 @@ void cleanupWnd()
220232
}
221233
DeleteDC(wb.hdc);
222234
ReleaseDC(NULL, wb.screenHDC);
235+
NOTIFYICONDATA notifData = { .cbSize = sizeof(notifData), .hWnd = wb.wnd };
236+
Shell_NotifyIcon(NIM_DELETE, &notifData);
223237
memset(&wb, 0, sizeof(wb));
224238
createWindowTimer = SetTimer(NULL, 0, 3000, (TIMERPROC)retryCreateWindow);
225239
}
@@ -501,6 +515,8 @@ JSValue jsShell(JSContext *ctx, JSValueConst this, int argc, JSValueConst *argv)
501515

502516
int CALLBACK WinMain(HINSTANCE inst, HINSTANCE prevInst, LPSTR cmdLine, int cmdShow)
503517
{
518+
hInst = inst;
519+
504520
// Load default font
505521
defaultBlock.font = xmalloc(sizeof(fontref_t));
506522
defaultBlock.font->handle = CreateFont(22, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, "Courier New");

wblocks.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
id ICON "icon.ico"
1+
100 ICON "icon.ico"

0 commit comments

Comments
 (0)