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

Allow multiple commands on key #21

Open
pjamar opened this issue Feb 24, 2016 · 3 comments
Open

Allow multiple commands on key #21

pjamar opened this issue Feb 24, 2016 · 3 comments

Comments

@pjamar
Copy link

pjamar commented Feb 24, 2016

I would like to be able to specify more than one action associated with a key to be able to perform move complicated interactions.

As an example this would be one of my use cases:

I would like to use keys G15 thru G19 and G20 to manage bookmarks in Android Developer Studio.

  • Keys G15, G16, G17, G18 and G19 are used to jump to different bookmarks (CTRL+0 .. CTRL+4).
  • Key G20 activates the bookmark set functionality and G21 restores the jump to bookmark bindings

G20 bind would be like this:

!rgb 255 0 0 # Put the screen red to flag the store functionality
!bind G15 LEFTCTRL+LEFTSHIFT+0
!bind G16 LEFTCTRL+LEFTSHIFT+1
!bind G17 LEFTCTRL+LEFTSHIFT+2
!bind G18 LEFTCTRL+LEFTSHIFT+3
!bind G19 LEFTCTRL+LEFTSHIFT+4

And G21 bind would be like this:

!rgb 0 255 0 # Put the screen back to standard color
!bind G15 LEFTCTRL+0
!bind G16 LEFTCTRL+1
!bind G17 LEFTCTRL+2
!bind G18 LEFTCTRL+3
!bind G19 LEFTCTRL+4

It would be even better if we can have an action to activate a profile (basically send a whole file to /tmp/g13-0)

BTW: Great tool, thanks a lot for all your effort :)

@james-fowler
Copy link
Collaborator

There is not currently a direct way to attach multiple commands to a key, however you can do most of what you describe using profiles, and there is already an action to activate a profile ( !profile foo )

  profile use_bookmarks

  profile set_bookmarks
  bind G15 LEFTCTRL+LEFTSHIFT+0
  bind G16 LEFTCTRL+LEFTSHIFT+1
  bind G17 LEFTCTRL+LEFTSHIFT+2
  bind G18 LEFTCTRL+LEFTSHIFT+3
  bind G19 LEFTCTRL+LEFTSHIFT+4
  bind g21 !profile use_bookmarks

  profile use_bookmarks
  bind G15 LEFTCTRL+0
  bind G16 LEFTCTRL+1
  bind G17 LEFTCTRL+2
  bind G18 LEFTCTRL+3
  bind G19 LEFTCTRL+4
  bind g20 !profile set_bookmarks

This should sets up two profiles, and set G20 and G21 to switch between them. The only thing it doesn't do is change the led color. You could also use the output pipe action to send a token to an outside process (I use python scripts) which responds by sending whatever commands you want to the input pipe (/tmp/g13-0) - that can get as complicated as you please.

Coming up with a solid syntax for specifying multiple commands for a single key/action can be tricky. If you use multiple lines, there's a potential for conflicts with commands coming from multiple sources concurrently which could get quite confusing. Could be done, but I'm a little concerned that it would add complexity without providing much benefit, as it would only help with static G13-specific changes that don't require outside interaction (i.e. sending a message to an external process). Bit of a slippery slope, as more use cases pop up we could eventually end up with a Turing complete configuration grammar... which IMHO is excessive overkill when the small number of users needing that complexity already had a much more powerful way to manage it.

Besides the currently available option ( bind G20 >switch_to_set_bookmarks, with and external script listening to /tmp/g13-0_out ), There are a few other ways to handle more complex configurations without multiple commands. It would be fairly simple to allow actions to be attached to a profile, such that they are executed whenever that profile is activated - that would fully support the use case you described, including color changes. It also would be possible to embed a python interpreter into g13d, but that's not so simple and adds overhead for people who don't need it (or build complexity for multiple targets).

Don't get me wrong, I'm all for enabling more complex use cases, and I actually use them myself (I've got a python script that allows me to reconfigure my G13 as I switch between screens using Synergy). But it's also good to keep g13d itself as simple as reasonable for most users, and avoid anything that will "break" current usage. Since this project hummed along for six years before getting features like profiles, pipe output, and multi-key bindings, I suspect that the vast majority of g13d users wouldn't get much out of an increasingly complex configuration grammar.

That said, you're welcome to take a crack at it. The syntax I'd suggest would be something like

macro add _name action_ : add _action_ to macro _name_ (creating it if necessary)
macro call _name_ : invoke macro _name_

so you're configuration would something look like this

  macro add switch_to_set_bookmarks !profile set_bookmarks
  macro add switch_to_set_bookmarks !rgb 255 0 0

  macro add switch_to_use_bookmarks !profile use_bookmarks
  macro add switch_to_use_bookmarks !rgb 0 255 0

  bind g20 !macro call switch_to_set_bookmarks
  bind g21 !macro call switch_to_use_bookmarks

  profile set_bookmarks
  bind G15 LEFTCTRL+LEFTSHIFT+0
  bind G16 LEFTCTRL+LEFTSHIFT+1
  bind G17 LEFTCTRL+LEFTSHIFT+2
  bind G18 LEFTCTRL+LEFTSHIFT+3
  bind G19 LEFTCTRL+LEFTSHIFT+4

  profile use_bookmarks
  bind G15 LEFTCTRL+0
  bind G16 LEFTCTRL+1
  bind G17 LEFTCTRL+2
  bind G18 LEFTCTRL+3
  bind G19 LEFTCTRL+4

@pjamar
Copy link
Author

pjamar commented Feb 26, 2016

Thanks so much for the detailed explanation.

Definitely is much easier to do with profiles even though I wouldn't be able to change screen colour. I'll go for that until I get some time to either add macros or make my own python script that processes /tmp/g13-0_out input.

@weverett
Copy link

Is it possible to attach actions to a profile? I'd like to set the LCD to display the name of the profile that's currently active without having a listener script.

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

No branches or pull requests

3 participants