source: trunk/src/3rdparty/os2/xsystray/plugin/w_xsystray.h@ 952

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

OS/2: xsystray: Fixed duplicate mouse click notifications.

This was due to the fact that the pointer to the notification data
passed to the client was not fixed up after making a local copy of
this data. As a result it would still point to the shared data cell
that could get already overwritten with a different notificaiton
message by the time it got processed in the client.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision Author Id
File size: 7.4 KB
Line 
1
2/*
3 *@@sourcefile w_xsystray.h:
4 * Extended system tray widget for XCenter/eCenter.
5 *
6 * Private declarations.
7 *
8 * Copyright (C) 2009-2011 Dmitriy Kuminov
9 *
10 * This file is part of the Extended system tray widget source package.
11 * Extended system tray widget is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, in version 2 as it comes in
14 * the "COPYING" file of the Extended system tray widget distribution. This
15 * program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 */
20
21#ifndef W_XSYSTRAY_HEADER_INCLUDED
22#define W_XSYSTRAY_HEADER_INCLUDED
23
24#include <sys/builtin.h> // atomics
25
26// primitive debug logging to a file (usage: #define ENABLE_LOG_TO "some_file")
27#ifdef ENABLE_LOG_TO
28#include <stdio.h>
29#include <stdarg.h>
30static void __LOG_WORKER(const char *fmt, ...)
31{
32 static FILE *f = NULL;
33 if (f == NULL)
34 {
35 f = fopen(ENABLE_LOG_TO, "w");
36 setbuf(f, NULL);
37 }
38 if (f != NULL)
39 {
40 va_list vl;
41 va_start(vl, fmt);
42 vfprintf(f, fmt, vl);
43 va_end(vl);
44 }
45}
46#define LOG(m) do { __LOG_WORKER m; } while(0)
47#define LOGF(m) do { __LOG_WORKER("%s: ", __FUNCTION__); __LOG_WORKER m; } while(0)
48#else
49#define LOG(m) do {} while (0)
50#define LOGF(m) do {} while (0)
51#endif
52
53#include "xsystray.h"
54
55#define XSYSTRAY_VERSION_MAJOR 0
56#define XSYSTRAY_VERSION_MINOR 1
57#define XSYSTRAY_VERSION_REVISION 1
58
59#define WNDCLASS_WIDGET_XSYSTRAY_SERVER "XWPCenterExtendedSysTrayServer"
60
61#define WNDCLASS_WIDGET_XSYSTRAY "XWPCenterExtendedSysTray"
62#define INTCLASS_WIDGET_XSYSTRAY "ExtendedSysTray"
63#define HUMANSTR_WIDGET_XSYSTRAY "Extended system tray"
64
65#define WM_XST_CREATED_ATOM "ExtendedSysTray.WM_XST_CREATED"
66#define WM_XST_NOTIFY_ATOM "ExtendedSysTray.WM_XST_NOTIFY"
67
68#define WM_XST_CONTROL (WM_USER + 0)
69 // message sent to the system tray server to request an action
70
71// server action commands
72typedef enum
73{
74 SYSTRAYCMD_GETVERSION,
75 SYSTRAYCMD_ADDICON,
76 SYSTRAYCMD_REPLACEICON,
77 SYSTRAYCMD_REMOVEICON,
78 SYSTRAYCMD_SETTOOLTIP,
79 SYSTRAYCMD_SHOWBALLOON,
80 SYSTRAYCMD_HIDEBALLOON,
81 SYSTRAYCMD_QUERYRECT,
82} SYSTRAYCMD;
83
84// server responses to WM_XST_CONTROL
85#define XST_OK 0 // command succeeded
86#define XST_FAIL 1 // command failed
87#define XST_REPLACED 2 // SYSTRAYCMD_ADDICON replaced the existing icon
88
89/*
90 *@@ SYSTRAYCTLDATA:
91 * Structure holding information accompanying WM_XST_CONTROL messages sent
92 * to the system tray server by clients (windows associated with system
93 * tray icons).
94 *
95 * NOTE: When you change the size of this structure, you may also need to
96 * change CLIENT_MEMORYPOOL_SIZE value (see the comments there for
97 * details).
98 */
99
100typedef struct
101{
102 SYSTRAYCMD ulCommand;
103 // command to execute, must always be set
104 HWND hwndSender;
105 // sender window, a must for SYSTRAYCMD_ADDICON, _CHANGEICON,
106 // _REMOVEICON, _SETTOOLTIP, _SHOWBALLOON, _HIDEBALLOON,
107 // _QUERYRECT
108 union
109 {
110 struct
111 {
112 ULONG ulMajor;
113 ULONG ulMinor;
114 ULONG ulRevision;
115 } version;
116 // used by SYSTRAYCMD_GETVERSION
117
118 struct
119 {
120 USHORT usId;
121 HPOINTER hIcon;
122 CHAR szToolTip[512];
123 ULONG ulMsgId;
124 } icon;
125 // used by SYSTRAYCMD_ADDICON, _CHANGEICON, _REMOVEICON, _SETTOOLTIP
126
127 struct
128 {
129 RECTL rclIcon;
130 } rect;
131 // used by SYSTRAYCMD_QUERYRECT
132 } u;
133
134 BOOL bAcknowledged : 1;
135 // set to true by the recipient if it processes the message
136
137} SYSTRAYCTLDATA, *PSYSTRAYCTLDATA;
138
139/*
140 *@@ NOTIFYDATA:
141 * Structure holding information acompanying notification messages
142 * posted to clients (windows associated with system tray icons) about
143 * icon events. This structure unions all public notification code
144 * dependent structures defined in xsystray.h (starting with XST*).
145 *
146 * All messages posted to the client have an ID corresponding to the
147 * WM_XST_NOTIFY_ATOM in the system atom table. The client-side API
148 * implementation intercepts these messages (using HK_INPUT), composes a
149 * new message given the information in NOTIFYDATA, frees the NOTIFYDATA
150 * pointer using FreeNotifyDataPtr() and then sends the composed message to
151 * the appropriate window.
152 *
153 * The layout of the XST_NOTIFY message is as follows:
154 *
155 * param1
156 * PNOTIFYDATA pNotifyData pointer to the NOTIFYDATA structure
157 *
158 * param2
159 * PVOID pvMemoryPool server memory pool (for the
160 * FreeNotifyDataPtr() call)
161 *
162 * NOTE: Structures in the union should only contain values; passing
163 * pointers to arbitrary data to the client side is not supported (yet).
164 *
165 * NOTE: When you change the size of this structure, you may also need to
166 * change SERVER_MEMORYPOOL_SIZE value in w_xsystray.c (see the comments
167 * there for details).
168 */
169
170typedef struct
171{
172 ULONG msg;
173 // ID of the message that is to be sent to the target window
174 MPARAM mp1;
175 // message parameter (USHORT usIconId, USHORT usNotifyCode)
176 MPARAM mp2;
177 // message parameter (a pointer to a struct from the union)
178 union
179 {
180 XSTMOUSEMSG MouseMsg;
181 XSTCONTEXTMSG ContextMsg;
182 XSTWHEELMSG WheelMsg;
183 } u;
184
185} NOTIFYDATA, *PNOTIFYDATA;
186
187// Header of the server-side memory pool
188typedef struct
189{
190 volatile HWND hwnd; // owner of the block or NULLHANDLE if free
191 NOTIFYDATA NotifyData; // data
192
193} MEMPOOLBLK, *PMEMPOOLBLK;
194
195// allocation unit in the server-side memory pool
196typedef struct
197{
198 ULONG ulBeyond; // address of the first byte beyond the memory pool
199
200 volatile ULONG ulNeedsCommit; // address of the first decommitted byte
201 volatile ULONG ulNext; // address of next possibly free block
202
203 MEMPOOLBLK aBlocks[0]; // fake array for easier addressing
204
205} MEMPOOLHDR, *PMEMPOOLHDR;
206
207/*
208 *@@ FreeNotifyDataPtr:
209 * Frees the NOTIFYDATA structure allocated by AllocNotifyDataPtr().
210 *
211 * See AllocNotifyDataPtr() for more details about allocating these
212 * structures.
213 */
214
215inline
216VOID FreeNotifyDataPtr(PVOID pvMemoryPool, // in: memory pool base address
217 HWND hwndOwner, // in: owner of the struct to free
218 PNOTIFYDATA pData) // in: address of the struct to free
219{
220 PMEMPOOLHDR pHdr = (PMEMPOOLHDR)pvMemoryPool;
221 PMEMPOOLBLK pBlk = (PMEMPOOLBLK)((ULONG)pData - sizeof(HWND));
222
223 ULONG ulNext = pHdr->ulNext;
224
225 __atomic_cmpxchg32((uint32_t *)&pBlk->hwnd, NULLHANDLE, hwndOwner);
226
227 // if the next possible free block is greater than we just freed,
228 // set it to us (to minimize the amount of committed pages)
229 if (ulNext > (ULONG)pBlk)
230 __atomic_cmpxchg32((uint32_t *)&pHdr->ulNext, (ULONG)pBlk, ulNext);
231}
232
233#endif // W_XSYSTRAY_HEADER_INCLUDED
234
235
Note: See TracBrowser for help on using the repository browser.