From 2e2cbb6296d2022d588a21fdefe3900015d17ea1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 20 Sep 2022 21:05:53 +0200 Subject: 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. --- keyboard_layout.lua | 22 ++++++++++++++-------- 1 file 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 -- cgit v1.2.3