Changeset 48823 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Oct 2, 2013 3:27:22 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp
r48816 r48823 22 22 *******************************************************************************/ 23 23 #define LOG_GROUP LOG_GROUP_GUI 24 //#define VBOX_WITH_KBD_LEDS_SYNC24 #define VBOX_WITH_KBD_LEDS_SYNC 25 25 26 26 #include "DarwinKeyboard.h" … … 1270 1270 rc = kIOReturnError; 1271 1271 } 1272 1273 CFRelease(valueRef); 1272 1274 } 1273 1275 … … 1313 1315 rc2 = kIOReturnError; 1314 1316 } 1315 1316 } 1317 } 1318 1319 CFRelease(matchingElementsArrayRef); 1317 1320 } 1318 1321 … … 1359 1362 } 1360 1363 } 1364 1365 CFRelease(matchingElementsArrayRef); 1361 1366 } 1362 1367 … … 1372 1377 IOHIDElementRef pElementRef = IOHIDValueGetElement(valueRef); 1373 1378 1374 if (IOHIDElementGetUsagePage(pElementRef) == kHIDPage_KeyboardOrKeypad) /* Keyboard or keypad event */ 1375 if (IOHIDValueGetIntegerValue(valueRef) == 1) /* key has been pressed down */ 1376 if (IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeyboardCapsLock || /* CapsLock key has been pressed */ 1377 IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeypadNumLock) /* ... or NumLock key has been pressed */ 1378 { 1379 Log2(("A modifier key has been pressed\n")); 1380 g_LastTouchedState = (VBoxHidLeds_t *)pData; 1381 } 1379 if (pElementRef) 1380 { 1381 if (IOHIDElementGetUsagePage(pElementRef) == kHIDPage_KeyboardOrKeypad) /* Keyboard or keypad event */ 1382 if (IOHIDValueGetIntegerValue(valueRef) == 1) /* key has been pressed down */ 1383 if (IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeyboardCapsLock || /* CapsLock key has been pressed */ 1384 IOHIDElementGetUsage(pElementRef) == kHIDUsage_KeypadNumLock) /* ... or NumLock key has been pressed */ 1385 { 1386 Log2(("A modifier key has been pressed\n")); 1387 g_LastTouchedState = (VBoxHidLeds_t *)pData; 1388 } 1389 1390 } 1382 1391 } 1383 1392 … … 1462 1471 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), pState->pLoopSourceRef, kCFRunLoopDefaultMode); 1463 1472 CFRelease(pState->pLoopSourceRef); 1473 CFRelease(pState->pTapRef); 1464 1474 } 1465 1475 … … 1508 1518 VBoxHidsState_t *hidsState; 1509 1519 1510 hidsState = (VBoxHidsState_t *) RTMemAllocZ(sizeof(VBoxHidsState_t));1520 hidsState = (VBoxHidsState_t *)malloc(sizeof(VBoxHidsState_t)); 1511 1521 if (hidsState) 1512 1522 { … … 1514 1524 if (hidsState->hidManagerRef) 1515 1525 { 1516 1517 1526 CFDictionaryRef deviceMatchingDictRef = darwinGetLedDeviceMatchingDictionary(); 1518 1527 if (deviceMatchingDictRef) 1519 1528 { 1529 IOHIDManagerScheduleWithRunLoop(hidsState->hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 1520 1530 IOHIDManagerSetDeviceMatching(hidsState->hidManagerRef, deviceMatchingDictRef); 1521 1531 … … 1530 1540 /* Get all the available devices and cycle through them. */ 1531 1541 hidsState->cDevices = CFSetGetCount(hidDevicesSetRef); 1532 hidsState->hidDevicesCollection = (IOHIDDeviceRef *) RTMemAllocZ((size_t)hidsState->cDevices * sizeof(IOHIDDeviceRef));1542 hidsState->hidDevicesCollection = (IOHIDDeviceRef *)malloc((size_t)hidsState->cDevices * sizeof(IOHIDDeviceRef)); 1533 1543 if (hidsState->hidDevicesCollection) 1534 1544 { 1535 hidsState->hidLedsCollection = (VBoxHidLeds_t *) RTMemAllocZ((size_t)hidsState->cDevices * sizeof(VBoxHidLeds_t));1545 hidsState->hidLedsCollection = (VBoxHidLeds_t *)malloc((size_t)hidsState->cDevices * sizeof(VBoxHidLeds_t)); 1536 1546 if (hidsState->hidLedsCollection) 1537 1547 { … … 1571 1581 if (darwinAddCarbonGlobalKeyPressHandler(hidsState) == 0) 1572 1582 { 1583 CFRelease(hidDevicesSetRef); 1573 1584 CFRelease(deviceMatchingDictRef); 1574 1585 return hidsState; … … 1576 1587 } 1577 1588 1578 RTMemFree(hidsState->hidLedsCollection);1589 free(hidsState->hidLedsCollection); 1579 1590 } 1580 1591 1581 RTMemFree(hidsState->hidDevicesCollection);1592 free(hidsState->hidDevicesCollection); 1582 1593 } 1594 1595 CFRelease(hidDevicesSetRef); 1583 1596 } 1584 1597 … … 1594 1607 } 1595 1608 1596 RTMemFree(hidsState);1609 free(hidsState); 1597 1610 } 1598 1611 … … 1630 1643 { 1631 1644 /* Cycle through supported devices only. */ 1632 if (darwinHidDeviceSupported(hidsState->hidDevicesCollection[i])) 1645 if (IOHIDDeviceConformsTo(hidsState->hidDevicesCollection[i], kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard) 1646 && darwinHidDeviceSupported(hidsState->hidDevicesCollection[i])) 1633 1647 { 1634 1648 rc = darwinSetDeviceLedsState(hidsState->hidDevicesCollection[i], … … 1643 1657 } 1644 1658 1659 IOHIDDeviceUnscheduleFromRunLoop(hidsState->hidDevicesCollection[i], CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 1645 1660 IOHIDDeviceRegisterInputValueCallback(hidsState->hidDevicesCollection[i], NULL, NULL); 1646 IOHIDDeviceUnscheduleFromRunLoop(hidsState->hidDevicesCollection[i], CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);1647 1661 } 1648 1662 } 1663 1664 CFRelease(elementMatchingDict); 1649 1665 } 1650 1666 1651 1667 /* Free resources */ 1652 1668 1653 RTMemFree(hidsState->hidLedsCollection);1654 RTMemFree(hidsState->hidDevicesCollection);1669 free(hidsState->hidLedsCollection); 1670 free(hidsState->hidDevicesCollection); 1655 1671 1656 1672 rc = IOHIDManagerClose(hidsState->hidManagerRef, 0); … … 1658 1674 Log2(("Warning! Something went wrong in attempt to close HID device manager!\n")); 1659 1675 1676 IOHIDManagerUnscheduleFromRunLoop(hidsState->hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 1677 1660 1678 CFRelease(hidsState->hidManagerRef); 1661 1679 1662 RTMemFree(hidsState);1680 free(hidsState); 1663 1681 } 1664 1682 1665 1683 return rc2; 1666 #else / / !VBOX_WITH_KBD_LEDS_SYNC1684 #else /* !VBOX_WITH_KBD_LEDS_SYNC */ 1667 1685 (void)pState; 1668 1686 return 0; … … 1693 1711 if (deviceMatchingDictRef) 1694 1712 { 1713 IOHIDManagerScheduleWithRunLoop(hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 1695 1714 IOHIDManagerSetDeviceMatching(hidManagerRef, deviceMatchingDictRef); 1696 1715 … … 1705 1724 /* Get all the available devices and cycle through them. */ 1706 1725 CFIndex cDevices = CFSetGetCount(hidDevicesSetRef); 1707 IOHIDDeviceRef *hidDevicesCollection = (IOHIDDeviceRef *) RTMemAllocZ((size_t)cDevices * sizeof(IOHIDDeviceRef));1726 IOHIDDeviceRef *hidDevicesCollection = (IOHIDDeviceRef *)malloc((size_t)cDevices * sizeof(IOHIDDeviceRef)); 1708 1727 if (hidDevicesCollection) 1709 1728 { … … 1731 1750 } 1732 1751 1733 RTMemFree(hidDevicesCollection);1752 free(hidDevicesCollection); 1734 1753 } 1754 1755 CFRelease(hidDevicesSetRef); 1735 1756 } 1736 1757 … … 1740 1761 } 1741 1762 1763 IOHIDManagerUnscheduleFromRunLoop(hidManagerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 1764 1742 1765 CFRelease(deviceMatchingDictRef); 1743 1766 } … … 1745 1768 CFRelease(hidManagerRef); 1746 1769 } 1747 #else // !VBOX_WITH_KBD_LEDS_SYNC 1748 1770 #else /* !VBOX_WITH_KBD_LEDS_SYNC */ 1749 1771 (void)fNumLockOn; 1750 1772 (void)fCapsLockOn;
Note:
See TracChangeset
for help on using the changeset viewer.