Skip to content

Commit a71808c

Browse files
Allow toggling of features and fixes via Info.plist values
Signed-off-by: black.dragon74 <[email protected]>
1 parent f088d84 commit a71808c

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ reenumerate -v 0x0b05,0x1869
5252

5353
</details>
5454

55+
## Configuring
56+
57+
You can enable or disable additonal features and fixes in this driver by editing the Info.plist file of the dext. Currently configurable options are:
58+
59+
Setting value to `0` disables and `1` enables the feature/fix.
60+
61+
- `FixCapsLockLED` - Fixes erratic behavior of Caps Lock LED on some keyboards. If your LED didn't work under macOS without this driver. You should disable this feature.
62+
- `BacklightAutoTurnOff` - Automatically turns off the keyboard backlight after 5 mins of inactivity. Recommended to disable it on devices where there are multiple `IOHIDInterface` nubs for a single device, like `0b05:1866`.
63+
64+
You need to edit ONLY the entry for your vendor and device id. Like for `0b05:1869` I would edit `0b05_1869` entry under `IOKitPersonalities` dict.
65+
5566
## Building
5667

5768
### From GitHub:

ROG-HID-Driver/Info.plist

+20
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
<dict>
2323
<key>0b05_1822</key>
2424
<dict>
25+
<key>BacklightAutoTurnOff</key>
26+
<integer>1</integer>
2527
<key>CFBundleIdentifier</key>
2628
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
29+
<key>FixCapsLockLED</key>
30+
<integer>1</integer>
2731
<key>IOClass</key>
2832
<string>AppleUserHIDEventService</string>
2933
<key>IOKitDebug</key>
@@ -41,8 +45,12 @@
4145
</dict>
4246
<key>0b05_1837</key>
4347
<dict>
48+
<key>BacklightAutoTurnOff</key>
49+
<integer>1</integer>
4450
<key>CFBundleIdentifier</key>
4551
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
52+
<key>FixCapsLockLED</key>
53+
<integer>1</integer>
4654
<key>IOClass</key>
4755
<string>AppleUserHIDEventService</string>
4856
<key>IOKitDebug</key>
@@ -60,8 +68,12 @@
6068
</dict>
6169
<key>0b05_1854</key>
6270
<dict>
71+
<key>BacklightAutoTurnOff</key>
72+
<integer>1</integer>
6373
<key>CFBundleIdentifier</key>
6474
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
75+
<key>FixCapsLockLED</key>
76+
<integer>1</integer>
6577
<key>IOClass</key>
6678
<string>AppleUserHIDEventService</string>
6779
<key>IOKitDebug</key>
@@ -79,8 +91,12 @@
7991
</dict>
8092
<key>0b05_1866</key>
8193
<dict>
94+
<key>BacklightAutoTurnOff</key>
95+
<integer>0</integer>
8296
<key>CFBundleIdentifier</key>
8397
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
98+
<key>FixCapsLockLED</key>
99+
<integer>0</integer>
84100
<key>IOClass</key>
85101
<string>AppleUserHIDEventService</string>
86102
<key>IOKitDebug</key>
@@ -98,8 +114,12 @@
98114
</dict>
99115
<key>0b05_1869</key>
100116
<dict>
117+
<key>BacklightAutoTurnOff</key>
118+
<integer>1</integer>
101119
<key>CFBundleIdentifier</key>
102120
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
121+
<key>FixCapsLockLED</key>
122+
<integer>1</integer>
103123
<key>IOClass</key>
104124
<string>AppleUserHIDEventService</string>
105125
<key>IOKitDebug</key>

ROG-HID-Driver/ROG_HID_Driver.cpp

+39-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct ROG_HID_Driver_IVars
2323
OSArray* customKeyboardElements { nullptr };
2424
IODispatchQueue* luxQueue { nullptr };
2525
uint8_t kbdFunction { 0 };
26+
bool fixCapsLockLED { false };
27+
bool bkltAutoTurnOff { false };
28+
2629
static uint64_t lastEventDispatchTime;
2730
static uint8_t kbdLux;
2831
static bool luxIsFadedOut;
@@ -53,6 +56,8 @@ bool ROG_HID_Driver::init()
5356
if (ivars == nullptr)
5457
return false;
5558

59+
ivars->fixCapsLockLED = false;
60+
ivars->bkltAutoTurnOff = false;
5661
_last_dispatch_time = 0;
5762

5863
return true;
@@ -91,6 +96,9 @@ kern_return_t IMPL(ROG_HID_Driver, Start)
9196
// Read the keyboard functions
9297
asusKbdGetFunctions();
9398

99+
// Parse Info.plist
100+
parseInfoPlist();
101+
94102
// Reflect the intital value on lux
95103
DBGLOG("Trying to set initial kbd lux to: 0x%x", _current_lux);
96104
asusKbdBacklightSet(_current_lux);
@@ -255,7 +263,7 @@ kern_return_t ROG_HID_Driver::dispatchKeyboardEvent(uint64_t timeStamp, uint32_t
255263
}
256264

257265
// Fix erratic caps lock key
258-
if (usage == kHIDUsage_KeyboardCapsLock)
266+
if (usage == kHIDUsage_KeyboardCapsLock && ivars->fixCapsLockLED)
259267
IOSleep(80);
260268

