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.

SMsgWriter.cxx 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2009-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. #include <stdio.h>
  21. #include <rdr/OutStream.h>
  22. #include <rdr/MemOutStream.h>
  23. #include <rdr/ZlibOutStream.h>
  24. #include <rfb/msgTypes.h>
  25. #include <rfb/fenceTypes.h>
  26. #include <rfb/clipboardTypes.h>
  27. #include <rfb/Exception.h>
  28. #include <rfb/ClientParams.h>
  29. #include <rfb/UpdateTracker.h>
  30. #include <rfb/Encoder.h>
  31. #include <rfb/SMsgWriter.h>
  32. #include <rfb/LogWriter.h>
  33. #include <rfb/ledStates.h>
  34. using namespace rfb;
  35. static LogWriter vlog("SMsgWriter");
  36. SMsgWriter::SMsgWriter(ClientParams* client_, rdr::OutStream* os_)
  37. : client(client_), os(os_),
  38. nRectsInUpdate(0), nRectsInHeader(0),
  39. needSetDesktopName(false), needCursor(false),
  40. needLEDState(false), needQEMUKeyEvent(false)
  41. {
  42. }
  43. SMsgWriter::~SMsgWriter()
  44. {
  45. }
  46. void SMsgWriter::writeServerInit(rdr::U16 width, rdr::U16 height,
  47. const PixelFormat& pf, const char* name)
  48. {
  49. os->writeU16(width);
  50. os->writeU16(height);
  51. pf.write(os);
  52. os->writeString(name);
  53. endMsg();
  54. }
  55. void SMsgWriter::writeSetColourMapEntries(int firstColour, int nColours,
  56. const rdr::U16 red[],
  57. const rdr::U16 green[],
  58. const rdr::U16 blue[])
  59. {
  60. startMsg(msgTypeSetColourMapEntries);
  61. os->pad(1);
  62. os->writeU16(firstColour);
  63. os->writeU16(nColours);
  64. for (int i = firstColour; i < firstColour+nColours; i++) {
  65. os->writeU16(red[i]);
  66. os->writeU16(green[i]);
  67. os->writeU16(blue[i]);
  68. }
  69. endMsg();
  70. }
  71. void SMsgWriter::writeBell()
  72. {
  73. startMsg(msgTypeBell);
  74. endMsg();
  75. }
  76. void SMsgWriter::writeServerCutText(const char* str)
  77. {
  78. size_t len;
  79. if (strchr(str, '\r') != NULL)
  80. throw Exception("Invalid carriage return in clipboard data");
  81. len = strlen(str);
  82. startMsg(msgTypeServerCutText);
  83. os->pad(3);
  84. os->writeU32(len);
  85. os->writeBytes(str, len);
  86. endMsg();
  87. }
  88. void SMsgWriter::writeClipboardCaps(rdr::U32 caps,
  89. const rdr::U32* lengths)
  90. {
  91. size_t i, count;
  92. if (!client->supportsEncoding(pseudoEncodingExtendedClipboard))
  93. throw Exception("Client does not support extended clipboard");
  94. count = 0;
  95. for (i = 0;i < 16;i++) {
  96. if (caps & (1 << i))
  97. count++;
  98. }
  99. startMsg(msgTypeServerCutText);
  100. os->pad(3);
  101. os->writeS32(-(4 + 4 * count));
  102. os->writeU32(caps | clipboardCaps);
  103. count = 0;
  104. for (i = 0;i < 16;i++) {
  105. if (caps & (1 << i))
  106. os->writeU32(lengths[count++]);
  107. }
  108. endMsg();
  109. }
  110. void SMsgWriter::writeClipboardRequest(rdr::U32 flags)
  111. {
  112. if (!client->supportsEncoding(pseudoEncodingExtendedClipboard))
  113. throw Exception("Client does not support extended clipboard");
  114. if (!(client->clipboardFlags() & clipboardRequest))
  115. throw Exception("Client does not support clipboard \"request\" action");
  116. startMsg(msgTypeServerCutText);
  117. os->pad(3);
  118. os->writeS32(-4);
  119. os->writeU32(flags | clipboardRequest);
  120. endMsg();
  121. }
  122. void SMsgWriter::writeClipboardPeek(rdr::U32 flags)
  123. {
  124. if (!client->supportsEncoding(pseudoEncodingExtendedClipboard))
  125. throw Exception("Client does not support extended clipboard");
  126. if (!(client->clipboardFlags() & clipboardPeek))
  127. throw Exception("Client does not support clipboard \"peek\" action");
  128. startMsg(msgTypeServerCutText);
  129. os->pad(3);
  130. os->writeS32(-4);
  131. os->writeU32(flags | clipboardPeek);
  132. endMsg();
  133. }
  134. void SMsgWriter::writeClipboardNotify(rdr::U32 flags)
  135. {
  136. if (!client->supportsEncoding(pseudoEncodingExtendedClipboard))
  137. throw Exception("Client does not support extended clipboard");
  138. if (!(client->clipboardFlags() & clipboardNotify))
  139. throw Exception("Client does not support clipboard \"notify\" action");
  140. startMsg(msgTypeServerCutText);
  141. os->pad(3);
  142. os->writeS32(-4);
  143. os->writeU32(flags | clipboardNotify);
  144. endMsg();
  145. }
  146. void SMsgWriter::writeClipboardProvide(rdr::U32 flags,
  147. const size_t* lengths,
  148. const rdr::U8* const* data)
  149. {
  150. rdr::MemOutStream mos;
  151. rdr::ZlibOutStream zos;
  152. int i, count;
  153. if (!client->supportsEncoding(pseudoEncodingExtendedClipboard))
  154. throw Exception("Client does not support extended clipboard");
  155. if (!(client->clipboardFlags() & clipboardProvide))
  156. throw Exception("Client does not support clipboard \"provide\" action");
  157. zos.setUnderlying(&mos);
  158. count = 0;
  159. for (i = 0;i < 16;i++) {
  160. if (!(flags & (1 << i)))
  161. continue;
  162. zos.writeU32(lengths[count]);
  163. zos.writeBytes(data[count], lengths[count]);
  164. count++;
  165. }
  166. zos.flush();
  167. startMsg(msgTypeServerCutText);
  168. os->pad(3);
  169. os->writeS32(-(4 + mos.length()));
  170. os->writeU32(flags | clipboardProvide);
  171. os->writeBytes(mos.data(), mos.length());
  172. endMsg();
  173. }
  174. void SMsgWriter::writeFence(rdr::U32 flags, unsigned len, const char data[])
  175. {
  176. if (!client->supportsEncoding(pseudoEncodingFence))
  177. throw Exception("Client does not support fences");
  178. if (len > 64)
  179. throw Exception("Too large fence payload");
  180. if ((flags & ~fenceFlagsSupported) != 0)
  181. throw Exception("Unknown fence flags");
  182. startMsg(msgTypeServerFence);
  183. os->pad(3);
  184. os->writeU32(flags);
  185. os->writeU8(len);
  186. if (len > 0)
  187. os->writeBytes(data, len);
  188. endMsg();
  189. }
  190. void SMsgWriter::writeEndOfContinuousUpdates()
  191. {
  192. if (!client->supportsEncoding(pseudoEncodingContinuousUpdates))
  193. throw Exception("Client does not support continuous updates");
  194. startMsg(msgTypeEndOfContinuousUpdates);
  195. endMsg();
  196. }
  197. void SMsgWriter::writeDesktopSize(rdr::U16 reason, rdr::U16 result)
  198. {
  199. ExtendedDesktopSizeMsg msg;
  200. if (!client->supportsEncoding(pseudoEncodingDesktopSize) &&
  201. !client->supportsEncoding(pseudoEncodingExtendedDesktopSize))
  202. throw Exception("Client does not support desktop size changes");
  203. msg.reason = reason;
  204. msg.result = result;
  205. extendedDesktopSizeMsgs.push_back(msg);
  206. }
  207. void SMsgWriter::writeSetDesktopName()
  208. {
  209. if (!client->supportsEncoding(pseudoEncodingDesktopName))
  210. throw Exception("Client does not support desktop name changes");
  211. needSetDesktopName = true;
  212. }
  213. void SMsgWriter::writeCursor()
  214. {
  215. if (!client->supportsEncoding(pseudoEncodingCursor) &&
  216. !client->supportsEncoding(pseudoEncodingXCursor) &&
  217. !client->supportsEncoding(pseudoEncodingCursorWithAlpha) &&
  218. !client->supportsEncoding(pseudoEncodingVMwareCursor))
  219. throw Exception("Client does not support local cursor");
  220. needCursor = true;
  221. }
  222. void SMsgWriter::writeLEDState()
  223. {
  224. if (!client->supportsEncoding(pseudoEncodingLEDState) &&
  225. !client->supportsEncoding(pseudoEncodingVMwareLEDState))
  226. throw Exception("Client does not support LED state");
  227. if (client->ledState() == ledUnknown)
  228. throw Exception("Server has not specified LED state");
  229. needLEDState = true;
  230. }
  231. void SMsgWriter::writeQEMUKeyEvent()
  232. {
  233. if (!client->supportsEncoding(pseudoEncodingQEMUKeyEvent))
  234. throw Exception("Client does not support QEMU key events");
  235. needQEMUKeyEvent = true;
  236. }
  237. bool SMsgWriter::needFakeUpdate()
  238. {
  239. if (needSetDesktopName)
  240. return true;
  241. if (needCursor)
  242. return true;
  243. if (needLEDState)
  244. return true;
  245. if (needQEMUKeyEvent)
  246. return true;
  247. if (needNoDataUpdate())
  248. return true;
  249. return false;
  250. }
  251. bool SMsgWriter::needNoDataUpdate()
  252. {
  253. if (!extendedDesktopSizeMsgs.empty())
  254. return true;
  255. return false;
  256. }
  257. void SMsgWriter::writeNoDataUpdate()
  258. {
  259. int nRects;
  260. nRects = 0;
  261. if (!extendedDesktopSizeMsgs.empty()) {
  262. if (client->supportsEncoding(pseudoEncodingExtendedDesktopSize))
  263. nRects += extendedDesktopSizeMsgs.size();
  264. else
  265. nRects++;
  266. }
  267. writeFramebufferUpdateStart(nRects);
  268. writeNoDataRects();
  269. writeFramebufferUpdateEnd();
  270. }
  271. void SMsgWriter::writeFramebufferUpdateStart(int nRects)
  272. {
  273. startMsg(msgTypeFramebufferUpdate);
  274. os->pad(1);
  275. if (nRects != 0xFFFF) {
  276. if (needSetDesktopName)
  277. nRects++;
  278. if (needCursor)
  279. nRects++;
  280. if (needLEDState)
  281. nRects++;
  282. if (needQEMUKeyEvent)
  283. nRects++;
  284. }
  285. os->writeU16(nRects);
  286. nRectsInUpdate = 0;
  287. if (nRects == 0xFFFF)
  288. nRectsInHeader = 0;
  289. else
  290. nRectsInHeader = nRects;
  291. writePseudoRects();
  292. }
  293. void SMsgWriter::writeFramebufferUpdateEnd()
  294. {
  295. if (nRectsInUpdate != nRectsInHeader && nRectsInHeader)
  296. throw Exception("SMsgWriter::writeFramebufferUpdateEnd: "
  297. "nRects out of sync");
  298. if (nRectsInHeader == 0) {
  299. // Send last rect. marker
  300. os->writeS16(0);
  301. os->writeS16(0);
  302. os->writeU16(0);
  303. os->writeU16(0);
  304. os->writeU32(pseudoEncodingLastRect);
  305. }
  306. endMsg();
  307. }
  308. void SMsgWriter::writeCopyRect(const Rect& r, int srcX, int srcY)
  309. {
  310. startRect(r,encodingCopyRect);
  311. os->writeU16(srcX);
  312. os->writeU16(srcY);
  313. endRect();
  314. }
  315. void SMsgWriter::startRect(const Rect& r, int encoding)
  316. {
  317. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  318. throw Exception("SMsgWriter::startRect: nRects out of sync");
  319. os->writeS16(r.tl.x);
  320. os->writeS16(r.tl.y);
  321. os->writeU16(r.width());
  322. os->writeU16(r.height());
  323. os->writeU32(encoding);
  324. }
  325. void SMsgWriter::endRect()
  326. {
  327. os->flush();
  328. }
  329. void SMsgWriter::startMsg(int type)
  330. {
  331. os->writeU8(type);
  332. }
  333. void SMsgWriter::endMsg()
  334. {
  335. os->flush();
  336. }
  337. void SMsgWriter::writePseudoRects()
  338. {
  339. if (needCursor) {
  340. const Cursor& cursor = client->cursor();
  341. if (client->supportsEncoding(pseudoEncodingCursorWithAlpha)) {
  342. writeSetCursorWithAlphaRect(cursor.width(), cursor.height(),
  343. cursor.hotspot().x, cursor.hotspot().y,
  344. cursor.getBuffer());
  345. } else if (client->supportsEncoding(pseudoEncodingVMwareCursor)) {
  346. writeSetVMwareCursorRect(cursor.width(), cursor.height(),
  347. cursor.hotspot().x, cursor.hotspot().y,
  348. cursor.getBuffer());
  349. } else if (client->supportsEncoding(pseudoEncodingCursor)) {
  350. rdr::U8Array data(cursor.width()*cursor.height() * (client->pf().bpp/8));
  351. rdr::U8Array mask(cursor.getMask());
  352. const rdr::U8* in;
  353. rdr::U8* out;
  354. in = cursor.getBuffer();
  355. out = data.buf;
  356. for (int i = 0;i < cursor.width()*cursor.height();i++) {
  357. client->pf().bufferFromRGB(out, in, 1);
  358. in += 4;
  359. out += client->pf().bpp/8;
  360. }
  361. writeSetCursorRect(cursor.width(), cursor.height(),
  362. cursor.hotspot().x, cursor.hotspot().y,
  363. data.buf, mask.buf);
  364. } else if (client->supportsEncoding(pseudoEncodingXCursor)) {
  365. rdr::U8Array bitmap(cursor.getBitmap());
  366. rdr::U8Array mask(cursor.getMask());
  367. writeSetXCursorRect(cursor.width(), cursor.height(),
  368. cursor.hotspot().x, cursor.hotspot().y,
  369. bitmap.buf, mask.buf);
  370. } else {
  371. throw Exception("Client does not support local cursor");
  372. }
  373. needCursor = false;
  374. }
  375. if (needSetDesktopName) {
  376. writeSetDesktopNameRect(client->name());
  377. needSetDesktopName = false;
  378. }
  379. if (needLEDState) {
  380. writeLEDStateRect(client->ledState());
  381. needLEDState = false;
  382. }
  383. if (needQEMUKeyEvent) {
  384. writeQEMUKeyEventRect();
  385. needQEMUKeyEvent = false;
  386. }
  387. }
  388. void SMsgWriter::writeNoDataRects()
  389. {
  390. if (!extendedDesktopSizeMsgs.empty()) {
  391. if (client->supportsEncoding(pseudoEncodingExtendedDesktopSize)) {
  392. std::list<ExtendedDesktopSizeMsg>::const_iterator ri;
  393. for (ri = extendedDesktopSizeMsgs.begin();ri != extendedDesktopSizeMsgs.end();++ri) {
  394. // FIXME: We can probably skip multiple reasonServer entries
  395. writeExtendedDesktopSizeRect(ri->reason, ri->result,
  396. client->width(), client->height(),
  397. client->screenLayout());
  398. }
  399. } else if (client->supportsEncoding(pseudoEncodingDesktopSize)) {
  400. // Some clients assume this is the last rectangle so don't send anything
  401. // more after this
  402. writeSetDesktopSizeRect(client->width(), client->height());
  403. } else {
  404. throw Exception("Client does not support desktop size changes");
  405. }
  406. extendedDesktopSizeMsgs.clear();
  407. }
  408. }
  409. void SMsgWriter::writeSetDesktopSizeRect(int width, int height)
  410. {
  411. if (!client->supportsEncoding(pseudoEncodingDesktopSize))
  412. throw Exception("Client does not support desktop resize");
  413. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  414. throw Exception("SMsgWriter::writeSetDesktopSizeRect: nRects out of sync");
  415. os->writeS16(0);
  416. os->writeS16(0);
  417. os->writeU16(width);
  418. os->writeU16(height);
  419. os->writeU32(pseudoEncodingDesktopSize);
  420. }
  421. void SMsgWriter::writeExtendedDesktopSizeRect(rdr::U16 reason,
  422. rdr::U16 result,
  423. int fb_width,
  424. int fb_height,
  425. const ScreenSet& layout)
  426. {
  427. ScreenSet::const_iterator si;
  428. if (!client->supportsEncoding(pseudoEncodingExtendedDesktopSize))
  429. throw Exception("Client does not support extended desktop resize");
  430. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  431. throw Exception("SMsgWriter::writeExtendedDesktopSizeRect: nRects out of sync");
  432. os->writeU16(reason);
  433. os->writeU16(result);
  434. os->writeU16(fb_width);
  435. os->writeU16(fb_height);
  436. os->writeU32(pseudoEncodingExtendedDesktopSize);
  437. os->writeU8(layout.num_screens());
  438. os->pad(3);
  439. for (si = layout.begin();si != layout.end();++si) {
  440. os->writeU32(si->id);
  441. os->writeU16(si->dimensions.tl.x);
  442. os->writeU16(si->dimensions.tl.y);
  443. os->writeU16(si->dimensions.width());
  444. os->writeU16(si->dimensions.height());
  445. os->writeU32(si->flags);
  446. }
  447. }
  448. void SMsgWriter::writeSetDesktopNameRect(const char *name)
  449. {
  450. if (!client->supportsEncoding(pseudoEncodingDesktopName))
  451. throw Exception("Client does not support desktop rename");
  452. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  453. throw Exception("SMsgWriter::writeSetDesktopNameRect: nRects out of sync");
  454. os->writeS16(0);
  455. os->writeS16(0);
  456. os->writeU16(0);
  457. os->writeU16(0);
  458. os->writeU32(pseudoEncodingDesktopName);
  459. os->writeString(name);
  460. }
  461. void SMsgWriter::writeSetCursorRect(int width, int height,
  462. int hotspotX, int hotspotY,
  463. const void* data, const void* mask)
  464. {
  465. if (!client->supportsEncoding(pseudoEncodingCursor))
  466. throw Exception("Client does not support local cursors");
  467. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  468. throw Exception("SMsgWriter::writeSetCursorRect: nRects out of sync");
  469. os->writeS16(hotspotX);
  470. os->writeS16(hotspotY);
  471. os->writeU16(width);
  472. os->writeU16(height);
  473. os->writeU32(pseudoEncodingCursor);
  474. os->writeBytes(data, width * height * (client->pf().bpp/8));
  475. os->writeBytes(mask, (width+7)/8 * height);
  476. }
  477. void SMsgWriter::writeSetXCursorRect(int width, int height,
  478. int hotspotX, int hotspotY,
  479. const void* data, const void* mask)
  480. {
  481. if (!client->supportsEncoding(pseudoEncodingXCursor))
  482. throw Exception("Client does not support local cursors");
  483. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  484. throw Exception("SMsgWriter::writeSetXCursorRect: nRects out of sync");
  485. os->writeS16(hotspotX);
  486. os->writeS16(hotspotY);
  487. os->writeU16(width);
  488. os->writeU16(height);
  489. os->writeU32(pseudoEncodingXCursor);
  490. if (width * height > 0) {
  491. os->writeU8(255);
  492. os->writeU8(255);
  493. os->writeU8(255);
  494. os->writeU8(0);
  495. os->writeU8(0);
  496. os->writeU8(0);
  497. os->writeBytes(data, (width+7)/8 * height);
  498. os->writeBytes(mask, (width+7)/8 * height);
  499. }
  500. }
  501. void SMsgWriter::writeSetCursorWithAlphaRect(int width, int height,
  502. int hotspotX, int hotspotY,
  503. const rdr::U8* data)
  504. {
  505. if (!client->supportsEncoding(pseudoEncodingCursorWithAlpha))
  506. throw Exception("Client does not support local cursors");
  507. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  508. throw Exception("SMsgWriter::writeSetCursorWithAlphaRect: nRects out of sync");
  509. os->writeS16(hotspotX);
  510. os->writeS16(hotspotY);
  511. os->writeU16(width);
  512. os->writeU16(height);
  513. os->writeU32(pseudoEncodingCursorWithAlpha);
  514. // FIXME: Use an encoder with compression?
  515. os->writeU32(encodingRaw);
  516. // Alpha needs to be pre-multiplied
  517. for (int i = 0;i < width*height;i++) {
  518. os->writeU8((unsigned)data[0] * data[3] / 255);
  519. os->writeU8((unsigned)data[1] * data[3] / 255);
  520. os->writeU8((unsigned)data[2] * data[3] / 255);
  521. os->writeU8(data[3]);
  522. data += 4;
  523. }
  524. }
  525. void SMsgWriter::writeSetVMwareCursorRect(int width, int height,
  526. int hotspotX, int hotspotY,
  527. const rdr::U8* data)
  528. {
  529. if (!client->supportsEncoding(pseudoEncodingVMwareCursor))
  530. throw Exception("Client does not support local cursors");
  531. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  532. throw Exception("SMsgWriter::writeSetVMwareCursorRect: nRects out of sync");
  533. os->writeS16(hotspotX);
  534. os->writeS16(hotspotY);
  535. os->writeU16(width);
  536. os->writeU16(height);
  537. os->writeU32(pseudoEncodingVMwareCursor);
  538. os->writeU8(1); // Alpha cursor
  539. os->pad(1);
  540. // FIXME: Should alpha be premultiplied?
  541. os->writeBytes(data, width*height*4);
  542. }
  543. void SMsgWriter::writeLEDStateRect(rdr::U8 state)
  544. {
  545. if (!client->supportsEncoding(pseudoEncodingLEDState) &&
  546. !client->supportsEncoding(pseudoEncodingVMwareLEDState))
  547. throw Exception("Client does not support LED state updates");
  548. if (client->ledState() == ledUnknown)
  549. throw Exception("Server does not support LED state updates");
  550. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  551. throw Exception("SMsgWriter::writeLEDStateRect: nRects out of sync");
  552. os->writeS16(0);
  553. os->writeS16(0);
  554. os->writeU16(0);
  555. os->writeU16(0);
  556. if (client->supportsEncoding(pseudoEncodingLEDState)) {
  557. os->writeU32(pseudoEncodingLEDState);
  558. os->writeU8(state);
  559. } else {
  560. os->writeU32(pseudoEncodingVMwareLEDState);
  561. os->writeU32(state);
  562. }
  563. }
  564. void SMsgWriter::writeQEMUKeyEventRect()
  565. {
  566. if (!client->supportsEncoding(pseudoEncodingQEMUKeyEvent))
  567. throw Exception("Client does not support QEMU extended key events");
  568. if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
  569. throw Exception("SMsgWriter::writeQEMUKeyEventRect: nRects out of sync");
  570. os->writeS16(0);
  571. os->writeS16(0);
  572. os->writeU16(0);
  573. os->writeU16(0);
  574. os->writeU32(pseudoEncodingQEMUKeyEvent);
  575. }