@@ -13,10 +13,11 @@ layout = "qwerty"
1313# Keymap for any physical keyboards. Defaults to the us rM pogo keyboard.
1414keymap = "rm-qwerty"
1515
16- # Orientation of yaft:
17- # Auto rotate if keyboard is connected
16+ # Auto rotate if keyboard is connected.
1817auto-rotate = true
19- # Orientation if no keyboard is connected
18+
19+ # Orientation if no keyboard is connected:
20+ # * none, clockwise, inverted, counterclockwise
2021rotation = "none"
2122
2223# Do a full refresh after 1024 updates.
@@ -29,25 +30,6 @@ repeat-delay = 600
2930repeat-rate = 25
3031)" ;
3132
32- std::filesystem::path
33- getConfigPath () {
34- const auto configDir = [] {
35- if (const auto * xdgCfg = getenv (" XDG_CONFIG_HOME" );
36- xdgCfg != nullptr && xdgCfg[0 ] != 0 ) {
37- return std::filesystem::path (xdgCfg);
38- }
39-
40- const auto * home = getenv (" HOME" );
41- if (home == nullptr || home[0 ] == 0 ) {
42- home = " /home/root" ;
43- }
44-
45- return std::filesystem::path (home) / " .config" / " yaft" ;
46- }();
47-
48- return configDir / " config.toml" ;
49- }
50-
5133void
5234addError (std::optional<YaftConfigError>& error, YaftConfigError err) {
5335 if (!error.has_value ()) {
@@ -135,24 +117,42 @@ getConfig(const toml::table& input) {
135117
136118} // namespace
137119
120+ std::filesystem::path
121+ getConfigPath () {
122+ const auto configDir = [] {
123+ if (const auto * xdgCfg = getenv (" XDG_CONFIG_HOME" );
124+ xdgCfg != nullptr && xdgCfg[0 ] != 0 ) {
125+ return std::filesystem::path (xdgCfg);
126+ }
127+
128+ const auto * home = getenv (" HOME" );
129+ if (home == nullptr || home[0 ] == 0 ) {
130+ home = " /home/root" ;
131+ }
132+
133+ return std::filesystem::path (home) / " .config" / " yaft" ;
134+ }();
135+
136+ return configDir / " config.toml" ;
137+ }
138+
138139YaftConfig
139140YaftConfig::getDefault () {
140141 auto tbl = toml::parse (default_config);
141142 return getConfig (tbl).config ;
142143}
143144
144145YaftConfigAndError
145- loadConfig () {
146+ loadConfig (const std::filesystem::path& path ) {
146147 toml::table tbl;
147148
148- const auto path = getConfigPath ();
149149 if (!std::filesystem::exists (path)) {
150150 return { YaftConfig::getDefault (),
151151 YaftConfigError{ YaftConfigError::Missing, path.string () } };
152152 }
153153
154154 try {
155- tbl = toml::parse_file (getConfigPath () .c_str ());
155+ tbl = toml::parse_file (path .c_str ());
156156 } catch (const toml::parse_error& err) {
157157 return { YaftConfig::getDefault (),
158158 YaftConfigError{ YaftConfigError::Syntax,
@@ -164,8 +164,7 @@ loadConfig() {
164164}
165165
166166OptError<>
167- saveDefaultConfig () {
168- const auto path = getConfigPath ();
167+ saveDefaultConfig (const std::filesystem::path& path) {
169168 const auto dir = path.parent_path ();
170169
171170 std::error_code ec;
@@ -189,16 +188,16 @@ saveDefaultConfig() {
189188}
190189
191190YaftConfigAndError
192- loadConfigOrMakeDefault () {
193- auto result = loadConfig ();
191+ loadConfigOrMakeDefault (const std::filesystem::path& path ) {
192+ auto result = loadConfig (path );
194193 if (!result.err .has_value ()) {
195194 return result;
196195 }
197196
198197 auto & err = *result.err ;
199198 if (err.type == YaftConfigError::Missing) {
200199 err.msg = " No config, creating new one\r\n " ;
201- if (const auto optErr = saveDefaultConfig (); !optErr.has_value ()) {
200+ if (const auto optErr = saveDefaultConfig (path ); !optErr.has_value ()) {
202201 err.msg += optErr.error ().msg + " \r\n " ;
203202 }
204203 } else {
0 commit comments