source: trunk/src/3rdparty/os2/xsystray/xsystray_api.c@ 270

Last change on this file since 270 was 270, checked in by Dmitry A. Kuminov, 16 years ago

3rdparty: os2/xsystray: Broadcast a special message to let interested parties re-add their icons when the system tray restarts (especially useful after a WPS/XCenter crash, etc).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 11.6 KB
Line 
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
30static HWND G_hwndSysTray = NULLHANDLE;
31static int G_itlsSysTrayCtlData = -1;
32
33static 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
50static 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)