Changeset 29374 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 11, 2010 4:16:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/X11/keyboard-new.c
r26714 r29374 401 401 } 402 402 403 static int checkHostKeycode(unsigned hostCode, unsigned targetCode) 404 { 405 if (!targetCode) 406 return 0; 407 if (hostCode && hostCode != targetCode) 408 return 0; 409 return 1; 410 } 411 412 static int compKBMaps(const keyboard_type *pHost, const keyboard_type *pTarget) 413 { 414 if ( !pHost->lctrl && !pHost->capslock && !pHost->lshift && !pHost->tab 415 && !pHost->esc && !pHost->enter && !pHost->up && !pHost->down 416 && !pHost->left && !pHost->right && !pHost->f1 && !pHost->f2 417 && !pHost->f3 && !pHost->f4 && !pHost->f5 && !pHost->f6 && !pHost->f7 418 && !pHost->f8) 419 return 0; 420 /* This test is for the people who like to swap control and caps lock */ 421 if ( ( !checkHostKeycode(pHost->lctrl, pTarget->lctrl) 422 || !checkHostKeycode(pHost->capslock, pTarget->capslock)) 423 && ( !checkHostKeycode(pHost->lctrl, pTarget->capslock) 424 || !checkHostKeycode(pHost->capslock, pTarget->lctrl))) 425 return 0; 426 if ( !checkHostKeycode(pHost->lshift, pTarget->lshift) 427 || !checkHostKeycode(pHost->tab, pTarget->tab) 428 || !checkHostKeycode(pHost->esc, pTarget->esc) 429 || !checkHostKeycode(pHost->enter, pTarget->enter) 430 || !checkHostKeycode(pHost->up, pTarget->up) 431 || !checkHostKeycode(pHost->down, pTarget->down) 432 || !checkHostKeycode(pHost->left, pTarget->left) 433 || !checkHostKeycode(pHost->right, pTarget->right) 434 || !checkHostKeycode(pHost->f1, pTarget->f1) 435 || !checkHostKeycode(pHost->f2, pTarget->f2) 436 || !checkHostKeycode(pHost->f3, pTarget->f3) 437 || !checkHostKeycode(pHost->f4, pTarget->f4) 438 || !checkHostKeycode(pHost->f5, pTarget->f5) 439 || !checkHostKeycode(pHost->f6, pTarget->f6) 440 || !checkHostKeycode(pHost->f7, pTarget->f7) 441 || !checkHostKeycode(pHost->f8, pTarget->f8)) 442 return 0; 443 return 1; 444 } 445 446 static int findHostKBInList(const keyboard_type *pHost, 447 const keyboard_type *pList, int cList) 448 { 449 int i = 0; 450 for (; i < cList; ++i) 451 if (compKBMaps(pHost, &pList[i])) 452 return i; 453 return -1; 454 } 455 456 #ifdef DEBUG 457 static void testFindHostKB(void) 458 { 459 keyboard_type hostBasic = 460 { NULL, 1 /* lctrl */, 2, 3, 4, 5, 6, 7 /* up */, 8, 9, 10, 11 /* F1 */, 461 12, 13, 14, 15, 16, 17, 18 }; 462 keyboard_type hostSwapCtrlCaps = 463 { NULL, 3 /* lctrl */, 2, 1, 4, 5, 6, 7 /* up */, 8, 9, 10, 11 /* F1 */, 464 12, 13, 14, 15, 16, 17, 18 }; 465 keyboard_type hostEmpty = 466 { NULL, 0 /* lctrl */, 0, 0, 0, 0, 0, 0 /* up */, 0, 0, 0, 0 /* F1 */, 467 0, 0, 0, 0, 0, 0, 0 }; 468 keyboard_type hostNearlyEmpty = 469 { NULL, 1 /* lctrl */, 0, 0, 0, 0, 0, 0 /* up */, 0, 0, 0, 0 /* F1 */, 470 0, 0, 0, 0, 0, 0, 18 }; 471 keyboard_type hostNearlyRight = 472 { NULL, 20 /* lctrl */, 2, 3, 4, 5, 6, 7 /* up */, 8, 9, 10, 11 /* F1 */, 473 12, 13, 14, 15, 16, 17, 18 }; 474 keyboard_type targetList[] = { 475 { NULL, 18 /* lctrl */, 17, 16, 15, 14, 13, 12 /* up */, 11, 10, 9, 476 8 /* F1 */, 7, 6, 5, 4, 3, 2, 1 }, 477 { NULL, 1 /* lctrl */, 2, 3, 4, 5, 6, 7 /* up */, 8, 9, 10, 478 11 /* F1 */, 12, 13, 14, 15, 16, 17, 18 } 479 }; 480 481 /* As we don't have assertions here, just printf. This should *really* 482 * never happen. */ 483 if ( hostBasic.f8 != 18 || hostSwapCtrlCaps.f8 != 18 484 || hostNearlyEmpty.f8 != 18 || hostNearlyRight.f8 != 18 485 || targetList[0].f8 != 1 || targetList[1].f8 != 18) 486 printf("ERROR: testFindHostKB: bad structures\n"); 487 if (findHostKBInList(&hostBasic, targetList, 2) != 1) 488 printf("ERROR: findHostKBInList failed to find a target in a list\n"); 489 if (findHostKBInList(&hostSwapCtrlCaps, targetList, 2) != 1) 490 printf("ERROR: findHostKBInList failed on a ctrl-caps swapped map\n"); 491 if (findHostKBInList(&hostEmpty, targetList, 2) != -1) 492 printf("ERROR: findHostKBInList accepted an empty host map\n"); 493 if (findHostKBInList(&hostNearlyEmpty, targetList, 2) != 1) 494 printf("ERROR: findHostKBInList failed on a partly empty host map\n"); 495 if (findHostKBInList(&hostNearlyRight, targetList, 2) != -1) 496 printf("ERROR: findHostKBInList failed to fail a wrong host map\n"); 497 } 498 #endif 499 403 500 static unsigned 404 501 X11DRV_InitKeyboardByType(Display *display) 405 502 { 406 unsigned i = 0, found = 0;407 408 503 keyboard_type hostKB; 409 memset(&hostKB, '\0', sizeof(hostKB)); 504 int cMap; 505 410 506 hostKB.lctrl = XKeysymToKeycode(display, XK_Control_L); 411 507 hostKB.capslock = XKeysymToKeycode(display, XK_Caps_Lock); … … 427 523 hostKB.f8 = XKeysymToKeycode(display, XK_F8); 428 524 429 for (; (main_keyboard_type_list[i].comment != NULL) && (0 == found); ++i) 525 #ifdef DEBUG 526 testFindHostKB(); 527 #endif 528 cMap = findHostKBInList(&hostKB, main_keyboard_type_list, 529 sizeof(main_keyboard_type_list) 530 / sizeof(main_keyboard_type_list[0])); 531 if (cMap >= 0) 430 532 { 431 keyboard_type *pType = &main_keyboard_type_list[i]; 432 if ( ( ( (pType->lctrl && (hostKB.lctrl == pType->lctrl)) 433 && (pType->capslock && (hostKB.capslock == pType->capslock)) 434 ) 435 || ( (pType->lctrl && (hostKB.capslock == pType->lctrl)) 436 && (pType->capslock && (hostKB.lctrl == pType->capslock)) 437 ) 438 ) /* Some people like to switch Capslock and left Ctrl */ 439 && (pType->lshift && (hostKB.lshift == pType->lshift)) 440 && (pType->tab && (hostKB.tab == pType->tab)) 441 && (pType->esc && (hostKB.esc == pType->esc)) 442 && (pType->enter && (hostKB.enter == pType->enter)) 443 && (pType->up && (hostKB.up == pType->up)) 444 && (pType->down && (hostKB.down == pType->down)) 445 && (pType->left && (hostKB.left == pType->left)) 446 && (pType->right && (hostKB.right == pType->right)) 447 && (pType->f1 && (hostKB.f1 == pType->f1)) 448 && (pType->f2 && (hostKB.f2 == pType->f2)) 449 && (pType->f3 && (hostKB.f3 == pType->f3)) 450 && (pType->f4 && (hostKB.f4 == pType->f4)) 451 && (pType->f5 && (hostKB.f5 == pType->f5)) 452 && (pType->f6 && (hostKB.f6 == pType->f6)) 453 && (pType->f7 && (hostKB.f7 == pType->f7)) 454 && (pType->f8 && (hostKB.f8 == pType->f8)) 455 ) 456 found = 1; 457 } 458 if (found != 0) 459 memcpy(keyc2scan, main_keyboard_type_scans[i - 1], KEYC2SCAN_SIZE); 460 return found; 533 memcpy(keyc2scan, main_keyboard_type_scans[cMap - 1], KEYC2SCAN_SIZE); 534 return 1; 535 } 536 return 0; 461 537 } 462 538
Note:
See TracChangeset
for help on using the changeset viewer.