-
Notifications
You must be signed in to change notification settings - Fork 1
/
rime_levers_api.ahk
427 lines (386 loc) · 14.9 KB
/
rime_levers_api.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
* Copyright (c) 2023 Xuesong Peng <pengxuesong.cn@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#Include rime_api.ahk
; Placeholder class processes the pointer to rime class `CustomSettings`. Do not presume the memory layout
class RimeCustomSettings extends Object {
__New(ptr := 0) {
this.Ptr := ptr
}
}
; Placeholder class processes the pointer to rime class `SwitcherSettings`. Do not presume the memory layout
class RimeSwitcherSettings extends Object {
__New(ptr := 0) {
this.Ptr := ptr
}
}
; Placeholder class processes the pointer to rime class `SchemaInfo`. Do not presume the memory layout
class RimeSchemaInfo extends Object {
/**
*
* @param `RimeSchemaListItem` item
*/
__New(item := 0) {
this.Ptr := item ? item.reserved : 0
}
}
class RimeUserDictIterator extends RimeStruct {
__New() {
super.__New(RimeUserDictIterator.struct_size, 0)
}
static ptr_offset := 0
static i_offset := RimeUserDictIterator.ptr_offset + A_PtrSize
static struct_size := RimeUserDictIterator.i_offset + A_PtrSize ; size_t
i {
get => this.num_get(RimeUserDictIterator.i_offset, "UInt") ; size_t
}
}
class RimeLeversApi extends RimeApiStruct {
__New(rime := RimeApi()) {
super.__New(RimeLeversApi.struct_size, 0)
if not rime or not this.module := rime.find_module("levers")
throw RimeError("Cannot find module levers.")
if not ptr := this.module.get_api()
throw RimeError("Failed to get levers API.")
this.copy(ptr)
}
static data_size_offset := 0
static custom_settings_init_offset := RimeLeversApi.data_size_offset + A_IntSize + A_IntPaddingSize
static custom_settings_destroy_offset := RimeLeversApi.custom_settings_init_offset + A_PtrSize
static load_settings_offset := RimeLeversApi.custom_settings_destroy_offset + A_PtrSize
static save_settings_offset := RimeLeversApi.load_settings_offset + A_PtrSize
static customize_bool_offset := RimeLeversApi.save_settings_offset + A_PtrSize
static customize_int_offset := RimeLeversApi.customize_bool_offset + A_PtrSize
static customize_double_offset := RimeLeversApi.customize_int_offset + A_PtrSize
static customize_string_offset := RimeLeversApi.customize_double_offset + A_PtrSize
static is_first_run_offset := RimeLeversApi.customize_string_offset + A_PtrSize
static settings_is_modified_offset := RimeLeversApi.is_first_run_offset + A_PtrSize
static settings_get_config_offset := RimeLeversApi.settings_is_modified_offset + A_PtrSize
static switcher_settings_init_offset := RimeLeversApi.settings_get_config_offset + A_PtrSize
static get_available_schema_list_offset := RimeLeversApi.switcher_settings_init_offset + A_PtrSize
static get_selected_schema_list_offset := RimeLeversApi.get_available_schema_list_offset + A_PtrSize
static schema_list_destroy_offset := RimeLeversApi.get_selected_schema_list_offset + A_PtrSize
static get_schema_id_offset := RimeLeversApi.schema_list_destroy_offset + A_PtrSize
static get_schema_name_offset := RimeLeversApi.get_schema_id_offset + A_PtrSize
static get_schema_version_offset := RimeLeversApi.get_schema_name_offset + A_PtrSize
static get_schema_author_offset := RimeLeversApi.get_schema_version_offset + A_PtrSize
static get_schema_description_offset := RimeLeversApi.get_schema_author_offset + A_PtrSize
static get_schema_file_path_offset := RimeLeversApi.get_schema_description_offset + A_PtrSize
static select_schemas_offset := RimeLeversApi.get_schema_file_path_offset + A_PtrSize
static get_hotkeys_offset := RimeLeversApi.select_schemas_offset + A_PtrSize
static set_hotkeys_offset := RimeLeversApi.get_hotkeys_offset + A_PtrSize
static user_dict_iterator_init_offset := RimeLeversApi.set_hotkeys_offset + A_PtrSize
static user_dict_iterator_destroy_offset := RimeLeversApi.user_dict_iterator_init_offset + A_PtrSize
static next_user_dict_offset := RimeLeversApi.user_dict_iterator_destroy_offset + A_PtrSize
static backup_user_dict_offset := RimeLeversApi.next_user_dict_offset + A_PtrSize
static restore_user_dict_offset := RimeLeversApi.backup_user_dict_offset + A_PtrSize
static export_user_dict_offset := RimeLeversApi.restore_user_dict_offset + A_PtrSize
static import_user_dict_offset := RimeLeversApi.export_user_dict_offset + A_PtrSize
static customize_item_offset := RimeLeversApi.import_user_dict_offset + A_PtrSize
static struct_size := RimeLeversApi.customize_item_offset + A_PtrSize
/**
*
* @param config_id type of `Str`
* @param generator_id type of `Str`
* @returns `RimeCustomSettings` on success, `0` on failure
*/
custom_settings_init(config_id, generator_id) {
if not ptr := DllCall(this.fp(RimeLeversApi.custom_settings_init_offset), "Ptr", RimeString(config_id), "Ptr", RimeString(generator_id), "CDecl Ptr")
return 0
return RimeCustomSettings(ptr)
}
/**
*
* @param settings type of `RimeCustomSettings`
*/
custom_settings_destroy(settings) {
DllCall(this.fp(RimeLeversApi.custom_settings_destroy_offset), "Ptr", settings, "CDecl")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @returns `True` on success, `False` on failure
*/
load_settings(settings) {
return DllCall(this.fp(RimeLeversApi.load_settings_offset), "Ptr", settings, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @returns `True` on success, `False` on failure
*/
save_settings(settings) {
return DllCall(this.fp(RimeLeversApi.save_settings_offset), "Ptr", settings, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @param key type of `Str`
* @param value `True` or `False`
* @returns `True` on success, `False` on failure
*/
customize_bool(settings, key, value) {
return DllCall(this.fp(RimeLeversApi.customize_bool_offset), "Ptr", settings, "Ptr", RimeString(key), "Int", value, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @param key type of `Str`
* @param value type of `Int`
* @returns `True` on success, `False` on failure
*/
customize_int(settings, key, value) {
return DllCall(this.fp(RimeLeversApi.customize_int_offset), "Ptr", settings, "Ptr", RimeString(key), "Int", value, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @param key type of `Str`
* @param value type of `Double`
* @returns `True` on success, `False` on failure
*/
customize_double(settings, key, value) {
return DllCall(this.fp(RimeLeversApi.customize_double_offset), "Ptr", settings, "Ptr", RimeString(key), "Double", value, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @param key type of `Str`
* @param value type of `Str`
* @returns `True` on success, `False` on failure
*/
customize_string(settings, key, value) {
return DllCall(this.fp(RimeLeversApi.customize_string_offset), "Ptr", settings, "Ptr", RimeString(key), "Ptr", RimeString(value), "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @returns `True` or `False`
*/
is_first_run(settings) {
return DllCall(this.fp(RimeLeversApi.is_first_run_offset), "Ptr", settings, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @returns `True` or `False`
*/
settings_is_modified(settings) {
return DllCall(this.fp(RimeLeversApi.settings_is_modified_offset), "Ptr", settings, "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @returns `RimeConfig` on success, `0` on failure
*/
settings_get_config(settings) {
config := RimeConfig()
res := DllCall(this.fp(RimeLeversApi.settings_get_config_offset), "Ptr", settings, "Ptr", config, "CDecl Int")
return res ? config : 0
}
/**
*
* @returns `RimeSwitcherSettings` on success, `0` on failure
*/
switcher_settings_init() {
if not ptr := DllCall(this.fp(RimeLeversApi.switcher_settings_init_offset), "CDecl Ptr")
return 0
return RimeSwitcherSettings(ptr)
}
/**
*
* @param settings type of `RimeSwitcherSettings`
* @returns `RimeSchemaList` on success, `0` on failure
*/
get_available_schema_list(settings) {
list := RimeSchemaList()
res := DllCall(this.fp(RimeLeversApi.get_available_schema_list_offset), "Ptr", settings, "Ptr", list, "CDecl Int")
if !!res ^ !!list.size
throw RimeError("levers get_available_schema_list result & list size mismatch")
return list
}
/**
*
* @param settings type of `RimeSwitcherSettings`
* @returns `RimeSchemaList`
*/
get_selected_schema_list(settings) {
list := RimeSchemaList()
res := DllCall(this.fp(RimeLeversApi.get_selected_schema_list_offset), "Ptr", settings, "Ptr", list, "CDecl Int")
if !!res ^ !!list.size
throw RimeError("levers get_selected_schema_list result & list size mismatch")
return list
}
/**
*
* @param list type of `RimeSchemaList`
*/
schema_list_destroy(list) {
DllCall(this.fp(RimeLeversApi.schema_list_destroy_offset), "Ptr", list, "CDecl")
}
/**
*
* @param info type of `RimeSchemaInfo`
* @returns `Str`
*/
get_schema_id(info) {
p := DllCall(this.fp(RimeLeversApi.get_schema_id_offset), "Ptr", info, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param info type of `RimeSchemaInfo`
* @returns `Str`
*/
get_schema_name(info) {
p := DllCall(this.fp(RimeLeversApi.get_schema_name_offset), "Ptr", info, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param info type of `RimeSchemaInfo`
* @returns `Str`
*/
get_schema_version(info) {
p := DllCall(this.fp(RimeLeversApi.get_schema_version_offset), "Ptr", info, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param info type of `RimeSchemaInfo`
* @returns `Str`
*/
get_schema_author(info) {
p := DllCall(this.fp(RimeLeversApi.get_schema_author_offset), "Ptr", info, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param info type of `RimeSchemaInfo`
* @returns `Str`
*/
get_schema_description(info) {
p := DllCall(this.fp(RimeLeversApi.get_schema_description_offset), "Ptr", info, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param info type of `RimeSchemaInfo`
* @returns `Str`
*/
get_schema_file_path(info) {
p := DllCall(this.fp(RimeLeversApi.get_schema_file_path_offset), "Ptr", info, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param settings type of `RimeSwitcherSettings`
* @param schema_id_list `Array` of `Str`
* @returns `True` on success, `False` on failure
*/
select_schemas(settings, schema_id_list) {
arr := RimeStringArray(schema_id_list)
return DllCall(this.fp(RimeLeversApi.select_schemas_offset), "Ptr", settings, "Ptr", arr, "Int", schema_id_list.Length, "CDecl Int")
}
/**
*
* @param settings type of `RimeSwitcherSettings`
* @returns `Str`
*/
get_hotkeys(settings) {
p := DllCall(this.fp(RimeLeversApi.get_hotkeys_offset), "Ptr", settings, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param settings type of `RimeSwitcherSettings`
* @param hotkeys type of `Str`
* @returns `True` on success, `False` on failure
*/
set_hotkeys(settings, hotkeys) {
return DllCall(this.fp(RimeLeversApi.set_hotkeys_offset), "Ptr", settings, "Ptr", RimeString(hotkeys), "CDecl Int")
}
/**
*
* @returns `RimeUserDictIterator` on success, `0` on failure
*/
user_dict_iterator_init() {
iter := RimeUserDictIterator()
res := DllCall(this.fp(RimeLeversApi.user_dict_iterator_init_offset), "Ptr", iter, "CDecl Int")
return res ? iter : 0
}
/**
*
* @param iter type of `RimeUserDictIterator`
*/
user_dict_iterator_destroy(iter) {
DllCall(this.fp(RimeLeversApi.user_dict_iterator_destroy_offset), "Ptr", iter, "CDecl")
}
/**
*
* @param iter type of `RimeUserDictIterator`
* @returns `Str`
*/
next_user_dict(iter) {
p := DllCall(this.fp(RimeLeversApi.next_user_dict_offset), "Ptr", iter, "CDecl Ptr")
return p ? StrGet(p, "UTF-8") : ""
}
/**
*
* @param dict_name type of `Str`
* @returns `True` on success, `False` on failure
*/
backup_user_dict(dict_name) {
return DllCall(this.fp(RimeLeversApi.backup_user_dict_offset), "Ptr", RimeString(dict_name), "CDecl Int")
}
/**
*
* @param snapshot_file type of `Str`
* @returns `True` on success, `False` on failure
*/
restore_user_dict(snapshot_file) {
return DllCall(this.fp(RimeLeversApi.restore_user_dict_offset), "Ptr", RimeString(snapshot_file), "CDecl Int")
}
/**
*
* @param dict_name type of `Str`
* @param text_file type of `Str`
* @returns `Int`
*/
export_user_dict(dict_name, text_file) {
return DllCall(this.fp(RimeLeversApi.export_user_dict_offset), "Ptr", RimeString(dict_name), "Ptr", RimeString(text_file), "CDecl Int")
}
/**
*
* @param dict_name type of `Str`
* @param text_file type of `Str`
* @returns `Int`
*/
import_user_dict(dict_name, text_file) {
return DllCall(this.fp(RimeLeversApi.import_user_dict_offset), "Ptr", RimeString(dict_name), "Ptr", RimeString(text_file), "CDecl Int")
}
/**
*
* @param settings type of `RimeCustomSettings`
* @param key type of `Str`
* @param value type of `RimeConfig`
* @returns `True` on success, `False` on failure
*/
customize_item(settings, key, value) {
return DllCall(this.fp(RimeLeversApi.customize_item_offset), "Ptr", settings, "Ptr", RimeString(key), "Ptr", value, "CDecl Int")
}
}