Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 66f1db5 | 2019-05-02 12:32:03 +0200 | [diff] [blame^] | 2 | * Copyright 2011-2019 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 3 | * |
| 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 | |
| 40 | namespace 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 Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 56 | class QueryConnectionHandler { |
| 57 | public: |
| 58 | virtual ~QueryConnectionHandler() {} |
| 59 | virtual void queryConnection(network::Socket* sock, |
| 60 | const char* userName) = 0; |
| 61 | }; |
| 62 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 63 | 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 Ossman | 10688ef | 2018-09-29 11:24:19 +0200 | [diff] [blame] | 76 | virtual void terminate(); |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 77 | virtual void queryConnection(network::Socket* sock, |
| 78 | const char* userName); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 79 | virtual void pointerEvent(const Point& pos, int buttonmask); |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 80 | virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down); |
Pierre Ossman | 66f1db5 | 2019-05-02 12:32:03 +0200 | [diff] [blame^] | 81 | virtual void clientCutText(const char* str); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 82 | |
| 83 | // -=- Clipboard |
| 84 | |
Pierre Ossman | 66f1db5 | 2019-05-02 12:32:03 +0200 | [diff] [blame^] | 85 | virtual void notifyClipboardChanged(const char* text); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 86 | |
| 87 | // -=- Display events |
| 88 | |
| 89 | virtual void notifyDisplayEvent(WMMonitor::Notifier::DisplayEventType evt); |
| 90 | |
| 91 | // -=- EventHandler interface |
| 92 | |
| 93 | HANDLE getUpdateEvent() {return updateEvent;} |
Pierre Ossman | 10688ef | 2018-09-29 11:24:19 +0200 | [diff] [blame] | 94 | HANDLE getTerminateEvent() {return terminateEvent;} |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 95 | virtual void processEvent(HANDLE event); |
| 96 | |
| 97 | // -=- Notification of whether or not SDisplay is started |
| 98 | |
| 99 | void setStatusLocation(bool* status) {statusLocation = status;} |
| 100 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 101 | // -=- Set handler for incoming connections |
| 102 | |
| 103 | void setQueryConnectionHandler(QueryConnectionHandler* qch) { |
| 104 | queryConnectionHandler = qch; |
| 105 | } |
| 106 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 107 | static IntParameter updateMethod; |
| 108 | static BoolParameter disableLocalInputs; |
| 109 | static StringParameter disconnectAction; |
| 110 | static BoolParameter removeWallpaper; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 111 | static BoolParameter disableEffects; |
| 112 | |
Pierre Ossman | 4ab1e5d | 2016-01-12 12:29:32 +0100 | [diff] [blame] | 113 | // -=- Use by VNC Config to determine whether hooks are available |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 114 | static bool areHooksAvailable(); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 115 | |
| 116 | |
| 117 | protected: |
| 118 | bool isRestartRequired(); |
| 119 | void startCore(); |
| 120 | void stopCore(); |
| 121 | void restartCore(); |
| 122 | void recreatePixelBuffer(bool force=false); |
| 123 | bool flushChangeTracker(); // true if flushed, false if empty |
Rahul Kale | c719e4a | 2017-07-13 00:36:02 +0200 | [diff] [blame] | 124 | bool checkLedState(); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 125 | |
| 126 | VNCServer* server; |
| 127 | |
| 128 | // -=- Display pixel buffer |
| 129 | DeviceFrameBuffer* pb; |
| 130 | DeviceContext* device; |
| 131 | |
| 132 | // -=- The coordinates of Window's entire virtual Screen |
| 133 | Rect screenRect; |
| 134 | |
| 135 | // -=- All changes are collected in UN-CLIPPED Display coords and merged |
| 136 | // When they are to be flushed to the VNCServer, they are changed |
| 137 | // to server coords and clipped appropriately. |
| 138 | SimpleUpdateTracker updates; |
| 139 | ClippingUpdateTracker clipper; |
| 140 | |
| 141 | // -=- Internal SDisplay implementation |
| 142 | SDisplayCore* core; |
| 143 | int updateMethod_; |
| 144 | |
| 145 | // Inputs |
| 146 | SPointer* ptr; |
| 147 | SKeyboard* kbd; |
| 148 | Clipboard* clipboard; |
| 149 | WMBlockInput* inputs; |
| 150 | |
| 151 | // Desktop state |
| 152 | WMMonitor* monitor; |
| 153 | |
| 154 | // Desktop optimisation |
| 155 | CleanDesktop* cleanDesktop; |
| 156 | bool isWallpaperRemoved; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 157 | bool areEffectsDisabled; |
| 158 | |
| 159 | // Cursor |
| 160 | WMCursor* cursor; |
| 161 | WMCursor::Info old_cursor; |
| 162 | Region old_cursor_region; |
| 163 | Point cursor_renderpos; |
| 164 | |
| 165 | // -=- Event signalled to trigger an update to be flushed |
| 166 | Handle updateEvent; |
Pierre Ossman | 10688ef | 2018-09-29 11:24:19 +0200 | [diff] [blame] | 167 | // -=- Event signalled to terminate the server |
| 168 | Handle terminateEvent; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 169 | |
| 170 | // -=- Where to write the active/inactive indicator to |
| 171 | bool* statusLocation; |
Rahul Kale | c719e4a | 2017-07-13 00:36:02 +0200 | [diff] [blame] | 172 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 173 | // -=- Whom to query incoming connections |
| 174 | QueryConnectionHandler* queryConnectionHandler; |
| 175 | |
Rahul Kale | c719e4a | 2017-07-13 00:36:02 +0200 | [diff] [blame] | 176 | unsigned ledState; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | #endif // __RFB_SDISPLAY_H__ |