diff options
author | Teddy Wing | 2022-09-20 21:05:53 +0200 |
---|---|---|
committer | Teddy Wing | 2022-09-20 21:05:53 +0200 |
commit | 2e2cbb6296d2022d588a21fdefe3900015d17ea1 (patch) | |
tree | 74fd6e32a070eda0af7da40103787977f6b3d6be /keyboard_layout.lua | |
parent | bd3f82c4731827ed4687660a1c9b7440ed8b6a26 (diff) | |
download | dothammerspoon-2e2cbb6296d2022d588a21fdefe3900015d17ea1.tar.bz2 |
keyboard_layout: Fix USB keyboard detection
The way I had written it before broke automatic switching support for
the iMate USB device.
Rewrite the device check so that both the iMate and generic keyboards
automatically switch keyboard layouts.
Diffstat (limited to 'keyboard_layout.lua')
-rw-r--r-- | keyboard_layout.lua | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/keyboard_layout.lua b/keyboard_layout.lua index f260163..26a38af 100644 --- a/keyboard_layout.lua +++ b/keyboard_layout.lua @@ -17,19 +17,25 @@ -- Change keyboard layouts depending on presence of external keyboard. -keyboard_usb_watcher = hs.usb.watcher.new(function(event) - if event['productName'] ~= 'iMate, USB To ADB Adaptor' - or event['vendorID'] ~= 1917 - or event['productID'] ~= 1029 - then - return - end +local function is_imate(event) + return event['productName'] == 'iMate, USB To ADB Adaptor' + and event['vendorID'] == 1917 + and event['productID'] == 1029 +end +local function is_generic_keyboard(event) local product_name_contains_word_keyboard = string.find( string.lower(event['productName']), "keyboard" ) - if not product_name_contains_word_keyboard then + + return product_name_contains_word_keyboard +end + +keyboard_usb_watcher = hs.usb.watcher.new(function(event) + if not is_imate(event) + and not is_generic_keyboard(event) + then return end |