Make config available in daemon main thread

timeout_old
Taeyeon Mori 3 years ago
parent 97d33f5856
commit f907833d78
  1. 8
      src/config.rs
  2. 7
      src/demon.rs

@ -23,7 +23,7 @@ use std::fs::OpenOptions;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::Path; use std::path::Path;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Config { pub struct Config {
menu: Option<Menu>, menu: Option<Menu>,
format: Option<Format>, format: Option<Format>,
@ -161,13 +161,13 @@ impl Config {
} }
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Menu { pub struct Menu {
executable: Option<String>, executable: Option<String>,
args: Option<Vec<String>>, args: Option<Vec<String>>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Format { pub struct Format {
output_format: Option<String>, output_format: Option<String>,
workspace_format: Option<String>, workspace_format: Option<String>,
@ -181,7 +181,7 @@ pub struct Format {
fallback_icon: Option<String>, fallback_icon: Option<String>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Layout { pub struct Layout {
auto_tile: Option<bool>, auto_tile: Option<bool>,
auto_tile_min_window_width_per_output_width: Option<Vec<[i32; 2]>>, auto_tile_min_window_width_per_output_width: Option<Vec<[i32; 2]>>,

@ -29,12 +29,15 @@ use std::thread;
use swayipc as s; use swayipc as s;
pub fn run_demon() { pub fn run_demon() {
let config = config::load_config();
let extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>> = let extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>> =
Arc::new(RwLock::new(HashMap::new())); Arc::new(RwLock::new(HashMap::new()));
let config_for_ev_handler = config.clone();
let extra_props_for_ev_handler = extra_props.clone(); let extra_props_for_ev_handler = extra_props.clone();
thread::spawn(move || { thread::spawn(move || {
monitor_sway_events(extra_props_for_ev_handler); monitor_sway_events(extra_props_for_ev_handler, config_for_ev_handler);
}); });
serve_client_requests(extra_props); serve_client_requests(extra_props);
@ -50,8 +53,8 @@ fn connect_and_subscribe() -> s::Fallible<s::EventStream> {
pub fn monitor_sway_events( pub fn monitor_sway_events(
extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>, extra_props: Arc<RwLock<HashMap<i64, t::ExtraProps>>>,
config: config::Config,
) { ) {
let config = config::load_config();
let mut focus_counter = 0; let mut focus_counter = 0;
let mut resets = 0; let mut resets = 0;
let max_resets = 10; let max_resets = 10;

Loading…
Cancel
Save