-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index dc90d9c..c43aed5 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -1,847 +1,847 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbserver.h" | 2 | #include "krfbserver.h" |
3 | #include "krfbserverinfo.h" | 3 | #include "krfbserverinfo.h" |
4 | #include "krfbdecoder.h" | 4 | #include "krfbdecoder.h" |
5 | #include "krfbbuffer.h" | 5 | #include "krfbbuffer.h" |
6 | 6 | ||
7 | #include <qpe/qpeapplication.h> | 7 | #include <qpe/qpeapplication.h> |
8 | 8 | ||
9 | #include <qpixmap.h> | 9 | #include <qpixmap.h> |
10 | #include <qsocket.h> | 10 | #include <qsocket.h> |
11 | #include <qevent.h> | 11 | #include <qevent.h> |
12 | #include <qstring.h> | 12 | #include <qstring.h> |
13 | #include <qclipboard.h> | 13 | #include <qclipboard.h> |
14 | 14 | ||
15 | #include <assert.h> | 15 | #include <assert.h> |
16 | 16 | ||
17 | // | 17 | // |
18 | // Endian stuff | 18 | // Endian stuff |
19 | // | 19 | // |
20 | #ifndef KDE_USE_FINAL | 20 | #ifndef KDE_USE_FINAL |
21 | const int endianTest = 1; | 21 | const int endianTest = 1; |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | #define Swap16IfLE(s) \ | 24 | #define Swap16IfLE(s) \ |
25 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 25 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
26 | 26 | ||
27 | #define Swap32IfLE(l) \ | 27 | #define Swap32IfLE(l) \ |
28 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 28 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
29 | (((l) & 0x00ff0000) >> 8) | \ | 29 | (((l) & 0x00ff0000) >> 8) | \ |
30 | (((l) & 0x0000ff00) << 8) | \ | 30 | (((l) & 0x0000ff00) << 8) | \ |
31 | (((l) & 0x000000ff) << 24)) : (l)) | 31 | (((l) & 0x000000ff) << 24)) : (l)) |
32 | 32 | ||
33 | // | 33 | // |
34 | // The lengths of the messages we need to wait for | 34 | // The lengths of the messages we need to wait for |
35 | // | 35 | // |
36 | const int ServerInitLength = 24; | 36 | const int ServerInitLength = 24; |
37 | const int UpdateHeaderLength = 4; | 37 | const int UpdateHeaderLength = 4; |
38 | const int RectHeaderLength = 12; | 38 | const int RectHeaderLength = 12; |
39 | const int RectChunkSize = 4; | 39 | const int RectChunkSize = 4; |
40 | const int CopyRectPosLength = 4; | 40 | const int CopyRectPosLength = 4; |
41 | const int ServerCutLenLength = 7; | 41 | const int ServerCutLenLength = 7; |
42 | 42 | ||
43 | // | 43 | // |
44 | // Client -> Server Message Identifiers | 44 | // Client -> Server Message Identifiers |
45 | // | 45 | // |
46 | static CARD8 SetPixelFormatId = 0; | 46 | static CARD8 SetPixelFormatId = 0; |
47 | //static CARD8 FixColourMapEntriesId = 1; // Not used | 47 | //static CARD8 FixColourMapEntriesId = 1; // Not used |
48 | static CARD8 SetEncodingsId = 2; | 48 | static CARD8 SetEncodingsId = 2; |
49 | static CARD8 UpdateRequestId = 3; | 49 | static CARD8 UpdateRequestId = 3; |
50 | static CARD8 KeyEventId = 4; | 50 | static CARD8 KeyEventId = 4; |
51 | static CARD8 PointerEventId = 5; | 51 | static CARD8 PointerEventId = 5; |
52 | static CARD8 ClientCutTextId = 6; | 52 | static CARD8 ClientCutTextId = 6; |
53 | 53 | ||
54 | // | 54 | // |
55 | // Server -> Client Message Identifiers | 55 | // Server -> Client Message Identifiers |
56 | // | 56 | // |
57 | static CARD8 UpdateId = 0; | 57 | static CARD8 UpdateId = 0; |
58 | static CARD8 BellId = 2; | 58 | static CARD8 BellId = 2; |
59 | static CARD8 ServerCutId = 3; | 59 | static CARD8 ServerCutId = 3; |
60 | 60 | ||
61 | // | 61 | // |
62 | // Encoding identifiers | 62 | // Encoding identifiers |
63 | // | 63 | // |
64 | static CARD32 RawEncoding = Swap32IfLE( 0 ); | 64 | static CARD32 RawEncoding = Swap32IfLE( 0 ); |
65 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); | 65 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); |
66 | static CARD32 RreEncoding = Swap32IfLE( 2 ); | 66 | static CARD32 RreEncoding = Swap32IfLE( 2 ); |
67 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); | 67 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); |
68 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); | 68 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); |
69 | 69 | ||
70 | static struct { | 70 | static struct { |
71 | int keysym; | 71 | int keysym; |
72 | int keycode; | 72 | int keycode; |
73 | } keyMap[] = { | 73 | } keyMap[] = { |
74 | { 0xff08, Qt::Key_Backspace }, | 74 | { 0xff08, Qt::Key_Backspace }, |
75 | { 0xff09, Qt::Key_Tab }, | 75 | { 0xff09, Qt::Key_Tab }, |
76 | { 0xff0d, Qt::Key_Return }, | 76 | { 0xff0d, Qt::Key_Return }, |
77 | { 0xff1b, Qt::Key_Escape }, | 77 | { 0xff1b, Qt::Key_Escape }, |
78 | { 0xff63, Qt::Key_Insert }, | 78 | { 0xff63, Qt::Key_Insert }, |
79 | { 0xffff, Qt::Key_Delete }, | 79 | { 0xffff, Qt::Key_Delete }, |
80 | { 0xff50, Qt::Key_Home }, | 80 | { 0xff50, Qt::Key_Home }, |
81 | { 0xff57, Qt::Key_End }, | 81 | { 0xff57, Qt::Key_End }, |
82 | { 0xff55, Qt::Key_Prior }, | 82 | { 0xff55, Qt::Key_Prior }, |
83 | { 0xff56, Qt::Key_Next }, | 83 | { 0xff56, Qt::Key_Next }, |
84 | { 0xff51, Qt::Key_Left }, | 84 | { 0xff51, Qt::Key_Left }, |
85 | { 0xff52, Qt::Key_Up }, | 85 | { 0xff52, Qt::Key_Up }, |
86 | { 0xff53, Qt::Key_Right }, | 86 | { 0xff53, Qt::Key_Right }, |
87 | { 0xff54, Qt::Key_Down }, | 87 | { 0xff54, Qt::Key_Down }, |
88 | { 0xffbe, Qt::Key_F1 }, | 88 | { 0xffbe, Qt::Key_F1 }, |
89 | { 0xffbf, Qt::Key_F2 }, | 89 | { 0xffbf, Qt::Key_F2 }, |
90 | { 0xffc0, Qt::Key_F3 }, | 90 | { 0xffc0, Qt::Key_F3 }, |
91 | { 0xffc1, Qt::Key_F4 }, | 91 | { 0xffc1, Qt::Key_F4 }, |
92 | { 0xffc2, Qt::Key_F5 }, | 92 | { 0xffc2, Qt::Key_F5 }, |
93 | { 0xffc3, Qt::Key_F6 }, | 93 | { 0xffc3, Qt::Key_F6 }, |
94 | { 0xffc4, Qt::Key_F7 }, | 94 | { 0xffc4, Qt::Key_F7 }, |
95 | { 0xffc5, Qt::Key_F8 }, | 95 | { 0xffc5, Qt::Key_F8 }, |
96 | { 0xffc6, Qt::Key_F9 }, | 96 | { 0xffc6, Qt::Key_F9 }, |
97 | { 0xffc7, Qt::Key_F10 }, | 97 | { 0xffc7, Qt::Key_F10 }, |
98 | { 0xffc8, Qt::Key_F11 }, | 98 | { 0xffc8, Qt::Key_F11 }, |
99 | { 0xffc9, Qt::Key_F12 }, | 99 | { 0xffc9, Qt::Key_F12 }, |
100 | { 0xffe1, Qt::Key_Shift }, | 100 | { 0xffe1, Qt::Key_Shift }, |
101 | { 0xffe2, Qt::Key_Shift }, | 101 | { 0xffe2, Qt::Key_Shift }, |
102 | { 0xffe3, Qt::Key_Control }, | 102 | { 0xffe3, Qt::Key_Control }, |
103 | { 0xffe4, Qt::Key_Control }, | 103 | { 0xffe4, Qt::Key_Control }, |
104 | { 0xffe7, Qt::Key_Meta }, | 104 | { 0xffe7, Qt::Key_Meta }, |
105 | { 0xffe8, Qt::Key_Meta }, | 105 | { 0xffe8, Qt::Key_Meta }, |
106 | { 0xffe9, Qt::Key_Alt }, | 106 | { 0xffe9, Qt::Key_Alt }, |
107 | { 0xffea, Qt::Key_Alt }, | 107 | { 0xffea, Qt::Key_Alt }, |
108 | { 0, 0 } | 108 | { 0, 0 } |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) | 112 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) |
113 | : QObject( con, "RFB Decoder" ) | 113 | : QObject( con, "RFB Decoder" ) |
114 | { | 114 | { |
115 | assert( con ); | 115 | assert( con ); |
116 | assert( con->state() == KRFBConnection::Connected ); | 116 | assert( con->state() == KRFBConnection::Connected ); |
117 | 117 | ||
118 | this->con = con; | 118 | this->con = con; |
119 | this->buf = 0; | 119 | this->buf = 0; |
120 | this->info = 0; | 120 | this->info = 0; |
121 | this->format = 0; | 121 | this->format = 0; |
122 | this->buttonMask = 0; | 122 | this->buttonMask = 0; |
123 | currentState = Idle; | 123 | currentState = Idle; |
124 | } | 124 | } |
125 | 125 | ||
126 | KRFBDecoder::~KRFBDecoder() | 126 | KRFBDecoder::~KRFBDecoder() |
127 | { | 127 | { |
128 | if ( info ) | 128 | if ( info ) |
129 | delete info; | 129 | delete info; |
130 | if ( format ) | 130 | if ( format ) |
131 | delete format; | 131 | delete format; |
132 | } | 132 | } |
133 | 133 | ||
134 | void KRFBDecoder::start() | 134 | void KRFBDecoder::start() |
135 | { | 135 | { |
136 | sendClientInit(); | 136 | sendClientInit(); |
137 | } | 137 | } |
138 | 138 | ||
139 | void KRFBDecoder::sendClientInit() | 139 | void KRFBDecoder::sendClientInit() |
140 | { | 140 | { |
141 | con->write( &( con->options()->shared ), 1 ); | 141 | con->write( &( con->options()->shared ), 1 ); |
142 | 142 | ||
143 | // Wait for server init | 143 | // Wait for server init |
144 | qWarning( "Waiting for server init" ); | 144 | qWarning( "Waiting for server init" ); |
145 | 145 | ||
146 | static QString statusMsg = tr( "Waiting for server initialisation..." ); | 146 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
147 | emit status( statusMsg ); | 147 | emit status( statusMsg ); |
148 | 148 | ||
149 | currentState = AwaitingServerInit; | 149 | currentState = AwaitingServerInit; |
150 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 150 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
151 | con->waitForData( ServerInitLength ); | 151 | con->waitForData( ServerInitLength ); |
152 | } | 152 | } |
153 | 153 | ||
154 | void KRFBDecoder::gotServerInit() | 154 | void KRFBDecoder::gotServerInit() |
155 | { | 155 | { |
156 | qWarning( "Got server init" ); | 156 | qWarning( "Got server init" ); |
157 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 157 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
158 | 158 | ||
159 | if ( info ) | 159 | if ( info ) |
160 | delete info; | 160 | delete info; |
161 | info = new KRFBServerInfo; | 161 | info = new KRFBServerInfo; |
162 | CHECK_PTR( info ); | 162 | CHECK_PTR( info ); |
163 | 163 | ||
164 | con->read( &(info->width), 2 ); | 164 | con->read( &(info->width), 2 ); |
165 | info->width = Swap16IfLE( info->width ); | 165 | info->width = Swap16IfLE( info->width ); |
166 | con->read( &info->height, 2 ); | 166 | con->read( &info->height, 2 ); |
167 | info->height = Swap16IfLE( info->height ); | 167 | info->height = Swap16IfLE( info->height ); |
168 | 168 | ||
169 | con->read( &(info->bpp), 1 ); | 169 | con->read( &(info->bpp), 1 ); |
170 | con->read( &(info->depth), 1 ); | 170 | con->read( &(info->depth), 1 ); |
171 | con->read( &(info->bigEndian), 1 ); | 171 | con->read( &(info->bigEndian), 1 ); |
172 | con->read( &(info->trueColor), 1 ); | 172 | con->read( &(info->trueColor), 1 ); |
173 | 173 | ||
174 | con->read( &(info->redMax), 2 ); | 174 | con->read( &(info->redMax), 2 ); |
175 | info->redMax = Swap16IfLE( info->redMax ); | 175 | info->redMax = Swap16IfLE( info->redMax ); |
176 | con->read( &(info->greenMax), 2 ); | 176 | con->read( &(info->greenMax), 2 ); |
177 | info->greenMax = Swap16IfLE( info->greenMax ); | 177 | info->greenMax = Swap16IfLE( info->greenMax ); |
178 | con->read( &(info->blueMax), 2 ); | 178 | con->read( &(info->blueMax), 2 ); |
179 | info->blueMax = Swap16IfLE( info->blueMax ); | 179 | info->blueMax = Swap16IfLE( info->blueMax ); |
180 | 180 | ||
181 | con->read( &(info->redShift), 1 ); | 181 | con->read( &(info->redShift), 1 ); |
182 | con->read( &(info->greenShift), 1 ); | 182 | con->read( &(info->greenShift), 1 ); |
183 | con->read( &(info->blueShift), 1 ); | 183 | con->read( &(info->blueShift), 1 ); |
184 | 184 | ||
185 | con->read( info->padding, 3 ); | 185 | con->read( info->padding, 3 ); |
186 | 186 | ||
187 | con->read( &(info->nameLength), 4 ); | 187 | con->read( &(info->nameLength), 4 ); |
188 | info->nameLength = Swap32IfLE( info->nameLength ); | 188 | info->nameLength = Swap32IfLE( info->nameLength ); |
189 | 189 | ||
190 | qWarning( "Width = %d, Height = %d", info->width, info->height ); | 190 | qWarning( "Width = %d, Height = %d", info->width, info->height ); |
191 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", | 191 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", |
192 | info->bpp, info->depth, info->bigEndian, info->trueColor ); | 192 | info->bpp, info->depth, info->bigEndian, info->trueColor ); |
193 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", | 193 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", |
194 | info->redMax, info->greenMax, info->blueMax ); | 194 | info->redMax, info->greenMax, info->blueMax ); |
195 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", | 195 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", |
196 | info->redShift, info->greenShift,info-> blueShift ); | 196 | info->redShift, info->greenShift,info-> blueShift ); |
197 | 197 | ||
198 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 198 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
199 | 199 | ||
200 | // Wait for desktop name | 200 | // Wait for desktop name |
201 | qWarning( "Waiting for desktop name" ); | 201 | qWarning( "Waiting for desktop name" ); |
202 | 202 | ||
203 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 203 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
204 | emit status( statusMsg ); | 204 | emit status( statusMsg ); |
205 | 205 | ||
206 | currentState = AwaitingDesktopName; | 206 | currentState = AwaitingDesktopName; |
207 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 207 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
208 | con->waitForData( info->nameLength ); | 208 | con->waitForData( info->nameLength ); |
209 | } | 209 | } |
210 | 210 | ||
211 | void KRFBDecoder::gotDesktopName() | 211 | void KRFBDecoder::gotDesktopName() |
212 | { | 212 | { |
213 | assert( info ); | 213 | assert( info ); |
214 | assert( currentState == AwaitingDesktopName ); | 214 | assert( currentState == AwaitingDesktopName ); |
215 | 215 | ||
216 | qWarning( "Got desktop name" ); | 216 | qWarning( "Got desktop name" ); |
217 | 217 | ||
218 | disconnect( con, SIGNAL( gotEnoughData() ), | 218 | disconnect( con, SIGNAL( gotEnoughData() ), |
219 | this, SLOT( gotDesktopName() ) ); | 219 | this, SLOT( gotDesktopName() ) ); |
220 | 220 | ||
221 | char *buf = new char[ info->nameLength + 1 ]; | 221 | char *buf = new char[ info->nameLength + 1 ]; |
222 | CHECK_PTR( buf ); | 222 | CHECK_PTR( buf ); |
223 | 223 | ||
224 | con->read( buf, info->nameLength ); | 224 | con->read( buf, info->nameLength ); |
225 | buf[ info->nameLength ] = '\0'; | 225 | buf[ info->nameLength ] = '\0'; |
226 | info->name = buf; | 226 | info->name = buf; |
227 | 227 | ||
228 | qWarning( "Desktop: %s", info->name.latin1() ); | 228 | qWarning( "Desktop: %s", info->name.latin1() ); |
229 | 229 | ||
230 | delete buf; | 230 | delete buf; |
231 | 231 | ||
232 | // Get the format we'll really use and tell the server | 232 | // Get the format we'll really use and tell the server |
233 | decidePixelFormat(); | 233 | decidePixelFormat(); |
234 | sendPixelFormat(); | 234 | sendPixelFormat(); |
235 | sendAllowedEncodings(); | 235 | sendAllowedEncodings(); |
236 | currentState = Idle; | 236 | currentState = Idle; |
237 | 237 | ||
238 | QString msg; | 238 | QString msg; |
239 | msg = tr( "Connected to %1" ); | 239 | msg = tr( "Connected to %1" ); |
240 | msg = msg.arg( info->name ); | 240 | msg = msg.arg( info->name ); |
241 | emit status( msg ); | 241 | emit status( msg ); |
242 | 242 | ||
243 | sendUpdateRequest( false ); | 243 | sendUpdateRequest( false ); |
244 | } | 244 | } |
245 | 245 | ||
246 | void KRFBDecoder::decidePixelFormat() | 246 | void KRFBDecoder::decidePixelFormat() |
247 | { | 247 | { |
248 | assert( info ); | 248 | assert( info ); |
249 | 249 | ||
250 | if ( format ) | 250 | if ( format ) |
251 | delete format; | 251 | delete format; |
252 | format = new KRFBPixelFormat; | 252 | format = new KRFBPixelFormat; |
253 | CHECK_PTR( format ); | 253 | CHECK_PTR( format ); |
254 | 254 | ||
255 | // What depth do we want? | 255 | // What depth do we want? |
256 | // | 256 | // |
257 | // We'll use the minimum of the remote and local depths, UNLESS an | 257 | // We'll use the minimum of the remote and local depths, UNLESS an |
258 | // eight bit session has been specifically requested by the user. | 258 | // eight bit session has been specifically requested by the user. |
259 | int screenDepth = QPixmap::defaultDepth(); | 259 | int screenDepth = QPixmap::defaultDepth(); |
260 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 260 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
261 | int chosenDepth; | 261 | int chosenDepth; |
262 | 262 | ||
263 | if ( con->options()->colors256 ) | 263 | if ( con->options()->colors256 ) |
264 | chosenDepth = 8; | 264 | chosenDepth = 8; |
265 | else | 265 | else |
266 | chosenDepth = bestDepth; | 266 | chosenDepth = bestDepth; |
267 | 267 | ||
268 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ | 268 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ |
269 | "eight bit %d, chosenDepth=%d", | 269 | "eight bit %d, chosenDepth=%d", |
270 | screenDepth, | 270 | screenDepth, |
271 | info->depth, | 271 | info->depth, |
272 | bestDepth, | 272 | bestDepth, |
273 | con->options()->colors256, chosenDepth ); | 273 | con->options()->colors256, chosenDepth ); |
274 | 274 | ||
275 | format->depth = chosenDepth; | 275 | format->depth = chosenDepth; |
276 | 276 | ||
277 | // If we're using the servers native depth | 277 | // If we're using the servers native depth |
278 | if ( chosenDepth == info->depth ) { | 278 | if ( chosenDepth == info->depth ) { |
279 | // Use the servers native format | 279 | // Use the servers native format |
280 | format->bpp = info->bpp; | 280 | format->bpp = info->bpp; |
281 | // format->bigEndian = info->bigEndian; | 281 | // format->bigEndian = info->bigEndian; |
282 | format->bigEndian = true; | 282 | format->bigEndian = true; |
283 | format->trueColor = info->trueColor; | 283 | format->trueColor = info->trueColor; |
284 | format->redMax = info->redMax; | 284 | format->redMax = info->redMax; |
285 | format->greenMax = info->greenMax; | 285 | format->greenMax = info->greenMax; |
286 | format->blueMax = info->blueMax; | 286 | format->blueMax = info->blueMax; |
287 | format->redShift = info->redShift; | 287 | format->redShift = info->redShift; |
288 | format->greenShift = info->greenShift; | 288 | format->greenShift = info->greenShift; |
289 | format->blueShift = info->blueShift; | 289 | format->blueShift = info->blueShift; |
290 | } | 290 | } |
291 | else { | 291 | else { |
292 | if ( chosenDepth == 8 ) { | 292 | if ( chosenDepth == 8 ) { |
293 | format->bpp = 8; | 293 | format->bpp = 8; |
294 | format->bigEndian = true; | 294 | format->bigEndian = true; |
295 | format->trueColor = true; | 295 | format->trueColor = true; |
296 | format->redMax = 7; | 296 | format->redMax = 7; |
297 | format->greenMax = 7; | 297 | format->greenMax = 7; |
298 | format->blueMax = 3; | 298 | format->blueMax = 3; |
299 | format->redShift = 0; | 299 | format->redShift = 0; |
300 | format->greenShift = 3; | 300 | format->greenShift = 3; |
301 | format->blueShift = 6; | 301 | format->blueShift = 6; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | format->redMax = Swap16IfLE( format->redMax ); | 305 | format->redMax = Swap16IfLE( format->redMax ); |
306 | format->greenMax = Swap16IfLE( format->greenMax ); | 306 | format->greenMax = Swap16IfLE( format->greenMax ); |
307 | format->blueMax = Swap16IfLE( format->blueMax ); | 307 | format->blueMax = Swap16IfLE( format->blueMax ); |
308 | } | 308 | } |
309 | 309 | ||
310 | void KRFBDecoder::sendPixelFormat() | 310 | void KRFBDecoder::sendPixelFormat() |
311 | { | 311 | { |
312 | static char padding[3]; | 312 | static char padding[3]; |
313 | con->write( &SetPixelFormatId, 1 ); | 313 | con->write( &SetPixelFormatId, 1 ); |
314 | con->write( padding, 3 ); | 314 | con->write( padding, 3 ); |
315 | 315 | ||
316 | con->write( &(format->bpp), 1 ); | 316 | con->write( &(format->bpp), 1 ); |
317 | con->write( &(format->depth), 1 ); | 317 | con->write( &(format->depth), 1 ); |
318 | con->write( &(format->bigEndian), 1 ); | 318 | con->write( &(format->bigEndian), 1 ); |
319 | con->write( &(format->trueColor), 1 ); | 319 | con->write( &(format->trueColor), 1 ); |
320 | 320 | ||
321 | con->write( &(format->redMax), 2 ); | 321 | con->write( &(format->redMax), 2 ); |
322 | con->write( &(format->greenMax), 2 ); | 322 | con->write( &(format->greenMax), 2 ); |
323 | con->write( &(format->blueMax), 2 ); | 323 | con->write( &(format->blueMax), 2 ); |
324 | 324 | ||
325 | con->write( &(format->redShift), 1 ); | 325 | con->write( &(format->redShift), 1 ); |
326 | con->write( &(format->greenShift), 1 ); | 326 | con->write( &(format->greenShift), 1 ); |
327 | con->write( &(format->blueShift), 1 ); | 327 | con->write( &(format->blueShift), 1 ); |
328 | con->write( format->padding, 3 ); // Padding | 328 | con->write( format->padding, 3 ); // Padding |
329 | } | 329 | } |
330 | 330 | ||
331 | void KRFBDecoder::sendAllowedEncodings() | 331 | void KRFBDecoder::sendAllowedEncodings() |
332 | { | 332 | { |
333 | static CARD8 padding[1]; | 333 | static CARD8 padding[1]; |
334 | con->write( &SetEncodingsId, 1 ); | 334 | con->write( &SetEncodingsId, 1 ); |
335 | con->write( padding, 1 ); | 335 | con->write( padding, 1 ); |
336 | 336 | ||
337 | CARD16 noEncodings = con->options()->encodings(); | 337 | CARD16 noEncodings = con->options()->encodings(); |
338 | noEncodings = Swap16IfLE( noEncodings ); | 338 | noEncodings = Swap16IfLE( noEncodings ); |
339 | con->write( &noEncodings, 2 ); | 339 | con->write( &noEncodings, 2 ); |
340 | 340 | ||
341 | if ( con->options()->corre ) | 341 | if ( con->options()->corre ) |
342 | con->write( &CorreEncoding, 4 ); | 342 | con->write( &CorreEncoding, 4 ); |
343 | if ( con->options()->hexTile ) | 343 | if ( con->options()->hexTile ) |
344 | con->write( &HexTileEncoding, 4 ); | 344 | con->write( &HexTileEncoding, 4 ); |
345 | if ( con->options()->rre ) | 345 | if ( con->options()->rre ) |
346 | con->write( &RreEncoding, 4 ); | 346 | con->write( &RreEncoding, 4 ); |
347 | if ( con->options()->copyrect ) | 347 | if ( con->options()->copyrect ) |
348 | con->write( &CopyRectEncoding, 4 ); | 348 | con->write( &CopyRectEncoding, 4 ); |
349 | // We always support this | 349 | // We always support this |
350 | con->write( &RawEncoding, 4 ); | 350 | con->write( &RawEncoding, 4 ); |
351 | } | 351 | } |
352 | 352 | ||
353 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 353 | void KRFBDecoder::sendUpdateRequest( bool incremental ) |
354 | { | 354 | { |
355 | if ( currentState != Idle ) | 355 | if ( currentState != Idle ) |
356 | return; | 356 | return; |
357 | 357 | ||
358 | con->write( &UpdateRequestId, 1 ); | 358 | con->write( &UpdateRequestId, 1 ); |
359 | con->write( &incremental, 1 ); | 359 | con->write( &incremental, 1 ); |
360 | 360 | ||
361 | static CARD16 x = 0, y = 0; | 361 | static CARD16 x = 0, y = 0; |
362 | static CARD16 w = Swap16IfLE( info->width ); | 362 | static CARD16 w = Swap16IfLE( info->width ); |
363 | static CARD16 h = Swap16IfLE( info->height ); | 363 | static CARD16 h = Swap16IfLE( info->height ); |
364 | 364 | ||
365 | con->write( &x, 2 ); | 365 | con->write( &x, 2 ); |
366 | con->write( &y, 2 ); | 366 | con->write( &y, 2 ); |
367 | con->write( &w, 2 ); | 367 | con->write( &w, 2 ); |
368 | con->write( &h, 2 ); | 368 | con->write( &h, 2 ); |
369 | 369 | ||
370 | // Now wait for the update | 370 | // Now wait for the update |
371 | currentState = AwaitingUpdate; | 371 | currentState = AwaitingUpdate; |
372 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 372 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
373 | con->waitForData( UpdateHeaderLength ); | 373 | con->waitForData( UpdateHeaderLength ); |
374 | } | 374 | } |
375 | 375 | ||
376 | void KRFBDecoder::gotUpdateHeader() | 376 | void KRFBDecoder::gotUpdateHeader() |
377 | { | 377 | { |
378 | assert( currentState == AwaitingUpdate ); | 378 | assert( currentState == AwaitingUpdate ); |
379 | 379 | ||
380 | // qWarning( "Got update header" ); | 380 | // qWarning( "Got update header" ); |
381 | 381 | ||
382 | disconnect( con, SIGNAL( gotEnoughData() ), | 382 | disconnect( con, SIGNAL( gotEnoughData() ), |
383 | this, SLOT( gotUpdateHeader() ) ); | 383 | this, SLOT( gotUpdateHeader() ) ); |
384 | 384 | ||
385 | CARD8 msgType; | 385 | CARD8 msgType; |
386 | con->read( &msgType, 1 ); | 386 | con->read( &msgType, 1 ); |
387 | 387 | ||
388 | if ( msgType != UpdateId ) { | 388 | if ( msgType != UpdateId ) { |
389 | // We might have a bell or server cut | 389 | // We might have a bell or server cut |
390 | if ( msgType == ServerCutId ) { | 390 | if ( msgType == ServerCutId ) { |
391 | oldState = currentState; | 391 | oldState = currentState; |
392 | gotServerCut(); | 392 | gotServerCut(); |
393 | } | 393 | } |
394 | else if ( msgType == BellId ) { | 394 | else if ( msgType == BellId ) { |
395 | oldState = currentState; | 395 | oldState = currentState; |
396 | gotBell(); | 396 | gotBell(); |
397 | } | 397 | } |
398 | else { | 398 | else { |
399 | int msg = msgType; | 399 | int msg = msgType; |
400 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 400 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
401 | "found when expecting an update " | 401 | "found when expecting an update " |
402 | "message." ).arg( msg ); | 402 | "message." ).arg( msg ); |
403 | currentState = Error; | 403 | currentState = Error; |
404 | emit error( protocolError ); | 404 | emit error( protocolError ); |
405 | } | 405 | } |
406 | return; | 406 | return; |
407 | } | 407 | } |
408 | 408 | ||
409 | CARD8 padding; | 409 | CARD8 padding; |
410 | con->read( &padding, 1 ); | 410 | con->read( &padding, 1 ); |
411 | 411 | ||
412 | con->read( &noRects, 2 ); | 412 | con->read( &noRects, 2 ); |
413 | noRects = Swap16IfLE( noRects ); | 413 | noRects = Swap16IfLE( noRects ); |
414 | 414 | ||
415 | // qWarning( "Expecting %d rects", noRects ); | 415 | // qWarning( "Expecting %d rects", noRects ); |
416 | 416 | ||
417 | // Now wait for the data | 417 | // Now wait for the data |
418 | currentState = AwaitingRectHeader; | 418 | currentState = AwaitingRectHeader; |
419 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 419 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
420 | con->waitForData( RectHeaderLength ); | 420 | con->waitForData( RectHeaderLength ); |
421 | } | 421 | } |
422 | 422 | ||
423 | void KRFBDecoder::gotRectHeader() | 423 | void KRFBDecoder::gotRectHeader() |
424 | { | 424 | { |
425 | assert( currentState == AwaitingRectHeader ); | 425 | assert( currentState == AwaitingRectHeader ); |
426 | 426 | ||
427 | // qWarning( "Got rect header" ); | 427 | // qWarning( "Got rect header" ); |
428 | 428 | ||
429 | disconnect( con, SIGNAL( gotEnoughData() ), | 429 | disconnect( con, SIGNAL( gotEnoughData() ), |
430 | this, SLOT( gotRectHeader() ) ); | 430 | this, SLOT( gotRectHeader() ) ); |
431 | 431 | ||
432 | con->read( &x, 2 ); | 432 | con->read( &x, 2 ); |
433 | x = Swap16IfLE( x ); | 433 | x = Swap16IfLE( x ); |
434 | con->read( &y, 2 ); | 434 | con->read( &y, 2 ); |
435 | y = Swap16IfLE( y ); | 435 | y = Swap16IfLE( y ); |
436 | 436 | ||
437 | con->read( &w, 2 ); | 437 | con->read( &w, 2 ); |
438 | w = Swap16IfLE( w ); | 438 | w = Swap16IfLE( w ); |
439 | con->read( &h, 2 ); | 439 | con->read( &h, 2 ); |
440 | h = Swap16IfLE( h ); | 440 | h = Swap16IfLE( h ); |
441 | 441 | ||
442 | con->read( &encoding, 4 ); | 442 | con->read( &encoding, 4 ); |
443 | 443 | ||
444 | // CARD32 encodingLocal = Swap32IfLE( encoding ); | 444 | // CARD32 encodingLocal = Swap32IfLE( encoding ); |
445 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", | 445 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", |
446 | // x, y, w, h, encodingLocal ); | 446 | // x, y, w, h, encodingLocal ); |
447 | 447 | ||
448 | // | 448 | // |
449 | // Each encoding needs to be handled differently. Some require | 449 | // Each encoding needs to be handled differently. Some require |
450 | // waiting for more data, but others like a copyrect do not. | 450 | // waiting for more data, but others like a copyrect do not. |
451 | // Our constants have already been byte swapped, so we use | 451 | // Our constants have already been byte swapped, so we use |
452 | // the remote value as is. | 452 | // the remote value as is. |
453 | // | 453 | // |
454 | if ( encoding == RawEncoding ) { | 454 | if ( encoding == RawEncoding ) { |
455 | // qWarning( "Raw encoding" ); | 455 | // qWarning( "Raw encoding" ); |
456 | handleRawRect(); | 456 | handleRawRect(); |
457 | } | 457 | } |
458 | else if ( encoding == CopyRectEncoding ) { | 458 | else if ( encoding == CopyRectEncoding ) { |
459 | // qWarning( "CopyRect encoding" ); | 459 | // qWarning( "CopyRect encoding" ); |
460 | handleCopyRect(); | 460 | handleCopyRect(); |
461 | } | 461 | } |
462 | else if ( encoding == RreEncoding ) { | 462 | else if ( encoding == RreEncoding ) { |
463 | qWarning( "RRE encoding" ); | 463 | qWarning( "RRE encoding" ); |
464 | handleRRERect(); | 464 | handleRRERect(); |
465 | } | 465 | } |
466 | else if ( encoding == CorreEncoding ) { | 466 | else if ( encoding == CorreEncoding ) { |
467 | qWarning( "CoRRE encoding" ); | 467 | qWarning( "CoRRE encoding" ); |
468 | handleCoRRERect(); | 468 | handleCoRRERect(); |
469 | } | 469 | } |
470 | else if ( encoding == HexTileEncoding ) { | 470 | else if ( encoding == HexTileEncoding ) { |
471 | qWarning( "HexTile encoding" ); | 471 | qWarning( "HexTile encoding" ); |
472 | handleHexTileRect(); | 472 | handleHexTileRect(); |
473 | } | 473 | } |
474 | else { | 474 | else { |
475 | int msg = Swap32IfLE( encoding ); | 475 | int msg = Swap32IfLE( encoding ); |
476 | QString protocolError = tr( "Protocol Error: An unknown encoding was " | 476 | QString protocolError = tr( "Protocol Error: An unknown encoding was " |
477 | "used by the server %1" ).arg( msg ); | 477 | "used by the server %1" ).arg( msg ); |
478 | currentState = Error; | 478 | currentState = Error; |
479 | qWarning( "Unknown encoding, %d", msg ); | 479 | qWarning( "Unknown encoding, %d", msg ); |
480 | emit error( protocolError ); | 480 | emit error( protocolError ); |
481 | return; | 481 | return; |
482 | } | 482 | } |
483 | } | 483 | } |
484 | 484 | ||
485 | // | 485 | // |
486 | // Raw Encoding | 486 | // Raw Encoding |
487 | // | 487 | // |
488 | 488 | ||
489 | void KRFBDecoder::handleRawRect() | 489 | void KRFBDecoder::handleRawRect() |
490 | { | 490 | { |
491 | // We need something a bit cleverer here to handle large | 491 | // We need something a bit cleverer here to handle large |
492 | // rectanges nicely. The chunking should be based on the | 492 | // rectanges nicely. The chunking should be based on the |
493 | // overall size (but has to be in complete lines). | 493 | // overall size (but has to be in complete lines). |
494 | 494 | ||
495 | // qWarning( "Handling a raw rect chunk" ); | 495 | // qWarning( "Handling a raw rect chunk" ); |
496 | 496 | ||
497 | // CARD32 lineCount = w * format->bpp / 8; | 497 | // CARD32 lineCount = w * format->bpp / 8; |
498 | 498 | ||
499 | if ( h > RectChunkSize ) { | 499 | if ( h > RectChunkSize ) { |
500 | // if ( con->sock->size() / lineCount ) { | 500 | // if ( con->sock->size() / lineCount ) { |
501 | // getRawRectChunk( con->sock->size() / lineCount ); | 501 | // getRawRectChunk( con->sock->size() / lineCount ); |
502 | // } | 502 | // } |
503 | // else { | 503 | // else { |
504 | getRawRectChunk( RectChunkSize ); | 504 | getRawRectChunk( RectChunkSize ); |
505 | // } | 505 | // } |
506 | } | 506 | } |
507 | else { | 507 | else { |
508 | getRawRectChunk( h ); | 508 | getRawRectChunk( h ); |
509 | } | 509 | } |
510 | } | 510 | } |
511 | 511 | ||
512 | void KRFBDecoder::getRawRectChunk( int lines ) | 512 | void KRFBDecoder::getRawRectChunk( int lines ) |
513 | { | 513 | { |
514 | this->lines = lines; | 514 | this->lines = lines; |
515 | CARD32 count = lines * w * format->bpp / 8; | 515 | CARD32 count = lines * w * format->bpp / 8; |
516 | 516 | ||
517 | // Wait for server init | 517 | // Wait for server init |
518 | // qWarning( "Waiting for raw rect chunk, %ld", count ); | 518 | // qWarning( "Waiting for raw rect chunk, %ld", count ); |
519 | 519 | ||
520 | currentState = AwaitingRawRectChunk; | 520 | currentState = AwaitingRawRectChunk; |
521 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 521 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
522 | con->waitForData( count ); | 522 | con->waitForData( count ); |
523 | } | 523 | } |
524 | 524 | ||
525 | void KRFBDecoder::gotRawRectChunk() | 525 | void KRFBDecoder::gotRawRectChunk() |
526 | { | 526 | { |
527 | assert( currentState == AwaitingRawRectChunk ); | 527 | assert( currentState == AwaitingRawRectChunk ); |
528 | 528 | ||
529 | disconnect( con, SIGNAL( gotEnoughData() ), | 529 | disconnect( con, SIGNAL( gotEnoughData() ), |
530 | this, SLOT( gotRawRectChunk() ) ); | 530 | this, SLOT( gotRawRectChunk() ) ); |
531 | 531 | ||
532 | // qWarning( "Got raw rect chunk" ); | 532 | // qWarning( "Got raw rect chunk" ); |
533 | 533 | ||
534 | // | 534 | // |
535 | // Read the rect data and copy it to the buffer. | 535 | // Read the rect data and copy it to the buffer. |
536 | // | 536 | // |
537 | 537 | ||
538 | // TODO: Replace this! | 538 | // TODO: Replace this! |
539 | int count = lines * w * format->bpp / 8; | 539 | int count = lines * w * format->bpp / 8; |
540 | char *hack = new char[ count ]; | 540 | char *hack = new char[ count ]; |
541 | con->read( hack, count ); | 541 | con->read( hack, count ); |
542 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 542 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
543 | delete hack; | 543 | delete hack; |
544 | // /TODO: | 544 | // /TODO: |
545 | 545 | ||
546 | h = h - lines; | 546 | h = h - lines; |
547 | y = y + lines; | 547 | y = y + lines; |
548 | 548 | ||
549 | if ( h > 0 ) { | 549 | if ( h > 0 ) { |
550 | handleRawRect(); | 550 | handleRawRect(); |
551 | } | 551 | } |
552 | else { | 552 | else { |
553 | noRects--; | 553 | noRects--; |
554 | 554 | ||
555 | // qWarning( "There are %d rects left", noRects ); | 555 | // qWarning( "There are %d rects left", noRects ); |
556 | 556 | ||
557 | if ( noRects ) { | 557 | if ( noRects ) { |
558 | currentState = AwaitingRectHeader; | 558 | currentState = AwaitingRectHeader; |
559 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 559 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
560 | con->waitForData( RectHeaderLength ); | 560 | con->waitForData( RectHeaderLength ); |
561 | } | 561 | } |
562 | else { | 562 | else { |
563 | // we are now ready for the next update - no need to wait for the timer | 563 | // we are now ready for the next update - no need to wait for the timer |
564 | currentState = Idle; | 564 | currentState = Idle; |
565 | sendUpdateRequest (1); | 565 | sendUpdateRequest (1); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | } | 568 | } |
569 | 569 | ||
570 | // | 570 | // |
571 | // Copy Rectangle Encoding | 571 | // Copy Rectangle Encoding |
572 | // | 572 | // |
573 | 573 | ||
574 | void KRFBDecoder::handleCopyRect() | 574 | void KRFBDecoder::handleCopyRect() |
575 | { | 575 | { |
576 | currentState = AwaitingCopyRectPos; | 576 | currentState = AwaitingCopyRectPos; |
577 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); | 577 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); |
578 | con->waitForData( CopyRectPosLength ); | 578 | con->waitForData( CopyRectPosLength ); |
579 | } | 579 | } |
580 | 580 | ||
581 | void KRFBDecoder::gotCopyRectPos() | 581 | void KRFBDecoder::gotCopyRectPos() |
582 | { | 582 | { |
583 | disconnect( con, SIGNAL( gotEnoughData() ), | 583 | disconnect( con, SIGNAL( gotEnoughData() ), |
584 | this, SLOT( gotCopyRectPos() ) ); | 584 | this, SLOT( gotCopyRectPos() ) ); |
585 | 585 | ||
586 | CARD16 srcX; | 586 | CARD16 srcX; |
587 | CARD16 srcY; | 587 | CARD16 srcY; |
588 | 588 | ||
589 | con->read( &srcX, 2 ); | 589 | con->read( &srcX, 2 ); |
590 | con->read( &srcY, 2 ); | 590 | con->read( &srcY, 2 ); |
591 | 591 | ||
592 | srcX = Swap16IfLE( srcX ); | 592 | srcX = Swap16IfLE( srcX ); |
593 | srcY = Swap16IfLE( srcY ); | 593 | srcY = Swap16IfLE( srcY ); |
594 | 594 | ||
595 | buf->copyRect( srcX, srcY, x, y, w, h ); | 595 | buf->copyRect( srcX, srcY, x, y, w, h ); |
596 | 596 | ||
597 | noRects--; | 597 | noRects--; |
598 | 598 | ||
599 | // qWarning( "There are %d rects left", noRects ); | 599 | // qWarning( "There are %d rects left", noRects ); |
600 | 600 | ||
601 | if ( noRects ) { | 601 | if ( noRects ) { |
602 | currentState = AwaitingRectHeader; | 602 | currentState = AwaitingRectHeader; |
603 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 603 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
604 | con->waitForData( RectHeaderLength ); | 604 | con->waitForData( RectHeaderLength ); |
605 | } | 605 | } |
606 | else | 606 | else |
607 | currentState = Idle; | 607 | currentState = Idle; |
608 | } | 608 | } |
609 | 609 | ||
610 | void KRFBDecoder::handleRRERect() | 610 | void KRFBDecoder::handleRRERect() |
611 | { | 611 | { |
612 | qWarning( "RRE not implemented" ); | 612 | qWarning( "RRE not implemented" ); |
613 | } | 613 | } |
614 | 614 | ||
615 | void KRFBDecoder::handleCoRRERect() | 615 | void KRFBDecoder::handleCoRRERect() |
616 | { | 616 | { |
617 | qWarning( "CoRRE not implemented" ); | 617 | qWarning( "CoRRE not implemented" ); |
618 | } | 618 | } |
619 | 619 | ||
620 | void KRFBDecoder::handleHexTileRect() | 620 | void KRFBDecoder::handleHexTileRect() |
621 | { | 621 | { |
622 | qWarning( "HexTile not implemented" ); | 622 | qWarning( "HexTile not implemented" ); |
623 | } | 623 | } |
624 | 624 | ||
625 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 625 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) |
626 | { | 626 | { |
627 | // Deal with the buttons | 627 | // Deal with the buttons |
628 | if ( e->type() != QEvent::MouseMove ) { | 628 | if ( e->type() != QEvent::MouseMove ) { |
629 | buttonMask = 0; | 629 | buttonMask = 0; |
630 | if ( e->type() == QEvent::MouseButtonPress ) { | 630 | if ( e->type() == QEvent::MouseButtonPress ) { |
631 | if ( e->button() & LeftButton ) | 631 | if ( e->button() & LeftButton ) |
632 | buttonMask |= 0x01; | 632 | buttonMask |= 0x01; |
633 | if ( e->button() & MidButton ) | 633 | if ( e->button() & MidButton ) |
634 | buttonMask |= 0x04; | 634 | buttonMask |= 0x04; |
635 | if ( e->button() & RightButton ) | 635 | if ( e->button() & RightButton ) |
636 | buttonMask |= 0x02; | 636 | buttonMask |= 0x02; |
637 | } | 637 | } |
638 | else if ( e->type() == QEvent::MouseButtonRelease ) { | 638 | else if ( e->type() == QEvent::MouseButtonRelease ) { |
639 | if ( e->button() & LeftButton ) | 639 | if ( e->button() & LeftButton ) |
640 | buttonMask &= 0x06; | 640 | buttonMask &= 0x06; |
641 | if ( e->button() & MidButton ) | 641 | if ( e->button() & MidButton ) |
642 | buttonMask |= 0x03; | 642 | buttonMask |= 0x03; |
643 | if ( e->button() & RightButton ) | 643 | if ( e->button() & RightButton ) |
644 | buttonMask |= 0x05; | 644 | buttonMask |= 0x05; |
645 | } | 645 | } |
646 | } | 646 | } |
647 | 647 | ||
648 | // HACK: Scaling | 648 | // HACK: Scaling |
649 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 649 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
650 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); | 650 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); |
651 | 651 | ||
652 | con->write( &PointerEventId, 1 ); | 652 | con->write( &PointerEventId, 1 ); |
653 | con->write( &buttonMask, 1 ); | 653 | con->write( &buttonMask, 1 ); |
654 | con->write( &x, 2 ); | 654 | con->write( &x, 2 ); |
655 | con->write( &y, 2 ); | 655 | con->write( &y, 2 ); |
656 | } | 656 | } |
657 | 657 | ||
658 | 658 | ||
659 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 659 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
660 | { | 660 | { |
661 | // | 661 | // |
662 | // Warning: There is a bug in the RFB protocol because there is no way to find | 662 | // Warning: There is a bug in the RFB protocol because there is no way to find |
663 | // out the codepage in use on the remote machine. This could be fixed by requiring | 663 | // out the codepage in use on the remote machine. This could be fixed by requiring |
664 | // the remote server to use utf8 etc. but for now we have to assume they're the | 664 | // the remote server to use utf8 etc. but for now we have to assume they're the |
665 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 665 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
666 | // immediate plans to fix the issue. :-( (rich) | 666 | // immediate plans to fix the issue. :-( (rich) |
667 | // | 667 | // |
668 | 668 | ||
669 | CARD8 padding[3]; | 669 | CARD8 padding[3]; |
670 | QCString text = unicode.local8Bit(); | 670 | QCString text = unicode.local8Bit(); |
671 | CARD32 length = text.length(); | 671 | CARD32 length = text.length(); |
672 | length = Swap32IfLE( length ); | 672 | length = Swap32IfLE( length ); |
673 | 673 | ||
674 | con->write( &ClientCutTextId, 1 ); | 674 | con->write( &ClientCutTextId, 1 ); |
675 | con->write( &padding, 3 ); | 675 | con->write( &padding, 3 ); |
676 | con->write( &length, 4 ); | 676 | con->write( &length, 4 ); |
677 | con->write( text.data(), length ); | 677 | con->write( text.data(), length ); |
678 | } | 678 | } |
679 | 679 | ||
680 | void KRFBDecoder::gotServerCut() | 680 | void KRFBDecoder::gotServerCut() |
681 | { | 681 | { |
682 | qWarning( "Got server cut" ); | 682 | qWarning( "Got server cut" ); |
683 | 683 | ||
684 | currentState = AwaitingServerCutLength; | 684 | currentState = AwaitingServerCutLength; |
685 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 685 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
686 | con->waitForData( ServerCutLenLength ); | 686 | con->waitForData( ServerCutLenLength ); |
687 | } | 687 | } |
688 | 688 | ||
689 | void KRFBDecoder::gotServerCutLength() | 689 | void KRFBDecoder::gotServerCutLength() |
690 | { | 690 | { |
691 | assert( currentState = AwaitingServerCutLength ); | 691 | assert( currentState = AwaitingServerCutLength ); |
692 | disconnect( con, SIGNAL( gotEnoughData() ), | 692 | disconnect( con, SIGNAL( gotEnoughData() ), |
693 | this, SLOT( gotServerCutLength() ) ); | 693 | this, SLOT( gotServerCutLength() ) ); |
694 | 694 | ||
695 | CARD8 padding[3]; | 695 | CARD8 padding[3]; |
696 | con->read( padding, 3 ); | 696 | con->read( padding, 3 ); |
697 | 697 | ||
698 | con->read( &serverCutTextLen, 4 ); | 698 | con->read( &serverCutTextLen, 4 ); |
699 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 699 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
700 | 700 | ||
701 | currentState = AwaitingServerCutText; | 701 | currentState = AwaitingServerCutText; |
702 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 702 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
703 | con->waitForData( serverCutTextLen ); | 703 | con->waitForData( serverCutTextLen ); |
704 | } | 704 | } |
705 | 705 | ||
706 | void KRFBDecoder::gotServerCutText() | 706 | void KRFBDecoder::gotServerCutText() |
707 | { | 707 | { |
708 | assert( currentState = AwaitingServerCutText ); | 708 | assert( currentState = AwaitingServerCutText ); |
709 | 709 | ||
710 | disconnect( con, SIGNAL( gotEnoughData() ), | 710 | disconnect( con, SIGNAL( gotEnoughData() ), |
711 | this, SLOT( gotServerCutText() ) ); | 711 | this, SLOT( gotServerCutText() ) ); |
712 | 712 | ||
713 | 713 | ||
714 | // | 714 | // |
715 | // Warning: There is a bug in the RFB protocol because there is no way to find | 715 | // Warning: There is a bug in the RFB protocol because there is no way to find |
716 | // out the codepage in use on the remote machine. This could be fixed by requiring | 716 | // out the codepage in use on the remote machine. This could be fixed by requiring |
717 | // the remote server to use utf8 etc. but for now we have to assume they're the | 717 | // the remote server to use utf8 etc. but for now we have to assume they're the |
718 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 718 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
719 | // immediate plans to fix the issue. :-( (rich) | 719 | // immediate plans to fix the issue. :-( (rich) |
720 | // | 720 | // |
721 | 721 | ||
722 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 722 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
723 | CHECK_PTR( cutbuf ); | 723 | CHECK_PTR( cutbuf ); |
724 | 724 | ||
725 | con->read( cutbuf, serverCutTextLen ); | 725 | con->read( cutbuf, serverCutTextLen ); |
726 | cutbuf[ serverCutTextLen ] = '\0'; | 726 | cutbuf[ serverCutTextLen ] = '\0'; |
727 | 727 | ||
728 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 728 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
729 | * from within keypebble's mass of signals and slots | 729 | * from within keypebble's mass of signals and slots |
730 | qWarning( "Server cut: %s", cutbuf ); | 730 | qWarning( "Server cut: %s", cutbuf ); |
731 | 731 | ||
732 | QString cutText( cutbuf ); // DANGER!! | 732 | QString cutText( cutbuf ); // DANGER!! |
733 | qApp->clipboard()->setText( cutText ); | 733 | qApp->clipboard()->setText( cutText ); |
734 | */ | 734 | */ |
735 | 735 | ||
736 | delete cutbuf; | 736 | delete cutbuf; |
737 | // Now wait for the update (again) | 737 | // Now wait for the update (again) |
738 | if ( oldState == AwaitingUpdate ) { | 738 | if ( oldState == AwaitingUpdate ) { |
739 | currentState = AwaitingUpdate; | 739 | currentState = AwaitingUpdate; |
740 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 740 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
741 | con->waitForData( UpdateHeaderLength ); | 741 | con->waitForData( UpdateHeaderLength ); |
742 | } | 742 | } |
743 | else if ( oldState == Idle ) { | 743 | else if ( oldState == Idle ) { |
744 | currentState = Idle; | 744 | currentState = Idle; |
745 | } | 745 | } |
746 | else { | 746 | else { |
747 | qWarning( "Async handled in weird state" ); | 747 | qWarning( "Async handled in weird state" ); |
748 | currentState = oldState; | 748 | currentState = oldState; |
749 | }; | 749 | }; |
750 | } | 750 | } |
751 | 751 | ||
752 | void KRFBDecoder::gotBell() | 752 | void KRFBDecoder::gotBell() |
753 | { | 753 | { |
754 | qWarning( "Got server bell" ); | 754 | qWarning( "Got server bell" ); |
755 | buf->soundBell(); | 755 | buf->soundBell(); |
756 | 756 | ||
757 | // Now wait for the update (again) | 757 | // Now wait for the update (again) |
758 | if ( oldState == AwaitingUpdate ) { | 758 | if ( oldState == AwaitingUpdate ) { |
759 | currentState = AwaitingUpdate; | 759 | currentState = AwaitingUpdate; |
760 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 760 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
761 | con->waitForData( UpdateHeaderLength ); | 761 | con->waitForData( UpdateHeaderLength ); |
762 | } | 762 | } |
763 | else if ( oldState == Idle ) { | 763 | else if ( oldState == Idle ) { |
764 | currentState = Idle; | 764 | currentState = Idle; |
765 | } | 765 | } |
766 | else { | 766 | else { |
767 | qWarning( "Async handled in weird state" ); | 767 | qWarning( "Async handled in weird state" ); |
768 | currentState = oldState; | 768 | currentState = oldState; |
769 | }; | 769 | }; |
770 | } | 770 | } |
771 | 771 | ||
772 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 772 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
773 | { | 773 | { |
774 | int key; | 774 | int key; |
775 | key = toKeySym( event ); | 775 | key = toKeySym( event ); |
776 | if ( key ) { | 776 | if ( key ) { |
777 | key = Swap32IfLE( key ); | 777 | key = Swap32IfLE( key ); |
778 | 778 | ||
779 | CARD8 mask = true; | 779 | CARD8 mask = true; |
780 | 780 | ||
781 | CARD16 padding = 0; | 781 | CARD16 padding = 0; |
782 | con->write( &KeyEventId, 1 ); | 782 | con->write( &KeyEventId, 1 ); |
783 | con->write( &mask, 1 ); | 783 | con->write( &mask, 1 ); |
784 | con->write( &padding, 2 ); | 784 | con->write( &padding, 2 ); |
785 | con->write( &key, 4 ); | 785 | con->write( &key, 4 ); |
786 | } | 786 | } |
787 | } | 787 | } |
788 | 788 | ||
789 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | 789 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) |
790 | { | 790 | { |
791 | int key; | 791 | int key; |
792 | key = toKeySym( event ); | 792 | key = toKeySym( event ); |
793 | if ( key ) { | 793 | if ( key ) { |
794 | key = Swap32IfLE( key ); | 794 | key = Swap32IfLE( key ); |
795 | 795 | ||
796 | CARD8 mask = false; | 796 | CARD8 mask = false; |
797 | 797 | ||
798 | CARD16 padding = 0; | 798 | CARD16 padding = 0; |
799 | con->write( &KeyEventId, 1 ); | 799 | con->write( &KeyEventId, 1 ); |
800 | con->write( &mask, 1 ); | 800 | con->write( &mask, 1 ); |
801 | con->write( &padding, 2 ); | 801 | con->write( &padding, 2 ); |
802 | con->write( &key, 4 ); | 802 | con->write( &key, 4 ); |
803 | } | 803 | } |
804 | } | 804 | } |
805 | 805 | ||
806 | 806 | ||
807 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 807 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
808 | { | 808 | { |
809 | int ke = 0; | 809 | int ke = 0; |
810 | 810 | ||
811 | ke = k->ascii(); | 811 | ke = k->ascii(); |
812 | // Markus: Crappy hack. I dont know why lower case letters are | 812 | // Markus: Crappy hack. I dont know why lower case letters are |
813 | // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. | 813 | // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. |
814 | // This sucks. :-( | 814 | // This sucks. :-( |
815 | 815 | ||
816 | if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') | 816 | if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') |
817 | || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') | 817 | || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') |
818 | || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') | 818 | || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') |
819 | || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') | 819 | || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') |
820 | || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') | 820 | || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') |
821 | || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') | 821 | || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') |
822 | || (ke == 'y') || (ke == 'z') ) { | 822 | || (ke == 'y') || (ke == 'z') ) { |
823 | ke = k->key(); | 823 | ke = k->key(); |
824 | ke = ke + 0x20; | 824 | ke = ke + 0x20; |
825 | return ke; | 825 | return ke; |
826 | } | 826 | } |
827 | 827 | ||
828 | // qkeydefs = xkeydefs! :-) | 828 | // qkeydefs = xkeydefs! :-) |
829 | if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) | 829 | if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) |
830 | return k->key(); | 830 | return k->key(); |
831 | 831 | ||
832 | if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) | 832 | if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) |
833 | return k->key(); | 833 | return k->key(); |
834 | 834 | ||
835 | // qkeydefs != xkeydefs! :-( | 835 | // qkeydefs != xkeydefs! :-( |
836 | // This is gonna suck :-( | 836 | // This is gonna suck :-( |
837 | 837 | ||
838 | int i = 0; | 838 | int i = 0; |
839 | while ( keyMap[i].keycode ) { | 839 | while ( keyMap[i].keycode ) { |
840 | if ( k->key() == keyMap[i].keycode ) | 840 | if ( k->key() == keyMap[i].keycode ) |
841 | return keyMap[i].keysym; | 841 | return keyMap[i].keysym; |
842 | i++; | 842 | i++; |
843 | } | 843 | } |
844 | 844 | ||
845 | return 0; | 845 | return 0; |
846 | } | 846 | } |
847 | 847 | ||