Move config stuff into one struct

This commit is contained in:
Ottatop 2023-09-20 17:40:36 -05:00
parent c06cb5b776
commit a2a46596f4
6 changed files with 21 additions and 34 deletions

View file

@ -949,7 +949,7 @@ impl State {
.as_ref()
.expect("Stream doesn't exist");
let mut stream = stream.lock().expect("Couldn't lock stream");
for callback_id in dt.state.output_callback_ids.iter() {
for callback_id in dt.state.config.output_callback_ids.iter() {
crate::config::api::send_to_client(
&mut stream,
&OutgoingMsg::CallCallback {

View file

@ -114,8 +114,8 @@ pub enum Key {
#[derive(Default, Debug)]
pub struct Config {
window_rules: Vec<(WindowRuleCondition, WindowRule)>,
output_callback_ids: Vec<CallbackId>,
pub window_rules: Vec<(WindowRuleCondition, WindowRule)>,
pub output_callback_ids: Vec<CallbackId>,
}
fn parse(config_dir: &Path) -> anyhow::Result<Metaconfig> {
@ -243,7 +243,7 @@ impl State {
tracing::debug!("Clearing mouse and keybinds");
self.input_state.keybinds.clear();
self.input_state.mousebinds.clear();
self.window_rules.clear();
self.config.window_rules.clear();
tracing::debug!("Killing old config");
if let Err(err) = self.api_state.config_process.kill() {

View file

@ -121,10 +121,8 @@ impl PinnacleSocketSource {
if multiple_instances {
if let Ok(exists) = socket_path.try_exists() {
if exists {
std::fs::remove_file(&socket_path).context(format!(
"Failed to remove old socket at {}",
socket_path.to_string_lossy()
))?;
std::fs::remove_file(&socket_path)
.context(format!("Failed to remove old socket at {socket_path:?}",))?;
}
}
} else {
@ -133,14 +131,9 @@ impl PinnacleSocketSource {
.filter_map(|entry| entry.ok())
.filter(|entry| entry.file_name().to_string_lossy().starts_with(SOCKET_NAME))
{
tracing::debug!(
"trying to remove socket at {}",
file.path().to_string_lossy()
);
std::fs::remove_file(file.path()).context(format!(
"Failed to remove old socket at {}",
file.path().to_string_lossy()
))?;
tracing::debug!("Removing socket at {:?}", file.path());
std::fs::remove_file(file.path())
.context(format!("Failed to remove old socket at {:?}", file.path()))?;
}
}

View file

@ -11,13 +11,7 @@ use std::{
use crate::{
backend::{udev::Udev, winit::Winit, BackendData},
config::{
api::msg::{
window_rules::{WindowRule, WindowRuleCondition},
CallbackId, Msg,
},
ConfigReturn,
},
config::{api::msg::Msg, Config, ConfigReturn},
cursor::Cursor,
focus::FocusState,
grab::resize_grab::ResizeSurfaceState,
@ -125,14 +119,11 @@ pub struct State {
pub dnd_icon: Option<WlSurface>,
pub windows: Vec<WindowElement>,
pub window_rules: Vec<(WindowRuleCondition, WindowRule)>,
pub config: Config,
pub async_scheduler: Scheduler<()>,
// TODO: move into own struct
// | basically just clean this mess up
pub output_callback_ids: Vec<CallbackId>,
pub xwayland: XWayland,
pub xwm: Option<X11Wm>,
pub xdisplay: Option<u32>,
@ -320,6 +311,8 @@ impl State {
},
focus_state: FocusState::new(),
config: Config::default(),
seat,
dnd_icon: None,
@ -331,8 +324,6 @@ impl State {
async_scheduler: sched,
windows: vec![],
window_rules: vec![],
output_callback_ids: vec![],
xwayland,
xwm: None,

View file

@ -30,7 +30,10 @@ impl State {
callback_id,
} => {
let key = match key {
KeyIntOrString::Int(num) => num,
KeyIntOrString::Int(num) => {
tracing::info!("set keybind: {:?}, raw {}", modifiers, num);
num
}
KeyIntOrString::String(s) => {
if s.chars().count() == 1 {
let Some(ch) = s.chars().next() else { unreachable!() };
@ -156,7 +159,7 @@ impl State {
self.update_windows(&output);
}
Msg::AddWindowRule { cond, rule } => {
self.window_rules.push((cond, rule));
self.config.window_rules.push((cond, rule));
}
Msg::WindowMoveGrab { button } => {
// TODO: in the future, there may be movable layer surfaces
@ -324,7 +327,7 @@ impl State {
)
.expect("Send to client failed");
}
self.output_callback_ids.push(callback_id);
self.config.output_callback_ids.push(callback_id);
}
Msg::SetOutputLocation { output_name, x, y } => {
let Some(output) = output_name.output(self) else { return };

View file

@ -595,7 +595,7 @@ impl Blocker for WindowBlocker {
impl State {
pub fn apply_window_rules(&mut self, window: &WindowElement) {
tracing::debug!("Applying window rules");
for (cond, rule) in self.window_rules.iter() {
for (cond, rule) in self.config.window_rules.iter() {
if cond.is_met(self, window) {
let WindowRule {
output,