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