-
Notifications
You must be signed in to change notification settings - Fork 219
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
How difficult do you estimate it would be to port this to linux? #81
Comments
The code that detects a keypress is pretty much entirely separate. We use something called an event tap in macOS to listen for key-down events, see this function: https://github.com/koekeishiya/skhd/blob/master/src/skhd.c#L147 During parsing we map the actual text to keycode and modifier values. These keycodes and modifier values are sort of interleaved with the code, but the definitions are easy to find and replace. See also https://github.com/koekeishiya/skhd/blob/master/src/locale.c for the code that builds our map from letters to their corresponding keycode. I actually have no clue how input works on Linux, but that will likely affect the difficulty of porting this code, due to how it is structured. The codebase should be fairly simple to understand, the main parts you care about would be the tokenize.c, parse.c and hotkey.c. If you want to port the full feature set, you also need some way to detect the currently active process for blacklisting and/or application specific bindings, as well as some way to retrieve file modified events for hotloading. |
Every programmer likes to think their codebase is easy to understand, but in your case, I believe you 😊. Re input, me neither. But I can scan Last two I think are simple, probably through |
To help understand this + control flow entry better, what function does the OS call when someone pushes/releases a key? |
The OS calls the function I referenced in my previous comment: https://github.com/koekeishiya/skhd/blob/master/src/skhd.c#L147 It uses the CoreGraphis event tap API to register that function as a callback. You can find the implementation of my event tap wrapper in the The code to simulate a keypress can be found in the file |
Next question: What do you use the CoreAudio framework for? |
Accurate timing information for profiling performance. The CoreAudio framework is the most accurate API that macOS has to offer if I remember correctly. Sent with GitHawk |
Aah, that's useful info. Thank you. |
I've taken a few cracks at this. Writing equivalent linux functions should be mostly simple. Where I'm struggling is understanding how skhd interacts with carbon and eventtaps. I constantly butt up against the fact that system and eventtap code is not particularly heavily abstracted, yet skhd.c contains lots of references to specific OSX and eventtap and features, flags or functions. This is a big proposal, and I'm loath to ask so much of you just for benefits you won't directly use, but how would you feel about adding an extra abstraction layer to any calls that interface with the system? I mean such that the main code calls functions like Sorry if this request is unclear, but it's hard to give examples without understanding more of the calls you make. I suppose what I'm asking for is a |
@BlueDrink9 I have recently found out about |
Hotloading, easy modes and chords that can run commands on entry, and sending keypresses without recursively receiving |
You should also consider autokey on linux\X11, if you are willing to sacrifice usability for flexibility |
I'm not asking you to do this, of course. But if you were willing to let someone else fork this, it would be a huge improvement over sxhkd on linux.
How separated is the code for handling keypresses? (Ie the OS-specific stuff)?
The text was updated successfully, but these errors were encountered: