Skip to content

Commit

Permalink
support quite after typing
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhtrancse committed Mar 19, 2020
1 parent 8546de5 commit d639f09
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 22 deletions.
42 changes: 23 additions & 19 deletions VoodooI2CSynaptics/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>IOKitPersonalities</key>
<dict>
<key>VoodooI2CHIDDevice</key>
<dict>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>IOClass</key>
<string>VoodooI2CSynapticsDevice</string>
<key>IOProbeScore</key>
<integer>400</integer>
<key>IOPropertyMatch</key>
<dict>
<key>name</key>
<string>SYNA2B33</string>
</dict>
<key>IOProviderClass</key>
<string>VoodooI2CDeviceNub</string>
</dict>
</dict>
<key>IOKitPersonalities</key>
<dict>
<key>VoodooI2CHIDDevice</key>
<dict>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>IOClass</key>
<string>VoodooI2CSynapticsDevice</string>
<key>IOProbeScore</key>
<integer>400</integer>
<key>IOPropertyMatch</key>
<dict>
<key>name</key>
<string>SYNA2B52</string>
</dict>
<key>IOProviderClass</key>
<string>VoodooI2CDeviceNub</string>
<key>RM,deliverNotifications</key>
<true/>
<key>QuietTimeAfterTyping</key>
<integer>500</integer>
</dict>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 Alexandre Daoud. All rights reserved.</string>
<key>CFBundleSpokenName</key>
Expand Down
57 changes: 55 additions & 2 deletions VoodooI2CSynaptics/VoodooI2CSynapticsDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ bool VoodooI2CSynapticsDevice::start(IOService* api) {
if (!super::start(api))
return false;

// Read QuietTimeAfterTyping configuration value (if available)
OSNumber* quietTimeAfterTyping = OSDynamicCast(OSNumber, getProperty("QuietTimeAfterTyping"));
if (quietTimeAfterTyping != NULL)
maxaftertyping = quietTimeAfterTyping->unsigned64BitValue() * 1000000; // Convert to nanoseconds


reading = true;

work_loop = getWorkLoop();
Expand Down Expand Up @@ -253,10 +259,10 @@ bool VoodooI2CSynapticsDevice::start(IOService* api) {
setProperty("VoodooI2CServices Supported", OSBoolean::withBoolean(true));

publish_multitouch_interface();
registerService();

reading = false;


return true;
exit:
releaseResources();
Expand Down Expand Up @@ -1007,6 +1013,15 @@ void VoodooI2CSynapticsDevice::interruptOccured(OSObject* owner, IOInterruptEven
}

void VoodooI2CSynapticsDevice::get_input() {
// Ignore input for specified time after keyboard usage
AbsoluteTime timestamp;
clock_get_uptime(&timestamp);
uint64_t timestamp_ns;
absolutetime_to_nanoseconds(timestamp, &timestamp_ns);

if (timestamp_ns - keytime < maxaftertyping)
return ;

reading = true;

uint8_t reg = 0;
Expand Down Expand Up @@ -1081,6 +1096,44 @@ void VoodooI2CSynapticsDevice::unpublish_multitouch_interface() {

/* Sasha - impl polling */
void VoodooI2CSynapticsDevice::simulateInterrupt(OSObject* owner, IOTimerEventSource *timer) {
interruptOccured(owner, NULL, NULL);
interruptOccured(owner, 0, 0);
interrupt_simulator->setTimeoutMS(INTERRUPT_SIMULATOR_TIMEOUT);
}

IOReturn VoodooI2CSynapticsDevice::message(UInt32 type, IOService* provider, void* argument) {
switch (type) {
case kKeyboardGetTouchStatus:
{
#if DEBUG
IOLog("%s::getEnabledStatus = %s\n", getName(), ignoreall ? "false" : "true");
#endif
bool* pResult = (bool*)argument;
*pResult = !ignoreall;
break;
}
case kKeyboardSetTouchStatus:
{
bool enable = *((bool*)argument);
#if DEBUG
IOLog("%s::setEnabledStatus = %s\n", getName(), enable ? "true" : "false");
#endif
// ignoreall is true when trackpad has been disabled
if (enable == ignoreall) {
// save state, and update LED
ignoreall = !enable;
}
break;
}
case kKeyboardKeyPressTime:
{
// Remember last time key was pressed
keytime = *((uint64_t*)argument);
#if DEBUG
IOLog("%s::keyPressed = %llu\n", getName(), keytime);
#endif
break;
}
}

return kIOReturnSuccess;
}
23 changes: 22 additions & 1 deletion VoodooI2CSynaptics/VoodooI2CSynapticsDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ enum rmi_mode_type {
RMI_MODE_NO_PACKED_ATTN_REPORTS = 2,
};

// Message types defined by ApplePS2Keyboard
enum {
// from keyboard to mouse/touchpad
kKeyboardSetTouchStatus = iokit_vendor_specific_msg(100), // set disable/enable touchpad (data is bool*)
kKeyboardGetTouchStatus = iokit_vendor_specific_msg(101), // get disable/enable touchpad (data is bool*)
kKeyboardKeyPressTime = iokit_vendor_specific_msg(110) // notify of timestamp a non-modifier key was pressed (data is uint64_t*)
};

struct rmi_function {
unsigned page; /* page of the function */
uint16_t query_base_addr; /* base address for queries */
Expand Down Expand Up @@ -103,12 +111,26 @@ class VoodooI2CSynapticsDevice : public IOService
unsigned long device_flags;
unsigned long firmware_id;

uint64_t maxaftertyping = 500000000;
uint64_t keytime = 0;
bool ignoreall;

uint8_t f01_ctrl0;
uint8_t interrupt_enable_mask;
bool restore_interrupt_mask;

VoodooI2CMultitouchInterface* mt_interface;

/*
* Called by ApplePS2Controller to notify of keyboard interactions
* @type Custom message type in iokit_vendor_specific_msg range
* @provider Calling IOService
* @argument Optional argument as defined by message type
*
* @return kIOSuccess if the message is processed
*/
IOReturn message(UInt32 type, IOService* provider, void* argument) override;

protected:
bool awake;
const char* name;
Expand Down Expand Up @@ -161,5 +183,4 @@ class VoodooI2CSynapticsDevice : public IOService
void simulateInterrupt(OSObject* owner, IOTimerEventSource* timer); /* Sasha - Implement polling mode */
};


#endif /* VoodooI2CSynapticsDevice_hpp */

0 comments on commit d639f09

Please sign in to comment.