Index: /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp	(revision 71658)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.cpp	(revision 71659)
@@ -1,11 +1,9 @@
 /* $Id$ */
 /** @file
- * Common GUI Library - Darwin Keyboard routines.
- *
- * @todo Move this up somewhere so that the two SDL GUIs can use parts of this code too (-HID stuff).
+ * VBox Qt GUI - Declarations of utility functions for handling Darwin Keyboard specific tasks.
  */
 
 /*
- * Copyright (C) 2006-2017 Oracle Corporation
+ * Copyright (C) 2006-2018 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,48 +16,46 @@
  */
 
-
-/*********************************************************************************************************************************
-*   Header Files                                                                                                                 *
-*********************************************************************************************************************************/
+/* Defines: */
 #define LOG_GROUP LOG_GROUP_GUI
-
 #define VBOX_WITH_KBD_LEDS_SYNC
 //#define VBOX_WITHOUT_KBD_LEDS_SYNC_FILTERING
 
+/* GUI includes: */
 #include "DarwinKeyboard.h"
+#ifndef USE_HID_FOR_MODIFIERS
+# include "CocoaEventHelper.h"
+#endif
+
+/* Other VBox includes: */
 #include <iprt/assert.h>
 #include <iprt/asm.h>
+#include <iprt/mem.h>
 #include <iprt/time.h>
-#include <iprt/mem.h>
 #include <VBox/log.h>
 #ifdef DEBUG_PRINTF
 # include <iprt/stream.h>
 #endif
-
 #ifdef VBOX_WITH_KBD_LEDS_SYNC
 # include <iprt/err.h>
 # include <iprt/semaphore.h>
 # include <VBox/sup.h>
+#endif
+
+/* External includes: */
+#include <ApplicationServices/ApplicationServices.h>
+#include <Carbon/Carbon.h>
+#include <IOKit/IOCFPlugIn.h>
+#include <IOKit/IOKitLib.h>
+#include <IOKit/hid/IOHIDLib.h>
+#include <IOKit/usb/USB.h>
+#ifdef USE_HID_FOR_MODIFIERS
+# include <CoreFoundation/CoreFoundation.h>
+# include <IOKit/hid/IOHIDUsageTables.h>
+# include <mach/mach.h>
+# include <mach/mach_error.h>
+#endif
+#ifdef VBOX_WITH_KBD_LEDS_SYNC
 # include <IOKit/IOMessage.h>
 # include <IOKit/usb/IOUSBLib.h>
-# include <IOKit/IOMessage.h>
-#endif
-
-#ifdef USE_HID_FOR_MODIFIERS
-# include <mach/mach.h>
-# include <mach/mach_error.h>
-# include <IOKit/hid/IOHIDUsageTables.h>
-# include <CoreFoundation/CoreFoundation.h>
-#endif
-
-#include <IOKit/IOKitLib.h>
-#include <IOKit/IOCFPlugIn.h>
-#include <IOKit/usb/USB.h>
-#include <IOKit/hid/IOHIDLib.h>
-#include <ApplicationServices/ApplicationServices.h>
-#include <Carbon/Carbon.h>
-
-#ifndef USE_HID_FOR_MODIFIERS
-# include "CocoaEventHelper.h"
 #endif
 
@@ -81,8 +77,5 @@
 
 
-/*********************************************************************************************************************************
-*   Defined Constants And Macros                                                                                                 *
-*********************************************************************************************************************************/
-
+/* Defined Constants And Macros: */
 #define QZ_RMETA        0x36
 #define QZ_LMETA        0x37
@@ -94,39 +87,29 @@
 #define QZ_RALT         0x3D
 #define QZ_RCTRL        0x3E
-/* Found the definition of the fn-key in:
- * http://stuff.mit.edu/afs/sipb/project/darwin/src/modules/IOHIDFamily/IOHIDSystem/IOHIKeyboardMapper.cpp &
- * http://stuff.mit.edu/afs/sipb/project/darwin/src/modules/AppleADBKeyboard/AppleADBKeyboard.cpp
- * Maybe we need this in the future.*/
+// Found the definition of the fn-key in:
+// http://stuff.mit.edu/afs/sipb/project/darwin/src/modules/IOHIDFamily/IOHIDSystem/IOHIKeyboardMapper.cpp &
+// http://stuff.mit.edu/afs/sipb/project/darwin/src/modules/AppleADBKeyboard/AppleADBKeyboard.cpp
+// Maybe we need this in the future.
 #define QZ_FN           0x3F
 #define QZ_NUMLOCK      0x47
-
-/** short hand for an extended key. */
+/** Short hand for an extended key. */
 #define K_EX            VBOXKEY_EXTENDED
-/** short hand for a modifier key. */
+/** Short hand for a modifier key. */
 #define K_MOD           VBOXKEY_MODIFIER
-/** short hand for a lock key. */
+/** Short hand for a lock key. */
 #define K_LOCK          VBOXKEY_LOCK
-
 #ifdef USE_HID_FOR_MODIFIERS
-
 /** An attempt at catching reference leaks. */
-#define MY_CHECK_CREFS(cRefs)   do { AssertMsg(cRefs < 25, ("%ld\n", cRefs)); NOREF(cRefs); } while (0)
-
+# define MY_CHECK_CREFS(cRefs)   do { AssertMsg(cRefs < 25, ("%ld\n", cRefs)); NOREF(cRefs); } while (0)
 #endif
 
 
