cognitive_qualia/settings.rs
1// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
2// the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/
3
4//! Various settings.
5
6// -------------------------------------------------------------------------------------------------
7
8use std::sync::{Arc, RwLock};
9use std::os::unix::io::RawFd;
10use std::path::PathBuf;
11
12// -------------------------------------------------------------------------------------------------
13
14/// Set of paths to XDG directories.
15pub struct Directories {
16 pub runtime: PathBuf,
17 pub data: PathBuf,
18 pub cache: PathBuf,
19 pub user_config: Option<PathBuf>,
20 pub system_config: Option<PathBuf>,
21}
22
23// -------------------------------------------------------------------------------------------------
24
25/// Structure containing settings for key map.
26#[derive(Clone, Debug)]
27#[repr(C)]
28pub struct KeymapSettings {
29 pub format: u32,
30 pub size: usize,
31 pub fd: RawFd,
32}
33
34// -------------------------------------------------------------------------------------------------
35
36/// Global settings.
37#[derive(Clone)]
38pub struct Settings {
39 keymap: Arc<RwLock<KeymapSettings>>,
40}
41
42// -------------------------------------------------------------------------------------------------
43
44impl Settings {
45 /// `Settings` constructor.
46 pub fn new(keymap: KeymapSettings) -> Self {
47 Settings { keymap: Arc::new(RwLock::new(keymap)) }
48 }
49
50 /// Get key map related settings.
51 pub fn get_keymap(&self) -> KeymapSettings {
52 self.keymap.read().unwrap().clone()
53 }
54}
55
56// -------------------------------------------------------------------------------------------------