Changeset 38649 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Sep 5, 2011 9:57:01 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c
r38596 r38649 138 138 139 139 /** The input device handle */ 140 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15) 141 static struct input_dev g_InputDevice; 142 #endif 140 143 static struct input_dev *g_pInputDevice = NULL; 141 144 /** Is the input device registered? */ … … 391 394 392 395 396 /** Calls the kernel IOCtl to report mouse status to the host on behalf of 397 * our kernel session. */ 393 398 static int vboxguestLinuxSetMouseStatus(uint32_t fStatus) 394 399 { … … 399 404 400 405 406 /** Called when the input device is first opened. Sets up absolute reporting. 407 */ 408 static int vboxguestOpenInputDevice(struct input_dev *pDev) 409 { 410 NOREF(pDev); 411 if (RT_FAILURE(vboxguestLinuxSetMouseStatus 412 ( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE 413 | VMMDEV_MOUSE_NEW_PROTOCOL))) 414 return ENODEV; 415 return 0; 416 } 417 418 419 /** Called if all open handles to the device are closed, disables absolute 420 * reporting. */ 421 static void vboxguestCloseInputDevice(struct input_dev *pDev) 422 { 423 NOREF(pDev); 424 vboxguestLinuxSetMouseStatus(0); 425 } 426 427 401 428 /** 402 429 * Creates the kernel input device. … … 404 431 static int __init vboxguestLinuxCreateInputDevice(void) 405 432 { 406 int rc; 407 433 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 29) 434 # define INPUT_DEV_ID(val) id.val 435 #else 436 # define INPUT_DEV_ID(val) id##val 437 #endif 438 439 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15) 408 440 g_pInputDevice = input_allocate_device(); 409 441 if (!g_pInputDevice) 410 442 return -ENOMEM; 411 g_pInputDevice->id.bustype = BUS_PCI; 412 g_pInputDevice->id.vendor = VMMDEV_VENDORID; 413 g_pInputDevice->id.product = VMMDEV_DEVICEID; 414 g_pInputDevice->id.version = (VBOX_VERSION_MAJOR << 11) 415 + (VBOX_VERSION_MINOR << 6) 416 + VBOX_VERSION_BUILD; /** @todo */ 443 g_pInputDevice->INPUT_DEV_ID(bustype) = BUS_PCI; 444 #else 445 g_pInputDevice = &g_InputDevice; 446 g_pInputDevice->INPUT_DEV_ID(bus) = BUS_PCI; 447 #endif 448 g_pInputDevice->INPUT_DEV_ID(vendor) = VMMDEV_VENDORID; 449 g_pInputDevice->INPUT_DEV_ID(product) = VMMDEV_DEVICEID; 450 g_pInputDevice->INPUT_DEV_ID(version) = (VBOX_VERSION_MAJOR << 11) 451 + (VBOX_VERSION_MINOR << 6) 452 + VBOX_VERSION_BUILD; /** @todo */ 453 g_pInputDevice->open = vboxguestOpenInputDevice; 454 g_pInputDevice->close = vboxguestCloseInputDevice; 417 455 /** @todo parent (PCI?) device in device model view. */ 418 456 /* g_pInputDevice->dev.parent = */ 419 rc = input_register_device(g_pInputDevice); 420 if (!rc) 421 g_fInputDeviceRegistered = true; 422 else 423 return rc; 457 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15) 458 { 459 int rc = input_register_device(g_pInputDevice); 460 if (rc) 461 { 462 input_free_device(g_pInputDevice); 463 return rc; 464 } 465 } 466 #else 467 input_register_device(g_pInputDevice); 468 #endif 424 469 /* Do what one of our competitors apparently does as that works. */ 425 g_pInputDevice->evbit[0] = RT_BIT(EV_ABS) | RT_BIT(EV_KEY); 426 __set_bit(BTN_MOUSE, g_pInputDevice->keybit); 470 ASMBitSet(g_pInputDevice->evbit, EV_ABS); 471 ASMBitSet(g_pInputDevice->evbit, EV_KEY); 472 #ifdef EV_SYN 473 ASMBitSet(g_pInputDevice->evbit, EV_SYN); 474 #endif 475 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7) 427 476 input_set_abs_params(g_pInputDevice, ABS_X, RANGE_MIN, RANGE_MAX, 0, 0); 428 477 input_set_abs_params(g_pInputDevice, ABS_Y, RANGE_MIN, RANGE_MAX, 0, 0); 478 #else 479 ASMBitSet(g_pInputDevice->absbit, ABS_X); 480 ASMBitSet(g_pInputDevice->absbit, ABS_Y); 481 ASMBitSet(g_pInputDevice->keybit, BTN_MOUSE); 482 g_pInputDevice->absmin[ABS_X] = g_pInputDevice->absmin[ABS_Y] = RANGE_MIN; 483 g_pInputDevice->absmax[ABS_X] = g_pInputDevice->absmax[ABS_Y] = RANGE_MAX; 484 #endif 429 485 /** @todo this string should be in a header file somewhere. */ 430 486 g_pInputDevice->name = "VirtualBox mouse integration"; 431 vboxguestLinuxSetMouseStatus( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE 432 | VMMDEV_MOUSE_NEW_PROTOCOL); 433 return rc; 487 return 0; 488 #undef INPUT_DEV_ID 434 489 } 435 490 … … 440 495 static void vboxguestLinuxTermInputDevice(void) 441 496 { 442 vboxguestLinuxSetMouseStatus(0); 443 if (g_fInputDeviceRegistered) 497 if (g_pInputDevice) 444 498 { 445 499 input_unregister_device(g_pInputDevice); 446 g_fInputDeviceRegistered = false; 447 } 448 if (g_pInputDevice) 449 { 500 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15) 450 501 input_free_device(g_pInputDevice); 502 #endif 451 503 g_pInputDevice = NULL; 452 504 } … … 900 952 input_report_abs(g_pInputDevice, ABS_X, pReq->pointerXPos); 901 953 input_report_abs(g_pInputDevice, ABS_Y, pReq->pointerYPos); 954 #ifdef EV_SYN 955 input_sync(g_pInputDevice); 956 #endif 902 957 VbglGRFree(&pReq->header); 903 958 }
Note:
See TracChangeset
for help on using the changeset viewer.