-/*********************************************************************************************************************************
-*   Global Variables                                                                                                             *
-*********************************************************************************************************************************/
-/**
- * This is derived partially from SDL_QuartzKeys.h and partially from testing.
- *
- * (The funny thing about the virtual scan codes on the mac is that they aren't
- * offically documented, which is rather silly to say the least. Thus, the need
- * for looking at SDL and other odd places for docs.)
- */
+/** This is derived partially from SDL_QuartzKeys.h and partially from testing.
+  * (The funny thing about the virtual scan codes on the mac is that they aren't
+  * offically documented, which is rather silly to say the least. Thus, the need
+  * for looking at SDL and other odd places for docs.) */
 static const uint16_t g_aDarwinToSet1[] =
 {
- /*  set-1                           SDL_QuartzKeys.h    */
+    /* set-1                           SDL_QuartzKeys.h */
     0x1e,                       /* QZ_a            0x00 */
     0x1f,                       /* QZ_s            0x01 */
@@ -263,7 +246,7 @@
 
 
-/** Whether we've connected or not. */
+/** Holds whether we've connected or not. */
 static bool g_fConnectedToCGS = false;
-/** Cached connection. */
+/** Holds the cached connection. */
 static CGSConnection g_CGSConnection;
 
@@ -271,8 +254,8 @@
 #ifdef USE_HID_FOR_MODIFIERS
 
-/** The IO Master Port. */
+/** Holds the IO Master Port. */
 static mach_port_t g_MasterPort = NULL;
 
-/** Keyboards in the cache. */
+/** Holds the amount of keyboards in the cache. */
 static unsigned g_cKeyboards = 0;
 /** Array of cached keyboard data. */
@@ -284,5 +267,5 @@
     IOHIDQueueInterface   **ppHidQueueInterface;
 
-    /* cookie translation array. */
+    /** Cookie translation array. */
     struct KeyboardCacheCookie
     {
@@ -295,38 +278,51 @@
     unsigned                cCookies;
 }                   g_aKeyboards[128];
-/** The keyboard cache creation timestamp. */
+/** Holds the keyboard cache creation timestamp. */
 static uint64_t     g_u64KeyboardTS = 0;
 
-/** HID queue status. */
+/** Holds the HID queue status. */
 static bool         g_fHIDQueueEnabled;
-/** The current modifier mask. */
+/** Holds the current modifier mask. */
 static uint32_t     g_fHIDModifierMask;
-/** The old modifier mask. */
+/** Holds the old modifier mask. */
 static uint32_t     g_fOldHIDModifierMask;
 
 #endif /* USE_HID_FOR_MODIFIERS */
 
+
 #ifdef VBOX_WITH_KBD_LEDS_SYNC
 
 #define VBOX_BOOL_TO_STR_STATE(x) (x) ? "ON" : "OFF"
-/* HID LEDs synchronization data: LED states. */
-typedef struct VBoxLedState_t {
-    bool fNumLockOn;                        /** A state of NUM LOCK */
-    bool fCapsLockOn;                       /** A state of CAPS LOCK */
-    bool fScrollLockOn;                     /** A state of SCROLL LOCK */
+/** HID LEDs synchronization data: LED states. */
+typedef struct VBoxLedState_t
+{
+    /** Holds the state of NUM LOCK. */
+    bool fNumLockOn;
+    /** Holds the  state of CAPS LOCK. */
+    bool fCapsLockOn;
+    /** Holds the  state of SCROLL LOCK. */
+    bool fScrollLockOn;
 } VBoxLedState_t;
 
-/* HID LEDs synchronization data: keyboard states. */
-typedef struct VBoxKbdState_t {
-    IOHIDDeviceRef    pDevice;              /** A reference to IOKit HID device */
-    VBoxLedState_t    LED;                  /** LED states */
-    void             *pParentContainer;     /** A pointer to a VBoxHidsState_t instance where VBoxKbdState_t instance is stored */
-    CFIndex           idxPosition;          /** Position in global storage (used to simplify CFArray navigation when removing detached device) */
-    uint64_t          cCapsLockTimeout;     /** KBD CAPS LOCK key hold timeout (some Apple keyboards only) */
-    uint32_t          idLocation;           /** HID Location ID: unique for an USB device registered in the system */
+/** HID LEDs synchronization data: keyboard states. */
+typedef struct VBoxKbdState_t
+{
+    /** Holds the reference to IOKit HID device. */
+    IOHIDDeviceRef    pDevice;
+    /** Holds the LED states. */
+    VBoxLedState_t    LED;
+    /** Holds the  pointer to a VBoxHidsState_t instance where VBoxKbdState_t instance is stored. */
+    void             *pParentContainer;
+    /** Holds the position in global storage (used to simplify CFArray navigation when removing detached device). */
+    CFIndex           idxPosition;
+    /** Holds the KBD CAPS LOCK key hold timeout (some Apple keyboards only). */
+    uint64_t          cCapsLockTimeout;
+    /** Holds the HID Location ID: unique for an USB device registered in the system. */
+    uint32_t          idLocation;
 } VBoxKbdState_t;
 
-/* A struct that used to pass input event info from IOKit callback to a Carbon one */
-typedef struct VBoxKbdEvent_t {
+/** A struct that used to pass input event info from IOKit callback to a Carbon one */
+typedef struct VBoxKbdEvent_t
+{
     VBoxKbdState_t *pKbd;
     uint32_t        iKeyCode;
@@ -334,40 +330,33 @@
 } VBoxKbdEvent_t;
 
-/* HID LEDs synchronization data: IOKit specific data. */
-typedef struct VBoxHidsState_t {
-    IOHIDManagerRef     hidManagerRef;      /** IOKit HID manager reference */
-    CFMutableArrayRef   pDeviceCollection;  /** This array consists of VBoxKbdState_t elements */
-    VBoxLedState_t      guestState;         /** LED states that were stored during last broadcast and reflect a guest LED states */
-
-    CFMutableArrayRef   pFifoEventQueue;    /** This queue will be appended in IOKit input callback. Carbon input callback will extract data from it */
-    RTSEMMUTEX          fifoEventQueueLock; /** Lock for pFifoEventQueue */
-
-    io_iterator_t         pUsbHidDeviceMatchNotify;     /** IOService notification reference: USB HID device matching */
-    io_iterator_t         pUsbHidGeneralInterestNotify; /** IOService notification reference: USB HID general interest
-                                                            notifications (IOService messages) */
-    IONotificationPortRef pNotificationPrortRef;        /** IOService notification port reference: used for both notification
-                                                            types - device match and device general interest message */
-
-    /* Carbon events data */
+/** HID LEDs synchronization data: IOKit specific data. */
+typedef struct VBoxHidsState_t
+{
+    /** Holds the IOKit HID manager reference. */
+    IOHIDManagerRef     hidManagerRef;
+    /** Holds the array which consists of VBoxKbdState_t elements. */
+    CFMutableArrayRef   pDeviceCollection;
+    /** Holds the LED states that were stored during last broadcast and reflect a guest LED states. */
+    VBoxLedState_t      guestState;
+
+    /** Holds the queue which will be appended in IOKit input callback. Carbon input callback will extract data from it. */
+    CFMutableArrayRef   pFifoEventQueue;
+    /** Holds the lock for pFifoEventQueue. */
+    RTSEMMUTEX          fifoEventQueueLock;
+
+    /** Holds the IOService notification reference: USB HID device matching. */
+    io_iterator_t         pUsbHidDeviceMatchNotify;
+    /** Holds the IOService notification reference: USB HID general interest notifications (IOService messages). */
+    io_iterator_t         pUsbHidGeneralInterestNotify;
+    /** Holds the IOService notification port reference: device match and device general interest message. */
+    IONotificationPortRef pNotificationPrortRef;
+
     CFMachPortRef       pTapRef;
     CFRunLoopSourceRef  pLoopSourceRef;
 } VBoxHidsState_t;
-#endif /* !VBOX_WITH_KBD_LEDS_SYNC */
-
-
-/*********************************************************************************************************************************
-*   Internal Functions                                                                                                           *
-*********************************************************************************************************************************/
-#ifdef USE_HID_FOR_MODIFIERS
-static void darwinBruteForcePropertySearch(CFDictionaryRef DictRef, struct KeyboardCacheData *pKeyboardEntry);
-#endif
-
-
-/**
- * Converts a darwin (virtual) key code to a set 1 scan code.
- *
- * @returns set 1 scan code.
- * @param   uKeyCode        The darwin key code.
- */
+
+#endif /* VBOX_WITH_KBD_LEDS_SYNC */
+
+
 unsigned DarwinKeycodeToSet1Scancode(unsigned uKeyCode)
 {
@@ -377,12 +366,64 @@
 }
 
-
-/**
- * Converts a single modifier to a set 1 scan code.
- *
- * @returns Set 1 scan code.
- * @returns ~0U if more than one modifier is set.
- * @param   fModifiers      The darwin modifier mask.
- */
+UInt32 DarwinAdjustModifierMask(UInt32 fModifiers, const void *pvCocoaEvent)
+{
+    /* Check if there is anything to adjust and perform the adjustment. */
+    if (fModifiers & (shiftKey | rightShiftKey | controlKey | rightControlKey | optionKey | rightOptionKey | cmdKey | kEventKeyModifierRightCmdKeyMask))
+    {
+#ifndef USE_HID_FOR_MODIFIERS
+        // WORKAROUND:
+        // Convert the Cocoa modifiers to Carbon ones (the Cocoa modifier
+        // definitions are tucked away in Objective-C headers, unfortunately).
+        //
+        // Update: CGEventTypes.h includes what looks like the Cocoa modifiers
+        //         and the NX_* defines should be available as well. We should look
+        //         into ways to intercept the CG (core graphics) events in the Carbon
+        //         based setup and get rid of all this HID mess. */
+        AssertPtr(pvCocoaEvent);
+        //::darwinPrintEvent("dbg-adjMods: ", pvCocoaEvent);
+        uint32_t fAltModifiers = ::darwinEventModifierFlagsXlated(pvCocoaEvent);
+#else  /* USE_HID_FOR_MODIFIERS */
+        /* Update the keyboard cache. */
+        darwinHIDKeyboardCacheUpdate();
+        const UInt32 fAltModifiers = g_fHIDModifierMask;
+#endif /* USE_HID_FOR_MODIFIERS */
+
+#ifdef DEBUG_PRINTF
+        RTPrintf("dbg-fAltModifiers=%#x fModifiers=%#x", fAltModifiers, fModifiers);
+#endif
+        if (   (fModifiers    & (rightShiftKey | shiftKey))
+            && (fAltModifiers & (rightShiftKey | shiftKey)))
+        {
+            fModifiers &= ~(rightShiftKey | shiftKey);
+            fModifiers |= fAltModifiers & (rightShiftKey | shiftKey);
+        }
+
+        if (   (fModifiers    & (rightControlKey | controlKey))
+            && (fAltModifiers & (rightControlKey | controlKey)))
+        {
+            fModifiers &= ~(rightControlKey | controlKey);
+            fModifiers |= fAltModifiers & (rightControlKey | controlKey);
+        }
+
+        if (   (fModifiers    & (optionKey | rightOptionKey))
+            && (fAltModifiers & (optionKey | rightOptionKey)))
+        {
+            fModifiers &= ~(optionKey | rightOptionKey);
+            fModifiers |= fAltModifiers & (optionKey | rightOptionKey);
+        }
+
+        if (   (fModifiers    & (cmdKey | kEventKeyModifierRightCmdKeyMask))
+            && (fAltModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask)))
+        {
+            fModifiers &= ~(cmdKey | kEventKeyModifierRightCmdKeyMask);
+            fModifiers |= fAltModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask);
+        }
+#ifdef DEBUG_PRINTF
+        RTPrintf(" -> %#x\n", fModifiers);
+#endif
+    }
+    return fModifiers;
+}
+
 unsigned DarwinModifierMaskToSet1Scancode(UInt32 fModifiers)
 {
@@ -395,13 +436,4 @@
 }
 
-
-/**
- * Converts a single modifier to a darwin keycode.
- *
- * @returns Darwin keycode.
- * @returns 0 if none of the support masks were set.
- * @returns ~0U if more than one modifier is set.
- * @param   fModifiers      The darwin modifier mask.
- */
 unsigned DarwinModifierMaskToDarwinKeycode(UInt32 fModifiers)
 {
@@ -440,12 +472,4 @@
 }
 
-
-/**
- * Converts a darwin keycode to a modifier mask.
- *
- * @returns Darwin modifier mask.
- * @returns 0 if the keycode isn't a modifier we know.
- * @param   uKeyCode        The darwin
- */
 UInt32 DarwinKeyCodeToDarwinModifierMask(unsigned uKeyCode)
 {
@@ -481,16 +505,9 @@
 
 
-/**
- * Disables or enabled global hot keys.
- *
- * @param   fDisable    Pass 'true' to disable the hot keys, pass 'false' to re-enable them.
- */
 void DarwinDisableGlobalHotKeys(bool fDisable)
 {
     static unsigned s_cComplaints = 0;
 
-    /*
-     * Lazy connect to the core graphics service.
-     */
+    /* Lazy connect to the core graphics service. */
     if (!g_fConnectedToCGS)
     {
@@ -499,7 +516,5 @@
     }
 
-    /*
-     * Get the current mode.
-     */
+    /* Get the current mode. */
     CGSGlobalHotKeyOperatingMode enmMode = kCGSGlobalHotKeyInvalid;
     CGSGetGlobalHotKeyOperatingMode(g_CGSConnection, &enmMode);
@@ -514,7 +529,5 @@
     }
 
-    /*
-     * Calc the new mode.
-     */
+    /* Calc the new mode. */
     if (fDisable)
     {
@@ -530,7 +543,5 @@
     }
 
-    /*
-     * Try set it and check the actual result.
-     */
+    /* Try set it and check the actual result. */
     CGSSetGlobalHotKeyOperatingMode(g_CGSConnection, enmMode);
     CGSGlobalHotKeyOperatingMode enmNewMode = kCGSGlobalHotKeyInvalid;
@@ -545,14 +556,12 @@
 }
 
+
 #ifdef USE_HID_FOR_MODIFIERS
 
-/**
- * Callback function for consuming queued events.
- *
- * @param   pvTarget    queue?
- * @param   rcIn        ?
- * @param   pvRefcon    Pointer to the keyboard cache entry.
- * @param   pvSender    ?
- */
+/** Callback function for consuming queued events.
+  * @param   pvTarget  Brings the queue?
+  * @param   rcIn      Brigns what?
+  * @param   pvRefcon  Brings the pointer to the keyboard cache entry.
+  * @param   pvSender  Brings what? */
 static void darwinQueueCallback(void *pvTarget, IOReturn rcIn, void *pvRefcon, void *pvSender)
 {
@@ -564,7 +573,5 @@
     NOREF(pvSender);
 
-    /*
-     * Consume the events.
-     */
+    /* Consume the events. */
     g_fOldHIDModifierMask = g_fHIDModifierMask;
     for (;;)
@@ -592,10 +599,5 @@
         }
 
-        /*
-         * Adjust the modifier mask.
-         *
-         * Note that we don't bother to deal with anyone pressing the same modifier
-         * on 2 or more keyboard. That's not worth the effort involved.
-         */
+        /* Adjust the modifier mask. */
         if (Event.value)
             g_fHIDModifierMask |= fMask;
@@ -611,9 +613,8 @@
 }
 
-
-
-/**
- * Element enumeration callback.
- */
+/* Forward declaration for darwinBruteForcePropertySearch. */
+static void darwinBruteForcePropertySearch(CFDictionaryRef DictRef, struct KeyboardCacheData *pKeyboardEntry);
+
+/** Element enumeration callback. */
 static void darwinBruteForcePropertySearchApplier(const void *pvValue, void *pvCacheEntry)
 {
@@ -622,18 +623,10 @@
 }
 
-
-/**
- * Recurses thru the keyboard properties looking for certain keys.
- *
- * @remark  Yes, this can probably be done in a more efficient way. If you
- *          know how to do this, don't hesitate to let us know!
- */
+/** Recurses through the keyboard properties looking for certain keys. */
 static void darwinBruteForcePropertySearch(CFDictionaryRef DictRef, struct KeyboardCacheData *pKeyboardEntry)
 {
     CFTypeRef ObjRef;
 
-    /*
-     * Check for the usage page and usage key we want.
-     */
+    /* Check for the usage page and usage key we want. */
     long lUsage;
     ObjRef = CFDictionaryGetValue(DictRef, CFSTR(kIOHIDElementUsageKey));
@@ -667,7 +660,5 @@
                 }
 
-                /*
-                 * Get the cookie and modifier mask.
-                 */
+                /* Get the cookie and modifier mask. */
                 long lCookie;
                 ObjRef = CFDictionaryGetValue(DictRef, CFSTR(kIOHIDElementCookieKey));
@@ -691,7 +682,5 @@
                 }
 
-                /*
-                 * If we've got a queue, add the cookie to the queue.
-                 */
+                /* If we've got a queue, add the cookie to the queue. */
                 if (pKeyboardEntry->ppHidQueueInterface)
                 {
@@ -703,7 +692,5 @@
                 }
 
-                /*
-                 * Add the cookie to the keyboard entry.
-                 */
+                /* Add the cookie to the keyboard entry. */
                 pKeyboardEntry->aCookies[pKeyboardEntry->cCookies].Cookie = (IOHIDElementCookie)lCookie;
                 pKeyboardEntry->aCookies[pKeyboardEntry->cCookies].fMask = fMask;
@@ -715,8 +702,5 @@
 
 
-    /*
-     * Get the elements key and recursively iterate the elements looking
-     * for they key cookies.
-     */
+    /* Get the elements key and recursively iterate the elements looking for they key cookies. */
     ObjRef = CFDictionaryGetValue(DictRef, CFSTR(kIOHIDElementKey));
     if (    ObjRef
@@ -729,13 +713,7 @@
 }
 
-
-/**
- * Creates a keyboard cache entry.
- *
- * @returns true if the entry was created successfully, otherwise false.
- * @param   pKeyboardEntry      Pointer to the entry.
- * @param   KeyboardDevice      The keyboard device to create the entry for.
- *
- */
+/** Creates a keyboard cache entry.
+  * @param  pKeyboardEntry  Brings the pointer to the entry.
+  * @param  KeyboardDevice  Brings the keyboard device to create the entry for. */
 static bool darwinHIDKeyboardCacheCreateEntry(struct KeyboardCacheData *pKeyboardEntry, io_object_t KeyboardDevice)
 {
@@ -743,7 +721,5 @@
     memset(pKeyboardEntry, 0, sizeof(*pKeyboardEntry));
 
-    /*
-     * Query the HIDDeviceInterface for this HID (keyboard) object.
-     */
+    /* Query the HIDDeviceInterface for this HID (keyboard) object. */
     SInt32 Score = 0;
     IOCFPlugInInterface **ppPlugInInterface = NULL;
@@ -763,13 +739,8 @@
             if (rc == kIOReturnSuccess)
             {
-                /*
-                 * create a removal callback.
-                 */
+                /* Create a removal callback. */
                 /** @todo */
 
-
-                /*
-                 * Create the queue so we can insert elements while searching the properties.
-                 */
+                /* Create the queue so we can insert elements while searching the properties. */
                 IOHIDQueueInterface   **ppHidQueueInterface = (*ppHidDeviceInterface)->allocQueue(ppHidDeviceInterface);
                 if (ppHidQueueInterface)
@@ -787,7 +758,5 @@
                 pKeyboardEntry->ppHidQueueInterface = ppHidQueueInterface;
 
-                /*
-                 * Brute force getting of attributes.
-                 */
+                /* Brute force getting of attributes. */
                 /** @todo read up on how to do this in a less resource intensive way! Suggestions are welcome! */
                 CFMutableDictionaryRef PropertiesRef = 0;
@@ -803,7 +772,5 @@
                 if (ppHidQueueInterface)
                 {
-                    /*
-                     * Now install our queue callback.
-                     */
+                    /* Now install our queue callback. */
                     CFRunLoopSourceRef RunLoopSrcRef = NULL;
                     rc = (*ppHidQueueInterface)->createAsyncEventSource(ppHidQueueInterface, &RunLoopSrcRef);
@@ -814,7 +781,5 @@
                     }
 
-                    /*
-                     * Now install our queue callback.
-                     */
+                    /* Now install our queue callback. */
                     rc = (*ppHidQueueInterface)->setEventCallout(ppHidQueueInterface, darwinQueueCallback, ppHidQueueInterface, pKeyboardEntry);
                     if (rc != kIOReturnSuccess)
@@ -822,7 +787,5 @@
                 }
 
-                /*
-                 * Complete the new keyboard cache entry.
-                 */
+                /* Complete the new keyboard cache entry. */
                 pKeyboardEntry->ppHidDeviceInterface = ppHidDeviceInterface;
                 pKeyboardEntry->ppHidQueueInterface = ppHidQueueInterface;
@@ -842,17 +805,10 @@
 }
 
-
-/**
- * Destroys a keyboard cache entry.
- *
- * @param   pKeyboardEntry      The entry.
- */
+/** Destroys a keyboard cache entry. */
 static void darwinHIDKeyboardCacheDestroyEntry(struct KeyboardCacheData *pKeyboardEntry)
 {
     unsigned long cRefs;
 
-    /*
-     * Destroy the queue
-     */
+    /* Destroy the queue. */
     if (pKeyboardEntry->ppHidQueueInterface)
     {
@@ -860,8 +816,8 @@
         pKeyboardEntry->ppHidQueueInterface = NULL;
 
-        /* stop it just in case we haven't done so. doesn't really matter I think. */
+        /* Stop it just in case we haven't done so. doesn't really matter I think. */
         (*ppHidQueueInterface)->stop(ppHidQueueInterface);
 
-        /* deal with the run loop source. */
+        /* Deal with the run loop source. */
         CFRunLoopSourceRef RunLoopSrcRef = (*ppHidQueueInterface)->getAsyncEventSource(ppHidQueueInterface);
         if (RunLoopSrcRef)
@@ -873,17 +829,13 @@
         }
 
-        /* dispose of and release the queue. */
+        /* Dispose of and release the queue. */
         (*ppHidQueueInterface)->dispose(ppHidQueueInterface);
         cRefs = (*ppHidQueueInterface)->Release(ppHidQueueInterface); MY_CHECK_CREFS(cRefs);
     }
 
-    /*
-     * Release the removal hook?
-     */
+    /* Release the removal hook? */
     /** @todo */
 
-    /*
-     * Close and release the device interface.
-     */
+    /* Close and release the device interface. */
     if (pKeyboardEntry->ppHidDeviceInterface)
     {
@@ -896,13 +848,8 @@
 }
 
-
-/**
- * Zap the keyboard cache.
- */
+/** Zap the keyboard cache. */
 static void darwinHIDKeyboardCacheZap(void)
 {
-    /*
-     * Release the old cache data first.
-     */
+    /* Release the old cache data first. */
     while (g_cKeyboards > 0)
     {
@@ -912,26 +859,18 @@
 }
 
-
-/**
- * Updates the cached keyboard data.
- *
- * @todo The current implementation is very brute force...
- *       Rewrite it so that it doesn't flush the cache completely but simply checks whether
- *       anything has changed in the HID config. With any luck, there might even be a callback
- *       or something we can poll for HID config changes...
- *       setRemovalCallback() is a start...
- */
+/** Updates the cached keyboard data.
+  * @todo The current implementation is very brute force...
+  *       Rewrite it so that it doesn't flush the cache completely but simply checks whether
+  *       anything has changed in the HID config. With any luck, there might even be a callback
+  *       or something we can poll for HID config changes...
+  *       setRemovalCallback() is a start... */
 static void darwinHIDKeyboardCacheDoUpdate(void)
 {
     g_u64KeyboardTS = RTTimeMilliTS();
 
-    /*
-     * Dispense with the old cache data.
-     */
+    /* Dispense with the old cache data. */
     darwinHIDKeyboardCacheZap();
 
-    /*
-     * Open the master port on the first invocation.
-     */
+    /* Open the master port on the first invocation. */
     if (!g_MasterPort)
     {
@@ -940,7 +879,5 @@
     }
 
-    /*
-     * Create a matching dictionary for searching for keyboards devices.
-     */
+    /* Create a matching dictionary for searching for keyboards devices. */
     static const UInt32 s_Page = kHIDPage_GenericDesktop;
     static const UInt32 s_Usage = kHIDUsage_GD_Keyboard;
@@ -952,7 +889,5 @@
                          CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &s_Usage));
 
-    /*
-     * Perform the search and get a collection of keyboard devices.
-     */
+    /* Perform the search and get a collection of keyboard devices. */
     io_iterator_t Keyboards = NULL;
     IOReturn rc = IOServiceGetMatchingServices(g_MasterPort, RefMatchingDict, &Keyboards);
@@ -960,7 +895,5 @@
     RefMatchingDict = NULL; /* the reference is consumed by IOServiceGetMatchingServices. */
 
-    /*
-     * Enumerate the keyboards and query the cache data.
-     */
+    /* Enumerate the keyboards and query the cache data. */
     unsigned i = 0;
     io_object_t KeyboardDevice;
@@ -977,8 +910,5 @@
 }
 
