mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-26 21:58:10 +01:00
Unify event loop running
This commit is contained in:
parent
96d5c9a70f
commit
d9116da20d
4 changed files with 34 additions and 43 deletions
|
@ -236,8 +236,11 @@ impl BackendData for Udev {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run_udev(no_config: bool, config_dir: Option<PathBuf>) -> anyhow::Result<()> {
|
||||
let mut event_loop = EventLoop::try_new()?;
|
||||
pub fn setup_udev(
|
||||
no_config: bool,
|
||||
config_dir: Option<PathBuf>,
|
||||
) -> anyhow::Result<(State, EventLoop<'static, State>)> {
|
||||
let event_loop = EventLoop::try_new()?;
|
||||
let display = Display::new()?;
|
||||
|
||||
// Initialize session
|
||||
|
@ -515,21 +518,7 @@ pub fn run_udev(no_config: bool, config_dir: Option<PathBuf>) -> anyhow::Result<
|
|||
tracing::error!("Failed to start XWayland: {err}");
|
||||
}
|
||||
|
||||
event_loop.run(
|
||||
Some(Duration::from_micros(((1.0 / 144.0) * 1000000.0) as u64)),
|
||||
&mut state,
|
||||
|state| {
|
||||
state.fixup_focus();
|
||||
state.space.refresh();
|
||||
state.popup_manager.cleanup();
|
||||
state
|
||||
.display_handle
|
||||
.flush_clients()
|
||||
.expect("failed to flush_clients");
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
Ok((state, event_loop))
|
||||
}
|
||||
|
||||
// TODO: document desperately
|
||||
|
|
|
@ -62,8 +62,11 @@ impl Backend {
|
|||
}
|
||||
|
||||
/// Start Pinnacle as a window in a graphical environment.
|
||||
pub fn run_winit(no_config: bool, config_dir: Option<PathBuf>) -> anyhow::Result<()> {
|
||||
let mut event_loop: EventLoop<State> = EventLoop::try_new()?;
|
||||
pub fn setup_winit(
|
||||
no_config: bool,
|
||||
config_dir: Option<PathBuf>,
|
||||
) -> anyhow::Result<(State, EventLoop<'static, State>)> {
|
||||
let event_loop: EventLoop<State> = EventLoop::try_new()?;
|
||||
|
||||
let display: Display<State> = Display::new()?;
|
||||
let display_handle = display.handle();
|
||||
|
@ -237,21 +240,7 @@ pub fn run_winit(no_config: bool, config_dir: Option<PathBuf>) -> anyhow::Result
|
|||
anyhow::bail!("Failed to insert winit events into event loop: {err}");
|
||||
}
|
||||
|
||||
event_loop.run(
|
||||
Some(Duration::from_micros(((1.0 / 144.0) * 1000000.0) as u64)),
|
||||
&mut state,
|
||||
|state| {
|
||||
state.fixup_focus();
|
||||
state.space.refresh();
|
||||
state.popup_manager.cleanup();
|
||||
state
|
||||
.display_handle
|
||||
.flush_clients()
|
||||
.expect("failed to flush client buffers");
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
Ok((state, event_loop))
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
|
@ -14,7 +14,7 @@ pub enum Backend {
|
|||
|
||||
/// The main CLI struct.
|
||||
#[derive(clap::Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
#[command(author, version, about, long_about = None, args_conflicts_with_subcommands = true)]
|
||||
pub struct Cli {
|
||||
/// Start Pinnacle with the config at this directory
|
||||
#[arg(short, long, value_name("DIR"), value_hint(ValueHint::DirPath))]
|
||||
|
@ -50,6 +50,7 @@ pub struct Cli {
|
|||
}
|
||||
|
||||
impl Cli {
|
||||
//
|
||||
pub fn parse_and_prompt() -> Option<Self> {
|
||||
let mut cli = Cli::parse();
|
||||
|
||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -97,48 +97,60 @@ async fn main() -> anyhow::Result<()> {
|
|||
warn!("You may see LOTS of file descriptors open under Pinnacle.");
|
||||
}
|
||||
|
||||
match (cli.backend, cli.force) {
|
||||
let (mut state, mut event_loop) = match (cli.backend, cli.force) {
|
||||
(None, _) => {
|
||||
if in_graphical_env {
|
||||
info!("Starting winit backend");
|
||||
crate::backend::winit::run_winit(cli.no_config, cli.config_dir)?;
|
||||
crate::backend::winit::setup_winit(cli.no_config, cli.config_dir)?
|
||||
} else {
|
||||
info!("Starting udev backend");
|
||||
crate::backend::udev::run_udev(cli.no_config, cli.config_dir)?;
|
||||
crate::backend::udev::setup_udev(cli.no_config, cli.config_dir)?
|
||||
}
|
||||
}
|
||||
(Some(cli::Backend::Winit), force) => {
|
||||
if !in_graphical_env {
|
||||
if force {
|
||||
warn!("Starting winit backend with no detected graphical environment");
|
||||
crate::backend::winit::run_winit(cli.no_config, cli.config_dir)?;
|
||||
crate::backend::winit::setup_winit(cli.no_config, cli.config_dir)?
|
||||
} else {
|
||||
warn!("Both WAYLAND_DISPLAY and DISPLAY are not set.");
|
||||
warn!("If you are trying to run the winit backend in a tty, it won't work.");
|
||||
warn!("If you really want to, additionally pass in the `--force` flag.");
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
info!("Starting winit backend");
|
||||
crate::backend::winit::run_winit(cli.no_config, cli.config_dir)?;
|
||||
crate::backend::winit::setup_winit(cli.no_config, cli.config_dir)?
|
||||
}
|
||||
}
|
||||
(Some(cli::Backend::Udev), force) => {
|
||||
if in_graphical_env {
|
||||
if force {
|
||||
warn!("Starting udev backend with a detected graphical environment");
|
||||
crate::backend::udev::run_udev(cli.no_config, cli.config_dir)?;
|
||||
crate::backend::udev::setup_udev(cli.no_config, cli.config_dir)?
|
||||
} else {
|
||||
warn!("WAYLAND_DISPLAY and/or DISPLAY are set.");
|
||||
warn!("If you are trying to run the udev backend in a graphical environment,");
|
||||
warn!("it won't work and may mess some things up.");
|
||||
warn!("If you really want to, additionally pass in the `--force` flag.");
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
info!("Starting udev backend");
|
||||
crate::backend::udev::run_udev(cli.no_config, cli.config_dir)?;
|
||||
crate::backend::udev::setup_udev(cli.no_config, cli.config_dir)?
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
event_loop.run(None, &mut state, |state| {
|
||||
state.fixup_focus();
|
||||
state.space.refresh();
|
||||
state.popup_manager.cleanup();
|
||||
state
|
||||
.display_handle
|
||||
.flush_clients()
|
||||
.expect("failed to flush client buffers");
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue