You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.3 KiB

  1. # Layouts: Using a Keymap with Multiple Keyboards
  2. The `layouts/` folder contains different physical key layouts that can apply to different keyboards.
  3. ```
  4. layouts/
  5. + default/
  6. | + 60_ansi/
  7. | | + readme.md
  8. | | + layout.json
  9. | | + a_good_keymap/
  10. | | | + keymap.c
  11. | | | + readme.md
  12. | | | + config.h
  13. | | | + rules.mk
  14. | | + <keymap folder>/
  15. | | + ...
  16. | + <layout folder>/
  17. + community/
  18. | + <layout folder>/
  19. | + ...
  20. ```
  21. The `layouts/default/` and `layouts/community/` are two examples of layout "repositories" - currently `default` will contain all of the information concerning the layout, and one default keymap named `default_<layout>`, for users to use as a reference. `community` contains all of the community keymaps, with the eventual goal of being split-off into a separate repo for users to clone into `layouts/`. QMK searches through all folders in `layouts/`, so it's possible to have multiple repositories here.
  22. Each layout folder is named (`[a-z0-9_]`) after the physical aspects of the layout, in the most generic way possible, and contains a `readme.md` with the layout to be defined by the keyboard:
  23. ```md
  24. # 60_ansi
  25. LAYOUT_60_ansi
  26. ```
  27. New names should try to stick to the standards set by existing layouts, and can be discussed in the PR/Issue.
  28. ## Supporting a Layout
  29. For a keyboard to support a layout, the variable must be defined in it's `<keyboard>.h`, and match the number of arguments/keys (and preferably the physical layout):
  30. #define LAYOUT_60_ansi KEYMAP_ANSI
  31. The name of the layout must match this regex: `[a-z0-9_]+`
  32. The folder name must be added to the keyboard's `rules.mk`:
  33. LAYOUTS = 60_ansi
  34. `LAYOUTS` can be set in any keyboard folder level's `rules.mk`:
  35. LAYOUTS = 60_iso
  36. but the `LAYOUT_<layout>` variable must be defined in `<folder>.h` as well.
  37. ## Building a Keymap
  38. You should be able to build the keyboard keymap with a command in this format:
  39. make <keyboard>:<layout>
  40. ### Conflicting layouts
  41. When a keyboard supports multiple layout options,
  42. LAYOUTS = ortho_4x4 ortho_4x12
  43. And a layout exists for both options,
  44. ```
  45. layouts/
  46. + community/
  47. | + ortho_4x4/
  48. | | + <layout>/
  49. | | | + ...
  50. | + ortho_4x12/
  51. | | + <layout>/
  52. | | | + ...
  53. | + ...
  54. ```
  55. The FORCE_LAYOUT argument can be used to specify which layout to build
  56. make <keyboard>:<layout> FORCE_LAYOUT=ortho_4x4
  57. make <keyboard>:<layout> FORCE_LAYOUT=ortho_4x12
  58. ## Tips for Making Layouts Keyboard-Agnostic
  59. ### Includes
  60. Instead of using `#include "planck.h"`, you can use this line to include whatever `<keyboard>.h` (`<folder>.h` should not be included here) file that is being compiled:
  61. #include QMK_KEYBOARD_H
  62. If you want to keep some keyboard-specific code, you can use these variables to escape it with an `#ifdef` statement:
  63. * `KEYBOARD_<folder1>_<folder2>`
  64. For example:
  65. ```c
  66. #ifdef KEYBOARD_planck
  67. #ifdef KEYBOARD_planck_rev4
  68. planck_rev4_function();
  69. #endif
  70. #endif
  71. ```
  72. Note that the names are lowercase and match the folder/file names for the keyboard/revision exactly.
  73. ### Keymaps
  74. In order to support both split and non-split keyboards with the same layout, you need to use the keyboard agnostic `LAYOUT_<layout name>` macro in your keymap. For instance, in order for a Let's Split and Planck to share the same layout file, you need to use `LAYOUT_ortho_4x12` instead of `LAYOUT_planck_grid` or just `{}` for a C array.