261269
// Update the last dispatch time to the current mach_time
@@ -339,7 +347,13 @@ void IMPL(ROG_HID_Driver, loadKbdLuxMonitor)
339347
void IMPL(ROG_HID_Driver, initLuxQueue)
340348
{
341349
if (!(SUPPORT_KEYBOARD_BACKLIGHT & _kbd_function)) {
342-
DBGLOG("Keyboard baclikght is not supported on this device, abort lux queue init");
350+
DBGLOG("Keyboard backlight is not supported on this device, abort lux queue init");
351+
return;
352+
}
353+
354+
if (!ivars->bkltAutoTurnOff)
355+
{
356+
DBGLOG("Backlight auto turn off is disabled via Info.plist");
343357
return;
344358
}
345359

@@ -393,6 +407,28 @@ void IMPL(ROG_HID_Driver, initLuxQueue)
393407
OSSafeReleaseNULL(deviceProps);
394408
}
395409

410+
void IMPL(ROG_HID_Driver, parseInfoPlist)
411+
{
412+
DBGLOG("Parse custom Info.plist properties");
413+
OSContainer* propContainer;
414+
415+
SearchProperty("BacklightAutoTurnOff", "IOService", kIOServiceSearchPropertyParents, &propContainer);
416+
ivars->fixCapsLockLED = OSDynamicCast(OSNumber, propContainer)->unsigned8BitValue() == kBooleanTrue;
417+
DBGLOG("Fix caps lock led: %s", ivars->fixCapsLockLED ? "True" : "False");
418+
419+
propContainer = nullptr;
420+
SearchProperty("BacklightAutoTurnOff", "IOService", kIOServiceSearchPropertyParents, &propContainer);
421+
if (!propContainer)
422+
goto exit;
423+
424+
ivars->bkltAutoTurnOff = OSDynamicCast(OSNumber, propContainer)->unsigned8BitValue() == kBooleanTrue;
425+
DBGLOG("Backlight auto turn off: %s", ivars->bkltAutoTurnOff ? "True" : "False");
426+
427+
exit:
428+
OSSafeReleaseNULL(propContainer);
429+
DBGLOG("Done parsing custom Info.plist properties");
430+
}
431+
396432
kern_return_t IMPL(ROG_HID_Driver, Stop)
397433
{
398434
DBGLOG("Stop");
@@ -440,7 +476,7 @@ void IMPL(ROG_HID_Driver, asusKbdInit)
440476
void IMPL(ROG_HID_Driver, asusKbdBacklightSet)
441477
{
442478
if (!(SUPPORT_KEYBOARD_BACKLIGHT & _kbd_function)) {
443-
DBGLOG("Setting keyboard baclikght is not supported on this device");
479+
DBGLOG("Setting keyboard backlight is not supported on this device");
444480
return;
445481
}
446482

ROG-HID-Driver/ROG_HID_Driver.iig

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define KBD_FEATURE_REPORT_SIZE 16
1616
#define LUX_FADE_OUT_DELAY STOMS(5 * 60) /* 5 mins */
1717
#define SUPPORT_KEYBOARD_BACKLIGHT BIT(0)
18+
#define kBooleanTrue 0x01
1819

1920
#define LOG_PREFIX "ROG-HID - "
2021
#define OSLOG(...) \
@@ -65,6 +66,7 @@ public:
6566

6667
private:
6768
virtual void parseKeyboardElementsHook(OSArray* elements);
69+
virtual void parseInfoPlist();
6870
virtual void setKbdLux(kLuxEvent luxEvent);
6971
virtual void initLuxQueue();
7072
virtual void loadKbdLuxMonitor();

ROG-HID.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@
435435
"@executable_path/../Frameworks",
436436
);
437437
MACOSX_DEPLOYMENT_TARGET = 10.15;
438-
MARKETING_VERSION = 1.2;
438+
MARKETING_VERSION = 1.3;
439439
PRODUCT_BUNDLE_IDENTIFIER = "com.black-dragon74.ROG-HID";
440440
PRODUCT_NAME = "$(TARGET_NAME)";
441441
SWIFT_VERSION = 5.0;
@@ -460,7 +460,7 @@
460460
"@executable_path/../Frameworks",
461461
);
462462
MACOSX_DEPLOYMENT_TARGET = 10.15;
463-
MARKETING_VERSION = 1.2;
463+
MARKETING_VERSION = 1.3;
464464
PRODUCT_BUNDLE_IDENTIFIER = "com.black-dragon74.ROG-HID";
465465
PRODUCT_NAME = "$(TARGET_NAME)";
466466
SWIFT_VERSION = 5.0;
@@ -482,7 +482,7 @@
482482
"$(SDKROOT)/System/DriverKit/System/Library/Frameworks",
483483
);
484484
INFOPLIST_FILE = "ROG-HID-Driver/Info.plist";
485-
MARKETING_VERSION = 1.2;
485+
MARKETING_VERSION = 1.3;
486486
PRODUCT_BUNDLE_IDENTIFIER = "com.black-dragon74.ROG-HID-Driver";
487487
PRODUCT_NAME = "$(inherited)";
488488
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -506,7 +506,7 @@
506506
"$(SDKROOT)/System/DriverKit/System/Library/Frameworks",
507507
);
508508
INFOPLIST_FILE = "ROG-HID-Driver/Info.plist";
509-
MARKETING_VERSION = 1.2;
509+
MARKETING_VERSION = 1.3;
510510
PRODUCT_BUNDLE_IDENTIFIER = "com.black-dragon74.ROG-HID-Driver";
511511
PRODUCT_NAME = "$(inherited)";
512512
PROVISIONING_PROFILE_SPECIFIER = "";

0 commit comments

Comments
 (0)