Skip to content

Commit 848700b

Browse files
committed
the big cleanup refactor
1 parent 15671d4 commit 848700b

File tree

17 files changed

+800
-963
lines changed

17 files changed

+800
-963
lines changed

src/cli.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ::pandora::pithos::config::LogLevel;
2-
use ::pandora::pithos::commands::{CommandType, DaemonCommand, StopCommand, RenderThreadCommand};
2+
use ::pandora::pithos::commands::{CommandType, DaemonCommand};
33
use clap::{arg, Parser};
44
use std::process;
55

@@ -17,7 +17,6 @@ struct Interface {
1717
#[derive(Clone, clap::Subcommand)]
1818
enum CliCommand {
1919
StopDaemon,
20-
StopThread(StopCommand),
2120
Lock,
2221
}
2322

@@ -26,7 +25,6 @@ pub fn cli() -> Option<LogLevel> { // the only config pass-able to the daemon vi
2625
if let Some(command) = cli.command {
2726
let cmd = match command {
2827
CliCommand::StopDaemon => CommandType::Dc(DaemonCommand::Stop),
29-
CliCommand::StopThread(c) => CommandType::Tc(RenderThreadCommand::Stop(c)),
3028
CliCommand::Lock => CommandType::Dc(DaemonCommand::Lock),
3129
};
3230
println!("{}", ::pandora::pithos::sockets::write_command_to_daemon_socket(&cmd).expect("could not send command (is the daemon running?)"));

src/daemon.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::pithos::error::DaemonError;
2+
use crate::wayland::render_base::{OutputState};
3+
use crate::{pithos::commands::CommandType, wayland::render_base::RenderThreadState};
4+
5+
use std::fs::File;
6+
use std::sync::Arc;
7+
8+
use wayrs_client::Connection;
9+
use wayrs_client::protocol::{WlSurface, WlOutput};
10+
11+
pub trait Daemon {
12+
fn log(&self, name: &str, msg: String);
13+
fn debug(&self, name: &str, msg: String);
14+
fn verbose(&self, name: &str, msg: String);
15+
16+
fn handle_cmd(self: Arc<Self>, cmd: &CommandType);
17+
18+
fn load_image(self: Arc<Self>, path: &String) -> Result<(), DaemonError>;
19+
fn get_image_dimensions(self: Arc<Self>, img: String) -> Result<(u32, u32), ()>;
20+
fn read_img_to_file(self: Arc<Self>, img: &String, f: &File, scale_to: Option<(Option<u32>, Option<u32>)>) -> Result<(u32, u32), DaemonError>;
21+
22+
fn apply_role_to_surface(self: Arc<Self>, conn: &mut Connection<RenderThreadState>, wl_surface: &WlSurface, wl_output: &WlOutput, output_state: &OutputState);
23+
}
24+

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
pub mod daemon;
12
pub mod pithos;
3+
pub mod threads;
24
pub mod wayland;

src/main.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod cli;
22
mod pandora;
3-
mod threads;
43
use ::pandora::pithos::config::load_config;
54
use std::sync::Arc;
65

@@ -13,22 +12,7 @@ fn main() -> miette::Result<()> {
1312
None => config.log_level,
1413
};
1514

16-
// initialize daemon & ipc handlers, and glue them together.
17-
let mut pandora = crate::pandora::Pandora::new(config.clone(), verbosity);
18-
// we initialize pandora mutably so that logging can be started
19-
// => other threads have The Logging Abstraction available for the entirety of their runtime
20-
let ipc = crate::threads::ipc::InboundCommandHandler::new();
21-
let outputs = crate::threads::outputs::OutputHandler::new(config.clone());
22-
let niri = crate::threads::niri::NiriAgent::new(config.clone());
23-
let config_watcher = crate::threads::config::ConfigWatcher::new();
24-
25-
Arc::make_mut(&mut pandora).bind_threads(
26-
ipc.clone(),
27-
outputs.clone(),
28-
niri.clone(),
29-
config_watcher.clone(),
30-
);
31-
32-
// give the subthreads a weak pointer now that we're done mutating pandora into some sort of daemon
33-
Ok(pandora.start(Arc::downgrade(&pandora)))
15+
let pandora = crate::pandora::Pandora::new(config.clone(), verbosity);
16+
let weak = Arc::downgrade(&pandora);
17+
pandora.start(weak, config.clone())
3418
}

0 commit comments

Comments
 (0)