@@ -1031,6 +1031,35 @@ export default class RFB extends EventTargetMixin {
1031
1031
this . sendKey ( keysym , code , down ) ;
1032
1032
}
1033
1033
1034
+ static _convertButtonMask ( buttons ) {
1035
+ /* The bits in MouseEvent.buttons property correspond
1036
+ * to the following mouse buttons:
1037
+ * 0: Left
1038
+ * 1: Right
1039
+ * 2: Middle
1040
+ * 3: Back
1041
+ * 4: Forward
1042
+ *
1043
+ * These bits needs to be converted to what they are defined as
1044
+ * in the RFB protocol.
1045
+ */
1046
+
1047
+ const buttonMaskMap = {
1048
+ 0 : 1 << 0 , // Left
1049
+ 1 : 1 << 2 , // Right
1050
+ 2 : 1 << 1 , // Middle
1051
+ 3 : 1 << 7 , // Back
1052
+ } ;
1053
+
1054
+ let bmask = 0 ;
1055
+ for ( let i = 0 ; i < 4 ; i ++ ) {
1056
+ if ( buttons & ( 1 << i ) ) {
1057
+ bmask |= buttonMaskMap [ i ] ;
1058
+ }
1059
+ }
1060
+ return bmask ;
1061
+ }
1062
+
1034
1063
_handleMouse ( ev ) {
1035
1064
/*
1036
1065
* We don't check connection status or viewOnly here as the
@@ -1060,15 +1089,15 @@ export default class RFB extends EventTargetMixin {
1060
1089
let pos = clientToElement ( ev . clientX , ev . clientY ,
1061
1090
this . _canvas ) ;
1062
1091
1092
+ let bmask = RFB . _convertButtonMask ( ev . buttons ) ;
1093
+
1063
1094
switch ( ev . type ) {
1064
1095
case 'mousedown' :
1065
1096
setCapture ( this . _canvas ) ;
1066
- this . _handleMouseButton ( pos . x , pos . y ,
1067
- true , 1 << ev . button ) ;
1097
+ this . _handleMouseButton ( pos . x , pos . y , true , bmask ) ;
1068
1098
break ;
1069
1099
case 'mouseup' :
1070
- this . _handleMouseButton ( pos . x , pos . y ,
1071
- false , 1 << ev . button ) ;
1100
+ this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1072
1101
break ;
1073
1102
case 'mousemove' :
1074
1103
this . _handleMouseMove ( pos . x , pos . y ) ;
@@ -1097,7 +1126,7 @@ export default class RFB extends EventTargetMixin {
1097
1126
// Otherwise we treat this as a mouse click event.
1098
1127
// Send the button down event here, as the button up
1099
1128
// event is sent at the end of this function.
1100
- this . _sendMouse ( x , y , bmask ) ;
1129
+ this . _sendMouse ( x , y , this . _mouseButtonMask ) ;
1101
1130
}
1102
1131
}
1103
1132
@@ -1108,12 +1137,7 @@ export default class RFB extends EventTargetMixin {
1108
1137
this . _sendMouse ( x , y , this . _mouseButtonMask ) ;
1109
1138
}
1110
1139
1111
- if ( down ) {
1112
- this . _mouseButtonMask |= bmask ;
1113
- } else {
1114
- this . _mouseButtonMask &= ~ bmask ;
1115
- }
1116
-
1140
+ this . _mouseButtonMask = bmask ;
1117
1141
this . _sendMouse ( x , y , this . _mouseButtonMask ) ;
1118
1142
}
1119
1143
@@ -1177,6 +1201,7 @@ export default class RFB extends EventTargetMixin {
1177
1201
let pos = clientToElement ( ev . clientX , ev . clientY ,
1178
1202
this . _canvas ) ;
1179
1203
1204
+ let bmask = RFB . _convertButtonMask ( ev . buttons ) ;
1180
1205
let dX = ev . deltaX ;
1181
1206
let dY = ev . deltaY ;
1182
1207
@@ -1196,26 +1221,27 @@ export default class RFB extends EventTargetMixin {
1196
1221
this . _accumulatedWheelDeltaX += dX ;
1197
1222
this . _accumulatedWheelDeltaY += dY ;
1198
1223
1224
+
1199
1225
// Generate a mouse wheel step event when the accumulated delta
1200
1226
// for one of the axes is large enough.
1201
1227
if ( Math . abs ( this . _accumulatedWheelDeltaX ) >= WHEEL_STEP ) {
1202
1228
if ( this . _accumulatedWheelDeltaX < 0 ) {
1203
- this . _handleMouseButton ( pos . x , pos . y , true , 1 << 5 ) ;
1204
- this . _handleMouseButton ( pos . x , pos . y , false , 1 << 5 ) ;
1229
+ this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 5 ) ;
1230
+ this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1205
1231
} else if ( this . _accumulatedWheelDeltaX > 0 ) {
1206
- this . _handleMouseButton ( pos . x , pos . y , true , 1 << 6 ) ;
1207
- this . _handleMouseButton ( pos . x , pos . y , false , 1 << 6 ) ;
1232
+ this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 6 ) ;
1233
+ this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1208
1234
}
1209
1235
1210
1236
this . _accumulatedWheelDeltaX = 0 ;
1211
1237
}
1212
1238
if ( Math . abs ( this . _accumulatedWheelDeltaY ) >= WHEEL_STEP ) {
1213
1239
if ( this . _accumulatedWheelDeltaY < 0 ) {
1214
- this . _handleMouseButton ( pos . x , pos . y , true , 1 << 3 ) ;
1215
- this . _handleMouseButton ( pos . x , pos . y , false , 1 << 3 ) ;
1240
+ this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 3 ) ;
1241
+ this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1216
1242
} else if ( this . _accumulatedWheelDeltaY > 0 ) {
1217
- this . _handleMouseButton ( pos . x , pos . y , true , 1 << 4 ) ;
1218
- this . _handleMouseButton ( pos . x , pos . y , false , 1 << 4 ) ;
1243
+ this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 4 ) ;
1244
+ this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1219
1245
}
1220
1246
1221
1247
this . _accumulatedWheelDeltaY = 0 ;
@@ -1255,7 +1281,7 @@ export default class RFB extends EventTargetMixin {
1255
1281
1256
1282
this . _fakeMouseMove ( this . _gestureFirstDoubleTapEv , pos . x , pos . y ) ;
1257
1283
this . _handleMouseButton ( pos . x , pos . y , true , bmask ) ;
1258
- this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1284
+ this . _handleMouseButton ( pos . x , pos . y , false , 0x0 ) ;
1259
1285
}
1260
1286
1261
1287
_handleGesture ( ev ) {
@@ -1313,23 +1339,23 @@ export default class RFB extends EventTargetMixin {
1313
1339
// every update.
1314
1340
this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1315
1341
while ( ( ev . detail . magnitudeY - this . _gestureLastMagnitudeY ) > GESTURE_SCRLSENS ) {
1316
- this . _handleMouseButton ( pos . x , pos . y , true , 0x8 ) ;
1317
- this . _handleMouseButton ( pos . x , pos . y , false , 0x8 ) ;
1342
+ this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x8 ) ;
1343
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x8 ) ;
1318
1344
this . _gestureLastMagnitudeY += GESTURE_SCRLSENS ;
1319
1345
}
1320
1346
while ( ( ev . detail . magnitudeY - this . _gestureLastMagnitudeY ) < - GESTURE_SCRLSENS ) {
1321
- this . _handleMouseButton ( pos . x , pos . y , true , 0x10 ) ;
1322
- this . _handleMouseButton ( pos . x , pos . y , false , 0x10 ) ;
1347
+ this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x10 ) ;
1348
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x10 ) ;
1323
1349
this . _gestureLastMagnitudeY -= GESTURE_SCRLSENS ;
1324
1350
}
1325
1351
while ( ( ev . detail . magnitudeX - this . _gestureLastMagnitudeX ) > GESTURE_SCRLSENS ) {
1326
- this . _handleMouseButton ( pos . x , pos . y , true , 0x20 ) ;
1327
- this . _handleMouseButton ( pos . x , pos . y , false , 0x20 ) ;
1352
+ this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x20 ) ;
1353
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x20 ) ;
1328
1354
this . _gestureLastMagnitudeX += GESTURE_SCRLSENS ;
1329
1355
}
1330
1356
while ( ( ev . detail . magnitudeX - this . _gestureLastMagnitudeX ) < - GESTURE_SCRLSENS ) {
1331
- this . _handleMouseButton ( pos . x , pos . y , true , 0x40 ) ;
1332
- this . _handleMouseButton ( pos . x , pos . y , false , 0x40 ) ;
1357
+ this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x40 ) ;
1358
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x40 ) ;
1333
1359
this . _gestureLastMagnitudeX -= GESTURE_SCRLSENS ;
1334
1360
}
1335
1361
break ;
@@ -1342,13 +1368,13 @@ export default class RFB extends EventTargetMixin {
1342
1368
if ( Math . abs ( magnitude - this . _gestureLastMagnitudeX ) > GESTURE_ZOOMSENS ) {
1343
1369
this . _handleKeyEvent ( KeyTable . XK_Control_L , "ControlLeft" , true ) ;
1344
1370
while ( ( magnitude - this . _gestureLastMagnitudeX ) > GESTURE_ZOOMSENS ) {
1345
- this . _handleMouseButton ( pos . x , pos . y , true , 0x8 ) ;
1346
- this . _handleMouseButton ( pos . x , pos . y , false , 0x8 ) ;
1371
+ this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x8 ) ;
1372
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x8 ) ;
1347
1373
this . _gestureLastMagnitudeX += GESTURE_ZOOMSENS ;
1348
1374
}
1349
1375
while ( ( magnitude - this . _gestureLastMagnitudeX ) < - GESTURE_ZOOMSENS ) {
1350
- this . _handleMouseButton ( pos . x , pos . y , true , 0x10 ) ;
1351
- this . _handleMouseButton ( pos . x , pos . y , false , 0x10 ) ;
1376
+ this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x10 ) ;
1377
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x10 ) ;
1352
1378
this . _gestureLastMagnitudeX -= GESTURE_ZOOMSENS ;
1353
1379
}
1354
1380
}
@@ -1367,11 +1393,11 @@ export default class RFB extends EventTargetMixin {
1367
1393
break ;
1368
1394
case 'drag' :
1369
1395
this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1370
- this . _handleMouseButton ( pos . x , pos . y , false , 0x1 ) ;
1396
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x1 ) ;
1371
1397
break ;
1372
1398
case 'longpress' :
1373
1399
this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1374
- this . _handleMouseButton ( pos . x , pos . y , false , 0x4 ) ;
1400
+ this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x4 ) ;
1375
1401
break ;
1376
1402
}
1377
1403
break ;
@@ -2941,6 +2967,7 @@ export default class RFB extends EventTargetMixin {
2941
2967
"raw" , passwordChars , { name : "DES-ECB" } , false , [ "encrypt" ] ) ;
2942
2968
return legacyCrypto . encrypt ( { name : "DES-ECB" } , key , challenge ) ;
2943
2969
}
2970
+
2944
2971
}
2945
2972
2946
2973
// Class Methods
0 commit comments