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

Host keymaps - conveniently define keymaps with respect to the keymap running on the host #721

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

noseglasses
Copy link
Collaborator

@noseglasses noseglasses commented Nov 12, 2019

This PR introduces host_keymaps, a convenient way to define keymaps like e.g.

#include "kaleidoscope/host_keymap/linux/us/standard/keymap.h"
#include "kaleidoscope/host_keymap/linux/de/standard/keymap.h"

// Define the us standard keymap as default.
//
USE_HOST_KEYMAP(linux, us, standard)

// Note: All unicode character strings like e.g. L"⌫" or L"ß" require to
//       be prefixed with an L to make C++ store them as wide characters.

enum Layers {
  US,
  German
};

constexpr Key llg = LockLayer(German);

START_KEYMAPS
  [US] = KEYMAP_STACKED
  (
      XXX,   "1",   "2",   "3",   "4",   "5",   XXX,
      "`",   "q",   "w",   "e",   "r",   "t",   "\t",
     L"",   "a",   "s",   "d",   "f",   "g",
     L"",   "z",   "x",   "c",   "v",   "b",   L"",

     L"", L"", L"", L"",
      XXX,

      XXX,   "6",   "7",   "8",   "9",   "0",   XXX,
     L"",   "y",   "u",   "i",   "o",   "p",   "=",
             "h",   "j",   "k",   "l",   ";",  "\"",
      XXX,   "n",   "m",   ",",   ".",   "/",   "-",

      llg, L"r⌥",  L"", L"r⌃",
      XXX
  ),

  // Reset the standard keymap to german
  //
  #undef CONVERT_TO_KEY
  #define CONVERT_TO_KEY(INPUT) MAP_WITH_HOST_KEYMAP(linux, de, standard, INPUT)

  [German] = KEYMAP_STACKED
  (
      XXX,   "1",   "2",   "3",   "4",   "5",   XXX,
      XXX,   "q",   "w",   "e",   "r",   "t",   "\t", // The backtick key does not exist on the german keyboard
     L"",   "a",   "s",   "d",   "f",   "g",
     L"",   "y",   "x",   "c",   "v",   "b",   L"",

     L"", L"", L"", L"",
      XXX,

      XXX,   "6",   "7",   "8",   "9",   "0",   L"ß",
     L"",   "z",   "u",   "i",   "o",   "p",   L"ü",
             "h",   "j",   "k",   "l",  L"ö",   L"ä",
      XXX,   "n",   "m",   ",",   ".",   "-",   XXX,

      ___, L"r⌥",  L"", L"r⌃",
      XXX
  )
END_KEYMAPS
...

See the individual commit messages for a thorough description of the changes as well as the comments in the code that I hope do explain the benefits of this

@noseglasses noseglasses changed the title WIP: Pr host keymap Host keymaps - conveniently define keymaps with respect to the keymap running on the host Nov 15, 2019
@noseglasses noseglasses changed the title Host keymaps - conveniently define keymaps with respect to the keymap running on the host WIP: Host keymaps - conveniently define keymaps with respect to the keymap running on the host Nov 15, 2019
@noseglasses
Copy link
Collaborator Author

I wrote a utility (https://github.com/CapeLeidokos/Kaleidoscope-host_keymap) to convert any existing linux xkb-keymap-variant to a corresponding header that can be used to define host keymaps.

All those 633 keymaps have been added in a subdirectory structure of src/kaleidoscope/host_keymap/linux.

@noseglasses
Copy link
Collaborator Author

Just noticed that I forgot to update the HostKeymap example. That's why travis fails.

@noseglasses
Copy link
Collaborator Author

Factored out the commit that adds all available GNU/Linux XKB keymaps/layouts/variants.

@noseglasses noseglasses force-pushed the pr_host_keymap branch 4 times, most recently from a82ce52 to 2315659 Compare November 17, 2019 16:06
@noseglasses
Copy link
Collaborator Author

Pushed an update that fixed issues with whitespaces and non word characters in xkb layout and variant names.

Added documentation file in Kaleidoscope/doc/host_keymap.md.

@noseglasses
Copy link
Collaborator Author

Pushed an elaborated version of the HostKeymap.ino example.

@obra
Copy link
Member

obra commented Nov 18, 2019

Keeping in mind my earlier caveats about back-compat and the fact that I have -not- studied the implementation of this, I ABSOLUTELY LOVE what it get us.

@obra
Copy link
Member

obra commented Nov 18, 2019

It probably makes sense for us to build a small tool to generate html keymap tables suitable for users to copy-paste values.

@noseglasses noseglasses changed the title WIP: Host keymaps - conveniently define keymaps with respect to the keymap running on the host Host keymaps - conveniently define keymaps with respect to the keymap running on the host Dec 4, 2019
@noseglasses
Copy link
Collaborator Author

Rebased after conflicts occurred.

Florian Fleissner added 4 commits March 4, 2020 12:42
Two new functions have been introduced in namespace kaleidoscope.
One to conveniently add keyflags to an existing Key variable and
another one that can be overloaded to convert other types to type Key.

The keymap definition macros and the modifier function macro (LCTRL,
LALT, ...) are now using the to-Key conversion functions. This
allows users to use alternative ways to define keymaps by
defining types of their own that automatically convert to type Key.

Signed-off-by: Florian Fleissner <[email protected]>
This refactors the KEYMAPS(...) macro and factors out
a header and footer portion that are now define as individual
macros START_KEYMAPS and END_KEYMAPS. The original
KEYMAPS(...) macro now relies on the newly defined macros.

The newly introduced macros enable keymap definitions that
allow for macro definitions between the start and end part
which is not possible inside the KEYMAPS(...) macro invocation.

Signed-off-by: Florian Fleissner <[email protected]>
host_keymaps enable defining keymaps in a natural fashion.
Instead of using Key constants like Key_A or LSHIFT(Key_A) it allows to
conveniently write "a" or "A".

The mappings between ascii and unicode characters to USB-HID keys
works by reverse engineering the host keymaps of a linux system.
The information of the provided keymap files allows for precisely
figuring out the Kaleidoscope-Key that is needed to generate a
specific utf8 character in a given keymap. For non-unicode
keycodes, the linux XKB-keysym name is mapped to a Kaleidoscope-Key.

The newly introduced host_keymap system is easily extensible and allows
users to define their own non-english keymaps, if necessary
by extending an existing keymap.

Signed-off-by: Florian Fleissner <[email protected]>
Signed-off-by: Florian Fleissner <[email protected]>
@fredcallaway
Copy link

Any chance this is going to make it in? I would love to be able to define unicode keypmaps this way!!

@obra
Copy link
Member

obra commented Jun 1, 2020 via email

@obra
Copy link
Member

obra commented Oct 6, 2020

As the first step to getting this or something like it merged, I've pulled in the first several commits from the branch. There's still work I'd like to do to clean up the API, test to see if we can get away with using the same set of keymaps on macos and Windows, and clean up the examples.

@fredcallaway
Copy link

fredcallaway commented Oct 6, 2020

@obra Happy to beta alpha test this (on macOS) if it would be helpful to you. (I know it would be helpful to me!)

@obra
Copy link
Member

obra commented Oct 7, 2020 via email

@fredcallaway
Copy link

I am comfortable working with multiple branches, merging, handling conflicts, and making pull requests.

@obra
Copy link
Member

obra commented Nov 19, 2020 via email

@fredcallaway
Copy link

fredcallaway commented Nov 19, 2020

EDIT: Sorry, false alarm. I am used to error messages showing the important part at the bottom, so I didn't see the real problem, which was easy to resolve.

It works! I'm going to play around a bit more and will report back.

@fredcallaway
Copy link

OK, so my hope for this plugin was that I would be able to create a layer with greek letters (for mathematical notation). However, I see now that this would depend on having a corresponding keymap file, and in turn requires having a Key_ defined for each of the greek letters. I'm now thinking this isn't really feasible :(

@obra
Copy link
Member

obra commented Nov 19, 2020 via email

@fredcallaway
Copy link

macos catalina (10.15)

@noseglasses
Copy link
Collaborator Author

@fredcallaway, this feature is designed in a way that it enables conveniently defining sketches for language specific keymaps.
If there is a host keymap that defines both normal letters and all the greek stuff, then this would work.
With respect to your sketch, I don't have mine at hand right now. But if you are still interested then you could post the one that exhibits the errors so I can have a look at it.

@fredcallaway
Copy link

@noseglasses I don't really understand keymaps well enough to know if one exists, but it sounds like @obra doesn't think there is one. I thought that this plugin was actually reading the string in from the keymap and associating it with the key, which would allow for arbitrary unicode (and even multi-character strings?) But I see now that the keymap files just create aliases for various keys. It doesn't actually allow you to map keys to characters that you couldn't before.

@noseglasses
Copy link
Collaborator Author

I am using Eurkey layout because I am german. It comes with a lot of umlauts and greek letters AFAIK. I can be easily installed on all major Systems.

@noseglasses
Copy link
Collaborator Author

Oh and there's a bunch of math symbols coming with Eurkey as well: https://eurkey.steffen.bruentjen.eu/download/windows/1.3/eurkey-layout-complete.pdf

@fredcallaway
Copy link

Ah this looks promising! But the math symbols are all two-step keys, where you first press alt-m and then press a second key to input the desired character. Is this case handled by your keymap plugin?

@noseglasses
Copy link
Collaborator Author

I understand the layout sheet differently. It looks like you have to press AltGr+Shift plus any other key to get a symbol. All of them at once. That can be done with a normal keymap by adding the respective modifiers if necessary.

@fredcallaway
Copy link

I'm talking specifically about this section
image

I installed the keymap and it behaves as I describe. You press alt-m (doesn't distinguish between left and right) and then an underlined Omega (Ω) comes up, then you press e.g. l to get λ.

By the way, this keymap is still very useful for me even if I can't get it to work with your plugin so thanks for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants