logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

feature_layouts.md (3415B)


  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. ```markdown
  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. ```c
  31. #define LAYOUT_60_ansi KEYMAP_ANSI
  32. ```
  33. The name of the layout must match this regex: `[a-z0-9_]+`
  34. The folder name must be added to the keyboard's `rules.mk`:
  35. ```
  36. LAYOUTS = 60_ansi
  37. ```
  38. `LAYOUTS` can be set in any keyboard folder level's `rules.mk`:
  39. ```
  40. LAYOUTS = 60_iso
  41. ```
  42. but the `LAYOUT_<layout>` variable must be defined in `<folder>.h` as well.
  43. ## Building a Keymap
  44. You should be able to build the keyboard keymap with a command in this format:
  45. ```
  46. make <keyboard>:<layout>
  47. ```
  48. ### Conflicting layouts
  49. When a keyboard supports multiple layout options,
  50. ```
  51. LAYOUTS = ortho_4x4 ortho_4x12
  52. ```
  53. And a layout exists for both options,
  54. ```
  55. layouts/
  56. + community/
  57. | + ortho_4x4/
  58. | | + <layout>/
  59. | | | + ...
  60. | + ortho_4x12/
  61. | | + <layout>/
  62. | | | + ...
  63. | + ...
  64. ```
  65. The FORCE_LAYOUT argument can be used to specify which layout to build
  66. ```
  67. make <keyboard>:<layout> FORCE_LAYOUT=ortho_4x4
  68. make <keyboard>:<layout> FORCE_LAYOUT=ortho_4x12
  69. ```
  70. ## Tips for Making Layouts Keyboard-Agnostic
  71. ### Includes
  72. 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:
  73. ```c
  74. #include QMK_KEYBOARD_H
  75. ```
  76. If you want to keep some keyboard-specific code, you can use these variables to escape it with an `#ifdef` statement:
  77. * `KEYBOARD_<folder1>_<folder2>`
  78. For example:
  79. ```c
  80. #ifdef KEYBOARD_planck
  81. #ifdef KEYBOARD_planck_rev4
  82. planck_rev4_function();
  83. #endif
  84. #endif
  85. ```
  86. Note that the names are lowercase and match the folder/file names for the keyboard/revision exactly.
  87. ### Keymaps
  88. 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.