yqrashawn / GokuRakuJoudo

config karabiner with ease
GNU General Public License v3.0
1.16k stars 121 forks source link

How to define a "layer" with `variable_if` for values other than 1? #133

Open lizyn opened 3 years ago

lizyn commented 3 years ago

In this issue and the example here , a way of defining conditions with variable_if is provided. (BTW, is variable_unless supported now in simple syntax?). This works well, but I'll have to define the condition for every single <from> and <to> pair, which seems a bit inconvenient in my case. Instead, I'd like to have the same condition apply to multiple rules, like what :in-alfred does in this snippet, which I have pasted below for your convenience.

{:main [{:des   "alfred"
         :rules [;; set f16 as the trigger key of alfred
                 ;; press h + l will trigger alfred and set "in-alfred" to 1
                 [[:h :j] [:f16 ["in-alfred" 1]]]

                 ==============================================
                 I want something like `["in-alfred" 2]`,
                 i.e. when "in-alfred" is 2, in replace of the following
                 ==============================================
                 :in-alfred ;; when "in-alfred" is 1

                 ;; press enter will select one alfred result and set "in-alfred" to 0
                 [:##return_or_enter [:return_or_enter ["in-alfred" 0]]]

                 ;; press esc will exit alfred and set "in-alfred" to 0
                 [:##escape [:escape ["in-alfred" 0]]]

                 ;; press ctrl + j will invoke down_arrow
                 [:!Tj :down_arrow]

                 ;; press ctrl + k will invoke up_arrow
                 [:!Tk :up_arrow]

                 ;; press ctrl + l will invoke return_or_enter and set "in-alfred" to 0
                 [:!Tl [:return_or_enter ["in-alfred 0"]]]]}]}

Anyway, I tinkered with the config for a while, but no luck till now. Could you please help me with this?

lizyn commented 3 years ago

I now realize the "old layers" are just another name for variable-based conditions, so I deleted some text above.