blob: 8e38edb326766189e422efaa047d93beee70844b [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossman66f1db52019-05-02 12:32:03 +02002 * Copyright 2011-2019 Pierre Ossman for Cendio AB
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20// -=- SDisplay.h
21//
22// The SDisplay class encapsulates a system display.
23
24#ifndef __RFB_SDISPLAY_H__
25#define __RFB_SDISPLAY_H__
26
27#include <rfb/SDesktop.h>
28#include <rfb/UpdateTracker.h>
29#include <rfb/Configuration.h>
30#include <rfb_win32/Handle.h>
31#include <rfb_win32/EventManager.h>
32#include <rfb_win32/SInput.h>
33#include <rfb_win32/Clipboard.h>
34#include <rfb_win32/CleanDesktop.h>
35#include <rfb_win32/WMCursor.h>
36#include <rfb_win32/WMNotifier.h>
37#include <rfb_win32/DeviceFrameBuffer.h>
38#include <rfb_win32/DeviceContext.h>
39
40namespace rfb {
41
42 namespace win32 {
43
44 //
45 // -=- SDisplay
46 //
47
48 class SDisplayCore {
49 public:
50 virtual ~SDisplayCore() {};
51 virtual void setScreenRect(const Rect& screenRect_) = 0;
52 virtual void flushUpdates() = 0;
53 virtual const char* methodName() const = 0;
54 };
55
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020056 class QueryConnectionHandler {
57 public:
58 virtual ~QueryConnectionHandler() {}
59 virtual void queryConnection(network::Socket* sock,
60 const char* userName) = 0;
61 };
62
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000063 class SDisplay : public SDesktop,
64 WMMonitor::Notifier,
65 Clipboard::Notifier,
66 public EventHandler
67 {
68 public:
69 SDisplay();
70 virtual ~SDisplay();
71
72 // -=- SDesktop interface
73
74 virtual void start(VNCServer* vs);
75 virtual void stop();
Pierre Ossman10688ef2018-09-29 11:24:19 +020076 virtual void terminate();
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020077 virtual void queryConnection(network::Socket* sock,
78 const char* userName);
Pierre Ossman615d16b2019-05-03 10:53:06 +020079 virtual void handleClipboardRequest();
80 virtual void handleClipboardAnnounce(bool available);
81 virtual void handleClipboardData(const char* data);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000082 virtual void pointerEvent(const Point& pos, int buttonmask);
Pierre Ossman5ae28212017-05-16 14:30:38 +020083 virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000084
Pierre Ossman615d16b2019-05-03 10:53:06 +020085 // -=- Clipboard events
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000086
Pierre Ossman615d16b2019-05-03 10:53:06 +020087 virtual void notifyClipboardChanged(bool available);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000088
89 // -=- Display events
90
91 virtual void notifyDisplayEvent(WMMonitor::Notifier::DisplayEventType evt);
92
93 // -=- EventHandler interface
94
95 HANDLE getUpdateEvent() {return updateEvent;}
Pierre Ossman10688ef2018-09-29 11:24:19 +020096 HANDLE getTerminateEvent() {return terminateEvent;}
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000097 virtual void processEvent(HANDLE event);
98
99 // -=- Notification of whether or not SDisplay is started
100
101 void setStatusLocation(bool* status) {statusLocation = status;}
102
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +0200103 // -=- Set handler for incoming connections
104
105 void setQueryConnectionHandler(QueryConnectionHandler* qch) {
106 queryConnectionHandler = qch;
107 }
108
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000109 static IntParameter updateMethod;
110 static BoolParameter disableLocalInputs;
111 static StringParameter disconnectAction;
112 static BoolParameter removeWallpaper;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000113 static BoolParameter disableEffects;
114
Pierre Ossman4ab1e5d2016-01-12 12:29:32 +0100115 // -=- Use by VNC Config to determine whether hooks are available
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000116 static bool areHooksAvailable();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000117
118
119 protected:
120 bool isRestartRequired();
121 void startCore();
122 void stopCore();
123 void restartCore();
124 void recreatePixelBuffer(bool force=false);
125 bool flushChangeTracker(); // true if flushed, false if empty
Rahul Kalec719e4a2017-07-13 00:36:02 +0200126 bool checkLedState();
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000127
128 VNCServer* server;
129
130 // -=- Display pixel buffer
131 DeviceFrameBuffer* pb;
132 DeviceContext* device;
133
134 // -=- The coordinates of Window's entire virtual Screen
135 Rect screenRect;
136
137 // -=- All changes are collected in UN-CLIPPED Display coords and merged
138 // When they are to be flushed to the VNCServer, they are changed
139 // to server coords and clipped appropriately.
140 SimpleUpdateTracker updates;
141 ClippingUpdateTracker clipper;
142
143 // -=- Internal SDisplay implementation
144 SDisplayCore* core;
145 int updateMethod_;
146
147 // Inputs
148 SPointer* ptr;
149 SKeyboard* kbd;
150 Clipboard* clipboard;
151 WMBlockInput* inputs;
152
153 // Desktop state
154 WMMonitor* monitor;
155
156 // Desktop optimisation
157 CleanDesktop* cleanDesktop;
158 bool isWallpaperRemoved;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000159 bool areEffectsDisabled;
160
161 // Cursor
162 WMCursor* cursor;
163 WMCursor::Info old_cursor;
164 Region old_cursor_region;
165 Point cursor_renderpos;
166
167 // -=- Event signalled to trigger an update to be flushed
168 Handle updateEvent;
Pierre Ossman10688ef2018-09-29 11:24:19 +0200169 // -=- Event signalled to terminate the server
170 Handle terminateEvent;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000171
172 // -=- Where to write the active/inactive indicator to
173 bool* statusLocation;
Rahul Kalec719e4a2017-07-13 00:36:02 +0200174
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +0200175 // -=- Whom to query incoming connections
176 QueryConnectionHandler* queryConnectionHandler;
177
Rahul Kalec719e4a2017-07-13 00:36:02 +0200178 unsigned ledState;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000179 };
180
181 }
182}
183
184#endif // __RFB_SDISPLAY_H__