vncdesktop.h
11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// Copyright (C) 2002 Ultr@VNC Team Members. All Rights Reserved.
// Copyright (C) 2000-2002 Const Kaplinsky. All Rights Reserved.
// Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This file is part of the VNC system.
//
// The VNC system is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// If the source code for the VNC system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on vnc@uk.research.att.com for information on obtaining it.
// vncDesktop object
// The vncDesktop object handles retrieval of data from the
// display buffer. It also uses the RFBLib DLL to supply
// information on mouse movements and screen updates to
// the server
class vncDesktop;
#if !defined(_WINVNC_VNCDESKTOP)
#define _WINVNC_VNCDESKTOP
#pragma once
// Include files
#include "stdhdrs.h"
class vncServer;
#include "rfbRegion.h"
#include "rfbUpdateTracker.h"
#include "vncBuffer.h"
#include "translate.h"
#include <omnithread.h>
// Modif rdv@2002 - v1.1.x - videodriver
#include "videodriver.h"
// Modif sf@2002 - v1.1.0
#include <list>
#include "textchat.h"
//#define COMPILE_MULTIMON_STUBS
//#include "Multimon.h"
#ifndef SM_CMONITORS
#define SM_XVIRTUALSCREEN 76
#define SM_YVIRTUALSCREEN 77
#define SM_CXVIRTUALSCREEN 78
#define SM_CYVIRTUALSCREEN 79
#define SM_CMONITORS 80
#define SM_SAMEDISPLAYFORMAT 81
// HMONITOR is already declared if WINVER >= 0x0500 in windef.h
// This is for components built with an older version number.
//
#if !defined(HMONITOR_DECLARED) && (WINVER < 0x0500)
DECLARE_HANDLE(HMONITOR);
#define HMONITOR_DECLARED
#endif
#define MONITOR_DEFAULTTONULL 0x00000000
#define MONITOR_DEFAULTTOPRIMARY 0x00000001
#define MONITOR_DEFAULTTONEAREST 0x00000002
#define MONITORINFOF_PRIMARY 0x00000001
typedef struct tagMONITORINFO
{
DWORD cbSize;
RECT rcMonitor;
RECT rcWork;
DWORD dwFlags;
} MONITORINFO, *LPMONITORINFO;
#ifndef CCHDEVICENAME
#define CCHDEVICENAME 32
#endif
#ifdef __cplusplus
typedef struct tagMONITORINFOEXA : public tagMONITORINFO
{
CHAR szDevice[CCHDEVICENAME];
} MONITORINFOEXA, *LPMONITORINFOEXA;
typedef struct tagMONITORINFOEXW : public tagMONITORINFO
{
WCHAR szDevice[CCHDEVICENAME];
} MONITORINFOEXW, *LPMONITORINFOEXW;
#ifdef UNICODE
typedef MONITORINFOEXW MONITORINFOEX;
typedef LPMONITORINFOEXW LPMONITORINFOEX;
#else
typedef MONITORINFOEXA MONITORINFOEX;
typedef LPMONITORINFOEXA LPMONITORINFOEX;
#endif // UNICODE
#else // ndef __cplusplus
typedef struct tagMONITORINFOEXA
{
MONITORINFO;
CHAR szDevice[CCHDEVICENAME];
} MONITORINFOEXA, *LPMONITORINFOEXA;
typedef struct tagMONITORINFOEXW
{
MONITORINFO;
WCHAR szDevice[CCHDEVICENAME];
} MONITORINFOEXW, *LPMONITORINFOEXW;
#ifdef UNICODE
typedef MONITORINFOEXW MONITORINFOEX;
typedef LPMONITORINFOEXW LPMONITORINFOEX;
#else
typedef MONITORINFOEXA MONITORINFOEX;
typedef LPMONITORINFOEXA LPMONITORINFOEX;
#endif // UNICODE
#endif
#endif
typedef std::list<COLORREF> RGBPixelList; // List of RGB values (pixels)
// sf@2002 - Generates ClassName lenght warning in debug mode compile.
// typedef std::list<RGBPixelList*> GridsList; // List of Grids of pixels
typedef std::list<void*> GridsList; // List of Grids of pixels
typedef std::list<HWND> WindowsList; // List of windows handles
// Constants
extern const UINT RFB_SCREEN_UPDATE;
extern const UINT RFB_COPYRECT_UPDATE;
extern const UINT RFB_MOUSE_UPDATE;
extern const char szDesktopSink[];
#define NONE 0
#define MIRROR 1
#define PSEUDO 2
typedef struct DrvWatch
{
HWND hwnd;
bool *stop;
}DrvWatch;
typedef BOOL (*SetHooksFn)(DWORD thread_id,UINT UpdateMsg,UINT CopyMsg,UINT MouseMsg,BOOL ddihook);
typedef BOOL (*UnSetHooksFn)(DWORD thread_id);
typedef BOOL (*SetKeyboardFilterHookFn)(BOOL activate);
typedef BOOL (*SetMouseFilterHookFn)(BOOL activate);
typedef BOOL (WINAPI* pBlockInput) (BOOL);
typedef BOOL (WINAPI* LPGETMONITORINFO)(HMONITOR, LPMONITORINFO);
typedef HMONITOR (WINAPI* LPMONITOTFROMPOINT) (POINT,DWORD);
// Class definition
// multi monitor
struct monitor
{
int Width;
int Height;
int Depth;
char device[32];
int offsetx;
int offsety;
};
class vncDesktop
{
// Fields
public:
// Methods
public:
// Make the desktop thread & window proc friends
friend class vncDesktopThread;
friend LRESULT CALLBACK DesktopWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
// Create/Destroy methods
vncDesktop();
~vncDesktop();
BOOL Init(vncServer *pSrv);
// Tell the desktop hooks to grab & update a particular rectangle
void QueueRect(const rfb::Rect &rect);
// Kick the desktop hooks to perform an update
void TriggerUpdate();
// Get a reference to the desktop update lock
// The lock is held while data is being grabbed and copied
// to the back buffer, and while changes are being passed to
// clients
omni_mutex &GetUpdateLock() {return m_update_lock;};
// Screen translation, capture, info
void FillDisplayInfo(rfbServerInitMsg *scrInfo);
void CaptureScreen(const rfb::Rect &UpdateArea, BYTE *scrBuff, UINT scrBuffSize);
int ScreenBuffSize();
HWND Window() {return m_hwnd;};
// Mouse related
void CaptureMouse(BYTE *scrBuff, UINT scrBuffSize);
rfb::Rect MouseRect();
void SetCursor(HCURSOR cursor);
// CURSOR HANDLING
BOOL GetRichCursorData(BYTE *databuf, HCURSOR hcursor, int width, int height);
HCURSOR GetCursor() { return m_hcursor; }
// Clipboard manipulation
void SetClipText(LPSTR text);
// Method to obtain the DIBsection buffer if fast blits are enabled
// If they're disabled, it'll return NULL
inline VOID *OptimisedBlitBuffer() {return m_DIBbits;};
BOOL m_initialClipBoardSeen;
// Handler for pixel data grabbing and region change checking
vncBuffer m_buffer;
//SINGLE WINDOW
vncServer *GetServerPointer() {return m_server;};
HWND m_Single_hWnd;
HWND m_Single_hWnd_backup;
BOOL CalculateSWrect(RECT &rect);
rfb::Rect GetSize();
rfb::Rect GetQuarterSize();
// Modif rdv@2002 - v1.1.x - videodriver
//BOOL IsVideoDriverEnabled();
BOOL VideoBuffer();
int m_ScreenOffsetx;
int m_ScreenOffsety;
int DriverType;
DWORD color[10];
// Modif rdv@2002 Dis/enable input
void SetDisableInput(bool enabled);
void SetSW(int x,int y);
//hook selection
BOOL m_hookdriver;
void SethookMechanism(BOOL hookall,BOOL hookdriver);
bool m_UltraEncoder_used;
rfb::Rect m_Cliprect;//the region to check
bool StopDriverWatches;
#ifdef DRIVER
PCHANGES_BUF pchanges_buf;
CHANGES_BUF changes_buf;
#endif
int GetNrMonitors();
void GetPrimaryDevice();
void GetSecondaryDevice();
void Checkmonitors();
// Implementation
protected:
// Routines to hook and unhook us
BOOL Startup();
BOOL Shutdown();
// Init routines called by the child thread
BOOL InitDesktop();
void KillScreenSaver();
void KillWallpaper();
void RestoreWallpaper();
BOOL InitBitmap();
BOOL InitWindow();
BOOL ThunkBitmapInfo();
BOOL SetPixFormat();
BOOL SetPixShifts();
BOOL InitHooks();
BOOL SetPalette();
int m_timer;
// Fetching pixel data to a buffer, and handling copyrects
void CopyToBuffer(const rfb::Rect &rect, BYTE *scrBuff, UINT scrBuffSize);
bool CalcCopyRects(rfb::UpdateTracker &tracker);
// Routine to attempt enabling optimised DIBsection blits
void EnableOptimisedBlits();
// Convert a bit mask eg. 00111000 to max=7, shift=3
static void MaskToMaxAndShift(DWORD mask, CARD16 &max, CARD8 &shift);
// Enabling & disabling clipboard handling
void SetClipboardActive(BOOL active) {m_clipboard_active = active;};
// Modif sf@2002 - v1.1.0 - FastDetectChanges stuff
void FastDetectChanges(rfb::Region2D &rgn, rfb::Rect &rect, int nZone, bool fTurbo);
GridsList m_lGridsList; // List of changes detection grids
WindowsList m_lWList; // List of Windows handles
// HDC m_hDC; // Local Screen Device context to capture our Grid of pixels
int m_nGridCycle; // Cycle index for grid shifting
// Modif sf@2002 - v1.1.0
long m_lLastMouseUpdateTime;
long m_lLastSlowClientTestTime;
// long m_lLastTempo;
// sf@2002 - TextChat - No more used for now
// bool m_fTextChatRunning;
// TextChat* m_pCurrentTextChat;
BOOL m_fCaptureAlphaBlending;
// DATA
// Generally useful stuff
vncServer *m_server;
omni_thread *m_thread;
HWND m_hwnd;
UINT m_timerid;
HWND m_hnextviewer;
BOOL m_clipboard_active;
// device contexts for memory and the screen
HDC m_hmemdc;
HDC m_hrootdc;
// New and old bitmaps
HBITMAP m_membitmap;
omni_mutex m_update_lock;
rfb::Rect m_bmrect;
struct _BMInfo {
BOOL truecolour;
BITMAPINFO bmi;
// Colormap info - comes straight after BITMAPINFO - **HACK**
RGBQUAD cmap[256];
} m_bminfo;
// Screen info
rfbServerInitMsg m_scrinfo;
// These are the red, green & blue masks for a pixel
DWORD m_rMask, m_gMask, m_bMask;
// This is always handy to have
int m_bytesPerRow;
// Handle of the default cursor
HCURSOR m_hcursor;
HCURSOR m_hOldcursor; // sf@2002
// Handle of the basic arrow cursor
HCURSOR m_hdefcursor;
// The current mouse position
rfb::Rect m_cursorpos;
// Boolean flag to indicate when the display resolution has changed
BOOL m_displaychanged;
// Boolean flag to indicate whether or not an update trigger message
// is already in the desktop thread message queue
BOOL m_update_triggered;
// Extra vars used for the DIBsection optimisation
VOID *m_DIBbits;
BOOL m_formatmunged;
// Info used for polling modes
UINT m_pollingcycle;
// rfb::Rect m_fullscreen; // sf@2002 - v1.1.0
// Handling of the foreground window, to produce CopyRects
HWND m_foreground_window;
rfb::Rect m_foreground_window_rect;
//SINGLE WINDOW
void SWinit();
int m_SWHeight;
int m_SWWidth;
BOOL m_SWSizeChanged;
BOOL m_SWmoved;
BOOL m_SWtoDesktop;
int m_SWOffsetx;
int m_SWOffsety;
//DDIHOOK
PCOPYDATASTRUCT pMyCDS;
#ifdef DRIVER
// Modif rdv@2002 - v1.1.x - videodriver
vncVideoDriver *m_videodriver;
BOOL InitVideoDriver();
void ShutdownVideoDriver();
omni_mutex m_videodriver_lock;
#endif
// Modif input dis/enabke
DWORD m_thread_hooks;
BOOL ddihook;
UINT OldPowerOffTimeout;
bool OldCaptureBlending;
//hook selection
BOOL m_hookdll;
BOOL On_Off_hookdll;
BOOL m_hookswitch;
BOOL Hookdll_Changed;
BOOL m_hookinited;
HANDLE m_hddihook;
void StartStopddihook(BOOL enabled);
void StartStophookdll(BOOL enabled);
void InitHookSettings();
HMODULE hModule;
SetHooksFn SetHooks;
UnSetHooksFn UnSetHooks;
SetKeyboardFilterHookFn SetKeyboardFilterHook;
SetMouseFilterHookFn SetMouseFilterHook;
pBlockInput pbi;
HMODULE hUser32;
BOOL Temp_Resolution;
BOOL m_OrigpollingSet;
BOOL m_Origpolling;
/* BOOL Check24bit();*/
BOOL DriverWanted;
BOOL HookWanted;
BOOL DriverWantedSet;
//Multi monitor
monitor mymonitor[3];
int nr_monitors;
int current_monitor;
int asked_display;
};
#endif // _WINVNC_VNCDESKTOP