1 | /*
|
---|
2 | * Extended system tray widget for XCenter/eCenter
|
---|
3 | *
|
---|
4 | * Public API implementation
|
---|
5 | *
|
---|
6 | * Made by netlabs.org
|
---|
7 | *
|
---|
8 | * Author: Dmitry A. Kuminov
|
---|
9 | *
|
---|
10 | * This software is public domain.
|
---|
11 | *
|
---|
12 | * WITHOUT ANY WARRANTY..., AT YOUR OWN RISC... ETC.
|
---|
13 | *
|
---|
14 | */
|
---|
15 |
|
---|
16 | #define INCL_DOSERRORS
|
---|
17 | #define INCL_DOSPROCESS
|
---|
18 | #define INCL_WINWINDOWMGR
|
---|
19 | #define INCL_WINATOM
|
---|
20 | #define INCL_WINPOINTERS
|
---|
21 | #include <os2.h>
|
---|
22 |
|
---|
23 | #include "xsystray_api.h"
|
---|
24 | #include "xsystray.h"
|
---|
25 |
|
---|
26 | #include <string.h>
|
---|
27 | #include <sys/builtin.h> // atomics
|
---|
28 | #include <InnotekLIBC/thread.h> // TLS
|
---|
29 |
|
---|
30 | static HWND G_hwndSysTray = NULLHANDLE;
|
---|
31 | static int G_itlsSysTrayCtlData = -1;
|
---|
32 |
|
---|
33 | static HWND FindSysTrayWindow()
|
---|
34 | {
|
---|
35 | char buf[sizeof(WNDCLASS_WIDGET_XSYSTRAY_SERVER) + 1];
|
---|
36 | HWND hwnd;
|
---|
37 | HENUM henum = WinBeginEnumWindows(HWND_DESKTOP);
|
---|
38 | while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
|
---|
39 | {
|
---|
40 | LONG len = WinQueryClassName(hwnd, sizeof(buf), buf);
|
---|
41 | buf[len] = '\0';
|
---|
42 | if (strcmp(WNDCLASS_WIDGET_XSYSTRAY_SERVER, buf) == 0)
|
---|
43 | break;
|
---|
44 | }
|
---|
45 | WinEndEnumWindows(henum);
|
---|
46 |
|
---|
47 | return hwnd;
|
---|
48 | }
|
---|
49 |
|
---|
50 | static BOOL SendSysTrayCtlMsg(PSYSTRAYCTLDATA pData)
|
---|
51 | {
|
---|
52 | APIRET arc;
|
---|
53 | PID pid;
|
---|
54 | TID tid;
|
---|
55 | MRESULT mrc;
|
---|
56 |
|
---|
57 | BOOL bTriedFind = FALSE;
|
---|
58 |
|
---|
59 | do
|
---|
60 | {
|
---|
61 | if (G_hwndSysTray == NULLHANDLE)
|
---|
62 | {
|
---|
63 | bTriedFind = TRUE;
|
---|
64 | HWND hwnd = FindSysTrayWindow();
|
---|
65 | __atomic_cmpxchg32((uint32_t *)&G_hwndSysTray, hwnd, NULLHANDLE);
|
---|
66 | if (G_hwndSysTray == NULLHANDLE)
|
---|
67 | break;
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (bTriedFind)
|
---|
71 | {
|
---|
72 | arc = ERROR_INVALID_HANDLE;
|
---|
73 | if (WinQueryWindowProcess(G_hwndSysTray, &pid, &tid))
|
---|
74 | arc = DosGiveSharedMem(__libc_TLSGet(G_itlsSysTrayCtlData),
|
---|
75 | pid, PAG_READ | PAG_WRITE);
|
---|
76 | if (arc != NO_ERROR)
|
---|
|
---|