Skip to content

Commit 4750009

Browse files
committed
feat: add frontmost_application_history_index support
software_function.open_application - :oi frontmost_application_history_index - :oid bundle_identifier BREAKING CHANGE: software_function.open_application :oi changed from bundle_identifier to frontmost_application_history_index
1 parent 6c6d1cb commit 4750009

File tree

5 files changed

+205
-159
lines changed

5 files changed

+205
-159
lines changed

CHANGELOG.org

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ All notable changes to this project will be documented in this file. This change
33

44
** Unreleased
55

6-
[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.7.2..HEAD
6+
[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.8.0..HEAD
7+
8+
** 0.8.0 - 2025-02-22
9+
*** Added
10+
*BREAKING*
11+
~:oi~ changed from ~bundle_identifier~ to ~frontmost_application_history_index~
12+
~:oid~ is now ~bundle_identifier~
13+
14+
- software_function.open_application.frontmost_application_history_index
715

816
** 0.7.2 - 2024-10-17
917
*** Added
@@ -15,7 +23,7 @@ All notable changes to this project will be documented in this file. This change
1523

1624
** 0.7.0 - 2024-10-16
1725
*** Added
18-
- BREAKING `software_function` support, [karabiner doc](https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/to/software_function/)
26+
- *BREAKING* `software_function` support, [karabiner doc](https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/to/software_function/)
1927
- example can be found at https://github.com/yqrashawn/GokuRakuJoudo/commit/8dfe510eeaec58c3314afceab0e4b8ac20cfa4ba#diff-bdf007c27f040fdb32781729c690e316b78cb697fac1e9b4f14f19aeb0cff70fR92-R691
2028
- homebrew goku now supports arm devices
2129

src/karabiner_configurator/data.clj

+7
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@
8383
(and (vector? vec)
8484
(let [[k i] vec]
8585
(and (= k :oi)
86+
(int? i)))))
87+
88+
(defn oid? [vec]
89+
(and (vector? vec)
90+
(let [[k i] vec]
91+
(and (= k :oid)
8692
(string? i)))))
93+
8794
(defn raw-rule? [rule]
8895
(and (map? rule)
8996
(or (= :basic (:type rule))

src/karabiner_configurator/rules.clj

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
(let [[_ path] to]
6565
(first (tos/parse-to des [{:softf {:open {:file_path path}}}]))))
6666
(defn parse-oi-with-tos [des to]
67+
(let [[_ idx] to]
68+
(first
69+
(tos/parse-to
70+
des
71+
[{:softf {:open {:frontmost_application_history_index idx}}}]))))
72+
(defn parse-oid-with-tos [des to]
6773
(let [[_ id] to]
6874
(first (tos/parse-to des [{:softf {:open {:bundle_identifier id}}}]))))
6975

@@ -75,6 +81,8 @@
7581
[(parse-noti-with-tos des to)]
7682
(d/op? to)
7783
[(parse-op-with-tos des to)]
84+
(d/oid? to)
85+
[(parse-oid-with-tos des to)]
7886
(d/oi? to)
7987
[(parse-oi-with-tos des to)]
8088
(d/softf? to)

src/karabiner_configurator/tos.clj

+78-62
Original file line numberDiff line numberDiff line change
@@ -65,68 +65,84 @@
6565
[tname tinfos]
6666
(mapv
6767
(fn [{:keys [set input shell lazy repeat halt hold_down_ms select_input_source noti softf] :as tinfo}]
68-
(let [result (parse-key tname tinfo true true)
69-
_validate-shell (massert (or (and (vector? shell) (contains? (:templates @conf-data) (first shell))) (string? shell) (nil? shell))
70-
(str "invalid `shell` in to definition " tname " " shell ", should be string or keyword"))
71-
_validate-input (massert (or (nil? input) (and (keyword? input) (contains? (:input-sources @conf-data) input)))
72-
(str "invalid `input` in to definition " tname " " input ", should be a keyword"))
73-
_validate-set (massert (or (vector? set) (nil? set))
74-
(str "invalid `set` in to definition " tname " " set ", should be a vector"))
75-
_validate-noti (massert (or (nil? noti) (and (map? noti)
76-
(or (keyword? (get noti :id))
77-
(string? (get noti :id)))
78-
(or (nil? (get noti :text))
79-
(keyword? (get noti :text))
80-
(string? (get noti :text)))))
81-
(str "invalid `noti`, must be a map with at least :id, :id must be string or keyword"))
82-
_validate-softf (massert (or (nil? softf) (map? softf))
83-
(str "invalid `softf`, must be a map with valid keys"))
84-
result (if (keyword? input)
85-
(assoc result :select_input_source (input (:input-sources @conf-data)))
86-
result)
87-
result (if (string? shell)
88-
(assoc result :shell_command shell)
89-
result)
90-
result (if (vector? shell)
91-
(assoc result
92-
:shell_command (apply
93-
format
94-
(flatten
95-
[((first shell)
96-
(:templates @conf-data))
97-
(rest shell)
98-
;; optional arguments
99-
"" "" "" "" "" ""])))
100-
result)
101-
result (if (vector? set)
102-
(assoc result :set_variable {:name (first set) :value (second set)})
103-
result)
104-
result (if (false? repeat)
105-
(assoc result :repeat false)
106-
result)
107-
result (if (true? halt)
108-
(assoc result :halt true)
109-
result)
110-
result (if (and (number? hold_down_ms) (not (= 0 hold_down_ms)))
111-
(assoc result :hold_down_milliseconds hold_down_ms)
112-
result)
113-
result (if (boolean? lazy)
114-
(assoc result :lazy lazy)
115-
result)
116-
result (if noti
117-
(let [{:keys [id text]} noti]
118-
(assoc result :set_notification_message {:id id :text (or text "")}))
119-
result)
120-
softf (when softf
121-
(cset/rename-keys softf {:dbc :cg_event_double_click
122-
:sleep :iokit_power_management_sleep_system
123-
:open :open_application
124-
:setmpos :set_mouse_cursor_position}))
125-
result (cond-> result
126-
(map? softf)
127-
(assoc :software_function softf))
128-
result (if select_input_source tinfo result)]
129-
result))
68+
;; validate-shell
69+
(massert (or (and (vector? shell)
70+
(contains? (:templates @conf-data) (first shell)))
71+
(string? shell) (nil? shell))
72+
(format
73+
"invalid `shell` in to definition %s %s, should be string or keyword"
74+
tname shell))
75+
;; validate-input
76+
(massert (or (nil? input)
77+
(and
78+
(keyword? input)
79+
(contains? (:input-sources @conf-data) input)))
80+
(format
81+
"invalid `input` in to definition %s %s, should be a keyword"
82+
tname input))
83+
;; validate-set
84+
(massert (or (vector? set) (nil? set))
85+
(format "invalid `set` in to definition %s %s, should be a vector"
86+
tname set))
87+
;; validate-noti
88+
(massert (or (nil? noti)
89+
(and (map? noti)
90+
(or (keyword? (get noti :id))
91+
(string? (get noti :id)))
92+
(or (nil? (get noti :text))
93+
(keyword? (get noti :text))
94+
(string? (get noti :text)))))
95+
(str "invalid `noti`, must be a map with at least :id, :id must be string or keyword"))
96+
;; validate-softf
97+
(massert (or (nil? softf) (map? softf))
98+
(str "invalid `softf`, must be a map with valid keys"))
99+
(let [softf
100+
(when softf
101+
(cset/rename-keys softf {:dbc :cg_event_double_click
102+
:sleep :iokit_power_management_sleep_system
103+
:open :open_application
104+
:setmpos :set_mouse_cursor_position}))
105+
result
106+
(cond-> (parse-key tname tinfo true true)
107+
(keyword? input)
108+
(assoc :select_input_source (input (:input-sources @conf-data)))
109+
110+
(string? shell)
111+
(assoc :shell_command shell)
112+
113+
(vector? shell)
114+
(assoc :shell_command
115+
(apply
116+
format
117+
(flatten
118+
[((first shell)
119+
(:templates @conf-data))
120+
(rest shell)
121+
;; optional arguments
122+
"" "" "" "" "" ""])))
123+
124+
(vector? set)
125+
(assoc :set_variable {:name (first set) :value (second set)})
126+
127+
(false? repeat)
128+
(assoc :repeat false)
129+
130+
(true? halt)
131+
(assoc :halt true)
132+
133+
(and (number? hold_down_ms) (not (= 0 hold_down_ms)))
134+
(assoc :hold_down_milliseconds hold_down_ms)
135+
136+
(boolean? lazy)
137+
(assoc :lazy lazy)
138+
139+
noti
140+
(assoc :set_notification_message {:id (:id noti)
141+
:text (or (:text noti) "")})
142+
143+
(map? softf)
144+
(assoc :software_function softf))]
145+
(if select_input_source tinfo result)))
130146
tinfos))
131147

132148
(defn generate [tos]

0 commit comments

Comments
 (0)