If get_config() fails to get the config corresponding to the active layout, cycle to the next layout
This commit is contained in:
parent
94fc3d150b
commit
3f3bd7e3e8
1 changed files with 20 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
use std::{sync::Arc, option::Option, str::FromStr, process::{Command, Stdio}};
|
use std::{sync::Arc, option::Option, str::FromStr, future::Future, pin::Pin, process::{Command, Stdio}};
|
||||||
|
//use futures::future::{BoxFuture, FutureExt};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
use fork::{fork, Fork, setsid};
|
use fork::{fork, Fork, setsid};
|
||||||
|
@ -607,10 +608,11 @@ impl EventReader {
|
||||||
|
|
||||||
async fn change_active_layout(&self) {
|
async fn change_active_layout(&self) {
|
||||||
let mut active_layout = self.active_layout.lock().await;
|
let mut active_layout = self.active_layout.lock().await;
|
||||||
|
let active_window = get_active_window(&self.environment.server, &self.config).await;
|
||||||
loop {
|
loop {
|
||||||
if *active_layout == 3 { *active_layout = 0 }
|
if *active_layout == 3 { *active_layout = 0 }
|
||||||
else { *active_layout += 1 };
|
else { *active_layout += 1 };
|
||||||
if let Some(_) = self.config.iter().find(|&x| x.associations.layout == *active_layout) {
|
if let Some(_) = self.config.iter().find(|&x| x.associations.layout == *active_layout && x.associations.client == active_window) {
|
||||||
break
|
break
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -620,16 +622,22 @@ impl EventReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_config(&self) -> &Config {
|
fn get_config(&self) -> Pin<Box<dyn Future<Output = &Config> + Send + '_>> {
|
||||||
let active_layout = self.active_layout.lock().await;
|
Box::pin(async move {
|
||||||
let active_window = get_active_window(&self.environment.server, &self.config).await;
|
let active_layout = self.active_layout.lock().await.clone();
|
||||||
let associations = Associations {
|
let active_window = get_active_window(&self.environment.server, &self.config).await;
|
||||||
client: active_window,
|
let associations = Associations {
|
||||||
layout: *active_layout,
|
client: active_window,
|
||||||
};
|
layout: active_layout,
|
||||||
let config = self.config.iter()
|
};
|
||||||
.find(|&x| x.associations == associations).unwrap();
|
match self.config.iter().find(|&x| x.associations == associations) {
|
||||||
config
|
Some(config) => return config,
|
||||||
|
None => {
|
||||||
|
self.change_active_layout().await;
|
||||||
|
return self.get_config().await
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cursor_loop(&self) {
|
pub async fn cursor_loop(&self) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue