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

How difficult do you estimate it would be to port this to linux? #81

Open
BlueDrink9 opened this issue May 13, 2019 · 11 comments
Open

How difficult do you estimate it would be to port this to linux? #81

BlueDrink9 opened this issue May 13, 2019 · 11 comments

Comments

@BlueDrink9
Copy link

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)?

@koekeishiya
Copy link
Owner

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.

@BlueDrink9
Copy link
Author

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 sxhkd and see what events they use. I just hope key up/down is the same…

Last two I think are simple, probably through inotify and some X program whose name escapes me.

@BlueDrink9
Copy link
Author

To help understand this + control flow entry better, what function does the OS call when someone pushes/releases a key?
What function might I call to simulate a key or letter press?

@koekeishiya
Copy link
Owner

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 event_tap.c: https://github.com/koekeishiya/skhd/blob/master/src/event_tap.c

The code to simulate a keypress can be found in the file synthesize.c: https://github.com/koekeishiya/skhd/blob/master/src/synthesize.c

@BlueDrink9
Copy link
Author

Next question: What do you use the CoreAudio framework for?

@koekeishiya
Copy link
Owner

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

@BlueDrink9
Copy link
Author

Aah, that's useful info. Thank you.

@BlueDrink9
Copy link
Author

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 listenForKeypress, respondToKeypressEvent, respondToKeyDown and such that keypress events are structures that contain only the data skhd needs, with clear implementation-independent variable names.

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 main function that doesn't require any knowledge of OSX apis to understand.

@dufferzafar
Copy link

it would be a huge improvement over sxhkd on linux.

@BlueDrink9 I have recently found out about sxhkd and was planning to use it. Could you please explain what is currently lacking in sxhkd? and how skhd would improve upon them?

@BlueDrink9
Copy link
Author

Hotloading, easy modes and chords that can run commands on entry, and sending keypresses without recursively receiving

@BlueDrink9
Copy link
Author

You should also consider autokey on linux\X11, if you are willing to sacrifice usability for flexibility

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

No branches or pull requests

3 participants