Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] Upgrade Karabiner-DriverKit-VirtualHIDDevice to v2.1.0 #716

Merged
merged 4 commits into from
Oct 25, 2023

Conversation

vosaica
Copy link
Contributor

@vosaica vosaica commented Jul 5, 2023

I tried upgrading Karabiner-DriverKit-VirtualHIDDevice to their latest version.

The required work seems surprisingly minimal. I tried compiling and running it on the Ventura and beta version of Sonoma, and it appears to be working fine.

I will update the installation documentation, once we confirm that the new code can be merged.

@slotThe
Copy link
Member

slotThe commented Jul 9, 2023

Well, any Mac people still around to test this? :)

@nightscape
Copy link
Contributor

@vosaica I'm getting the following error when building on a MacBook Air M1:

Building executable 'kmonad' for kmonad-0.4.1..
[1 of 1] Compiling Main
Linking .stack-work/dist/aarch64-osx/Cabal-3.6.3.0/build/kmonad/kmonad ...
ld: Undefined symbols:
  _grab_kb, referenced from:
       in libHSkmonad-0.4.1-Ad3nJCqjF5mD0QGALQE0NP.a[34](IOKitSource.o)
       in libHSkmonad-0.4.1-Ad3nJCqjF5mD0QGALQE0NP.a[34](IOKitSource.o)
  _release_kb, referenced from:
       in libHSkmonad-0.4.1-Ad3nJCqjF5mD0QGALQE0NP.a[34](IOKitSource.o)
  _send_key, referenced from:
       in libHSkmonad-0.4.1-Ad3nJCqjF5mD0QGALQE0NP.a[35](KextSink.o)
  _wait_key, referenced from:
       in libHSkmonad-0.4.1-Ad3nJCqjF5mD0QGALQE0NP.a[34](IOKitSource.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the error:

       [S-7011]
       While building package kmonad-0.4.1 (scroll up to its section to see the error) using:
       /Users/martin/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_6HauvNHV_3.6.3.0_ghc-9.2.5 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build lib:kmonad exe:kmonad --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1

I updated to the most recent version of all Haskell stacks, maybe they're too new?

┌───────────────────────────────────────────────────────────────────────────────────────────────────GHCup──────────────────────────────────────────────────────────────────────────────────────────────────┐
│    Tool  Version         Tags                          Notes                                                                                                                                             │
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│✔✔  GHCup 0.1.19.4        latest,recommended                                                                                                                                                              │
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│✔✔  Stack 2.11.1          latest                                                                                                                                                                          │
│✓   Stack 2.9.3           recommended                                                                                                                                                                     │
│✗   Stack 2.9.1                                                                                                                                                                                           │
│✗   Stack 2.7.5                                                                                                                                                                                           │
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│✔✔  HLS   2.0.0.1         latest,recommended                                                                                                                                                              │
│✗   HLS   2.0.0.0                                                                                                                                                                                         │
│✗   HLS   1.10.0.0                                                                                                                                                                                        │
│✓   HLS   1.9.1.0                                                                                                                                                                                         │
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│✔✔  cabal 3.10.1.0        latest                                                                                                                                                                          │
│✗   cabal 3.8.1.0                                                                                                                                                                                         │
│✗   cabal 3.6.2.0         recommended                                                                                                                                                                     │
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│✔✔  GHC   9.6.2           latest,base-4.18.0.0          hls-powered                                                                                                                                       │
│✗   GHC   9.6.1           base-4.18.0.0                                                                                                                                                                   │
│✗   GHC   9.4.5           base-4.17.1.0                 hls-powered                                                                                                                                       │
│✗   GHC   9.4.4           base-4.17.0.0                                                                                                                                                                   │
│✗   GHC   9.2.8           recommended,base-4.16.4.0     hls-powered                                                                                                                                       │
│✗   GHC   9.2.7           base-4.16.4.0                 hls-powered                                                                                                                                       │
│✗   GHC   9.0.2           base-4.15.1.0                                                                                                                                                                   │
│✗   GHC   8.10.7          base-4.14.3.0                 hls-powered                                                                                                                                       │
│✓   GHC   8.10.4          base-4.14.1.0                                                                                                                                                                   │
│✗   GHC   8.8.4           base-4.13.0.0                                                                                                                                                                   │
│✗   GHC   8.6.5           base-4.12.0.0                                                                                                                                                                   │
│✗   GHC   8.4.4           base-4.11.1.0                                                                                                                                                                   

@vosaica
Copy link
Contributor Author

vosaica commented Jul 11, 2023

I am also using Stack 2.11.1 for building.

Are you using the stack command stack build --flag kmonad:dext --extra-include-dirs=c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/include/pqrs/karabiner/driverkit:c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/src/Client/vendor/include? It is the command written in the installation document. I tried to run stack build, and it generates the same error.

@martin-hyca
Copy link

martin-hyca commented Jul 19, 2023

I am happy to test it, I just have no experience with installing anything else than the master branch. If I understand properly, I would have to install some other branch??

Following the instructions from the installation document, I am getting the same error message in the end as @nightscape .
Using freshly installed stack...

I am on MBA M1, Ventura 13.5
If I am not able to install it on Ventura, I will just go back to Monterey where I had it working already...

@vosaica
Copy link
Contributor Author

vosaica commented Jul 20, 2023

@agemartin I guess you might have encountered an issue related to submodules. Here are steps I took to compile:

git clone --recursive https://github.com/vosaica/kmonad.git
cd kmonad
git checkout Upgrade-DriverKit-VirtualHIDDevice
git submodule update --init
stack build --flag kmonad:dext --extra-include-dirs=c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/include/pqrs/karabiner/driverkit:c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/src/Client/vendor/include

If that still doesn't work, please let me know :-)

I wonder if this is also the problem you have met?@nightscape

@martin-hyca
Copy link

@vosaica Thanks a lot for the support, I successfully compiled your branch. However, when I try to run kmonad, I am getting the following error:

connect_failed asio.system:2

I have added it to Input Monitoring in Security & Privacy.
I am running it as sudo
I can confirm the dext version 1.15.0

I also checked other issues mentioning this error but don't really get what could the solution here. Any ideas?

@vosaica
Copy link
Contributor Author

vosaica commented Jul 20, 2023

Yes, the reason for this branch is to upgrade the dext version to 2.1.0 since the older version is no longer supported on later version of macOS. You just need to upgrade your dext, and you can find them here.

@martin-hyca
Copy link

martin-hyca commented Jul 20, 2023

@vosaica did that, now when I run it it says the following and the whole keyboard does not react. I can only kill monad by pressing the 7,100 key next to 1

connected
driver_loaded 0
driver_version_matched 0
driver_loaded 1

@vosaica
Copy link
Contributor Author

vosaica commented Jul 21, 2023

I'm sorry to hear that. This seems weird. Normally, there would be a log that says driver_version_matched 1. I can't come up with any ideas about why it's missing on yours. However, since the driver_version_matched failed, I would suggest trying to reinstall the drivers according to Karabiner's documentation. Additionally, you can run kmonad -l debug for more information.

@nightscape
Copy link
Contributor

@vosaica I installed the dext from the link you provided, compiled kmonad with the provided command, but I face the same issue as @agemartin. Keyboard does not respond except for the 7,100 key which kills kmonad.

@vosaica
Copy link
Contributor Author

vosaica commented Jul 21, 2023

@vosaica I installed the dext from the link you provided, compiled kmonad with the provided command, but I face the same issue as @agemartin. Keyboard does not respond except for the 7,100 key which kills kmonad.

@nightscape @agemartin After reinstall my system, I think I reproduced the problem. Probably both of you forgot to activate the Karabiner driver. Which can be activated using /Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager activate

@nightscape
Copy link
Contributor

The command you provided + a reboot actually worked!
I'm successfully running your branch now 👍 👍

@martin-hyca
Copy link

martin-hyca commented Jul 21, 2023

I tried it, also with forceactivate, also tried compiling it again after activating, no success, still the same story
I can recall I had similar issue when installing on Big Sur some time ago, back then it was just "connected" and keyboard not responding. Back then reinstallation of the OS helped...
I guess I just install Monterey and hope it works

@vosaica
Copy link
Contributor Author

vosaica commented Jul 21, 2023

I tried it, also with forceactivate, also tried compiling it again after activating, no success, still the same story I can recall I had similar issue when installing on Big Sur some time ago, back then it was just "connected" and keyboard not responding. Back then reinstallation of the OS helped... I guess I just install Monterey and hope it works

If the activate is successful, then there will be a virtual keyboard in keyboard's settings. If it is not there then it might be a clue for the true problem.
Screenshot 2023-07-21 at 11 05 21 PM

@martin-hyca
Copy link

martin-hyca commented Jul 21, 2023

@vosaica I simply installed a new copy of the OS (which turns out to be ventura beta) (without sweeping the disk) and now it works.
Thanks a lot for the help. So happy I can run kmonad again :))

@martin-hyca
Copy link

@vosaica Every once in a while the keyboard stops responding, so I have to kill and run it again. Not particularly often so I can still use it. So far did not spot in what situation does it happen.
Happy to run some tests / some debugging if that's an option to help to find the cause.

(btw I indeed see the Karabiner virtual keyboard in keyboards)

@martin-hyca
Copy link

martin-hyca commented Jul 23, 2023

I have been running it now with -l debug so as to check what's actually happening when the keyboard stops responding. Previously I have already noticed couple of times that it happens while the computer is laying around unused. This was also the case here.

Seems to me like the issue started somewhere here:


--------------------------------------------------------------------------------
Received event: Release <met>
Running hooks

--------------------------------------------------------------------------------
Received event: Press <f>
Running hooks
Block level set to: 1
Registering untimed hook: 98
Registering 160ms hook: 97

--------------------------------------------------------------------------------
Received event: Release <f>
Running hooks
Emitting: Press <n>
Unblocking input stream, no stored events
Emitting: Release <n>

--------------------------------------------------------------------------------
Received event: Press <n>
Running hooks
Emitting: Press <n>
Registering untimed hook: 99

--------------------------------------------------------------------------------
Received event: Release <n>
Running hooks
Emitting: Release <n>

--------------------------------------------------------------------------------
Received event: Press <n>
Running hooks
Registering untimed hook: 100
Emitting: Press <n>

and would have gone like that forever:


--------------------------------------------------------------------------------
Received event: Release <n>
Running hooks
Emitting: Release <n>

--------------------------------------------------------------------------------
Received event: Press <n>
Running hooks
Registering untimed hook: 70594
Emitting: Press <n>

--------------------------------------------------------------------------------

The keymap I am running is not particularly simple but I hadn't observed this issues on Monterey.

@martin-hyca
Copy link

Also, I have been getting errors like this:

Encountered error in KeySource: [Cannot interpret mac switch: 4, Cannot translate from mac keycode: (255, 4294967295) 1

tried every single key on the keyboard and did not find any which would actually cause that. I believe I already saw a message regarding switch 5.

@martin-hyca
Copy link

typically the keyboard stop responding after closing the laptop

@nightscape
Copy link
Contributor

I have the same issue. After standby, the keyboard does not work any more. I press ^ to kill kmonad and start it again to make everything work again. This wasn't an issue before.

@sixtysecrun
Copy link
Contributor

sixtysecrun commented Jul 28, 2023

Unfortunately this PR breaks the nix build on MacOS (or any usage in nix managed configurations):

$ nix build "./nix?submodules=1"

error: builder for '/nix/store/md7ram8vzy47r9vws5k9aka5c57pvxv5-kmonad-0.4.1.drv' failed with exit code 1;
       last 10 log lines:
       >
       > c_src/mac/keyio_mac.hpp:169:72: error:
       >      error: use of undeclared identifier 'kIOMainPortDefault'
       >         IONotificationPortRef notification_port = IONotificationPortCreate(kIOMainPortDefault);
       >                                                                            ^
       >     |
       > 169 |     IONotificationPortRef notification_port = IONotificationPortCreate(kIOMainPortDefault);
       >     |                                                                        ^
       > 2 errors generated.
       > `cc' failed in phase `C Compiler'. (Exit code: 1)

This is because this PR actually mixes two updates:

  1. Update of the Karabiner-DriverKit-VirtualHIDDevice
  2. Update of the Apple SDK

For just an update of Karabiner-DriverKit-VirtualHIDDevice all that is actually needed is to update the submodule and import <filesystem>

Patch
From 1f488532cf268509b3c8b0a4805169c1b062840b Mon Sep 17 00:00:00 2001
From: sixtysecrun <--redacted-->
Date: Fri, 28 Jul 2023 15:34:00 +0200
Subject: [PATCH] Update Karabiner-DriverKit-VirtualHIDDevice to 2.1.0

---
 c_src/mac/Karabiner-DriverKit-VirtualHIDDevice | 2 +-
 c_src/mac/dext.cpp                             | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/c_src/mac/Karabiner-DriverKit-VirtualHIDDevice b/c_src/mac/Karabiner-DriverKit-VirtualHIDDevice
index bfe93e7..31ac0d9 160000
--- a/c_src/mac/Karabiner-DriverKit-VirtualHIDDevice
+++ b/c_src/mac/Karabiner-DriverKit-VirtualHIDDevice
@@ -1 +1 @@
-Subproject commit bfe93e7bdd13f766937becd640f91f4b0c02444f
+Subproject commit 31ac0d996e6a2d02034ac295bb6a2806a2ab3c55
diff --git a/c_src/mac/dext.cpp b/c_src/mac/dext.cpp
index 4c7a089..7048998 100644
--- a/c_src/mac/dext.cpp
+++ b/c_src/mac/dext.cpp
@@ -1,3 +1,5 @@
+#include <filesystem> // Include this before virtual_hid_device_service.hpp to avoid compile error
+
 #include "keyio_mac.hpp"

 #include "virtual_hid_device_driver.hpp"
--
2.41.0

The rest of the changes in this PR are only because you are compiling it against newer SDK that is defined in nixpkgs.
I believe that symbol kIOMainPortDefault was introduced in Apple SDK 12+ and nixpkgs uses the 10.12 SDK by default.

Unfortunately it is not possible (AFAIK) to update nix build to use newer Apple SDK until this change in nixpkgs is merged: NixOS/nixpkgs#242666

Is it possible to use some C++ macro and switch between kIOMainPortDefault and kIOMasterPortDefault depending on the Apple SDK version?

@martin-hyca
Copy link

Hi everyboday, I was just wondering if there's any chance to resolve this (kmonad freezing whenever/mostly when computer goes to sleep mode)?
Unfortunately I have very little understanding on how these things work so I cannot really participate now.
Unless there is some fix in sight I would simply go back to Monterey where it worked for me already, or even Big Sur if I fail this time with Monterey.
Thanks for any responses!

@nightscape
Copy link
Contributor

I haven't found a solution yet, but a launcher script as OK'ish workaround:

#!/bin/bash

# Path to the kmonad binary
KMONAD_PATH="~/.local/bin/kmonad"
KMONAD_CONFIG_PATH="~/Workspaces/devtools/kmonad-contrib/keymaps/nightscape/bone_mac.kbd"

# Counter for how many times kmonad has crashed
CRASH_COUNT=0

# Timestamp of the first crash in the current sequence
FIRST_CRASH_TIMESTAMP=0

while true; do
    # Run kmonad with superuser permissions
	echo "Starting kmonad"
	echo "sudo $KMONAD_PATH $KMONAD_CONFIG_PATH"
    sudo $KMONAD_PATH $KMONAD_CONFIG_PATH

    # If kmonad exits, it has crashed. Increment the crash counter.
    CRASH_COUNT=$((CRASH_COUNT + 1))

    # If this is the first crash in the current sequence, record the timestamp
    if [ $CRASH_COUNT -eq 1 ]; then
        FIRST_CRASH_TIMESTAMP=$(date +%s)
    fi

    # Get the current timestamp
    CURRENT_TIMESTAMP=$(date +%s)

    # Calculate the time difference between the first crash and now
    TIME_DIFF=$((CURRENT_TIMESTAMP - FIRST_CRASH_TIMESTAMP))

    # If kmonad has crashed 3 times in less than 60 seconds, exit the loop
    if [ $CRASH_COUNT -ge 3 ] && [ $TIME_DIFF -lt 60 ]; then
        echo "kmonad has crashed too frequently. Exiting."
        exit 1
    fi

    # If more than 60 seconds have passed since the first crash, reset the crash counter
    if [ $TIME_DIFF -ge 60 ]; then
        CRASH_COUNT=0
    fi

    # Wait for a second before trying to restart kmonad
    sleep 1
done

@martin-hyca
Copy link

@nightscape Thank you so much for the script - it works and would be a totally OK'ish solution if only I could run KMONAD without entering my password. So far I have been failing with that. I edited the sudoers file to be able to run all commands without sudo but whenever I run KMONAD without sudo, I get the following error, which to my understanding indicates I am not allowed to access some files without the sudo privileges. Any idea what I could do to fix this?

libc++abi: terminating due to uncaught exception of type std::__1::__fs::filesystem::filesystem_error: filesystem error: in posix_stat: failed to determine attributes for the specified path: Permission denied ["/Library/Application Support/org.pqrs/tmp/rootonly/vhidd_server"] zsh: abort /Users/martinhyca/kmonad/keymap/agemartin.kbd

@nightscape
Copy link
Contributor

Hi @agemartin, I always have the following script ready:

bash -c "sudo chmod u+w /etc/pam.d/sudo; if ! grep -qxE 'auth[[:space:]]+sufficient[[:space:]]+pam_tid\\.so' /etc/pam.d/sudo; then awk 'NR==2{print \"auth       sufficient     pam_tid.so\"} {print}' /etc/pam.d/sudo > temp_sudo && sudo mv temp_sudo /etc/pam.d/sudo; fi; sudo chmod u-w /etc/pam.d/sudo"

That adds the required line to enable the fingerprint sensor to /etc/pam.d/sudo (but only if it's not in there already):

auth       sufficient     pam_tid.so

@amiorin
Copy link

amiorin commented Sep 11, 2023

I have written a guide for macOS

@martin-hyca
Copy link

martin-hyca commented Sep 11, 2023

@nightscape nice, that works and certainly it is nicer to use the fingerprint than entering the password all the time. thanks!

@amiorin thanks! I tried the command from your guide, sudo visudo -f /private/etc/sudoers.d/kmonad which opens an empty file for me in Vi, not sure how to proceed - should I write anything in that file? I tried to save and exit it, does not change anything for me though, still getting the same error when trying to run kmonad without sudo

@amiorin
Copy link

amiorin commented Sep 11, 2023

@agemartin Try now. https://gist.github.com/amiorin/4c74f63fe599a1dcbd0933628df1aac9#skip-sudo-password

@martin-hyca
Copy link

martin-hyca commented Sep 11, 2023

@amiorin
great, thanks for the support!

  • which kmonad did not work for me, however, I know the path of the kmonad binary since this is how I normally run it
  • I failed to create the hash using the command from your guide but followed some other notes to create it by cd to the folder where my kmonad binary resides and then running shasum -a 256 kmonad
  • I successfully updated the private/etc/sudoers.d/kmonad.tmp

EDIT: now it works! I just run it with sudo and it goes through without asking for the password.

(trying to run it without sudo leads to the same error as before, so the way to go is to run it with sudo...)

@slotThe
Copy link
Member

slotThe commented Sep 21, 2023

I have lost track a bit @vosaica where do we stand with this?

@willpuckett
Copy link

All is working great here. Best keyboard experience I've ever had on MacOS.

@slotThe
Copy link
Member

slotThe commented Oct 18, 2023

I'd like to merge this as well! Currently just waiting on how the nix situation develops. @sixtysecrun do you perhaps have a fix already in mind?

@sixtysecrun
Copy link
Contributor

sixtysecrun commented Oct 22, 2023

@sixtysecrun do you perhaps have a fix already in mind?

I have created a PR vosaica#3 that should fix nix build and SDK version problem. I was able to compile it successfully in Nix environment. Can you verify that it is still OK in your setup?

@RKBethke
Copy link

I can confirm that the above patch works great. nix build runs without a hitch and the produced binary runs without issues.

vosaica and others added 4 commits October 25, 2023 07:49
Compiling against Apple SDK older than 12.0 ends with errors:

error: use of undeclared identifier 'kIOMainPortDefault'

That is because `kIOMainPortDefault` was introduced in SDK 12.0
(Monterey) and before that the `kIOMasterPortDefault` should be used.

`kIOMasterPortDefault` was deprecated and was removed in SDK 12.0

References:
- https://developer.apple.com/documentation/iokit/kiomainportdefault
- https://developer.apple.com/documentation/iokit/kiomasterportdefault
@slotThe slotThe force-pushed the Upgrade-DriverKit-VirtualHIDDevice branch from 261e4ef to a96f039 Compare October 25, 2023 05:51
@slotThe slotThe merged commit 1b2ec00 into kmonad:master Oct 25, 2023
13 checks passed
@slotThe
Copy link
Member

slotThe commented Oct 25, 2023

Thanks everyone for the testing and patching up! :)

@sidneydurant
Copy link

sidneydurant commented Oct 29, 2023

My understanding based on this thread is that Monterey (12), Ventura (13) and Sonoma (14) are now all supported? Should kmonad/docs/installation.md be updated? Installation.md only mentions macos up to Big Sur (11)

Edit: seems to be correct - am now running kmonad on Sonoma, seems to be working well so far.

@asciible
Copy link

Could you update the installation documentation for mac?

@robrecord
Copy link

robrecord commented Dec 13, 2023

Can I confirm this is working only for Karabiner-DriverKit-VirtualHIDDevice v2.1.0 and not (yet) for the latest v3.1.0 as included with Karabiner?
I followed the instructions which seemed to work, then upgraded my Karabiner and now I'm not getting any keypresses output. The debug output suggests all is working. Shall I open a new issue?

@vosaica
Copy link
Contributor Author

vosaica commented Dec 13, 2023

Can I confirm this is working only for Karabiner-DriverKit-VirtualHIDDevice v2.1.0 and not (yet) for the latest v3.1.0 as included with Karabiner? I followed the instructions which seemed to work, then upgraded my Karabiner and now I'm not getting any keypresses output. The debug output suggests all is working. Shall I open a new issue?

Merely install v3.1.0 while still using the kmonad compiled with v2.1.0 should not work. There are some breaking changes in v3.1.0.

However, if you want to use the newer version of v3.1.0, you can try this branch where I updated the Karabiner-DriverKit https://github.com/vosaica/kmonad/tree/Dev-DriverKit-v3.1.0

If you have got the compile environment set up, this will do the compilation

git clone --recursive https://github.com/vosaica/kmonad.git
cd kmonad
git checkout Dev-DriverKit-v3.1.0
git submodule update --init
stack build --flag kmonad:dext --extra-include-dirs=c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/include/pqrs/karabiner/driverkit:c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/src/Client/vendor/include

@vosaica
Copy link
Contributor Author

vosaica commented Dec 13, 2023

Can I confirm this is working only for Karabiner-DriverKit-VirtualHIDDevice v2.1.0 and not (yet) for the latest v3.1.0 as included with Karabiner? I followed the instructions which seemed to work, then upgraded my Karabiner and now I'm not getting any keypresses output. The debug output suggests all is working. Shall I open a new issue?

Merely install v3.1.0 while still using the kmonad compiled with v2.1.0 should not work. There are some breaking changes in v3.1.0.

However, if you want to use the newer version of v3.1.0, you can try this branch where I updated the Karabiner-DriverKit https://github.com/vosaica/kmonad/tree/Dev-DriverKit-v3.1.0

If you have got the compile environment set up, this will do the compilation

git clone --recursive https://github.com/vosaica/kmonad.git
cd kmonad
git checkout Dev-DriverKit-v3.1.0
git submodule update --init
stack build --flag kmonad:dext --extra-include-dirs=c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/include/pqrs/karabiner/driverkit:c_src/mac/Karabiner-DriverKit-VirtualHIDDevice/src/Client/vendor/include

I have been using this branch for several months, and it's been running well. I'm not sure if someone wants to upgrade Karabiner-DriverKit to v3.1.0. On one hand, there are some breaking changes so I have to edit the dext.cpp, and on the other hand, v3.1.0 doesn't seem to introduce any new features.

@slotThe If you want, I can create a PR for this upgrade

@robrecord
Copy link

robrecord commented Dec 13, 2023 via email

@slotThe
Copy link
Member

slotThe commented Dec 14, 2023

@vosaica Sure, go ahead!

@TC72
Copy link

TC72 commented Dec 15, 2023

I tried this and it didn't fix it for me.

I upgraded to Karabiner 14.13.0 and System Settings is showing Karabiner DriverKit VirtualHIDKeyboard 1.7.0.
Running

 defaults read /Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/Info.plist CFBundleVersion

Returns 3.1.0

If I run kmonad I get the connected message but there is no keyboard input at all. I have to use my mouse to shutdown the iTerm window kmonad is running in and reconnect my keyboard to get it working again.
As well as upgrading to Karabiner 14.13.0 I upgraded to Sonoma 14.2, just in case that's relevant.

@robrecord
Copy link

robrecord commented Dec 15, 2023

@TC72 Have you tried activating the extension as mentioned before?

It is working for me on Sonoma.

@TC72
Copy link

TC72 commented Dec 15, 2023

@TC72 Have you tried activating the extension as mentioned before?

It is working for me on Sonoma.

Thanks for the reply, as it's showing in system settings I thought that was enough to be sure it's activated?
Are you using the new version of Karabiner?

CleanShot 2023-12-15 at 10 12 56

@robrecord
Copy link

robrecord commented Dec 16, 2023

Hi @TC72 - yes I recently upgraded to the newest Karabiner, then I tried the fork using the instructions given here by @vosaica - I can't remember if I activated the extension then but I have had to do this in the past so I probably did. Forgive me for stating the obvious but have you tried a restart? Otherwise perhaps it might be a case of having more that one extension installed; I'm not sure how that might occur but you could search your system for the filename and see if there's a duplicate.

@TC72
Copy link

TC72 commented Dec 16, 2023

@robrecord thanks I did try to restart. I'll see if activating helps.

@robrecord
Copy link

@robrecord thanks I did try to restart. I'll see if activating helps.

/Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager activate
or
/Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager forceactivate

Good luck

@TC72
Copy link

TC72 commented Dec 17, 2023

@robrecord thanks once again for all your help. I'm not sure what combination fixed this but now when I run kmonad I see this output instead of just connected and it seems to be working.

connected
driver_connected 0
driver_version_mismatched 0
driver_connected 1

Now I learn to create keymaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet