nickcoutsos / keymap-editor

A web based graphical editor of ZMK keymaps.
http://nickcoutsos.github.io/keymap-editor
MIT License
1.11k stars 284 forks source link

Generate a hacky layout by parsing <keyboard>.dtsi #25

Closed nickcoutsos closed 2 years ago

nickcoutsos commented 2 years ago

Using the devicetree parser and treating the default_transform.map node as row-based grid we can put together a rough ortholinear layout.

  1. Each line in the map is a new row.
  2. Find the column start/end location of each RC(...) instance
  3. Compare each column's approximate position to the columns in the previous row
  4. Cells with the greatest amount of text overlap are considered to be the same column

The result is a simple layout of 1u keys that means the end user doesn't need to have created an info.json file to get started. This process could spit one out, however, and give the user an opportunity to tweak it as required.

This will likely look like shit for row-staggered keyboards but I don't care.

nickcoutsos commented 2 years ago

I've got a preliminary implementation just testing against various map = < ... > strings, but going forward it should be noted that the location of the mapping isn't totally straightforward

Probably not going to try too hard for some of these.

nickcoutsos commented 2 years ago

A basic implementation is in place for testing now.

If the server reports that the repo/branch doesn't have a config/info.json file it will prompt the user to try enabling the experimental auto layout functionality.

Screen Shot 2022-04-18 at 7 29 34 PM

The settings dialog presents the option and describes its use and limitations.

Screen Shot 2022-04-18 at 7 28 55 PM

With the experimental option enabled the backend will parse config/boards/shields/<keyboard>.dtsi, get the appropriate matrix transform's map, and create a layout to approximate the textual layout.

Screen Shot 2022-04-18 at 7 30 12 PM

I haven some unit tests to see how it handles a small selection of layouts (including row staggered) and it's going better than I'd thought. I still need to add some error handling and a little more planning around where to actually find the matrix transform per the last comment.

nickcoutsos commented 2 years ago

Another note: if we're going as far as looking in boards/(shields|arm)/<keyboard>/ to find to find the matrix transform then we can also look out for a default <keyboard>.keymap there in case one doesn't exist under config/.

nickcoutsos commented 2 years ago

Finished this a little while ago. For the moment it expects to find the necessary files in the local repository or in the ZMK core repo. I may eventually add support for discovering and searching alternate remotes defined in west.yml.