-
-/**
- * Updates the keyboard cache if it's time to do it again.
- */
+/** Updates the keyboard cache if it's time to do it again. */
 static void darwinHIDKeyboardCacheUpdate(void)
 {
@@ -988,15 +918,8 @@
 }
 
-
-/**
- * Queries the modifier keys from the (IOKit) HID Manager.
- *
- * @returns Carbon modifier mask with right/left set correctly.
- */
+/** Queries the modifier keys from the (IOKit) HID Manager. */
 static UInt32 darwinQueryHIDModifiers(void)
 {
-    /*
-     * Iterate thru the keyboards collecting their modifier masks.
-     */
+    /* Iterate thru the keyboards collecting their modifier masks. */
     UInt32 fHIDModifiers = 0;
     unsigned i = g_cKeyboards;
@@ -1029,101 +952,14 @@
 #endif /* USE_HID_FOR_MODIFIERS */
 
-/**
- * Left / right adjust the modifier mask using the current
- * keyboard state.
- *
- * @returns left/right adjusted fModifiers.
- * @param   fModifiers      The mask to adjust.
- * @param   pvCocoaEvent    The associated Cocoa keyboard event. This is NULL
- *                          when using HID for modifier corrections.
- *
- */
-UInt32 DarwinAdjustModifierMask(UInt32 fModifiers, const void *pvCocoaEvent)
-{
-    /*
-     * Check if there is anything to adjust and perform the adjustment.
-     */
-    if (fModifiers & (shiftKey | rightShiftKey | controlKey | rightControlKey | optionKey | rightOptionKey | cmdKey | kEventKeyModifierRightCmdKeyMask))
-    {
-#ifndef USE_HID_FOR_MODIFIERS
-        /*
-         * Convert the Cocoa modifiers to Carbon ones (the Cocoa modifier
-         * definitions are tucked away in Objective-C headers, unfortunately).
-         *
-         * Update: CGEventTypes.h includes what looks like the Cocoa modifiers
-         *         and the NX_* defines should be available as well. We should look
-         *         into ways to intercept the CG (core graphics) events in the Carbon
-         *         based setup and get rid of all this HID mess.
-         */
-        AssertPtr(pvCocoaEvent);
-        //::darwinPrintEvent("dbg-adjMods: ", pvCocoaEvent);
-        uint32_t fAltModifiers = ::darwinEventModifierFlagsXlated(pvCocoaEvent);
-
-#else  /* USE_HID_FOR_MODIFIERS */
-        /*
-         * Update the keyboard cache.
-         */
-        darwinHIDKeyboardCacheUpdate();
-        const UInt32 fAltModifiers = g_fHIDModifierMask;
-
-#endif /* USE_HID_FOR_MODIFIERS */
-#ifdef DEBUG_PRINTF
-        RTPrintf("dbg-fAltModifiers=%#x fModifiers=%#x", fAltModifiers, fModifiers);
-#endif
-        if (   (fModifiers    & (rightShiftKey | shiftKey))
-            && (fAltModifiers & (rightShiftKey | shiftKey)))
-        {
-            fModifiers &= ~(rightShiftKey | shiftKey);
-            fModifiers |= fAltModifiers & (rightShiftKey | shiftKey);
-        }
-
-        if (   (fModifiers    & (rightControlKey | controlKey))
-            && (fAltModifiers & (rightControlKey | controlKey)))
-        {
-            fModifiers &= ~(rightControlKey | controlKey);
-            fModifiers |= fAltModifiers & (rightControlKey | controlKey);
-        }
-
-        if (   (fModifiers    & (optionKey | rightOptionKey))
-            && (fAltModifiers & (optionKey | rightOptionKey)))
-        {
-            fModifiers &= ~(optionKey | rightOptionKey);
-            fModifiers |= fAltModifiers & (optionKey | rightOptionKey);
-        }
-
-        if (   (fModifiers    & (cmdKey | kEventKeyModifierRightCmdKeyMask))
-            && (fAltModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask)))
-        {
-            fModifiers &= ~(cmdKey | kEventKeyModifierRightCmdKeyMask);
-            fModifiers |= fAltModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask);
-        }
-#ifdef DEBUG_PRINTF
-        RTPrintf(" -> %#x\n", fModifiers);
-#endif
-    }
-    return fModifiers;
-}
-
-
-/**
- * Start grabbing keyboard events.
- *
- * This only concerns itself with modifiers and disabling global hotkeys (if requested).
- *
- * @param   fGlobalHotkeys      Whether to disable global hotkeys or not.
- */
-void     DarwinGrabKeyboard(bool fGlobalHotkeys)
+
+void DarwinGrabKeyboard(bool fGlobalHotkeys)
 {
     LogFlow(("DarwinGrabKeyboard: fGlobalHotkeys=%RTbool\n", fGlobalHotkeys));
 
 #ifdef USE_HID_FOR_MODIFIERS
-    /*
-     * Update the keyboard cache.
-     */
+    /* Update the keyboard cache. */
     darwinHIDKeyboardCacheUpdate();
 
-    /*
-     * Start the keyboard queues and query the current mask.
-     */
+    /* Start the keyboard queues and query the current mask. */
     g_fHIDQueueEnabled = true;
 
@@ -1138,28 +974,18 @@
 #endif /* USE_HID_FOR_MODIFIERS */
 
-    /*
-     * Disable hotkeys if requested.
-     */
+    /* Disable hotkeys if requested. */
     if (fGlobalHotkeys)
         DarwinDisableGlobalHotKeys(true);
 }
 
-
-/**
- * Reverses the actions taken by DarwinGrabKeyboard.
- */
-void     DarwinReleaseKeyboard(void)
+void DarwinReleaseKeyboard()
 {
     LogFlow(("DarwinReleaseKeyboard\n"));
 
-    /*
-     * Re-enable hotkeys.
-     */
+    /* Re-enable hotkeys. */
     DarwinDisableGlobalHotKeys(false);
 
 #ifdef USE_HID_FOR_MODIFIERS
-    /*
-     * Stop and drain the keyboard queues.
-     */
+    /* Stop and drain the keyboard queues. */
     g_fHIDQueueEnabled = false;
 
@@ -1187,9 +1013,5 @@
     }
 #else
-
-    /*
-     * Kill the keyboard cache.
-     * This will hopefully fix the crash in getElementValue()/fillElementValue()...
-     */
+    /* Kill the keyboard cache. */
     darwinHIDKeyboardCacheZap();
 #endif
@@ -1200,13 +1022,15 @@
 }
 
+
 #ifdef VBOX_WITH_KBD_LEDS_SYNC
-/** Prepare dictionary that will be used to match HID LED device(s) while discovering. */
+
+/** Prepares dictionary that will be used to match HID LED device(s) while discovering. */
 static CFDictionaryRef darwinQueryLedDeviceMatchingDictionary()
 {
     CFDictionaryRef deviceMatchingDictRef;
 
-    /* Use two (key, value) pairs:
-     *      - (kIOHIDDeviceUsagePageKey, kHIDPage_GenericDesktop),
-     *      - (kIOHIDDeviceUsageKey,     kHIDUsage_GD_Keyboard). */
+    // Use two (key, value) pairs:
+    //      - (kIOHIDDeviceUsagePageKey, kHIDPage_GenericDesktop),
+    //      - (kIOHIDDeviceUsageKey,     kHIDUsage_GD_Keyboard). */
 
     CFNumberRef usagePageKeyCFNumberRef; int usagePageKeyCFNumberValue = kHIDPage_GenericDesktop;
@@ -1251,6 +1075,6 @@
     CFDictionaryRef elementMatchingDictRef;
 
-    /* Use only one (key, value) pair to match LED device element:
-     *      - (kIOHIDElementUsagePageKey, kHIDPage_LEDs).  */
+    // Use only one (key, value) pair to match LED device element:
+    //      - (kIOHIDElementUsagePageKey, kHIDPage_LEDs).  */
 
     CFNumberRef usagePageKeyCFNumberRef; int usagePageKeyCFNumberValue = kHIDPage_LEDs;
@@ -1472,7 +1296,7 @@
 
 /** Some keyboard devices might freeze after LEDs manipulation. We filter out such devices here.
- * In the list below, devices that known to have such issues. If you want to add new device,
- * then add it here. Currently, we only filter devices by Vendor ID.
- * In future it might make sense to take Product ID into account as well. */
+  * In the list below, devices that known to have such issues. If you want to add new device,
+  * then add it here. Currently, we only filter devices by Vendor ID.
+  * In future it might make sense to take Product ID into account as well. */
 static bool darwinHidDeviceSupported(IOHIDDeviceRef pHidDeviceRef)
 {
@@ -1502,5 +1326,5 @@
 
 /** IOKit key press callback helper: take care about key-down event.
- * This code should be executed within a critical section under pHidState->fifoEventQueueLock. */
+  * This code should be executed within a critical section under pHidState->fifoEventQueueLock. */
 static void darwinHidInputCbKeyDown(VBoxKbdState_t *pKbd, uint32_t iKeyCode, VBoxHidsState_t *pHidState)
 {
@@ -1523,16 +1347,15 @@
 
 /** IOkit and Carbon key press callbacks helper: CapsLock timeout checker.
- *
- * Returns FALSE if CAPS LOCK timeout not occurred and its state still was not switched (Apple kbd).
- * Returns TRUE if CAPS LOCK timeout occurred and its state was switched (Apple kbd).
- * Returns TRUE for non-Apple kbd. */
+  *
+  * Returns FALSE if CAPS LOCK timeout not occurred and its state still was not switched (Apple kbd).
+  * Returns TRUE if CAPS LOCK timeout occurred and its state was switched (Apple kbd).
+  * Returns TRUE for non-Apple kbd. */
 static bool darwinKbdCapsEventMatches(VBoxKbdEvent_t *pEvent, bool fCapsLed)
 {
-    /* CapsLock timeout is only applicable if conditions
-     * below are satisfied:
-     *
-     * a) Key pressed on Apple keyboard
-     * b) CapsLed is OFF at the moment when CapsLock key is pressed
-     */
+    // CapsLock timeout is only applicable if conditions
+    // below are satisfied:
+    //
+    // a) Key pressed on Apple keyboard
+    // b) CapsLed is OFF at the moment when CapsLock key is pressed
 
     bool fAppleKeyboard = (pEvent->pKbd->cCapsLockTimeout > 0);
@@ -1550,5 +1373,5 @@
 
 /** IOKit key press callback helper: take care about key-up event.
- * This code should be executed within a critical section under pHidState->fifoEventQueueLock. */
+  * This code should be executed within a critical section under pHidState->fifoEventQueueLock. */
 static void darwinHidInputCbKeyUp(VBoxKbdState_t *pKbd, uint32_t iKeyCode, VBoxHidsState_t *pHidState)
 {
@@ -1556,6 +1379,6 @@
     VBoxKbdEvent_t *pEvent = NULL;
 
-    /* Key-up event assumes that key-down event occured previously. If so, an event
-     * data should be in event queue. Attempt to find it. */
+    // Key-up event assumes that key-down event occured previously. If so, an event
+    // data should be in event queue. Attempt to find it.
     for (CFIndex i = 0; i < CFArrayGetCount(pHidState->pFifoEventQueue); i++)
     {
@@ -1573,7 +1396,7 @@
     if (pEvent)
     {
-        /* NUM LOCK should not have timeout and its press should immidiately trigger Carbon callback.
-         * Therefore, if it is still in queue this is a problem because it was not handled by Carbon callback.
-         * This mean that NUM LOCK is most likely out of sync. */
+        // NUM LOCK should not have timeout and its press should immidiately trigger Carbon callback.
+        // Therefore, if it is still in queue this is a problem because it was not handled by Carbon callback.
+        // This mean that NUM LOCK is most likely out of sync.
         if (iKeyCode == kHIDUsage_KeypadNumLock)
         {
@@ -1583,6 +1406,6 @@
         else if (iKeyCode == kHIDUsage_KeyboardCapsLock)
         {
-            /* If CAPS LOCK key-press event still not match CAPS LOCK timeout criteria, Carbon callback
-             * should not be triggered for this event at all. Threfore, event should be removed from queue. */
+            // If CAPS LOCK key-press event still not match CAPS LOCK timeout criteria, Carbon callback
+            // should not be triggered for this event at all. Threfore, event should be removed from queue.
             if (!darwinKbdCapsEventMatches(pEvent, pHidState->guestState.fCapsLockOn))
             {
@@ -1596,8 +1419,8 @@
             else
             {
-                /* CAPS LOCK key-press event matches to CAPS LOCK timeout criteria and still present in queue.
-                 * This might mean that Carbon callback was triggered for this event, but cached keyboard state was not updated.
-                 * It also might mean that Carbon callback still was not triggered, but it will be soon.
-                 * Threfore, CAPS LOCK might be out of sync. */
+                // CAPS LOCK key-press event matches to CAPS LOCK timeout criteria and still present in queue.
+                // This might mean that Carbon callback was triggered for this event, but cached keyboard state was not updated.
+                // It also might mean that Carbon callback still was not triggered, but it will be soon.
+                // Threfore, CAPS LOCK might be out of sync.
                 LogRel2(("IOHID: KBD %d: Modifier Key-Up event. Key-Down event was triggered %llu ms "
                     "ago and still was not handled by Carbon callback. CAPS LOCK might out of sync if "
@@ -1852,5 +1675,5 @@
 
 /** Get pre-cached KBD device by its Location ID. */
-static VBoxKbdState_t * darwinUsbHidQueryKbdByLocationId(uint32_t idLocation, VBoxHidsState_t *pHidState)
+static VBoxKbdState_t *darwinUsbHidQueryKbdByLocationId(uint32_t idLocation, VBoxHidsState_t *pHidState)
 {
     AssertReturn(pHidState, NULL);
@@ -1987,5 +1810,5 @@
 }
 
-/* Check if we already cached given device */
+/** Check if we already cached given device */
 static bool darwinIsDeviceInCache(VBoxHidsState_t *pState, IOHIDDeviceRef pDevice)
 {
@@ -2021,7 +1844,7 @@
                 pKbd->idLocation = darwinHidLocationId(pDevice);
 
-                /* Some Apple keyboards have CAPS LOCK key timeout. According to corresponding
-                 * kext plist files, it is equals to 75 ms. For such devices we only add info into our FIFO event
-                 * queue if the time between Key-Down and Key-Up events >= 75 ms. */
+                // Some Apple keyboards have CAPS LOCK key timeout. According to corresponding
+                // kext plist files, it is equals to 75 ms. For such devices we only add info into our FIFO event
+                // queue if the time between Key-Down and Key-Up events >= 75 ms.
                 pKbd->cCapsLockTimeout = (darwinHidVendorId(pKbd->pDevice) == kIOUSBVendorIDAppleComputer) ? 75 : 0;
 
@@ -2035,6 +1858,6 @@
                                                   &pKbd->LED.fScrollLockOn);
 
-                    /* This should never happen, but if happened -- mark all the leds of current
-                     * device as turned OFF. */
+                    // This should never happen, but if happened -- mark all the leds of current
+                    // device as turned OFF.
                     if (rc != 0)
                     {
@@ -2158,8 +1981,9 @@
     RTSemMutexDestroy(pHidState->fifoEventQueueLock);
 }
+
 #endif /* !VBOX_WITH_KBD_LEDS_SYNC */
 
-/** Save the states of leds for all HID devices attached to the system and return it. */
-void * DarwinHidDevicesKeepLedsState(void)
+
+void *DarwinHidDevicesKeepLedsState()
 {
 #ifdef VBOX_WITH_KBD_LEDS_SYNC
@@ -2241,11 +2065,5 @@
 }
 
-/**
- * Apply LEDs state stored in *pState and release resources aquired by *pState.
- *
- * @param pState            Pointer to saved LEDs state
- *
- * @return 0 on success, error code otherwise.
- */
+
 int DarwinHidDevicesApplyAndReleaseLedsState(void *pState)
 {
@@ -2258,5 +2076,5 @@
     darwinUsbHidUnsubscribeInterestNotifications(pHidState);
 
-    /* Need to unregister Carbon stuff first */
+    /* Need to unregister Carbon stuff first: */
     darwinRemoveCarbonHandler(pHidState);
 
@@ -2264,5 +2082,5 @@
     if (elementMatchingDict)
     {
-        /* Restore LEDs */
+        /* Restore LEDs: */
         for (CFIndex i = 0; i < CFArrayGetCount(pHidState->pDeviceCollection); i++)
         {
@@ -2297,5 +2115,5 @@
     }
 
-    /* Free resources */
+    /* Free resources: */
     CFRelease(pHidState->pDeviceCollection);
 
@@ -2317,21 +2135,9 @@
     (void)pState;
     return 0;
-#endif
-}
-
-/**
- * Set states for host keyboard LEDs.
- *
- * NOTE: This function will set led values for all
- * keyboard devices attached to the system.
- *
- * @param pState            Pointer to saved LEDs state
- * @param fNumLockOn        Turn on NumLock led if TRUE, turn off otherwise
- * @param fCapsLockOn       Turn on CapsLock led if TRUE, turn off otherwise
- * @param fScrollLockOn     Turn on ScrollLock led if TRUE, turn off otherwise
- */
+#endif /* !VBOX_WITH_KBD_LEDS_SYNC */
+}
+
 void DarwinHidDevicesBroadcastLeds(void *pState, bool fNumLockOn, bool fCapsLockOn, bool fScrollLockOn)
 {
-/* Temporary disabled */
 #ifdef VBOX_WITH_KBD_LEDS_SYNC
     VBoxHidsState_t *pHidState = (VBoxHidsState_t *)pState;
@@ -2370,13 +2176,13 @@
     }
 
-    /* Dynamically attached device will use these states */
+    /* Dynamically attached device will use these states: */
     pHidState->guestState.fNumLockOn    = fNumLockOn;
     pHidState->guestState.fCapsLockOn   = fCapsLockOn;
     pHidState->guestState.fScrollLockOn = fScrollLockOn;
-
 #else /* !VBOX_WITH_KBD_LEDS_SYNC */
     (void)fNumLockOn;
     (void)fCapsLockOn;
     (void)fScrollLockOn;
-#endif
-}
+#endif /* !VBOX_WITH_KBD_LEDS_SYNC */
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.h	(revision 71658)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/DarwinKeyboard.h	(revision 71659)
@@ -1,11 +1,9 @@
 /* $Id$ */
 /** @file
- * VBox Qt GUI - Common GUI Library - Darwin Keyboard routines.
- *
- * @todo Move this up somewhere so that the two SDL GUIs can use this code too.
+ * VBox Qt GUI - Declarations of utility functions for handling Darwin Keyboard specific tasks.
  */
 
 /*
- * Copyright (C) 2006-2017 Oracle Corporation
+ * Copyright (C) 2006-2018 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,10 +16,13 @@
  */
 
-
 #ifndef ___DarwinKeyboard_h___
 #define ___DarwinKeyboard_h___
 
+/* Other VBox includes: */
 #include <iprt/cdefs.h>
+
+/* External includes: */
 #include <CoreFoundation/CFBase.h>
+
 
 RT_C_DECLS_BEGIN
@@ -39,19 +40,41 @@
 #define VBOXKEY_LOCK                0x0800
 
+/** Converts a darwin (virtual) key code to a set 1 scan code. */
 unsigned DarwinKeycodeToSet1Scancode(unsigned uKeyCode);
+/** Adjusts the modifier mask left / right using the current keyboard state. */
 UInt32   DarwinAdjustModifierMask(UInt32 fModifiers, const void *pvCocoaEvent);
+/** Converts a single modifier to a set 1 scan code. */
 unsigned DarwinModifierMaskToSet1Scancode(UInt32 fModifiers);
+/** Converts a single modifier to a darwin keycode. */
 unsigned DarwinModifierMaskToDarwinKeycode(UInt32 fModifiers);
+/** Converts a darwin keycode to a modifier mask. */
 UInt32   DarwinKeyCodeToDarwinModifierMask(unsigned uKeyCode);
+
+/** Disables or enabled global hot keys. */
 void     DarwinDisableGlobalHotKeys(bool fDisable);
+
+/** Start grabbing keyboard events.
+  * @param   fGlobalHotkeys  Brings whether to disable global hotkeys or not. */
 void     DarwinGrabKeyboard(bool fGlobalHotkeys);
-void     DarwinReleaseKeyboard(void);
+/** Reverses the actions taken by DarwinGrabKeyboard. */
+void     DarwinReleaseKeyboard();
 
-void   * DarwinHidDevicesKeepLedsState(void);
+/** Saves the states of leds for all HID devices attached to the system and return it. */
+void    *DarwinHidDevicesKeepLedsState();
+
+/** Applies LEDs @a pState release its resources afterwards. */
 int      DarwinHidDevicesApplyAndReleaseLedsState(void *pState);
+/** Set states for host keyboard LEDs.
+  * @note This function will set led values for all
+  *       keyboard devices attached to the system.
+  * @param pState         Brings the pointer to saved LEDs state.
+  * @param fNumLockOn     Turns on NumLock led if TRUE, off otherwise
+  * @param fCapsLockOn    Turns on CapsLock led if TRUE, off otherwise
+  * @param fScrollLockOn  Turns on ScrollLock led if TRUE, off otherwise */
 void     DarwinHidDevicesBroadcastLeds(void *pState, bool fNumLockOn, bool fCapsLockOn, bool fScrollLockOn);
 
 RT_C_DECLS_END
 
-#endif
 
+#endif /* !___DarwinKeyboard_h___ */
+
