[280] | 1 |
|
---|
[255] | 2 | /*
|
---|
[280] | 3 | *@@sourcefile xsystray.h:
|
---|
| 4 | * Extended system tray widget for XCenter/eCenter.
|
---|
[255] | 5 | *
|
---|
[280] | 6 | * Private declarations.
|
---|
[255] | 7 | *
|
---|
[280] | 8 | * Copyright (C) 2009 Dmitry A. Kuminov
|
---|
[255] | 9 | *
|
---|
[280] | 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.
|
---|
[255] | 19 | */
|
---|
| 20 |
|
---|
| 21 | #ifndef XSYSTRAY_HEADER_INCLUDED
|
---|
| 22 | #define XSYSTRAY_HEADER_INCLUDED
|
---|
| 23 |
|
---|
[273] | 24 | #include "xsystray_api.h"
|
---|
| 25 |
|
---|
| 26 | #include <sys/builtin.h> // atomics
|
---|
| 27 |
|
---|
[256] | 28 | #define XSYSTRAY_VERSION_MAJOR 0
|
---|
| 29 | #define XSYSTRAY_VERSION_MINOR 1
|
---|
| 30 | #define XSYSTRAY_VERSION_REVISION 0
|
---|
| 31 |
|
---|
[255] | 32 | #define WNDCLASS_WIDGET_XSYSTRAY_SERVER "XWPCenterExtendedSysTrayServer"
|
---|
| 33 |
|
---|
| 34 | #define WNDCLASS_WIDGET_XSYSTRAY "XWPCenterExtendedSysTray"
|
---|
| 35 | #define INTCLASS_WIDGET_XSYSTRAY "ExtendedSysTray"
|
---|
| 36 | #define HUMANSTR_WIDGET_XSYSTRAY "Extended system tray"
|
---|
| 37 |
|
---|
[273] | 38 | #define WM_XST_CREATED_ATOM "ExtendedSysTray.WM_XST_CREATED"
|
---|
| 39 | #define WM_XST_NOTIFY_ATOM "ExtendedSysTray.WM_XST_NOTIFY"
|
---|
| 40 |
|
---|
[255] | 41 | #define WM_XST_CONTROL (WM_USER + 0)
|
---|
[281] | 42 | // message sent to the system tray server to request an action
|
---|
[255] | 43 |
|
---|
[281] | 44 | // server action commands
|
---|
[255] | 45 | typedef enum
|
---|
| 46 | {
|
---|
| 47 | SYSTRAYCMD_GETVERSION,
|
---|
| 48 | SYSTRAYCMD_ADDICON,
|
---|
[282] | 49 | SYSTRAYCMD_REPLACEICON,
|
---|
[255] | 50 | SYSTRAYCMD_REMOVEICON,
|
---|
| 51 | SYSTRAYCMD_SETTOOLTIP,
|
---|
| 52 | SYSTRAYCMD_SHOWBALLOON,
|
---|
| 53 | SYSTRAYCMD_HIDEBALLOON,
|
---|
[285] | 54 | SYSTRAYCMD_QUERYRECT,
|
---|
[255] | 55 | } SYSTRAYCMD;
|
---|
| 56 |
|
---|
[281] | 57 | // server responses to WM_XST_CONTROL
|
---|
| 58 | #define XST_OK 0 // command succeeded
|
---|
| 59 | #define XST_FAIL 1 // command failed
|
---|
| 60 | #define XST_REPLACED 2 // SYSTRAYCMD_ADDICON replaced the existing icon
|
---|
| 61 |
|
---|
[273] | 62 | /*
|
---|
| 63 | *@@ SYSTRAYCTLDATA:
|
---|
| 64 | * Structure holding information accompanying WM_XST_CONTROL messages sent
|
---|
| 65 | * to the system tray server by clients (windows associated with system
|
---|
| 66 | * tray icons).
|
---|
| 67 | *
|
---|
| 68 | * NOTE: When you change the size of this structure, you may also need to
|
---|
| 69 | * change CLIENT_MEMORYPOOL_SIZE value (see the comments there for
|
---|
| 70 | * details).
|
---|
| 71 | */
|
---|
| 72 |
|
---|
[255] | 73 | typedef struct
|
---|
| 74 | {
|
---|
| 75 | SYSTRAYCMD ulCommand;
|
---|
| 76 | // command to execute, must always be set
|
---|
| 77 | HWND hwndSender;
|
---|
[282] | 78 | // sender window, a must for SYSTRAYCMD_ADDICON, _CHANGEICON,
|
---|
[285] | 79 | // _REMOVEICON, _SETTOOLTIP, _SHOWBALLOON, _HIDEBALLOON,
|
---|
| 80 | // _QUERYRECT
|
---|
[255] | 81 | union
|
---|
| 82 | {
|
---|
| 83 | struct
|
---|
| 84 | {
|
---|
| 85 | ULONG ulMajor;
|
---|
| 86 | ULONG ulMinor;
|
---|
| 87 | ULONG ulRevision;
|
---|
| 88 | } version;
|
---|
| 89 | // used by SYSTRAYCMD_GETVERSION
|
---|
| 90 |
|
---|
| 91 | struct
|
---|
| 92 | {
|
---|
[273] | 93 | USHORT usId;
|
---|
[255] | 94 | HPOINTER hIcon;
|
---|
[282] | 95 | CHAR szToolTip[512];
|
---|
[255] | 96 | ULONG ulMsgId;
|
---|
| 97 | } icon;
|
---|
[282] | 98 | // used by SYSTRAYCMD_ADDICON, _CHANGEICON, _REMOVEICON, _SETTOOLTIP
|
---|
[285] | 99 |
|
---|
| 100 | struct
|
---|
| 101 | {
|
---|
| 102 | RECTL rclIcon;
|
---|
| 103 | } rect;
|
---|
| 104 | // used by SYSTRAYCMD_QUERYRECT
|
---|
[255] | 105 | } u;
|
---|
| 106 |
|
---|
| 107 | BOOL bAcknowledged : 1;
|
---|
| 108 | // set to true by the recipient if it processes the message
|
---|
| 109 |
|
---|
[256] | 110 | } SYSTRAYCTLDATA, *PSYSTRAYCTLDATA;
|
---|
[255] | 111 |
|
---|
[273] | 112 | /*
|
---|
| 113 | *@@ NOTIFYDATA:
|
---|
| 114 | * Structure holding information acompanying notification messages
|
---|
| 115 | * posted to clients (windows associated with system tray icons) about
|
---|
| 116 | * icon events. This structure unions all public notification code
|
---|
| 117 | * dependent structures defined in xsystray_api.h (starting with XST*).
|
---|
| 118 | *
|
---|
| 119 | * All messages posted to the client have an ID corresponding to the
|
---|
| 120 | * WM_XST_NOTIFY_ATOM in the system atom table. The client-side API
|
---|
| 121 | * implementation intercepts these messages (using HK_INPUT), composes a
|
---|
| 122 | * new message given the information in NOTIFYDATA, frees the NOTIFYDATA
|
---|
| 123 | * pointer using FreeNotifyDataPtr() and then sends the composed message to
|
---|
| 124 | * the appropriate window.
|
---|
| 125 | *
|
---|
| 126 | * The layout of the XST_NOTIFY message is as follows:
|
---|
| 127 | *
|
---|
| 128 | * param1
|
---|
| 129 | * PNOTIFYDATA pNotifyData pointer to the NOTIFYDATA structure
|
---|
| 130 | *
|
---|
| 131 | * param2
|
---|
| 132 | * PVOID pvMemoryPool server memory pool (for the
|
---|
| 133 | * FreeNotifyDataPtr() call)
|
---|
| 134 | *
|
---|
[275] | 135 | * NOTE: Structures in the union should only contain values; passing
|
---|
| 136 | * pointers to arbitrary data to the client side is not supported (yet).
|
---|
| 137 | *
|
---|
[273] | 138 | * NOTE: When you change the size of this structure, you may also need to
|
---|
| 139 | * change SERVER_MEMORYPOOL_SIZE value in xsystray.c (see the comments
|
---|
| 140 | * there for details).
|
---|
| 141 | */
|
---|
| 142 |
|
---|
| 143 | typedef struct
|
---|
| 144 | {
|
---|
| 145 | ULONG msg;
|
---|
| 146 | // ID of the message that is to be sent to the target window
|
---|
| 147 | MPARAM mp1;
|
---|
| 148 | // message parameter (usually: USHORT usIconId, USHORT usNotifyCode)
|
---|
| 149 | MPARAM mp2;
|
---|
| 150 | // message parameter (usually, a pointer to a struct from the union)
|
---|
| 151 | union
|
---|
| 152 | {
|
---|
| 153 | XSTMOUSEMSG MouseMsg;
|
---|
| 154 | XSTCONTEXTMSG ContextMsg;
|
---|
| 155 | XSTWHEELMSG WheelMsg;
|
---|
| 156 | } u;
|
---|
| 157 |
|
---|
| 158 | } NOTIFYDATA, *PNOTIFYDATA;
|
---|
| 159 |
|
---|
| 160 | // Header of the server-side memory pool
|
---|
| 161 | typedef struct
|
---|
| 162 | {
|
---|
| 163 | volatile HWND hwnd; // owner of the block or NULLHANDLE if free
|
---|
| 164 | NOTIFYDATA NotifyData; // data
|
---|
| 165 |
|
---|
| 166 | } MEMPOOLBLK, *PMEMPOOLBLK;
|
---|
| 167 |
|
---|
| 168 | // allocation unit in the server-side memory pool
|
---|
| 169 | typedef struct
|
---|
| 170 | {
|
---|
| 171 | ULONG ulBeyond; // address of the first byte beyond the memory pool
|
---|
| 172 |
|
---|
| 173 | volatile ULONG ulNeedsCommit; // address of the first decommitted byte
|
---|
| 174 | volatile ULONG ulNext; // address of next possibly free block
|
---|
| 175 |
|
---|
| 176 | MEMPOOLBLK aBlocks[0]; // fake array for easier addressing
|
---|
| 177 |
|
---|
| 178 | } MEMPOOLHDR, *PMEMPOOLHDR;
|
---|
| 179 |
|
---|
| 180 | /*
|
---|
| 181 | *@@ FreeNotifyDataPtr:
|
---|
| 182 | * Frees the NOTIFYDATA structure allocated by AllocNotifyDataPtr().
|
---|
| 183 | *
|
---|
| 184 | * See AllocNotifyDataPtr() for more details about allocating these
|
---|
| 185 | * structures.dd
|
---|
| 186 | */
|
---|
| 187 |
|
---|
| 188 | inline
|
---|
| 189 | VOID FreeNotifyDataPtr(PVOID pvMemoryPool, // in: memory pool base address
|
---|
| 190 | HWND hwndOwner, // in: owner of the struct to free
|
---|
| 191 | PNOTIFYDATA pData) // in: address of the struct to free
|
---|
| 192 | {
|
---|
| 193 | PMEMPOOLHDR pHdr = (PMEMPOOLHDR)pvMemoryPool;
|
---|
| 194 | PMEMPOOLBLK pBlk = (PMEMPOOLBLK)((ULONG)pData - sizeof(HWND));
|
---|
| 195 |
|
---|
| 196 | ULONG ulNext = pHdr->ulNext;
|
---|
| 197 |
|
---|
| 198 | __atomic_cmpxchg32((uint32_t *)&pBlk->hwnd, NULLHANDLE, hwndOwner);
|
---|
| 199 |
|
---|
| 200 | // if the next possible free block is greater than we just freed,
|
---|
| 201 | // set it to us (to minimize the amount of committed pages)
|
---|
| 202 | if (ulNext > (ULONG)pBlk)
|
---|
| 203 | __atomic_cmpxchg32((uint32_t *)&pHdr->ulNext, (ULONG)pBlk, ulNext);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[255] | 206 | #endif // XSYSTRAY_HEADER_INCLUDED
|
---|
| 207 |
|
---|
| 208 |
|
---|