aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-02-01 16:55:46 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-02-01 16:55:46 +0400
commit9afd728ae98059c9405fe2430399ecb89fd1a7a9 (patch)
tree9907809ee2926e127dc722b2d681ca98b6633b9d
parente51268a39eeffd56d016a8d25dc98a40ff045a9c (diff)
downloadniri-9afd728ae98059c9405fe2430399ecb89fd1a7a9.tar.gz
niri-9afd728ae98059c9405fe2430399ecb89fd1a7a9.tar.bz2
niri-9afd728ae98059c9405fe2430399ecb89fd1a7a9.zip
Add error messages to backend initialization
-rw-r--r--src/backend/tty.rs43
-rw-r--r--src/backend/winit.rs11
-rw-r--r--src/main.rs3
-rw-r--r--src/niri.rs11
4 files changed, 45 insertions, 23 deletions
diff --git a/src/backend/tty.rs b/src/backend/tty.rs
index c1fba4e1..474f12e9 100644
--- a/src/backend/tty.rs
+++ b/src/backend/tty.rs
@@ -144,11 +144,19 @@ pub struct SurfaceDmabufFeedback {
}
impl Tty {
- pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<'static, State>) -> Self {
- let (session, notifier) = LibSeatSession::new().unwrap();
+ pub fn new(
+ config: Rc<RefCell<Config>>,
+ event_loop: LoopHandle<'static, State>,
+ ) -> anyhow::Result<Self> {
+ let (session, notifier) = LibSeatSession::new().context(
+ "Error creating a session. This might mean that you're trying to run niri on a TTY \
+ that is already busy, for example if you're running this inside tmux that had been \
+ originally started on a different TTY",
+ )?;
let seat_name = session.seat();
- let udev_backend = UdevBackend::new(session.seat()).unwrap();
+ let udev_backend =
+ UdevBackend::new(session.seat()).context("error creating a udev backend")?;
let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, state: &mut State| {
state.backend.tty().on_udev_event(&mut state.niri, event);
});
@@ -157,7 +165,9 @@ impl Tty {
.unwrap();
let mut libinput = Libinput::new_with_udev(LibinputSessionInterface::from(session.clone()));
- libinput.udev_assign_seat(&seat_name).unwrap();
+ libinput
+ .udev_assign_seat(&seat_name)
+ .map_err(|()| anyhow!("error assigning the seat to libinput"))?;
let input_backend = LibinputInputBackend::new(libinput.clone());
event_loop
@@ -192,18 +202,23 @@ impl Tty {
Ok(gles)
};
let api = GbmGlesBackend::with_factory(Box::new(create_renderer));
- let gpu_manager = GpuManager::new(api).unwrap();
+ let gpu_manager = GpuManager::new(api).context("error creating the GPU manager")?;
let (primary_node, primary_render_node) = primary_node_from_config(&config.borrow())
- .unwrap_or_else(|| {
- let primary_gpu_path = udev::primary_gpu(&seat_name).unwrap().unwrap();
- let primary_node = DrmNode::from_path(primary_gpu_path).unwrap();
+ .ok_or(())
+ .or_else(|()| {
+ let primary_gpu_path = udev::primary_gpu(&seat_name)
+ .context("error getting the primary GPU")?
+ .context("couldn't find a GPU")?;
+ let primary_node = DrmNode::from_path(primary_gpu_path)
+ .context("error opening the primary GPU DRM node")?;
let primary_render_node = primary_node
.node_with_type(NodeType::Render)
- .unwrap()
- .unwrap();
- (primary_node, primary_render_node)
- });
+ .context("error getting the render node for the primary GPU")?
+ .context("error getting the render node for the primary GPU")?;
+
+ Ok::<_, anyhow::Error>((primary_node, primary_render_node))
+ })?;
let mut node_path = String::new();
if let Some(path) = primary_render_node.dev_path() {
@@ -213,7 +228,7 @@ impl Tty {
}
info!("using as the render node: {}", node_path);
- Self {
+ Ok(Self {
config,
session,
udev_dispatcher,
@@ -227,7 +242,7 @@ impl Tty {
update_output_config_on_resume: false,
ipc_outputs: Rc::new(RefCell::new(HashMap::new())),
enabled_outputs: Arc::new(Mutex::new(HashMap::new())),
- }
+ })
}
pub fn init(&mut self, niri: &mut Niri) {
diff --git a/src/backend/winit.rs b/src/backend/winit.rs
index b11f8e79..e06e8abe 100644
--- a/src/backend/winit.rs
+++ b/src/backend/winit.rs
@@ -32,12 +32,15 @@ pub struct Winit {
}
impl Winit {
- pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<State>) -> Self {
+ pub fn new(
+ config: Rc<RefCell<Config>>,
+ event_loop: LoopHandle<State>,
+ ) -> Result<Self, winit::Error> {
let builder = WindowBuilder::new()
.with_inner_size(LogicalSize::new(1280.0, 800.0))
// .with_resizable(false)
.with_title("niri");
- let (backend, winit) = winit::init_from_builder(builder).unwrap();
+ let (backend, winit) = winit::init_from_builder(builder)?;
let output = Output::new(
"winit".to_string(),
@@ -110,14 +113,14 @@ impl Winit {
})
.unwrap();
- Self {
+ Ok(Self {
config,
output,
backend,
damage_tracker,
ipc_outputs,
enabled_outputs,
- }
+ })
}
pub fn init(&mut self, niri: &mut Niri) {
diff --git a/src/main.rs b/src/main.rs
index ec32546d..587d9218 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -220,7 +220,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
event_loop.handle(),
event_loop.get_signal(),
display,
- );
+ )
+ .unwrap();
// Set WAYLAND_DISPLAY for children.
let socket_name = &state.niri.socket_name;
diff --git a/src/niri.rs b/src/niri.rs
index b2d583be..e880ffa8 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -298,7 +298,7 @@ impl State {
event_loop: LoopHandle<'static, State>,
stop_signal: LoopSignal,
display: Display<State>,
- ) -> Self {
+ ) -> Result<Self, Box<dyn std::error::Error>> {
let _span = tracy_client::span!("State::new");
let config = Rc::new(RefCell::new(config));
@@ -307,15 +307,18 @@ impl State {
env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
let mut backend = if has_display {
- Backend::Winit(Winit::new(config.clone(), event_loop.clone()))
+ let winit = Winit::new(config.clone(), event_loop.clone())?;
+ Backend::Winit(winit)
} else {
- Backend::Tty(Tty::new(config.clone(), event_loop.clone()))
+ let tty = Tty::new(config.clone(), event_loop.clone())
+ .context("error initializing the TTY backend")?;
+ Backend::Tty(tty)
};
let mut niri = Niri::new(config.clone(), event_loop, stop_signal, display, &backend);
backend.init(&mut niri);
- Self { backend, niri }
+ Ok(Self { backend, niri })
}
pub fn refresh_and_flush_clients(&mut self) {