You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClientParams.cxx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2014-2019 Pierre Ossman for Cendio AB
  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. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23. #include <rfb/Exception.h>
  24. #include <rfb/encodings.h>
  25. #include <rfb/ledStates.h>
  26. #include <rfb/clipboardTypes.h>
  27. #include <rfb/ClientParams.h>
  28. using namespace rfb;
  29. ClientParams::ClientParams()
  30. : majorVersion(0), minorVersion(0),
  31. compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
  32. subsampling(subsampleUndefined),
  33. width_(0), height_(0), name_(0),
  34. cursorPos_(0, 0), ledState_(ledUnknown)
  35. {
  36. setName("");
  37. cursor_ = new Cursor(0, 0, Point(), NULL);
  38. clipFlags = clipboardUTF8 | clipboardRTF | clipboardHTML |
  39. clipboardRequest | clipboardNotify | clipboardProvide;
  40. memset(clipSizes, 0, sizeof(clipSizes));
  41. clipSizes[0] = 20 * 1024 * 1024;
  42. }
  43. ClientParams::~ClientParams()
  44. {
  45. delete [] name_;
  46. delete cursor_;
  47. }
  48. void ClientParams::setDimensions(int width, int height)
  49. {
  50. ScreenSet layout;
  51. layout.add_screen(rfb::Screen(0, 0, 0, width, height, 0));
  52. setDimensions(width, height, layout);
  53. }
  54. void ClientParams::setDimensions(int width, int height, const ScreenSet& layout)
  55. {
  56. if (!layout.validate(width, height))
  57. throw Exception("Attempted to configure an invalid screen layout");
  58. width_ = width;
  59. height_ = height;
  60. screenLayout_ = layout;
  61. }
  62. void ClientParams::setPF(const PixelFormat& pf)
  63. {
  64. pf_ = pf;
  65. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  66. throw Exception("setPF: not 8, 16 or 32 bpp?");
  67. }
  68. void ClientParams::setName(const char* name)
  69. {
  70. delete [] name_;
  71. name_ = strDup(name);
  72. }
  73. void ClientParams::setCursor(const Cursor& other)
  74. {
  75. delete cursor_;
  76. cursor_ = new Cursor(other);
  77. }
  78. void ClientParams::setCursorPos(const Point& pos)
  79. {
  80. cursorPos_ = pos;
  81. }
  82. bool ClientParams::supportsEncoding(rdr::S32 encoding) const
  83. {
  84. return encodings_.count(encoding) != 0;
  85. }
  86. void ClientParams::setEncodings(int nEncodings, const rdr::S32* encodings)
  87. {
  88. compressLevel = -1;
  89. qualityLevel = -1;
  90. fineQualityLevel = -1;
  91. subsampling = subsampleUndefined;
  92. encodings_.clear();
  93. encodings_.insert(encodingRaw);
  94. for (int i = nEncodings-1; i >= 0; i--) {
  95. switch (encodings[i]) {
  96. case pseudoEncodingSubsamp1X:
  97. subsampling = subsampleNone;
  98. break;
  99. case pseudoEncodingSubsampGray:
  100. subsampling = subsampleGray;
  101. break;
  102. case pseudoEncodingSubsamp2X:
  103. subsampling = subsample2X;
  104. break;
  105. case pseudoEncodingSubsamp4X:
  106. subsampling = subsample4X;
  107. break;
  108. case pseudoEncodingSubsamp8X:
  109. subsampling = subsample8X;
  110. break;
  111. case pseudoEncodingSubsamp16X:
  112. subsampling = subsample16X;
  113. break;
  114. }
  115. if (encodings[i] >= pseudoEncodingCompressLevel0 &&
  116. encodings[i] <= pseudoEncodingCompressLevel9)
  117. compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
  118. if (encodings[i] >= pseudoEncodingQualityLevel0 &&
  119. encodings[i] <= pseudoEncodingQualityLevel9)
  120. qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
  121. if (encodings[i] >= pseudoEncodingFineQualityLevel0 &&
  122. encodings[i] <= pseudoEncodingFineQualityLevel100)
  123. fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
  124. encodings_.insert(encodings[i]);
  125. }
  126. }
  127. void ClientParams::setLEDState(unsigned int state)
  128. {
  129. ledState_ = state;
  130. }
  131. rdr::U32 ClientParams::clipboardSize(unsigned int format) const
  132. {
  133. int i;
  134. for (i = 0;i < 16;i++) {
  135. if (((unsigned)1 << i) == format)
  136. return clipSizes[i];
  137. }
  138. throw Exception("Invalid clipboard format 0x%x", format);
  139. }
  140. void ClientParams::setClipboardCaps(rdr::U32 flags, const rdr::U32* lengths)
  141. {
  142. int i, num;
  143. clipFlags = flags;
  144. num = 0;
  145. for (i = 0;i < 16;i++) {
  146. if (!(flags & (1 << i)))
  147. continue;
  148. clipSizes[i] = lengths[num++];
  149. }
  150. }
  151. bool ClientParams::supportsLocalCursor() const
  152. {
  153. if (supportsEncoding(pseudoEncodingCursorWithAlpha))
  154. return true;
  155. if (supportsEncoding(pseudoEncodingVMwareCursor))
  156. return true;
  157. if (supportsEncoding(pseudoEncodingCursor))
  158. return true;
  159. if (supportsEncoding(pseudoEncodingXCursor))
  160. return true;
  161. return false;
  162. }
  163. bool ClientParams::supportsCursorPosition() const
  164. {
  165. if (supportsEncoding(pseudoEncodingVMwareCursorPosition))
  166. return true;
  167. return false;
  168. }
  169. bool ClientParams::supportsDesktopSize() const
  170. {
  171. if (supportsEncoding(pseudoEncodingExtendedDesktopSize))
  172. return true;
  173. if (supportsEncoding(pseudoEncodingDesktopSize))
  174. return true;
  175. return false;
  176. }
  177. bool ClientParams::supportsLEDState() const
  178. {
  179. if (supportsEncoding(pseudoEncodingLEDState))
  180. return true;
  181. if (supportsEncoding(pseudoEncodingVMwareLEDState))
  182. return true;
  183. return false;
  184. }
  185. bool ClientParams::supportsFence() const
  186. {
  187. if (supportsEncoding(pseudoEncodingFence))
  188. return true;
  189. return false;
  190. }
  191. bool ClientParams::supportsContinuousUpdates() const
  192. {
  193. if (supportsEncoding(pseudoEncodingContinuousUpdates))
  194. return true;
  195. return false;
  196. }