Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 3 | * Copyright 2009-2014 Pierre Ossman for Cendio AB |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 18 | * USA. |
| 19 | */ |
| 20 | |
Peter Åstrand | c359f36 | 2011-08-23 12:04:46 +0000 | [diff] [blame] | 21 | #ifdef HAVE_CONFIG_H |
| 22 | #include <config.h> |
| 23 | #endif |
| 24 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 25 | #include <assert.h> |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 26 | #ifndef _WIN32 |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 27 | #include <unistd.h> |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 28 | #endif |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 29 | |
| 30 | #include <rfb/CMsgWriter.h> |
Pierre Ossman | 0068a4f | 2015-11-09 15:48:19 +0100 | [diff] [blame] | 31 | #include <rfb/CSecurity.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 32 | #include <rfb/Hostname.h> |
| 33 | #include <rfb/LogWriter.h> |
Pierre Ossman | 0068a4f | 2015-11-09 15:48:19 +0100 | [diff] [blame] | 34 | #include <rfb/Security.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 35 | #include <rfb/util.h> |
| 36 | #include <rfb/screenTypes.h> |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 37 | #include <rfb/fenceTypes.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 38 | #include <rfb/Timer.h> |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 39 | #include <rdr/MemInStream.h> |
| 40 | #include <rdr/MemOutStream.h> |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 41 | #include <network/TcpSocket.h> |
| 42 | |
| 43 | #include <FL/Fl.H> |
| 44 | #include <FL/fl_ask.H> |
| 45 | |
| 46 | #include "CConn.h" |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 47 | #include "OptionsDialog.h" |
Pierre Ossman | 947b48d | 2014-01-27 16:52:35 +0100 | [diff] [blame] | 48 | #include "DesktopWindow.h" |
Pierre Ossman | c9dd3a4 | 2015-11-18 16:24:16 +0100 | [diff] [blame] | 49 | #include "PlatformPixelBuffer.h" |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 50 | #include "i18n.h" |
| 51 | #include "parameters.h" |
Pierre Ossman | 39ceb50 | 2011-07-12 15:54:25 +0000 | [diff] [blame] | 52 | #include "vncviewer.h" |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 53 | |
DRC | b65bb93 | 2011-06-24 03:17:00 +0000 | [diff] [blame] | 54 | #ifdef WIN32 |
| 55 | #include "win32.h" |
| 56 | #endif |
| 57 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 58 | using namespace rdr; |
| 59 | using namespace rfb; |
| 60 | using namespace std; |
| 61 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 62 | static rfb::LogWriter vlog("CConn"); |
| 63 | |
Pierre Ossman | cf836f2 | 2011-07-14 14:34:09 +0000 | [diff] [blame] | 64 | // 8 colours (1 bit per component) |
| 65 | static const PixelFormat verylowColourPF(8, 3,false, true, |
| 66 | 1, 1, 1, 2, 1, 0); |
| 67 | // 64 colours (2 bits per component) |
| 68 | static const PixelFormat lowColourPF(8, 6, false, true, |
| 69 | 3, 3, 3, 4, 2, 0); |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 70 | // 256 colours (2-3 bits per component) |
| 71 | static const PixelFormat mediumColourPF(8, 8, false, true, |
| 72 | 7, 7, 3, 5, 2, 0); |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 73 | |
Pierre Ossman | 2a7a8d6 | 2013-02-15 08:33:39 +0000 | [diff] [blame] | 74 | CConn::CConn(const char* vncServerName, network::Socket* socket=NULL) |
| 75 | : serverHost(0), serverPort(0), desktop(NULL), |
Pierre Ossman | 921f6c8 | 2017-02-24 12:33:09 +0100 | [diff] [blame] | 76 | frameCount(0), pixelCount(0), pendingPFChange(false), |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 77 | currentEncoding(encodingTight), lastServerEncoding((unsigned int)-1), |
| 78 | formatChange(false), encodingChange(false), |
Pierre Ossman | aa73c89 | 2011-11-15 12:13:37 +0000 | [diff] [blame] | 79 | firstUpdate(true), pendingUpdate(false), continuousUpdates(false), |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 80 | forceNonincremental(true), supportsSyncFence(false) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 81 | { |
| 82 | setShared(::shared); |
Pierre Ossman | 2a7a8d6 | 2013-02-15 08:33:39 +0000 | [diff] [blame] | 83 | sock = socket; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 84 | |
| 85 | int encNum = encodingNum(preferredEncoding); |
| 86 | if (encNum != -1) |
| 87 | currentEncoding = encNum; |
| 88 | |
Pierre Ossman | da38956 | 2011-06-09 08:24:37 +0000 | [diff] [blame] | 89 | cp.supportsLocalCursor = true; |
| 90 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 91 | cp.supportsDesktopResize = true; |
| 92 | cp.supportsExtendedDesktopSize = true; |
| 93 | cp.supportsDesktopRename = true; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 94 | |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 95 | cp.supportsLEDState = true; |
| 96 | |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 97 | if (customCompressLevel) |
| 98 | cp.compressLevel = compressLevel; |
| 99 | else |
| 100 | cp.compressLevel = -1; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 101 | |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 102 | if (!noJpeg) |
| 103 | cp.qualityLevel = qualityLevel; |
| 104 | else |
| 105 | cp.qualityLevel = -1; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 106 | |
Pierre Ossman | 2a7a8d6 | 2013-02-15 08:33:39 +0000 | [diff] [blame] | 107 | if(sock == NULL) { |
| 108 | try { |
| 109 | getHostAndPort(vncServerName, &serverHost, &serverPort); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 110 | |
Pierre Ossman | 2a7a8d6 | 2013-02-15 08:33:39 +0000 | [diff] [blame] | 111 | sock = new network::TcpSocket(serverHost, serverPort); |
| 112 | vlog.info(_("connected to host %s port %d"), serverHost, serverPort); |
| 113 | } catch (rdr::Exception& e) { |
| 114 | vlog.error("%s", e.str()); |
Dr. David Alan Gilbert | f4d1d89 | 2017-07-11 12:11:50 +0100 | [diff] [blame] | 115 | if (alertOnFatalError) |
| 116 | fl_alert("%s", e.str()); |
Pierre Ossman | 2a7a8d6 | 2013-02-15 08:33:39 +0000 | [diff] [blame] | 117 | exit_vncviewer(); |
| 118 | return; |
| 119 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | Fl::add_fd(sock->getFd(), FL_READ | FL_EXCEPT, socketEvent, this); |
| 123 | |
| 124 | // See callback below |
| 125 | sock->inStream().setBlockCallback(this); |
| 126 | |
| 127 | setServerName(serverHost); |
| 128 | setStreams(&sock->inStream(), &sock->outStream()); |
| 129 | |
| 130 | initialiseProtocol(); |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 131 | |
| 132 | OptionsDialog::addCallback(handleOptions, this); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | CConn::~CConn() |
| 136 | { |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 137 | OptionsDialog::removeCallback(handleOptions); |
Pierre Ossman | d9b9003 | 2015-09-23 12:18:52 +0200 | [diff] [blame] | 138 | Fl::remove_timeout(handleUpdateTimeout, this); |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 139 | |
Pierre Ossman | 6a9e2e6 | 2011-05-19 14:47:43 +0000 | [diff] [blame] | 140 | if (desktop) |
| 141 | delete desktop; |
| 142 | |
Pierre Ossman | 5e04c26 | 2011-11-09 11:31:12 +0000 | [diff] [blame] | 143 | delete [] serverHost; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 144 | if (sock) |
| 145 | Fl::remove_fd(sock->getFd()); |
| 146 | delete sock; |
| 147 | } |
| 148 | |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 149 | void CConn::refreshFramebuffer() |
| 150 | { |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 151 | forceNonincremental = true; |
| 152 | |
| 153 | // Without fences, we cannot safely trigger an update request directly |
| 154 | // but must wait for the next update to arrive. |
| 155 | if (supportsSyncFence) |
| 156 | requestNewUpdate(); |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 159 | const char *CConn::connectionInfo() |
| 160 | { |
| 161 | static char infoText[1024] = ""; |
| 162 | |
Pierre Ossman | b204643 | 2014-09-22 11:17:34 +0200 | [diff] [blame] | 163 | char scratch[100]; |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 164 | char pfStr[100]; |
Pierre Ossman | b204643 | 2014-09-22 11:17:34 +0200 | [diff] [blame] | 165 | |
| 166 | // Crude way of avoiding constant overflow checks |
| 167 | assert((sizeof(scratch) + 1) * 10 < sizeof(infoText)); |
| 168 | |
| 169 | infoText[0] = '\0'; |
| 170 | |
| 171 | snprintf(scratch, sizeof(scratch), |
| 172 | _("Desktop name: %.80s"), cp.name()); |
| 173 | strcat(infoText, scratch); |
| 174 | strcat(infoText, "\n"); |
| 175 | |
| 176 | snprintf(scratch, sizeof(scratch), |
| 177 | _("Host: %.80s port: %d"), serverHost, serverPort); |
| 178 | strcat(infoText, scratch); |
| 179 | strcat(infoText, "\n"); |
| 180 | |
| 181 | snprintf(scratch, sizeof(scratch), |
| 182 | _("Size: %d x %d"), cp.width, cp.height); |
| 183 | strcat(infoText, scratch); |
| 184 | strcat(infoText, "\n"); |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 185 | |
Pierre Ossman | 744e55c | 2014-12-03 14:00:54 +0100 | [diff] [blame] | 186 | // TRANSLATORS: Will be filled in with a string describing the |
| 187 | // protocol pixel format in a fairly language neutral way |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 188 | cp.pf().print(pfStr, 100); |
Pierre Ossman | b204643 | 2014-09-22 11:17:34 +0200 | [diff] [blame] | 189 | snprintf(scratch, sizeof(scratch), |
| 190 | _("Pixel format: %s"), pfStr); |
| 191 | strcat(infoText, scratch); |
| 192 | strcat(infoText, "\n"); |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 193 | |
Pierre Ossman | 744e55c | 2014-12-03 14:00:54 +0100 | [diff] [blame] | 194 | // TRANSLATORS: Similar to the earlier "Pixel format" string |
Pierre Ossman | b204643 | 2014-09-22 11:17:34 +0200 | [diff] [blame] | 195 | serverPF.print(pfStr, 100); |
| 196 | snprintf(scratch, sizeof(scratch), |
| 197 | _("(server default %s)"), pfStr); |
| 198 | strcat(infoText, scratch); |
| 199 | strcat(infoText, "\n"); |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 200 | |
Pierre Ossman | b204643 | 2014-09-22 11:17:34 +0200 | [diff] [blame] | 201 | snprintf(scratch, sizeof(scratch), |
| 202 | _("Requested encoding: %s"), encodingName(currentEncoding)); |
| 203 | strcat(infoText, scratch); |
| 204 | strcat(infoText, "\n"); |
| 205 | |
| 206 | snprintf(scratch, sizeof(scratch), |
| 207 | _("Last used encoding: %s"), encodingName(lastServerEncoding)); |
| 208 | strcat(infoText, scratch); |
| 209 | strcat(infoText, "\n"); |
| 210 | |
| 211 | snprintf(scratch, sizeof(scratch), |
| 212 | _("Line speed estimate: %d kbit/s"), sock->inStream().kbitsPerSecond()); |
| 213 | strcat(infoText, scratch); |
| 214 | strcat(infoText, "\n"); |
| 215 | |
| 216 | snprintf(scratch, sizeof(scratch), |
| 217 | _("Protocol version: %d.%d"), cp.majorVersion, cp.minorVersion); |
| 218 | strcat(infoText, scratch); |
| 219 | strcat(infoText, "\n"); |
| 220 | |
| 221 | snprintf(scratch, sizeof(scratch), |
| 222 | _("Security method: %s"), secTypeName(csecurity->getType())); |
| 223 | strcat(infoText, scratch); |
| 224 | strcat(infoText, "\n"); |
Pierre Ossman | 2eb1d11 | 2011-05-16 12:18:08 +0000 | [diff] [blame] | 225 | |
| 226 | return infoText; |
| 227 | } |
| 228 | |
Pierre Ossman | 921f6c8 | 2017-02-24 12:33:09 +0100 | [diff] [blame] | 229 | unsigned CConn::getFrameCount() |
| 230 | { |
| 231 | return frameCount; |
| 232 | } |
| 233 | |
| 234 | unsigned CConn::getPixelCount() |
| 235 | { |
| 236 | return pixelCount; |
| 237 | } |
| 238 | |
| 239 | unsigned CConn::getPosition() |
| 240 | { |
| 241 | return sock->inStream().pos(); |
| 242 | } |
| 243 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 244 | // The RFB core is not properly asynchronous, so it calls this callback |
| 245 | // whenever it needs to block to wait for more data. Since FLTK is |
| 246 | // monitoring the socket, we just make sure FLTK gets to run. |
| 247 | |
| 248 | void CConn::blockCallback() |
| 249 | { |
Pierre Ossman | 5102fa9 | 2015-11-18 16:23:21 +0100 | [diff] [blame] | 250 | run_mainloop(); |
Pierre Ossman | 1db7324 | 2015-09-23 12:20:32 +0200 | [diff] [blame] | 251 | |
| 252 | if (should_exit()) |
| 253 | throw rdr::Exception("Termination requested"); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 254 | } |
| 255 | |
DRC | 3e7ed81 | 2013-02-26 10:34:22 +0000 | [diff] [blame] | 256 | void CConn::socketEvent(FL_SOCKET fd, void *data) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 257 | { |
| 258 | CConn *cc; |
| 259 | static bool recursing = false; |
| 260 | |
| 261 | assert(data); |
| 262 | cc = (CConn*)data; |
| 263 | |
| 264 | // I don't think processMsg() is recursion safe, so add this check |
| 265 | if (recursing) |
| 266 | return; |
| 267 | |
| 268 | recursing = true; |
| 269 | |
| 270 | try { |
| 271 | // processMsg() only processes one message, so we need to loop |
| 272 | // until the buffers are empty or things will stall. |
| 273 | do { |
| 274 | cc->processMsg(); |
Pierre Ossman | 9a73adf | 2016-12-29 16:52:56 +0100 | [diff] [blame] | 275 | |
| 276 | // Make sure that the FLTK handling and the timers gets some CPU |
| 277 | // time in case of back to back messages |
| 278 | Fl::check(); |
| 279 | Timer::checkTimeouts(); |
| 280 | |
| 281 | // Also check if we need to stop reading and terminate |
| 282 | if (should_exit()) |
| 283 | break; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 284 | } while (cc->sock->inStream().checkNoWait(1)); |
| 285 | } catch (rdr::EndOfStream& e) { |
Pierre Ossman | ad8609a | 2012-04-26 09:04:14 +0000 | [diff] [blame] | 286 | vlog.info("%s", e.str()); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 287 | exit_vncviewer(); |
| 288 | } catch (rdr::Exception& e) { |
Pierre Ossman | ad8609a | 2012-04-26 09:04:14 +0000 | [diff] [blame] | 289 | vlog.error("%s", e.str()); |
Pierre Ossman | 1db7324 | 2015-09-23 12:20:32 +0200 | [diff] [blame] | 290 | // Somebody might already have requested us to terminate, and |
| 291 | // might have already provided an error message. |
| 292 | if (!should_exit()) |
| 293 | exit_vncviewer(e.str()); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | recursing = false; |
| 297 | } |
| 298 | |
| 299 | ////////////////////// CConnection callback methods ////////////////////// |
| 300 | |
| 301 | // serverInit() is called when the serverInit message has been received. At |
| 302 | // this point we create the desktop window and display it. We also tell the |
| 303 | // server the pixel format and encodings to use and request the first update. |
| 304 | void CConn::serverInit() |
| 305 | { |
| 306 | CConnection::serverInit(); |
| 307 | |
| 308 | // If using AutoSelect with old servers, start in FullColor |
| 309 | // mode. See comment in autoSelectFormatAndEncoding. |
| 310 | if (cp.beforeVersion(3, 8) && autoSelect) |
| 311 | fullColour.setParam(true); |
| 312 | |
| 313 | serverPF = cp.pf(); |
| 314 | |
| 315 | desktop = new DesktopWindow(cp.width, cp.height, cp.name(), serverPF, this); |
| 316 | fullColourPF = desktop->getPreferredPF(); |
| 317 | |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 318 | // Force a switch to the format and encoding we'd like |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 319 | formatChange = encodingChange = true; |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 320 | |
| 321 | // And kick off the update cycle |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 322 | requestNewUpdate(); |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 323 | |
| 324 | // This initial update request is a bit of a corner case, so we need |
| 325 | // to help out setting the correct format here. |
| 326 | assert(pendingPFChange); |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 327 | cp.setPF(pendingPF); |
| 328 | pendingPFChange = false; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // setDesktopSize() is called when the desktop size changes (including when |
| 332 | // it is set initially). |
| 333 | void CConn::setDesktopSize(int w, int h) |
| 334 | { |
| 335 | CConnection::setDesktopSize(w,h); |
| 336 | resizeFramebuffer(); |
| 337 | } |
| 338 | |
| 339 | // setExtendedDesktopSize() is a more advanced version of setDesktopSize() |
Pierre Ossman | 28c1d54 | 2015-03-03 16:27:44 +0100 | [diff] [blame] | 340 | void CConn::setExtendedDesktopSize(unsigned reason, unsigned result, |
| 341 | int w, int h, const rfb::ScreenSet& layout) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 342 | { |
| 343 | CConnection::setExtendedDesktopSize(reason, result, w, h, layout); |
| 344 | |
| 345 | if ((reason == reasonClient) && (result != resultSuccess)) { |
| 346 | vlog.error(_("SetDesktopSize failed: %d"), result); |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | resizeFramebuffer(); |
| 351 | } |
| 352 | |
| 353 | // setName() is called when the desktop name changes |
| 354 | void CConn::setName(const char* name) |
| 355 | { |
| 356 | CConnection::setName(name); |
| 357 | if (desktop) |
| 358 | desktop->setName(name); |
| 359 | } |
| 360 | |
| 361 | // framebufferUpdateStart() is called at the beginning of an update. |
| 362 | // Here we try to send out a new framebuffer update request so that the |
| 363 | // next update can be sent out in parallel with us decoding the current |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 364 | // one. |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 365 | void CConn::framebufferUpdateStart() |
| 366 | { |
Pierre Ossman | 3da238d | 2015-11-12 12:20:05 +0100 | [diff] [blame] | 367 | CConnection::framebufferUpdateStart(); |
| 368 | |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 369 | // Note: This might not be true if sync fences are supported |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 370 | pendingUpdate = false; |
| 371 | |
| 372 | requestNewUpdate(); |
Pierre Ossman | d9b9003 | 2015-09-23 12:18:52 +0200 | [diff] [blame] | 373 | |
| 374 | // Update the screen prematurely for very slow updates |
| 375 | Fl::add_timeout(1.0, handleUpdateTimeout, this); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | // framebufferUpdateEnd() is called at the end of an update. |
| 379 | // For each rectangle, the FdInStream will have timed the speed |
| 380 | // of the connection, allowing us to select format and encoding |
| 381 | // appropriately, and then request another incremental update. |
| 382 | void CConn::framebufferUpdateEnd() |
| 383 | { |
Pierre Ossman | 3da238d | 2015-11-12 12:20:05 +0100 | [diff] [blame] | 384 | CConnection::framebufferUpdateEnd(); |
| 385 | |
Pierre Ossman | 921f6c8 | 2017-02-24 12:33:09 +0100 | [diff] [blame] | 386 | frameCount++; |
| 387 | |
Pierre Ossman | d9b9003 | 2015-09-23 12:18:52 +0200 | [diff] [blame] | 388 | Fl::remove_timeout(handleUpdateTimeout, this); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 389 | desktop->updateWindow(); |
| 390 | |
| 391 | if (firstUpdate) { |
Pierre Ossman | aa73c89 | 2011-11-15 12:13:37 +0000 | [diff] [blame] | 392 | // We need fences to make extra update requests and continuous |
| 393 | // updates "safe". See fence() for the next step. |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 394 | if (cp.supportsFence) |
| 395 | writer()->writeFence(fenceFlagRequest | fenceFlagSyncNext, 0, NULL); |
| 396 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 397 | firstUpdate = false; |
| 398 | } |
| 399 | |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 400 | // A format change has been scheduled and we are now past the update |
| 401 | // with the old format. Time to active the new one. |
| 402 | if (pendingPFChange) { |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 403 | cp.setPF(pendingPF); |
| 404 | pendingPFChange = false; |
| 405 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 406 | |
| 407 | // Compute new settings based on updated bandwidth values |
| 408 | if (autoSelect) |
| 409 | autoSelectFormatAndEncoding(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | // The rest of the callbacks are fairly self-explanatory... |
| 413 | |
| 414 | void CConn::setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs) |
| 415 | { |
Pierre Ossman | 8ca4c1d | 2014-09-22 12:54:26 +0200 | [diff] [blame] | 416 | vlog.error(_("Invalid SetColourMapEntries from server!")); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void CConn::bell() |
| 420 | { |
| 421 | fl_beep(); |
| 422 | } |
| 423 | |
| 424 | void CConn::serverCutText(const char* str, rdr::U32 len) |
| 425 | { |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 426 | char *buffer; |
| 427 | int size, ret; |
Pierre Ossman | d81e8f4 | 2011-05-19 14:47:15 +0000 | [diff] [blame] | 428 | |
Pierre Ossman | 5010488 | 2013-05-24 10:47:27 +0000 | [diff] [blame] | 429 | if (!acceptClipboard) |
| 430 | return; |
| 431 | |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 432 | size = fl_utf8froma(NULL, 0, str, len); |
| 433 | if (size <= 0) |
Pierre Ossman | d81e8f4 | 2011-05-19 14:47:15 +0000 | [diff] [blame] | 434 | return; |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 435 | |
| 436 | size++; |
| 437 | |
| 438 | buffer = new char[size]; |
| 439 | |
| 440 | ret = fl_utf8froma(buffer, size, str, len); |
| 441 | assert(ret < size); |
Pierre Ossman | d81e8f4 | 2011-05-19 14:47:15 +0000 | [diff] [blame] | 442 | |
Pierre Ossman | fb450fb | 2015-03-03 16:34:56 +0100 | [diff] [blame] | 443 | vlog.debug("Got clipboard data (%d bytes)", (int)strlen(buffer)); |
Pierre Ossman | d81e8f4 | 2011-05-19 14:47:15 +0000 | [diff] [blame] | 444 | |
Pierre Ossman | cf2443c | 2011-09-07 09:01:20 +0000 | [diff] [blame] | 445 | // RFB doesn't have separate selection and clipboard concepts, so we |
| 446 | // dump the data into both variants. |
Pierre Ossman | f862c2e | 2016-03-29 14:15:38 +0200 | [diff] [blame] | 447 | if (setPrimary) |
| 448 | Fl::copy(buffer, ret, 0); |
Pierre Ossman | d81e8f4 | 2011-05-19 14:47:15 +0000 | [diff] [blame] | 449 | Fl::copy(buffer, ret, 1); |
Pierre Ossman | 689c458 | 2011-05-26 15:39:41 +0000 | [diff] [blame] | 450 | |
| 451 | delete [] buffer; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 454 | void CConn::dataRect(const Rect& r, int encoding) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 455 | { |
| 456 | sock->inStream().startTiming(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 457 | |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 458 | if (encoding != encodingCopyRect) |
| 459 | lastServerEncoding = encoding; |
| 460 | |
Pierre Ossman | 9f273e9 | 2015-11-09 16:34:54 +0100 | [diff] [blame] | 461 | CConnection::dataRect(r, encoding); |
Pierre Ossman | fdba3fe | 2014-01-31 13:12:18 +0100 | [diff] [blame] | 462 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 463 | sock->inStream().stopTiming(); |
Pierre Ossman | 921f6c8 | 2017-02-24 12:33:09 +0100 | [diff] [blame] | 464 | |
| 465 | pixelCount += r.area(); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 468 | void CConn::setCursor(int width, int height, const Point& hotspot, |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 469 | const rdr::U8* data) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 470 | { |
Pierre Ossman | 6a1a0d0 | 2017-02-19 15:48:17 +0100 | [diff] [blame] | 471 | desktop->setCursor(width, height, hotspot, data); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 474 | void CConn::fence(rdr::U32 flags, unsigned len, const char data[]) |
| 475 | { |
| 476 | CMsgHandler::fence(flags, len, data); |
| 477 | |
| 478 | if (flags & fenceFlagRequest) { |
| 479 | // We handle everything synchronously so we trivially honor these modes |
| 480 | flags = flags & (fenceFlagBlockBefore | fenceFlagBlockAfter); |
| 481 | |
| 482 | writer()->writeFence(flags, len, data); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | if (len == 0) { |
| 487 | // Initial probe |
Pierre Ossman | aa73c89 | 2011-11-15 12:13:37 +0000 | [diff] [blame] | 488 | if (flags & fenceFlagSyncNext) { |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 489 | supportsSyncFence = true; |
Pierre Ossman | aa73c89 | 2011-11-15 12:13:37 +0000 | [diff] [blame] | 490 | |
| 491 | if (cp.supportsContinuousUpdates) { |
| 492 | vlog.info(_("Enabling continuous updates")); |
| 493 | continuousUpdates = true; |
| 494 | writer()->writeEnableContinuousUpdates(true, 0, 0, cp.width, cp.height); |
| 495 | } |
| 496 | } |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 497 | } else { |
| 498 | // Pixel format change |
| 499 | rdr::MemInStream memStream(data, len); |
| 500 | PixelFormat pf; |
| 501 | |
| 502 | pf.read(&memStream); |
| 503 | |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 504 | cp.setPF(pf); |
| 505 | } |
| 506 | } |
| 507 | |
Pierre Ossman | 2fa63f8 | 2016-12-05 15:26:21 +0100 | [diff] [blame] | 508 | void CConn::setLEDState(unsigned int state) |
| 509 | { |
| 510 | CConnection::setLEDState(state); |
| 511 | |
| 512 | desktop->setLEDState(state); |
| 513 | } |
| 514 | |
DRC | 33c15e3 | 2011-11-03 18:49:21 +0000 | [diff] [blame] | 515 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 516 | ////////////////////// Internal methods ////////////////////// |
| 517 | |
| 518 | void CConn::resizeFramebuffer() |
| 519 | { |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 520 | if (!desktop) |
| 521 | return; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 522 | |
Pierre Ossman | aa73c89 | 2011-11-15 12:13:37 +0000 | [diff] [blame] | 523 | if (continuousUpdates) |
| 524 | writer()->writeEnableContinuousUpdates(true, 0, 0, cp.width, cp.height); |
| 525 | |
Pierre Ossman | 6455d85 | 2011-06-01 09:33:00 +0000 | [diff] [blame] | 526 | desktop->resizeFramebuffer(cp.width, cp.height); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | // autoSelectFormatAndEncoding() chooses the format and encoding appropriate |
| 530 | // to the connection speed: |
| 531 | // |
| 532 | // First we wait for at least one second of bandwidth measurement. |
| 533 | // |
| 534 | // Above 16Mbps (i.e. LAN), we choose the second highest JPEG quality, |
| 535 | // which should be perceptually lossless. |
| 536 | // |
| 537 | // If the bandwidth is below that, we choose a more lossy JPEG quality. |
| 538 | // |
| 539 | // If the bandwidth drops below 256 Kbps, we switch to palette mode. |
| 540 | // |
| 541 | // Note: The system here is fairly arbitrary and should be replaced |
| 542 | // with something more intelligent at the server end. |
| 543 | // |
| 544 | void CConn::autoSelectFormatAndEncoding() |
| 545 | { |
| 546 | int kbitsPerSecond = sock->inStream().kbitsPerSecond(); |
| 547 | unsigned int timeWaited = sock->inStream().timeWaited(); |
| 548 | bool newFullColour = fullColour; |
| 549 | int newQualityLevel = qualityLevel; |
| 550 | |
| 551 | // Always use Tight |
| 552 | if (currentEncoding != encodingTight) { |
| 553 | currentEncoding = encodingTight; |
| 554 | encodingChange = true; |
| 555 | } |
| 556 | |
| 557 | // Check that we have a decent bandwidth measurement |
| 558 | if ((kbitsPerSecond == 0) || (timeWaited < 10000)) |
| 559 | return; |
| 560 | |
| 561 | // Select appropriate quality level |
| 562 | if (!noJpeg) { |
| 563 | if (kbitsPerSecond > 16000) |
| 564 | newQualityLevel = 8; |
| 565 | else |
| 566 | newQualityLevel = 6; |
| 567 | |
| 568 | if (newQualityLevel != qualityLevel) { |
| 569 | vlog.info(_("Throughput %d kbit/s - changing to quality %d"), |
| 570 | kbitsPerSecond, newQualityLevel); |
| 571 | cp.qualityLevel = newQualityLevel; |
| 572 | qualityLevel.setParam(newQualityLevel); |
| 573 | encodingChange = true; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | if (cp.beforeVersion(3, 8)) { |
| 578 | // Xvnc from TightVNC 1.2.9 sends out FramebufferUpdates with |
| 579 | // cursors "asynchronously". If this happens in the middle of a |
| 580 | // pixel format change, the server will encode the cursor with |
| 581 | // the old format, but the client will try to decode it |
| 582 | // according to the new format. This will lead to a |
| 583 | // crash. Therefore, we do not allow automatic format change for |
| 584 | // old servers. |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | // Select best color level |
| 589 | newFullColour = (kbitsPerSecond > 256); |
| 590 | if (newFullColour != fullColour) { |
| 591 | vlog.info(_("Throughput %d kbit/s - full color is now %s"), |
| 592 | kbitsPerSecond, |
| 593 | newFullColour ? _("enabled") : _("disabled")); |
| 594 | fullColour.setParam(newFullColour); |
| 595 | formatChange = true; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | // checkEncodings() sends a setEncodings message if one is needed. |
| 600 | void CConn::checkEncodings() |
| 601 | { |
| 602 | if (encodingChange && writer()) { |
| 603 | vlog.info(_("Using %s encoding"),encodingName(currentEncoding)); |
| 604 | writer()->writeSetEncodings(currentEncoding, true); |
| 605 | encodingChange = false; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | // requestNewUpdate() requests an update from the server, having set the |
| 610 | // format and encoding appropriately. |
| 611 | void CConn::requestNewUpdate() |
| 612 | { |
| 613 | if (formatChange) { |
| 614 | PixelFormat pf; |
| 615 | |
| 616 | /* Catch incorrect requestNewUpdate calls */ |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 617 | assert(!pendingUpdate || supportsSyncFence); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 618 | |
| 619 | if (fullColour) { |
| 620 | pf = fullColourPF; |
| 621 | } else { |
| 622 | if (lowColourLevel == 0) |
Pierre Ossman | cf836f2 | 2011-07-14 14:34:09 +0000 | [diff] [blame] | 623 | pf = verylowColourPF; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 624 | else if (lowColourLevel == 1) |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 625 | pf = lowColourPF; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 626 | else |
Pierre Ossman | cf836f2 | 2011-07-14 14:34:09 +0000 | [diff] [blame] | 627 | pf = mediumColourPF; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 628 | } |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 629 | |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 630 | if (supportsSyncFence) { |
| 631 | // We let the fence carry the pixel format and switch once we |
| 632 | // get the response back. That way we will be synchronised with |
| 633 | // when the server switches. |
| 634 | rdr::MemOutStream memStream; |
| 635 | |
| 636 | pf.write(&memStream); |
| 637 | |
| 638 | writer()->writeFence(fenceFlagRequest | fenceFlagSyncNext, |
| 639 | memStream.length(), (const char*)memStream.data()); |
| 640 | } else { |
| 641 | // New requests are sent out at the start of processing the last |
| 642 | // one, so we cannot switch our internal format right now (doing so |
| 643 | // would mean misdecoding the current update). |
| 644 | pendingPFChange = true; |
| 645 | pendingPF = pf; |
| 646 | } |
Pierre Ossman | 5d512c3 | 2011-11-04 11:42:16 +0000 | [diff] [blame] | 647 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 648 | char str[256]; |
| 649 | pf.print(str, 256); |
| 650 | vlog.info(_("Using pixel format %s"),str); |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 651 | writer()->writeSetPixelFormat(pf); |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 652 | |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 653 | formatChange = false; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 654 | } |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 655 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 656 | checkEncodings(); |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 657 | |
Pierre Ossman | aa73c89 | 2011-11-15 12:13:37 +0000 | [diff] [blame] | 658 | if (forceNonincremental || !continuousUpdates) { |
| 659 | pendingUpdate = true; |
| 660 | writer()->writeFramebufferUpdateRequest(Rect(0, 0, cp.width, cp.height), |
| 661 | !forceNonincremental); |
| 662 | } |
Pierre Ossman | d4c61ce | 2011-04-29 11:18:12 +0000 | [diff] [blame] | 663 | |
| 664 | forceNonincremental = false; |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 665 | } |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 666 | |
| 667 | void CConn::handleOptions(void *data) |
| 668 | { |
| 669 | CConn *self = (CConn*)data; |
| 670 | |
| 671 | // Checking all the details of the current set of encodings is just |
| 672 | // a pain. Assume something has changed, as resending the encoding |
| 673 | // list is cheap. Avoid overriding what the auto logic has selected |
| 674 | // though. |
| 675 | if (!autoSelect) { |
| 676 | int encNum = encodingNum(preferredEncoding); |
| 677 | |
| 678 | if (encNum != -1) |
| 679 | self->currentEncoding = encNum; |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Pierre Ossman | da38956 | 2011-06-09 08:24:37 +0000 | [diff] [blame] | 682 | self->cp.supportsLocalCursor = true; |
| 683 | |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 684 | if (customCompressLevel) |
| 685 | self->cp.compressLevel = compressLevel; |
| 686 | else |
| 687 | self->cp.compressLevel = -1; |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 688 | |
Pierre Ossman | a22459d | 2014-03-17 14:42:10 +0100 | [diff] [blame] | 689 | if (!noJpeg && !autoSelect) |
| 690 | self->cp.qualityLevel = qualityLevel; |
| 691 | else |
| 692 | self->cp.qualityLevel = -1; |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 693 | |
| 694 | self->encodingChange = true; |
| 695 | |
| 696 | // Format changes refreshes the entire screen though and are therefore |
| 697 | // very costly. It's probably worth the effort to see if it is necessary |
| 698 | // here. |
| 699 | PixelFormat pf; |
| 700 | |
| 701 | if (fullColour) { |
| 702 | pf = self->fullColourPF; |
| 703 | } else { |
| 704 | if (lowColourLevel == 0) |
Pierre Ossman | cf836f2 | 2011-07-14 14:34:09 +0000 | [diff] [blame] | 705 | pf = verylowColourPF; |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 706 | else if (lowColourLevel == 1) |
| 707 | pf = lowColourPF; |
| 708 | else |
Pierre Ossman | cf836f2 | 2011-07-14 14:34:09 +0000 | [diff] [blame] | 709 | pf = mediumColourPF; |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 712 | if (!pf.equal(self->cp.pf())) { |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 713 | self->formatChange = true; |
Pierre Ossman | e28bdb2 | 2011-11-14 16:02:06 +0000 | [diff] [blame] | 714 | |
| 715 | // Without fences, we cannot safely trigger an update request directly |
| 716 | // but must wait for the next update to arrive. |
| 717 | if (self->supportsSyncFence) |
| 718 | self->requestNewUpdate(); |
| 719 | } |
Pierre Ossman | f4f3094 | 2011-05-17 09:39:07 +0000 | [diff] [blame] | 720 | } |
Pierre Ossman | d9b9003 | 2015-09-23 12:18:52 +0200 | [diff] [blame] | 721 | |
| 722 | void CConn::handleUpdateTimeout(void *data) |
| 723 | { |
| 724 | CConn *self = (CConn *)data; |
| 725 | |
| 726 | assert(self); |
| 727 | |
| 728 | self->desktop->updateWindow(); |
| 729 | |
| 730 | Fl::repeat_timeout(1.0, handleUpdateTimeout, data); |
| 731 | } |