-
Notifications
You must be signed in to change notification settings - Fork 103
/
rime_settings.c
92 lines (79 loc) · 2.65 KB
/
rime_settings.c
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
#include "rime_config.h"
#include "rime_settings.h"
#include <rime_api.h>
#include <string.h>
extern RimeApi *rime_api;
static struct ColorSchemeDefinition preset_color_schemes[] = {
{ "aqua", 0xffffff, 0x0a3dfa },
{ "azure", 0xffffff, 0x0a3dea },
{ "ink", 0xffffff, 0x000000 },
{ "luna", 0x000000, 0xffff7f },
{ NULL, 0, 0 }
};
static struct IBusRimeSettings ibus_rime_settings_default = {
.embed_preedit_text = TRUE,
.preedit_style = PREEDIT_STYLE_COMPOSITION,
.cursor_type = CURSOR_TYPE_INSERT,
.lookup_table_orientation = IBUS_ORIENTATION_SYSTEM,
.color_scheme = NULL,
};
struct IBusRimeSettings g_ibus_rime_settings;
static void
select_color_scheme(struct IBusRimeSettings* settings,
const char* color_scheme_id)
{
struct ColorSchemeDefinition* c;
for (c = preset_color_schemes; c->color_scheme_id; ++c) {
if (!strcmp(c->color_scheme_id, color_scheme_id)) {
settings->color_scheme = c;
g_debug("selected color scheme: %s", color_scheme_id);
return;
}
}
// fallback to default
settings->color_scheme = NULL;
}
void
ibus_rime_load_settings()
{
g_ibus_rime_settings = ibus_rime_settings_default;
RimeConfig config = {0};
if (!rime_api->config_open("ibus_rime", &config)) {
g_error("error loading settings for ibus_rime");
return;
}
Bool inline_preedit = False;
if (rime_api->config_get_bool(
&config, "style/inline_preedit", &inline_preedit)) {
g_ibus_rime_settings.embed_preedit_text = !!inline_preedit;
}
const char* preedit_style_str =
rime_api->config_get_cstring(&config, "style/preedit_style");
if(preedit_style_str) {
if(!strcmp(preedit_style_str, "composition")) {
g_ibus_rime_settings.preedit_style = PREEDIT_STYLE_COMPOSITION;
} else if(!strcmp(preedit_style_str, "preview")) {
g_ibus_rime_settings.preedit_style = PREEDIT_STYLE_PREVIEW;
}
}
const char* cursor_type_str =
rime_api->config_get_cstring(&config, "style/cursor_type");
if (cursor_type_str) {
if (!strcmp(cursor_type_str, "insert")) {
g_ibus_rime_settings.cursor_type = CURSOR_TYPE_INSERT;
} else if (!strcmp(cursor_type_str, "select")) {
g_ibus_rime_settings.cursor_type = CURSOR_TYPE_SELECT;
}
}
Bool horizontal = False;
if (rime_api->config_get_bool(&config, "style/horizontal", &horizontal)) {
g_ibus_rime_settings.lookup_table_orientation =
horizontal ? IBUS_ORIENTATION_HORIZONTAL : IBUS_ORIENTATION_VERTICAL;
}
const char* color_scheme =
rime_api->config_get_cstring(&config, "style/color_scheme");
if (color_scheme) {
select_color_scheme(&g_ibus_rime_settings, color_scheme);
}
rime_api->config_close(&config);
}