blob: 987abe32e4392f30496ad60076a73933f6b68821 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCb4a83232011-08-19 04:57:18 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Pierre Ossman0ff26552016-02-05 10:26:56 +01003 * Copyright 2014-2019 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00004 *
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 */
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rfb/Exception.h>
21#include <rfb/encodings.h>
Pierre Ossman2fa63f82016-12-05 15:26:21 +010022#include <rfb/ledStates.h>
Pierre Ossman0ff26552016-02-05 10:26:56 +010023#include <rfb/clipboardTypes.h>
Pierre Ossman0d3ce872018-06-18 15:59:00 +020024#include <rfb/ClientParams.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000025
26using namespace rfb;
27
Pierre Ossman0d3ce872018-06-18 15:59:00 +020028ClientParams::ClientParams()
Adam Tkac3d0af202010-11-18 15:19:47 +000029 : majorVersion(0), minorVersion(0),
Pierre Ossmana22459d2014-03-17 14:42:10 +010030 compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
Pierre Ossman9312b0e2018-06-20 12:25:14 +020031 subsampling(subsampleUndefined),
32 width_(0), height_(0), name_(0),
Pierre Ossman2fa63f82016-12-05 15:26:21 +010033 ledState_(ledUnknown)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034{
35 setName("");
Pierre Ossman0ff26552016-02-05 10:26:56 +010036
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010037 cursor_ = new Cursor(0, 0, Point(), NULL);
Pierre Ossman0ff26552016-02-05 10:26:56 +010038
39 clipFlags = clipboardUTF8 | clipboardRTF | clipboardHTML |
40 clipboardRequest | clipboardNotify | clipboardProvide;
41 memset(clipSizes, 0, sizeof(clipSizes));
42 clipSizes[0] = 20 * 1024 * 1024;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043}
44
Pierre Ossman0d3ce872018-06-18 15:59:00 +020045ClientParams::~ClientParams()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000046{
47 delete [] name_;
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010048 delete cursor_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049}
50
Pierre Ossman0d3ce872018-06-18 15:59:00 +020051void ClientParams::setDimensions(int width, int height)
Pierre Ossman9312b0e2018-06-20 12:25:14 +020052{
53 ScreenSet layout;
54 layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
55 setDimensions(width, height, layout);
56}
57
Pierre Ossman0d3ce872018-06-18 15:59:00 +020058void ClientParams::setDimensions(int width, int height, const ScreenSet& layout)
Pierre Ossman9312b0e2018-06-20 12:25:14 +020059{
60 if (!layout.validate(width, height))
61 throw Exception("Attempted to configure an invalid screen layout");
62
63 width_ = width;
64 height_ = height;
65 screenLayout_ = layout;
66}
67
Pierre Ossman0d3ce872018-06-18 15:59:00 +020068void ClientParams::setPF(const PixelFormat& pf)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069{
70 pf_ = pf;
71
72 if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
73 throw Exception("setPF: not 8, 16 or 32 bpp?");
74}
75
Pierre Ossman0d3ce872018-06-18 15:59:00 +020076void ClientParams::setName(const char* name)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077{
78 delete [] name_;
Adam Tkacd36b6262009-09-04 10:57:20 +000079 name_ = strDup(name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000080}
81
Pierre Ossman0d3ce872018-06-18 15:59:00 +020082void ClientParams::setCursor(const Cursor& other)
Pierre Ossman126e5642014-02-13 14:40:25 +010083{
Pierre Ossman6a1a0d02017-02-19 15:48:17 +010084 delete cursor_;
85 cursor_ = new Cursor(other);
Pierre Ossman126e5642014-02-13 14:40:25 +010086}
87
Pierre Ossman0d3ce872018-06-18 15:59:00 +020088bool ClientParams::supportsEncoding(rdr::S32 encoding) const
Pierre Ossmanc0397262014-03-14 15:59:46 +010089{
90 return encodings_.count(encoding) != 0;
91}
92
Pierre Ossman0d3ce872018-06-18 15:59:00 +020093void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000094{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000095 compressLevel = -1;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000096 qualityLevel = -1;
DRCb4a83232011-08-19 04:57:18 +000097 fineQualityLevel = -1;
Pierre Ossmanb948a912014-01-15 13:23:43 +010098 subsampling = subsampleUndefined;
Pierre Ossmanc0397262014-03-14 15:59:46 +010099
100 encodings_.clear();
101 encodings_.insert(encodingRaw);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000102
103 for (int i = nEncodings-1; i >= 0; i--) {
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100104 switch (encodings[i]) {
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100105 case pseudoEncodingSubsamp1X:
106 subsampling = subsampleNone;
107 break;
108 case pseudoEncodingSubsampGray:
109 subsampling = subsampleGray;
110 break;
111 case pseudoEncodingSubsamp2X:
112 subsampling = subsample2X;
113 break;
114 case pseudoEncodingSubsamp4X:
115 subsampling = subsample4X;
116 break;
117 case pseudoEncodingSubsamp8X:
118 subsampling = subsample8X;
119 break;
120 case pseudoEncodingSubsamp16X:
121 subsampling = subsample16X;
122 break;
123 }
124
125 if (encodings[i] >= pseudoEncodingCompressLevel0 &&
126 encodings[i] <= pseudoEncodingCompressLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000127 compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100128
129 if (encodings[i] >= pseudoEncodingQualityLevel0 &&
130 encodings[i] <= pseudoEncodingQualityLevel9)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000131 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
Pierre Ossman6bcf1372014-01-15 13:44:04 +0100132
133 if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
134 encodings[i] <= pseudoEncodingFineQualityLevel100)
135 fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
136
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200137 encodings_.insert(encodings[i]);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000138 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000139}
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100140
Pierre Ossman0d3ce872018-06-18 15:59:00 +0200141void ClientParams::setLEDState(unsigned int state)
Pierre Ossman2fa63f82016-12-05 15:26:21 +0100142{
143 ledState_ = state;
144}
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200145
Pierre Ossman0ff26552016-02-05 10:26:56 +0100146void ClientParams::setClipboardCaps(rdr::U32 flags, const rdr::U32* lengths)
147{
148 int i, num;
149
150 clipFlags = flags;
151
152 num = 0;
153 for (i = 0;i < 16;i++) {
154 if (!(flags & (1 << i)))
155 continue;
156 clipSizes[i] = lengths[num++];
157 }
158}
159
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200160bool ClientParams::supportsLocalCursor() const
161{
162 if (supportsEncoding(pseudoEncodingCursorWithAlpha))
163 return true;
Pierre Ossman4a6266f2018-11-05 16:28:18 +0100164 if (supportsEncoding(pseudoEncodingVMwareCursor))
165 return true;
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200166 if (supportsEncoding(pseudoEncodingCursor))
167 return true;
168 if (supportsEncoding(pseudoEncodingXCursor))
169 return true;
170 return false;
171}
172
Pierre Ossman2daba9b2018-10-29 10:03:37 +0100173bool ClientParams::supportsDesktopSize() const
174{
175 if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
176 return true;
177 if (supportsEncoding(pseudoEncodingDesktopSize))
178 return true;
179 return false;
180}
181
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200182bool ClientParams::supportsLEDState() const
183{
184 if (supportsEncoding(pseudoEncodingLEDState))
185 return true;
Pierre Ossman62b07862018-11-05 16:28:57 +0100186 if (supportsEncoding(pseudoEncodingVMwareLEDState))
187 return true;
Pierre Ossmanb114f5c2018-06-18 16:34:16 +0200188 return false;
189}
190
191bool ClientParams::supportsFence() const
192{
193 if (supportsEncoding(pseudoEncodingFence))
194 return true;
195 return false;
196}
197
198bool ClientParams::supportsContinuousUpdates() const
199{
200 if (supportsEncoding(pseudoEncodingContinuousUpdates))
201 return true;
202 return false;
203}