-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 69457e2..d61433f 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -1,405 +1,405 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbserverinfo.h" | 2 | #include "krfbserverinfo.h" |
3 | #include "krfbdecoder.h" | 3 | #include "krfbdecoder.h" |
4 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qpixmap.h> | 11 | #include <qpixmap.h> |
12 | 12 | ||
13 | /* STD */ | 13 | /* STD */ |
14 | #include <assert.h> | 14 | #include <assert.h> |
15 | 15 | ||
16 | // | 16 | // |
17 | // Endian stuff | 17 | // Endian stuff |
18 | // | 18 | // |
19 | #ifndef OPIE_NO_DEBUG | 19 | //#ifndef OPIE_NO_DEBUG |
20 | const int endianTest = 1; | 20 | const int endianTest = 1; |
21 | #endif | 21 | //#endif |
22 | 22 | ||
23 | #define Swap16IfLE(s) \ | 23 | #define Swap16IfLE(s) \ |
24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
25 | 25 | ||
26 | #define Swap32IfLE(l) \ | 26 | #define Swap32IfLE(l) \ |
27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
28 | (((l) & 0x00ff0000) >> 8) | \ | 28 | (((l) & 0x00ff0000) >> 8) | \ |
29 | (((l) & 0x0000ff00) << 8) | \ | 29 | (((l) & 0x0000ff00) << 8) | \ |
30 | (((l) & 0x000000ff) << 24)) : (l)) | 30 | (((l) & 0x000000ff) << 24)) : (l)) |
31 | 31 | ||
32 | // | 32 | // |
33 | // The lengths of the messages we need to wait for | 33 | // The lengths of the messages we need to wait for |
34 | // | 34 | // |
35 | const int ServerInitLength = 24; | 35 | const int ServerInitLength = 24; |
36 | const int UpdateHeaderLength = 4; | 36 | const int UpdateHeaderLength = 4; |
37 | const int RectHeaderLength = 12; | 37 | const int RectHeaderLength = 12; |
38 | const int RectChunkSize = 4; | 38 | const int RectChunkSize = 4; |
39 | const int CopyRectPosLength = 4; | 39 | const int CopyRectPosLength = 4; |
40 | const int ServerCutLenLength = 7; | 40 | const int ServerCutLenLength = 7; |
41 | 41 | ||
42 | // | 42 | // |
43 | // Client -> Server Message Identifiers | 43 | // Client -> Server Message Identifiers |
44 | // | 44 | // |
45 | static CARD8 SetPixelFormatId = 0; | 45 | static CARD8 SetPixelFormatId = 0; |
46 | //static CARD8 FixColourMapEntriesId = 1; // Not used | 46 | //static CARD8 FixColourMapEntriesId = 1; // Not used |
47 | static CARD8 SetEncodingsId = 2; | 47 | static CARD8 SetEncodingsId = 2; |
48 | static CARD8 UpdateRequestId = 3; | 48 | static CARD8 UpdateRequestId = 3; |
49 | static CARD8 KeyEventId = 4; | 49 | static CARD8 KeyEventId = 4; |
50 | static CARD8 PointerEventId = 5; | 50 | static CARD8 PointerEventId = 5; |
51 | static CARD8 ClientCutTextId = 6; | 51 | static CARD8 ClientCutTextId = 6; |
52 | 52 | ||
53 | // | 53 | // |
54 | // Server -> Client Message Identifiers | 54 | // Server -> Client Message Identifiers |
55 | // | 55 | // |
56 | static CARD8 UpdateId = 0; | 56 | static CARD8 UpdateId = 0; |
57 | static CARD8 BellId = 2; | 57 | static CARD8 BellId = 2; |
58 | static CARD8 ServerCutId = 3; | 58 | static CARD8 ServerCutId = 3; |
59 | 59 | ||
60 | // | 60 | // |
61 | // Encoding identifiers | 61 | // Encoding identifiers |
62 | // | 62 | // |
63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); | 63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); |
64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); | 64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); |
65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); | 65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); |
66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); | 66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); |
67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); | 67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); |
68 | 68 | ||
69 | static struct { | 69 | static struct { |
70 | int keysym; | 70 | int keysym; |
71 | int keycode; | 71 | int keycode; |
72 | } keyMap[] = { | 72 | } keyMap[] = { |
73 | { 0xff08, Qt::Key_Backspace }, | 73 | { 0xff08, Qt::Key_Backspace }, |
74 | { 0xff09, Qt::Key_Tab }, | 74 | { 0xff09, Qt::Key_Tab }, |
75 | { 0xff0d, Qt::Key_Return }, | 75 | { 0xff0d, Qt::Key_Return }, |
76 | { 0xff1b, Qt::Key_Escape }, | 76 | { 0xff1b, Qt::Key_Escape }, |
77 | { 0xff63, Qt::Key_Insert }, | 77 | { 0xff63, Qt::Key_Insert }, |
78 | { 0xffff, Qt::Key_Delete }, | 78 | { 0xffff, Qt::Key_Delete }, |
79 | { 0xff50, Qt::Key_Home }, | 79 | { 0xff50, Qt::Key_Home }, |
80 | { 0xff57, Qt::Key_End }, | 80 | { 0xff57, Qt::Key_End }, |
81 | { 0xff55, Qt::Key_Prior }, | 81 | { 0xff55, Qt::Key_Prior }, |
82 | { 0xff56, Qt::Key_Next }, | 82 | { 0xff56, Qt::Key_Next }, |
83 | { 0xff51, Qt::Key_Left }, | 83 | { 0xff51, Qt::Key_Left }, |
84 | { 0xff52, Qt::Key_Up }, | 84 | { 0xff52, Qt::Key_Up }, |
85 | { 0xff53, Qt::Key_Right }, | 85 | { 0xff53, Qt::Key_Right }, |
86 | { 0xff54, Qt::Key_Down }, | 86 | { 0xff54, Qt::Key_Down }, |
87 | { 0xffbe, Qt::Key_F1 }, | 87 | { 0xffbe, Qt::Key_F1 }, |
88 | { 0xffbf, Qt::Key_F2 }, | 88 | { 0xffbf, Qt::Key_F2 }, |
89 | { 0xffc0, Qt::Key_F3 }, | 89 | { 0xffc0, Qt::Key_F3 }, |
90 | { 0xffc1, Qt::Key_F4 }, | 90 | { 0xffc1, Qt::Key_F4 }, |
91 | { 0xffc2, Qt::Key_F5 }, | 91 | { 0xffc2, Qt::Key_F5 }, |
92 | { 0xffc3, Qt::Key_F6 }, | 92 | { 0xffc3, Qt::Key_F6 }, |
93 | { 0xffc4, Qt::Key_F7 }, | 93 | { 0xffc4, Qt::Key_F7 }, |
94 | { 0xffc5, Qt::Key_F8 }, | 94 | { 0xffc5, Qt::Key_F8 }, |
95 | { 0xffc6, Qt::Key_F9 }, | 95 | { 0xffc6, Qt::Key_F9 }, |
96 | { 0xffc7, Qt::Key_F10 }, | 96 | { 0xffc7, Qt::Key_F10 }, |
97 | { 0xffc8, Qt::Key_F11 }, | 97 | { 0xffc8, Qt::Key_F11 }, |
98 | { 0xffc9, Qt::Key_F12 }, | 98 | { 0xffc9, Qt::Key_F12 }, |
99 | { 0xffe1, Qt::Key_Shift }, | 99 | { 0xffe1, Qt::Key_Shift }, |
100 | { 0xffe2, Qt::Key_Shift }, | 100 | { 0xffe2, Qt::Key_Shift }, |
101 | { 0xffe3, Qt::Key_Control }, | 101 | { 0xffe3, Qt::Key_Control }, |
102 | { 0xffe4, Qt::Key_Control }, | 102 | { 0xffe4, Qt::Key_Control }, |
103 | { 0xffe7, Qt::Key_Meta }, | 103 | { 0xffe7, Qt::Key_Meta }, |
104 | { 0xffe8, Qt::Key_Meta }, | 104 | { 0xffe8, Qt::Key_Meta }, |
105 | { 0xffe9, Qt::Key_Alt }, | 105 | { 0xffe9, Qt::Key_Alt }, |
106 | { 0xffea, Qt::Key_Alt }, | 106 | { 0xffea, Qt::Key_Alt }, |
107 | { 0, 0 } | 107 | { 0, 0 } |
108 | }; | 108 | }; |
109 | 109 | ||
110 | 110 | ||
111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) | 111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) |
112 | : QObject( con, "RFB Decoder" ) | 112 | : QObject( con, "RFB Decoder" ) |
113 | { | 113 | { |
114 | assert( con ); | 114 | assert( con ); |
115 | assert( con->state() == KRFBConnection::Connected ); | 115 | assert( con->state() == KRFBConnection::Connected ); |
116 | 116 | ||
117 | this->con = con; | 117 | this->con = con; |
118 | this->buf = 0; | 118 | this->buf = 0; |
119 | this->info = 0; | 119 | this->info = 0; |
120 | this->format = 0; | 120 | this->format = 0; |
121 | this->buttonMask = 0; | 121 | this->buttonMask = 0; |
122 | currentState = Idle; | 122 | currentState = Idle; |
123 | } | 123 | } |
124 | 124 | ||
125 | KRFBDecoder::~KRFBDecoder() | 125 | KRFBDecoder::~KRFBDecoder() |
126 | { | 126 | { |
127 | if ( info ) | 127 | if ( info ) |
128 | delete info; | 128 | delete info; |
129 | if ( format ) | 129 | if ( format ) |
130 | delete format; | 130 | delete format; |
131 | } | 131 | } |
132 | 132 | ||
133 | void KRFBDecoder::start() | 133 | void KRFBDecoder::start() |
134 | { | 134 | { |
135 | sendClientInit(); | 135 | sendClientInit(); |
136 | } | 136 | } |
137 | 137 | ||
138 | void KRFBDecoder::sendClientInit() | 138 | void KRFBDecoder::sendClientInit() |
139 | { | 139 | { |
140 | con->write( &( con->options()->shared ), 1 ); | 140 | con->write( &( con->options()->shared ), 1 ); |
141 | 141 | ||
142 | // Wait for server init | 142 | // Wait for server init |
143 | owarn << "Waiting for server init" << oendl; | 143 | owarn << "Waiting for server init" << oendl; |
144 | 144 | ||
145 | static QString statusMsg = tr( "Waiting for server initialization..." ); | 145 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
146 | emit status( statusMsg ); | 146 | emit status( statusMsg ); |
147 | 147 | ||
148 | currentState = AwaitingServerInit; | 148 | currentState = AwaitingServerInit; |
149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
150 | con->waitForData( ServerInitLength ); | 150 | con->waitForData( ServerInitLength ); |
151 | } | 151 | } |
152 | 152 | ||
153 | void KRFBDecoder::gotServerInit() | 153 | void KRFBDecoder::gotServerInit() |
154 | { | 154 | { |
155 | owarn << "Got server init" << oendl; | 155 | owarn << "Got server init" << oendl; |
156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
157 | 157 | ||
158 | if ( info ) | 158 | if ( info ) |
159 | delete info; | 159 | delete info; |
160 | info = new KRFBServerInfo; | 160 | info = new KRFBServerInfo; |
161 | CHECK_PTR( info ); | 161 | CHECK_PTR( info ); |
162 | 162 | ||
163 | con->read( &(info->width), 2 ); | 163 | con->read( &(info->width), 2 ); |
164 | info->width = Swap16IfLE( info->width ); | 164 | info->width = Swap16IfLE( info->width ); |
165 | con->read( &info->height, 2 ); | 165 | con->read( &info->height, 2 ); |
166 | info->height = Swap16IfLE( info->height ); | 166 | info->height = Swap16IfLE( info->height ); |
167 | 167 | ||
168 | con->read( &(info->bpp), 1 ); | 168 | con->read( &(info->bpp), 1 ); |
169 | con->read( &(info->depth), 1 ); | 169 | con->read( &(info->depth), 1 ); |
170 | con->read( &(info->bigEndian), 1 ); | 170 | con->read( &(info->bigEndian), 1 ); |
171 | con->read( &(info->trueColor), 1 ); | 171 | con->read( &(info->trueColor), 1 ); |
172 | 172 | ||
173 | con->read( &(info->redMax), 2 ); | 173 | con->read( &(info->redMax), 2 ); |
174 | info->redMax = Swap16IfLE( info->redMax ); | 174 | info->redMax = Swap16IfLE( info->redMax ); |
175 | con->read( &(info->greenMax), 2 ); | 175 | con->read( &(info->greenMax), 2 ); |
176 | info->greenMax = Swap16IfLE( info->greenMax ); | 176 | info->greenMax = Swap16IfLE( info->greenMax ); |
177 | con->read( &(info->blueMax), 2 ); | 177 | con->read( &(info->blueMax), 2 ); |
178 | info->blueMax = Swap16IfLE( info->blueMax ); | 178 | info->blueMax = Swap16IfLE( info->blueMax ); |
179 | 179 | ||
180 | con->read( &(info->redShift), 1 ); | 180 | con->read( &(info->redShift), 1 ); |
181 | con->read( &(info->greenShift), 1 ); | 181 | con->read( &(info->greenShift), 1 ); |
182 | con->read( &(info->blueShift), 1 ); | 182 | con->read( &(info->blueShift), 1 ); |
183 | 183 | ||
184 | con->read( info->padding, 3 ); | 184 | con->read( info->padding, 3 ); |
185 | 185 | ||
186 | con->read( &(info->nameLength), 4 ); | 186 | con->read( &(info->nameLength), 4 ); |
187 | info->nameLength = Swap32IfLE( info->nameLength ); | 187 | info->nameLength = Swap32IfLE( info->nameLength ); |
188 | 188 | ||
189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; | 189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; |
190 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", | 190 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", |
191 | info->bpp, info->depth, info->bigEndian, info->trueColor ); | 191 | info->bpp, info->depth, info->bigEndian, info->trueColor ); |
192 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", | 192 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", |
193 | info->redMax, info->greenMax, info->blueMax ); | 193 | info->redMax, info->greenMax, info->blueMax ); |
194 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", | 194 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", |
195 | info->redShift, info->greenShift,info-> blueShift ); | 195 | info->redShift, info->greenShift,info-> blueShift ); |
196 | 196 | ||
197 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 197 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
198 | 198 | ||
199 | // Wait for desktop name | 199 | // Wait for desktop name |
200 | owarn << "Waiting for desktop name" << oendl; | 200 | owarn << "Waiting for desktop name" << oendl; |
201 | 201 | ||
202 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 202 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
203 | emit status( statusMsg ); | 203 | emit status( statusMsg ); |
204 | 204 | ||
205 | currentState = AwaitingDesktopName; | 205 | currentState = AwaitingDesktopName; |
206 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 206 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
207 | con->waitForData( info->nameLength ); | 207 | con->waitForData( info->nameLength ); |
208 | } | 208 | } |
209 | 209 | ||
210 | void KRFBDecoder::gotDesktopName() | 210 | void KRFBDecoder::gotDesktopName() |
211 | { | 211 | { |
212 | assert( info ); | 212 | assert( info ); |
213 | assert( currentState == AwaitingDesktopName ); | 213 | assert( currentState == AwaitingDesktopName ); |
214 | 214 | ||
215 | owarn << "Got desktop name" << oendl; | 215 | owarn << "Got desktop name" << oendl; |
216 | 216 | ||
217 | disconnect( con, SIGNAL( gotEnoughData() ), | 217 | disconnect( con, SIGNAL( gotEnoughData() ), |
218 | this, SLOT( gotDesktopName() ) ); | 218 | this, SLOT( gotDesktopName() ) ); |
219 | 219 | ||
220 | char *buf = new char[ info->nameLength + 1 ]; | 220 | char *buf = new char[ info->nameLength + 1 ]; |
221 | CHECK_PTR( buf ); | 221 | CHECK_PTR( buf ); |
222 | 222 | ||
223 | con->read( buf, info->nameLength ); | 223 | con->read( buf, info->nameLength ); |
224 | buf[ info->nameLength ] = '\0'; | 224 | buf[ info->nameLength ] = '\0'; |
225 | info->name = buf; | 225 | info->name = buf; |
226 | 226 | ||
227 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; | 227 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; |
228 | 228 | ||
229 | delete buf; | 229 | delete buf; |
230 | 230 | ||
231 | // Get the format we'll really use and tell the server | 231 | // Get the format we'll really use and tell the server |
232 | decidePixelFormat(); | 232 | decidePixelFormat(); |
233 | sendPixelFormat(); | 233 | sendPixelFormat(); |
234 | sendAllowedEncodings(); | 234 | sendAllowedEncodings(); |
235 | currentState = Idle; | 235 | currentState = Idle; |
236 | 236 | ||
237 | QString msg; | 237 | QString msg; |
238 | msg = tr( "Connected to %1" ); | 238 | msg = tr( "Connected to %1" ); |
239 | msg = msg.arg( info->name ); | 239 | msg = msg.arg( info->name ); |
240 | emit status( msg ); | 240 | emit status( msg ); |
241 | 241 | ||
242 | sendUpdateRequest( false ); | 242 | sendUpdateRequest( false ); |
243 | } | 243 | } |
244 | 244 | ||
245 | void KRFBDecoder::decidePixelFormat() | 245 | void KRFBDecoder::decidePixelFormat() |
246 | { | 246 | { |
247 | assert( info ); | 247 | assert( info ); |
248 | 248 | ||
249 | if ( format ) | 249 | if ( format ) |
250 | delete format; | 250 | delete format; |
251 | format = new KRFBPixelFormat; | 251 | format = new KRFBPixelFormat; |
252 | CHECK_PTR( format ); | 252 | CHECK_PTR( format ); |
253 | 253 | ||
254 | // What depth do we want? | 254 | // What depth do we want? |
255 | // | 255 | // |
256 | // We'll use the minimum of the remote and local depths, UNLESS an | 256 | // We'll use the minimum of the remote and local depths, UNLESS an |
257 | // eight bit session has been specifically requested by the user. | 257 | // eight bit session has been specifically requested by the user. |
258 | int screenDepth = QPixmap::defaultDepth(); | 258 | int screenDepth = QPixmap::defaultDepth(); |
259 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 259 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
260 | int chosenDepth; | 260 | int chosenDepth; |
261 | 261 | ||
262 | if ( con->options()->colors256 ) | 262 | if ( con->options()->colors256 ) |
263 | chosenDepth = 8; | 263 | chosenDepth = 8; |
264 | else | 264 | else |
265 | chosenDepth = bestDepth; | 265 | chosenDepth = bestDepth; |
266 | 266 | ||
267 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ | 267 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ |
268 | "eight bit %d, chosenDepth=%d", | 268 | "eight bit %d, chosenDepth=%d", |
269 | screenDepth, | 269 | screenDepth, |
270 | info->depth, | 270 | info->depth, |
271 | bestDepth, | 271 | bestDepth, |
272 | con->options()->colors256, chosenDepth ); | 272 | con->options()->colors256, chosenDepth ); |
273 | 273 | ||
274 | format->depth = chosenDepth; | 274 | format->depth = chosenDepth; |
275 | 275 | ||
276 | // If we're using the servers native depth | 276 | // If we're using the servers native depth |
277 | if ( chosenDepth == info->depth ) { | 277 | if ( chosenDepth == info->depth ) { |
278 | // Use the servers native format | 278 | // Use the servers native format |
279 | format->bpp = info->bpp; | 279 | format->bpp = info->bpp; |
280 | // format->bigEndian = info->bigEndian; | 280 | // format->bigEndian = info->bigEndian; |
281 | format->bigEndian = true; | 281 | format->bigEndian = true; |
282 | format->trueColor = info->trueColor; | 282 | format->trueColor = info->trueColor; |
283 | format->redMax = info->redMax; | 283 | format->redMax = info->redMax; |
284 | format->greenMax = info->greenMax; | 284 | format->greenMax = info->greenMax; |
285 | format->blueMax = info->blueMax; | 285 | format->blueMax = info->blueMax; |
286 | format->redShift = info->redShift; | 286 | format->redShift = info->redShift; |
287 | format->greenShift = info->greenShift; | 287 | format->greenShift = info->greenShift; |
288 | format->blueShift = info->blueShift; | 288 | format->blueShift = info->blueShift; |
289 | } | 289 | } |
290 | else { | 290 | else { |
291 | if ( chosenDepth == 8 ) { | 291 | if ( chosenDepth == 8 ) { |
292 | format->bpp = 8; | 292 | format->bpp = 8; |
293 | format->bigEndian = true; | 293 | format->bigEndian = true; |
294 | format->trueColor = true; | 294 | format->trueColor = true; |
295 | format->redMax = 7; | 295 | format->redMax = 7; |
296 | format->greenMax = 7; | 296 | format->greenMax = 7; |
297 | format->blueMax = 3; | 297 | format->blueMax = 3; |
298 | format->redShift = 0; | 298 | format->redShift = 0; |
299 | format->greenShift = 3; | 299 | format->greenShift = 3; |
300 | format->blueShift = 6; | 300 | format->blueShift = 6; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | format->redMax = Swap16IfLE( format->redMax ); | 304 | format->redMax = Swap16IfLE( format->redMax ); |
305 | format->greenMax = Swap16IfLE( format->greenMax ); | 305 | format->greenMax = Swap16IfLE( format->greenMax ); |
306 | format->blueMax = Swap16IfLE( format->blueMax ); | 306 | format->blueMax = Swap16IfLE( format->blueMax ); |
307 | } | 307 | } |
308 | 308 | ||
309 | void KRFBDecoder::sendPixelFormat() | 309 | void KRFBDecoder::sendPixelFormat() |
310 | { | 310 | { |
311 | static char padding[3]; | 311 | static char padding[3]; |
312 | con->write( &SetPixelFormatId, 1 ); | 312 | con->write( &SetPixelFormatId, 1 ); |
313 | con->write( padding, 3 ); | 313 | con->write( padding, 3 ); |
314 | 314 | ||
315 | con->write( &(format->bpp), 1 ); | 315 | con->write( &(format->bpp), 1 ); |
316 | con->write( &(format->depth), 1 ); | 316 | con->write( &(format->depth), 1 ); |
317 | con->write( &(format->bigEndian), 1 ); | 317 | con->write( &(format->bigEndian), 1 ); |
318 | con->write( &(format->trueColor), 1 ); | 318 | con->write( &(format->trueColor), 1 ); |
319 | 319 | ||
320 | con->write( &(format->redMax), 2 ); | 320 | con->write( &(format->redMax), 2 ); |
321 | con->write( &(format->greenMax), 2 ); | 321 | con->write( &(format->greenMax), 2 ); |
322 | con->write( &(format->blueMax), 2 ); | 322 | con->write( &(format->blueMax), 2 ); |
323 | 323 | ||
324 | con->write( &(format->redShift), 1 ); | 324 | con->write( &(format->redShift), 1 ); |
325 | con->write( &(format->greenShift), 1 ); | 325 | con->write( &(format->greenShift), 1 ); |
326 | con->write( &(format->blueShift), 1 ); | 326 | con->write( &(format->blueShift), 1 ); |
327 | con->write( format->padding, 3 ); // Padding | 327 | con->write( format->padding, 3 ); // Padding |
328 | } | 328 | } |
329 | 329 | ||
330 | void KRFBDecoder::sendAllowedEncodings() | 330 | void KRFBDecoder::sendAllowedEncodings() |
331 | { | 331 | { |
332 | static CARD8 padding[1]; | 332 | static CARD8 padding[1]; |
333 | con->write( &SetEncodingsId, 1 ); | 333 | con->write( &SetEncodingsId, 1 ); |
334 | con->write( padding, 1 ); | 334 | con->write( padding, 1 ); |
335 | 335 | ||
336 | CARD16 noEncodings = con->options()->encodings(); | 336 | CARD16 noEncodings = con->options()->encodings(); |
337 | noEncodings = Swap16IfLE( noEncodings ); | 337 | noEncodings = Swap16IfLE( noEncodings ); |
338 | con->write( &noEncodings, 2 ); | 338 | con->write( &noEncodings, 2 ); |
339 | 339 | ||
340 | if ( con->options()->corre ) | 340 | if ( con->options()->corre ) |
341 | con->write( &CorreEncoding, 4 ); | 341 | con->write( &CorreEncoding, 4 ); |
342 | if ( con->options()->hexTile ) | 342 | if ( con->options()->hexTile ) |
343 | con->write( &HexTileEncoding, 4 ); | 343 | con->write( &HexTileEncoding, 4 ); |
344 | if ( con->options()->rre ) | 344 | if ( con->options()->rre ) |
345 | con->write( &RreEncoding, 4 ); | 345 | con->write( &RreEncoding, 4 ); |
346 | if ( con->options()->copyrect ) | 346 | if ( con->options()->copyrect ) |
347 | con->write( &CopyRectEncoding, 4 ); | 347 | con->write( &CopyRectEncoding, 4 ); |
348 | // We always support this | 348 | // We always support this |
349 | con->write( &RawEncoding, 4 ); | 349 | con->write( &RawEncoding, 4 ); |
350 | } | 350 | } |
351 | 351 | ||
352 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 352 | void KRFBDecoder::sendUpdateRequest( bool incremental ) |
353 | { | 353 | { |
354 | if ( currentState != Idle ) | 354 | if ( currentState != Idle ) |
355 | return; | 355 | return; |
356 | 356 | ||
357 | con->write( &UpdateRequestId, 1 ); | 357 | con->write( &UpdateRequestId, 1 ); |
358 | con->write( &incremental, 1 ); | 358 | con->write( &incremental, 1 ); |
359 | 359 | ||
360 | static CARD16 x = 0, y = 0; | 360 | static CARD16 x = 0, y = 0; |
361 | static CARD16 w = Swap16IfLE( info->width ); | 361 | static CARD16 w = Swap16IfLE( info->width ); |
362 | static CARD16 h = Swap16IfLE( info->height ); | 362 | static CARD16 h = Swap16IfLE( info->height ); |
363 | 363 | ||
364 | con->write( &x, 2 ); | 364 | con->write( &x, 2 ); |
365 | con->write( &y, 2 ); | 365 | con->write( &y, 2 ); |
366 | con->write( &w, 2 ); | 366 | con->write( &w, 2 ); |
367 | con->write( &h, 2 ); | 367 | con->write( &h, 2 ); |
368 | 368 | ||
369 | // Now wait for the update | 369 | // Now wait for the update |
370 | currentState = AwaitingUpdate; | 370 | currentState = AwaitingUpdate; |
371 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 371 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
372 | con->waitForData( UpdateHeaderLength ); | 372 | con->waitForData( UpdateHeaderLength ); |
373 | } | 373 | } |
374 | 374 | ||
375 | void KRFBDecoder::gotUpdateHeader() | 375 | void KRFBDecoder::gotUpdateHeader() |
376 | { | 376 | { |
377 | assert( currentState == AwaitingUpdate ); | 377 | assert( currentState == AwaitingUpdate ); |
378 | 378 | ||
379 | // owarn << "Got update header" << oendl; | 379 | // owarn << "Got update header" << oendl; |
380 | 380 | ||
381 | disconnect( con, SIGNAL( gotEnoughData() ), | 381 | disconnect( con, SIGNAL( gotEnoughData() ), |
382 | this, SLOT( gotUpdateHeader() ) ); | 382 | this, SLOT( gotUpdateHeader() ) ); |
383 | 383 | ||
384 | CARD8 msgType; | 384 | CARD8 msgType; |
385 | con->read( &msgType, 1 ); | 385 | con->read( &msgType, 1 ); |
386 | 386 | ||
387 | if ( msgType != UpdateId ) { | 387 | if ( msgType != UpdateId ) { |
388 | // We might have a bell or server cut | 388 | // We might have a bell or server cut |
389 | if ( msgType == ServerCutId ) { | 389 | if ( msgType == ServerCutId ) { |
390 | oldState = currentState; | 390 | oldState = currentState; |
391 | gotServerCut(); | 391 | gotServerCut(); |
392 | } | 392 | } |
393 | else if ( msgType == BellId ) { | 393 | else if ( msgType == BellId ) { |
394 | oldState = currentState; | 394 | oldState = currentState; |
395 | gotBell(); | 395 | gotBell(); |
396 | } | 396 | } |
397 | else { | 397 | else { |
398 | int msg = msgType; | 398 | int msg = msgType; |
399 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 399 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
400 | "found when expecting an update " | 400 | "found when expecting an update " |
401 | "message." ).arg( msg ); | 401 | "message." ).arg( msg ); |
402 | currentState = Error; | 402 | currentState = Error; |
403 | emit error( protocolError ); | 403 | emit error( protocolError ); |
404 | } | 404 | } |
405 | return; | 405 | return; |