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

refactor: Moved all layouts into their own files #2582

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Nick-Munnich
Copy link
Contributor

@Nick-Munnich Nick-Munnich commented Oct 21, 2024

As discussed on Discord. Also adjusted the docs for consistency.

I am not entirely sold on the matrix transform assignments happening in the separate file as well, thoughts?

@Nick-Munnich Nick-Munnich requested a review from a team as a code owner October 21, 2024 17:47
@caksoylar
Copy link
Contributor

Maybe I missed the aforementioned conversation -- I don't think pulling out layouts that simply import and modify the common layouts are necessary, is it? It adds a lot of noise for a few lines of config.

@Nick-Munnich
Copy link
Contributor Author

Maybe I missed the aforementioned conversation -- I don't think pulling out layouts that simply import and modify the common layouts are necessary, is it? It adds a lot of noise for a few lines of config.

Yeah, that's the part I wasn't certain on myself. I think it would make sense to leave that kind of thing in, but then that raises the question of how to handle situations like the Kyria correctly. I like the way you defined it originally, but I'm not sure how best to extend that to a convention.

@caksoylar
Copy link
Contributor

caksoylar commented Oct 21, 2024

My thinking would be that if a keys property is to be defined then you should pull it off to a separate file. You'd do that even if the keyboard only has one physical layout, which we seem to have left in the dtsi/overlay before this PR.

@joelspadin
Copy link
Collaborator

joelspadin commented Oct 22, 2024

The presence of a keys property seems like a weird condition for switching to use a separate file to me. Part of the reason I started the discussion on Discord that led to this was because I was updating the ZMK CLI new keyboard templates for Studio, and our current documentation says to use a layouts.dtsi file only if you use keys, so then I'd need the template to either

  1. Create a -layouts.dtsi file with a keys property and add a comment that you should delete keys, move the contents back to the main file, and delete -layouts.dtsi if you don't intend to support Studio.
  2. Put the position map into the main file with no keys property by default and add a comment that you should create a -layouts.dtsi file and move the position map there before adding keys if you intend to support Studio.

Both of those options seemed needlessly complicated.

I don't really have strong feelings on what to do with matrix transforms. We could either

  1. Define the physical layouts and position map in -layouts.dtsi and assign their matrix transforms in the main file, which is a bit verbose.
  2. Define the physical layouts and position map and assign their matrix transforms in the -layouts.dtsi file, since you can reference nodes before they're actually defined.
  3. Move the matrix transforms into the -layouts.dtsi file too? Then it's easier to compare them with the matching position maps, but harder to compare them with the kscan definitions (unless we also moved those).

I also don't really have strong feelings on whether -layouts.dtsi is needed if you're just pulling in common layouts. I think I'm leaning towards no.

@caksoylar
Copy link
Contributor

Nick pointed me to the previous discussion on Discord offline, where there seemed to be a consensus on always splitting off to a dtsi, similar to pinctrl. I don't have strong opinions against that, so I'd be fine with the current state of the PR. I am also OK with keeping the separate file even if it is just using a common layout, for consistency.

Re: matrix transforms, 2. might be the most practical right now, however 3. might be the most consistent.

@Nick-Munnich
Copy link
Contributor Author

Any thoughts on how to handle the kyria case? It's failing compilation because despite being disabled the 5 col node still exists and references an undefined 5 col matrix transform in the rev3 case. I could delete-node it. Could also rearrange a bunch of things to avoid needing to resort to that, but I'm not sure what the best way to rearrange would be.

@joelspadin
Copy link
Collaborator

Maybe you could mirror the structure of the common layouts with one physical layout + position map child per file, and then have each of the rev2 and rev3 files include just the relevant ones?

@Nick-Munnich Nick-Munnich force-pushed the physical-layouts-refactor branch 2 times, most recently from b6fd56f to 317f83b Compare October 23, 2024 08:42
@Nick-Munnich
Copy link
Contributor Author

Maybe you could mirror the structure of the common layouts with one physical layout + position map child per file, and then have each of the rev2 and rev3 files include just the relevant ones?

I've ended up going with this, at least for the time being. I think I'd be in favor of assigning matrix transform names to the common layouts, and then importing those directly. The layouts file would then appear if there was a need to change the name used for the matrix transform for the common layouts, something I would imagine mostly would only occur if there are other non-common layouts being defined as well. I think that approach would be just as consistent, but much less noisy.

I did try the /delete-node/ approach, but then we'd also need to delete node the position map child node and that just feels messy.

Comment on lines +8 to +9
transform = <&default_transform>;
kscan = <&kscan0>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really stuck on this aspect of the refactor. In particular, this makes this import still highly coupled with the importing environment, and makes it harder to refactor without surprising side effects. It also makes it so that future refactors that might identify "Hey, this layout is actually useful, and should be shared!" requires extracting this coupling later anyways.

It also leads to a "two ways to do things" situation, between "using shared layouts" and "using local layouts" that would potentially lead to more confusion. IMHO, I favor Joel's first proposed option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like consistency between the shared and the local approaches on this point, which way around it goes I'm not too fussy about. That option is a bit ugly, but justifiable imo. What would your thoughts be on applying option 2 to all the shared layouts?

I do think that option 1 should be used for binding kscans to physical transforms when different kscans are used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO matrix transforms are just as tightly coupled to the "host" that is going to inject them, and shouldn't be set either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor studio ZMK Studio (runtime keymaps)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants