Visual indication of Layer on Atreus

Hi all,

I am trying to define a (supposedly) simple plugin for my Atreus that will send a signal to my computer based on what Layer I am currently on (example of this working in QMK here: Add QMK visual layer indicator using Hammerspoon | david balatero ) unfortunately, the documentation for Kaleidoscope is too sparse for me to find out how to use the layer.isactive method in a plugin so I was hoping you all could help me out/ point me in the correct direction for implementing this functionality.

The trick here is using the onLayerChange() event in the plugin, and send, well, whatever you want via Focus. Something along these lines:

class LayerIndicator_: public kaleidoscope::Plugin {
 public:
   kaleidoscope::EventHandlerResult onLayerChange() {
     Focus.send("layer-activated", Layer.mostRecent(), "\n");
     return kaleidoscope::EventHandlerResult::OK;
   };
};

This will send the string layer-activated 1\n to the host when layer 1 is activated, and so on and so forth. If you want to send the layer name, you can check the most recent layer with Layer.mostRecent(), and do something like:

Focus.send("layer-activated:");
switch (Layer.mostRecent()) {
  case 0:
    Focus.send("QWERTY");
    break;
  case 1:
    Focus.send("FUN");
    break;
  default:
    Focus.send(Layer.mostRecent());
    break;
}
Focus.send("\n");

Do keep in mind that doing this will interfere with Chrysalis, as they use the same communication channel, so don’t switch layers while Chrysalis is open and connected to your Atreus.

oh awesome, thanks for the assistance! out of curiosity, if i wanted to send a key stroke (for example f_13, an unused key in MacOS) would Focus.send(key_F13) accomplish that?

No, Focus can only send text over USB serial. If you want to send a sequence of key events, the easiest I think is using macros: Macros.send(MACRO(T(F13)));. If you want to send a key whose name does not begin with Key_, you can use Tr(Key_F13) instead of T(F13) (T is the same as Tr, but adds the Key_ prefix). T means Tap, by the way: it presses the key, sends a report, then releases it, and sends another report, thus, simulating a real key tap.

The Macros docs have more info about all the different macro steps you can use.

Thanks for the assistance! I got it to work following your advice. Set up two macros for switching between layers that both changed the layer and sent an unused key to alert the hammerspoon script i have running to change an alert in my system menu bar!

1 Like