From 9fe23d5de54f14ff57bac80cf4d80e0c2ad733c7 Mon Sep 17 00:00:00 2001 From: yqrashawn Date: Thu, 28 May 2020 17:38:38 +0800 Subject: [PATCH] Add: modifier keys without left or right (#63) resolve #62 --- CHANGELOG.org | 23 ++++++++- src/karabiner_configurator/keys.clj | 56 +++++++++++++++++----- test/karabiner_configurator/rules_test.clj | 29 +++++++++-- 3 files changed, 93 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 6dacc93..5f78f32 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -3,7 +3,28 @@ All notable changes to this project will be documented in this file. This change ** Unreleased -[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.3.1...HEAD +[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.3.2...HEAD + +** 0.3.2 - 2020-05-28 +*** Added +- support specify ~command~ rather than ~left_command~ or ~shift~ rather than + ~left_shift~ or ... in ~!CTOS~ format + - ~!~ to ~[:left_command :left_control :left_option :left_shift]~ + - ~!A~ to ~[:command :control :option :shift]~ + - ~C~ to ~:left_command~ + - ~Q~ to ~:right_command~ + - ~CC~ to ~:command~ + - ~T~ to ~:left_control~ + - ~W~ to ~:right_control~ + - ~TT~ to ~:control~ + - ~O~ to ~:left_option~ + - ~E~ to ~:right_option~ + - ~OO~ to ~:option~ + - ~S~ to ~:left_shift~ + - ~R~ to ~:right_shift~ + - ~SS~ to ~:shift~ + +[commits in 0.3.2]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.3.1...0.3.2 ** 0.3.1 - 2020-05-10 *** Fixed diff --git a/src/karabiner_configurator/keys.clj b/src/karabiner_configurator/keys.clj index 0d33058..3e486bb 100644 --- a/src/karabiner_configurator/keys.clj +++ b/src/karabiner_configurator/keys.clj @@ -2,7 +2,8 @@ (:require [karabiner-configurator.misc :refer :all] [karabiner-configurator.data :refer :all] - [karabiner-configurator.modifiers :as kmodifier])) + [karabiner-configurator.modifiers :as kmodifier] + [clojure.string :refer [includes? join]])) (def any-key-keywords {:consumer_key_code {} :pointing_button {} @@ -30,8 +31,8 @@ [mkey] (into {} (map update-mouse-map mkey))) -(def special-modi-re #"(^![!CSTOQWERFP]+#[#CSTOQWERFP]+)") -(def special-modi-mandatory-re #"(^![!CSTOQWERFP]+)") +(def special-modi-re #"(^![!ACSTOQWERFP]+#[#CSTOQWERFP]+)") +(def special-modi-mandatory-re #"(^![!ACSTOQWERFP]+)") (def special-modi-optional-re #"(^#[#CSTOQWERFP]+)") (def special-modi-optional-both-re #"(#[#CSTOQWERFP]+)") @@ -60,10 +61,34 @@ [vec] (if (vector? vec) (let [result [] - result (if (contains?? vec \C) (conj result (name :left_command)) result) - result (if (contains?? vec \T) (conj result (name :left_control)) result) - result (if (contains?? vec \O) (conj result (name :left_option)) result) - result (if (contains?? vec \S) (conj result (name :left_shift)) result) + s (join "" vec) + result (cond + (includes? s "CC") + (conj result (name :command)) + (contains?? vec \C) + (conj result (name :left_command)) + :else + result) + result (cond + (includes? s "TT") + (conj result (name :control)) + (contains?? vec \T) + (conj result (name :left_control)) + :else + result) + result (cond + (includes? s "OO") + (conj result (name :option)) + (contains?? vec \O) (conj result (name :left_option)) + :else + result) + result (cond + (includes? s "SS") + (conj result (name :shift)) + (contains?? vec \S) + (conj result (name :left_shift)) + :else + result) result (if (contains?? vec \Q) (conj result (name :right_command)) result) result (if (contains?? vec \W) (conj result (name :right_control)) result) result (if (contains?? vec \E) (conj result (name :right_option)) result) @@ -71,10 +96,19 @@ result (if (contains?? vec \F) (conj result (name :fn)) result) result (if (contains?? vec \P) (conj result (name :caps_lock)) result) result (if (contains?? vec \#) [(name :any)] result) - result (if (contains?? vec \!) [(name :left_command) - (name :left_control) - (name :left_option) - (name :left_shift)] result)] + result (cond + (includes? s "!A") + [(name :command) + (name :control) + (name :option) + (name :shift)] + (contains?? vec \!) + [(name :left_command) + (name :left_control) + (name :left_option) + (name :left_shift)] + :else + result)] result) nil)) diff --git a/test/karabiner_configurator/rules_test.clj b/test/karabiner_configurator/rules_test.clj index 2659b0c..16cfded 100644 --- a/test/karabiner_configurator/rules_test.clj +++ b/test/karabiner_configurator/rules_test.clj @@ -6,7 +6,9 @@ (def example-mains [{:des "a to 1" :rules [[:condi :chunkwm-move-mode] [:profiles :Default :test-profile-2] [:a :1]]} ;; a to 1 - {:des "left command a to control 1" :rules [[:!C#Pa :!T1]]} + {:des "[left] command a to control 1" :rules [[:!C#Pa :!T1] + [:!CC#Pa :!TT1] + [:!CCTTOOSS#Pa :!TT1]]} {:des "right command a to control 1" :rules [[:!Q#Pa :!T1]]} ;; command a to control 1 {:des "my spacebar to control 1" :rules [[:my-spacebar :!T1]]} ;; my-spacebar to control 1 {:des "press b to insert 12" :rules [[:b [:1 :2]]]} ;; key to key @@ -26,7 +28,8 @@ [:!C#Pq ["command-q" 1] :safari {:delayed {:invoked ["command-q" 0] :canceled ["command-q" 0]}}]]} {:des "Mouse button" :rules [[{:pkey :button5} :mission_control] - [{:pkey :button4} [{:pkey :button1} {:pkey :button1} :!!grave_accent_and_tilde]]]} + [{:pkey :button4} [{:pkey :button1} {:pkey :button1} :!!grave_accent_and_tilde]] + [{:pkey :button4} [{:pkey :button1} {:pkey :button1} :!!Agrave_accent_and_tilde]]]} {:des "Change input source" :rules [[:i :us :q-mode] [:o :squirrel :q-mode]]} @@ -142,13 +145,25 @@ :conditions [{:name "chunkwm-move-mode", :value 1, :type "variable_if"}], :type "basic"}]} - {:description "left command a to control 1", + {:description "[left] command a to control 1", :manipulators [{:from {:key_code "a", :modifiers {:mandatory ["left_command"], :optional ["caps_lock"]}}, :to [{:key_code "1", :modifiers ["left_control"]}], + :type "basic"} + {:from + {:key_code "a", + :modifiers + {:mandatory ["command"], :optional ["caps_lock"]}}, + :to [{:key_code "1", :modifiers ["control"]}], + :type "basic"} + {:from + {:key_code "a", + :modifiers + {:mandatory ["command", "control", "option", "shift"], :optional ["caps_lock"]}}, + :to [{:key_code "1", :modifiers ["control"]}], :type "basic"}]} {:description "right command a to control 1", :manipulators @@ -327,6 +342,14 @@ {:key_code "grave_accent_and_tilde", :modifiers ["left_command" "left_control" "left_option" "left_shift"]}], + :type "basic"} + {:from {:pointing_button "button4"}, + :to + [{:pointing_button "button1"} + {:pointing_button "button1"} + {:key_code "grave_accent_and_tilde", + :modifiers + ["command" "control" "option" "shift"]}], :type "basic"}]} {:description "Change input source", :manipulators