Cross platform scaffolding#64
Conversation
|
Thanks @LikeTheSalad! I'll look into it. There are little unit tests unfortunately, the hard parts are difficult to test (keyboard/mouse OS interaction and overlay UI). |
Thanks 🙏 I'm interested in a macOS version. I still haven't tried to make it work locally, so I'm frankly not sure if all the Windows apis have a 1-1 alternative here, but still, fully isolating the existing platform should make it easier to test it later. I still haven't tried mousemaster before, but from the docs, it seems the most feature-rich tool available out there, which is why it'd be nice to use it on other platforms. |
|
Forgot about your PR, sorry. I just reviewed and it's looking good, thanks a lot for this. I just tested quickly and it's working fine.
|
b00b583 to
a5219fa
Compare
|
Thanks for the feedback, @petoncle
I removed the
Done
This one's tricky because it's not possible to reuse the same codes across platforms, and Btw, the refactorings were substantial so those were AI assisted. Let me know what you think 👍 |
|
Great work! Many thanks. I have one comment about the keyboard layout stuff. Let me start by trying to explain how things are architected. I scraped keyboard layout data (KbdlayoutinfoParser) from https://kbdlayout.info/ because there was no reliable way to get it from the Windows API. It outputs KeyboardLayout objects holding a record KeyboardLayoutKey(int scanCode, WindowsVirtualKey virtualKey, Key key,
String text, String name) {}scanCode identifies the physical key, independent of layout. virtualKey identifies the key after a layout is applied: scan code 0x10 reports as VK_Q on US QWERTY but VK_A on AZERTY. I only briefly looked into it, but I believe this record could be extended with the physical-key identifiers macOS/Linux use (W3C KeyboardEvent.code "KeyQ", macOS keycode, X11/XKB code, Linux evdev code, USB HID usage), all derivable from the scan code by joining Chromium's dom_code_data.inc, whose rows are The Key record is the OS-independent and layout-independent key representation: record Key(String staticName, String staticSingleCharacterName, String character) {}
// Two examples:
static final Key esc = new Key("esc", "⎋", null);
static final Key plus = new Key("plus", null, "+");It is identified by a static name or by a produced character because no single identifier fits every key, and what a user writes in a config to refer to a key must be typeable and stable across layouts. Layout-independent keys (esc, f1, arrows, modifiers) sit in the same place on all layouts and mostly produce no character, so they get a staticName. Layout-dependent keys (letters, digits, punctuation) produce different characters per layout, so they are identified by character: +a means "wherever a lives on the active layout". Key holds no scanCode/virtual key so combo matching, macros, and config parsing stay platform-agnostic; KeyboardLayoutKey is the only place that maps a Key to and from the OS-level scanCode/virtualKey. All of that to say instead of |
|
Now about naming, this is what I would suggest:
|
|
Thanks for the quick response, @petoncle. I addressed all your comments in the latest commit (again, it's a lot of changes, so the work is AI-assisted). Let me know if some further changes are needed. |
|
Thank you! I just realized there was an existing MouseController class which I forgot about. I renamed it to MouseManager. I also updated the GraalVM native-image build files with the new class names and packages. |
These changes attempt to abstract Windows-specific functionality into interfaces and create implementations for Windows. The functionality should remain the same, however, it sets up a scaffolding for adding new platform support in the future.
Since I'm not using Windows, the validations I ran are the existing unit tests, so it's probably wise to try these changes out in a Windows machine to make sure nothing's broken (in case some use cases aren't covered by tests).