From 6982587a84f1b82d5aa65ad832f8f39005d6d266 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Mon, 27 May 2024 15:58:57 -0500 Subject: [PATCH] Fix tests --- src/api.rs | 69 ++++++++++++++++++++------------------- src/api/window.rs | 6 ++-- src/backend.rs | 11 ++++--- src/backend/udev.rs | 6 ++-- src/handlers.rs | 35 +++++++++++--------- src/handlers/window.rs | 4 +-- src/handlers/xdg_shell.rs | 2 +- src/handlers/xwayland.rs | 4 +-- src/layout.rs | 4 +-- 9 files changed, 74 insertions(+), 67 deletions(-) diff --git a/src/api.rs b/src/api.rs index 1cf2ba5..8669f75 100644 --- a/src/api.rs +++ b/src/api.rs @@ -742,10 +742,9 @@ impl tag_service_server::TagService for TagService { return; }; - let (fs_and_up_snapshots, under_fs_snapshots) = - state.backend.with_renderer(|renderer| { - capture_snapshots_on_output(&mut state.pinnacle, renderer, &output, []) - }); + let snapshots = state.backend.with_renderer(|renderer| { + capture_snapshots_on_output(&mut state.pinnacle, renderer, &output, []) + }); match set_or_toggle { SetOrToggle::Set => tag.set_active(true, state), @@ -756,13 +755,15 @@ impl tag_service_server::TagService for TagService { state.pinnacle.fixup_xwayland_window_layering(); - output.with_state_mut(|op_state| { - op_state.new_wait_layout_transaction( - state.pinnacle.loop_handle.clone(), - fs_and_up_snapshots, - under_fs_snapshots, - ) - }); + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + output.with_state_mut(|op_state| { + op_state.new_wait_layout_transaction( + state.pinnacle.loop_handle.clone(), + fs_and_up_snapshots, + under_fs_snapshots, + ) + }); + } state.pinnacle.request_layout(&output); state.update_keyboard_focus(&output); @@ -786,10 +787,9 @@ impl tag_service_server::TagService for TagService { return; }; - let (fs_and_up_snapshots, under_fs_snapshots) = - state.backend.with_renderer(|renderer| { - capture_snapshots_on_output(&mut state.pinnacle, renderer, &output, []) - }); + let snapshots = state.backend.with_renderer(|renderer| { + capture_snapshots_on_output(&mut state.pinnacle, renderer, &output, []) + }); output.with_state(|op_state| { for op_tag in op_state.tags.iter() { @@ -800,13 +800,15 @@ impl tag_service_server::TagService for TagService { state.pinnacle.fixup_xwayland_window_layering(); - output.with_state_mut(|op_state| { - op_state.new_wait_layout_transaction( - state.pinnacle.loop_handle.clone(), - fs_and_up_snapshots, - under_fs_snapshots, - ) - }); + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + output.with_state_mut(|op_state| { + op_state.new_wait_layout_transaction( + state.pinnacle.loop_handle.clone(), + fs_and_up_snapshots, + under_fs_snapshots, + ) + }); + } state.pinnacle.request_layout(&output); state.update_keyboard_focus(&output); @@ -1095,10 +1097,9 @@ impl output_service_server::OutputService for OutputService { current_scale = f64::max(current_scale, 0.25); - let (fs_and_up_snapshots, under_fs_snapshots) = - state.backend.with_renderer(|renderer| { - capture_snapshots_on_output(&mut state.pinnacle, renderer, &output, []) - }); + let snapshots = state.backend.with_renderer(|renderer| { + capture_snapshots_on_output(&mut state.pinnacle, renderer, &output, []) + }); state.pinnacle.change_output_state( &output, @@ -1108,13 +1109,15 @@ impl output_service_server::OutputService for OutputService { None, ); - output.with_state_mut(|op_state| { - op_state.new_wait_layout_transaction( - state.pinnacle.loop_handle.clone(), - fs_and_up_snapshots, - under_fs_snapshots, - ); - }); + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + output.with_state_mut(|op_state| { + op_state.new_wait_layout_transaction( + state.pinnacle.loop_handle.clone(), + fs_and_up_snapshots, + under_fs_snapshots, + ) + }); + } state.pinnacle.request_layout(&output); state.schedule_render(&output); diff --git a/src/api/window.rs b/src/api/window.rs index 2e630fc..0ea4cbf 100644 --- a/src/api/window.rs +++ b/src/api/window.rs @@ -248,7 +248,7 @@ impl window_service_server::WindowService for WindowService { return; }; - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|op_state| { op_state.new_wait_layout_transaction( pinnacle.loop_handle.clone(), @@ -380,7 +380,7 @@ impl window_service_server::WindowService for WindowService { let Some(output) = tag.output(pinnacle) else { return }; - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|op_state| { op_state.new_wait_layout_transaction( pinnacle.loop_handle.clone(), @@ -453,7 +453,7 @@ impl window_service_server::WindowService for WindowService { let Some(output) = tag.output(pinnacle) else { return }; - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|op_state| { op_state.new_wait_layout_transaction( pinnacle.loop_handle.clone(), diff --git a/src/backend.rs b/src/backend.rs index 0a92b6d..ad191a7 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -107,12 +107,15 @@ impl Backend { } } - pub fn with_renderer(&mut self, with_renderer: impl FnOnce(&mut GlesRenderer) -> T) -> T { + pub fn with_renderer( + &mut self, + with_renderer: impl FnOnce(&mut GlesRenderer) -> T, + ) -> Option { match self { - Backend::Winit(winit) => with_renderer(winit.backend.renderer()), - Backend::Udev(udev) => with_renderer(udev.renderer().as_mut()), + Backend::Winit(winit) => Some(with_renderer(winit.backend.renderer())), + Backend::Udev(udev) => Some(with_renderer(udev.renderer().ok()?.as_mut())), #[cfg(feature = "testing")] - Backend::Dummy(_) => todo!(), + Backend::Dummy(_) => None, } } diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 754e4b1..7fb5e31 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -866,10 +866,8 @@ fn render_frame<'a>( } impl Udev { - pub fn renderer(&mut self) -> UdevRenderer<'_> { - self.gpu_manager - .single_renderer(&self.primary_gpu) - .expect("failed to create multirenderer") + pub fn renderer(&mut self) -> anyhow::Result> { + Ok(self.gpu_manager.single_renderer(&self.primary_gpu)?) } /// A GPU was plugged in. diff --git a/src/handlers.rs b/src/handlers.rs index 11fcfdf..143a5ae 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -211,7 +211,9 @@ impl CompositorHandler for State { if unmapped_window.is_on_active_tag() { self.update_keyboard_focus(&focused_output); - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = + snapshots.flatten() + { focused_output.with_state_mut(|state| { state.new_wait_layout_transaction( self.pinnacle.loop_handle.clone(), @@ -253,23 +255,24 @@ impl CompositorHandler for State { } if let Some(output) = window.output(&self.pinnacle) { - let (fs_and_up_snapshots, under_fs_snapshots) = - self.backend.with_renderer(|renderer| { - capture_snapshots_on_output( - &mut self.pinnacle, - renderer, - &output, - [], + let snapshots = self.backend.with_renderer(|renderer| { + capture_snapshots_on_output( + &mut self.pinnacle, + renderer, + &output, + [], + ) + }); + + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + output.with_state_mut(|op_state| { + op_state.new_wait_layout_transaction( + self.pinnacle.loop_handle.clone(), + fs_and_up_snapshots, + under_fs_snapshots, ) }); - - output.with_state_mut(|state| { - state.new_wait_layout_transaction( - self.pinnacle.loop_handle.clone(), - fs_and_up_snapshots, - under_fs_snapshots, - ); - }); + } } self.pinnacle.remove_window(&window, true); diff --git a/src/handlers/window.rs b/src/handlers/window.rs index bdcb5b1..44687db 100644 --- a/src/handlers/window.rs +++ b/src/handlers/window.rs @@ -21,7 +21,7 @@ impl State { } if let Some(output) = window.output(&self.pinnacle) { - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|op_state| { op_state.new_wait_layout_transaction( self.pinnacle.loop_handle.clone(), @@ -52,7 +52,7 @@ impl State { } if let Some(output) = window.output(&self.pinnacle) { - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|op_state| { op_state.new_wait_layout_transaction( self.pinnacle.loop_handle.clone(), diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 1b68d1b..1b2b7f2 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -73,7 +73,7 @@ impl XdgShellHandler for State { if let Some(output) = window.output(&self.pinnacle) { self.pinnacle.request_layout(&output); - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|state| { state.new_wait_layout_transaction( self.pinnacle.loop_handle.clone(), diff --git a/src/handlers/xwayland.rs b/src/handlers/xwayland.rs index 8d75994..a64522c 100644 --- a/src/handlers/xwayland.rs +++ b/src/handlers/xwayland.rs @@ -116,7 +116,7 @@ impl XwmHandler for State { output.with_state_mut(|state| state.focus_stack.set_focus(window.clone())); self.update_keyboard_focus(&output); - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|state| { state.new_wait_layout_transaction( self.pinnacle.loop_handle.clone(), @@ -426,7 +426,7 @@ impl State { self.pinnacle.remove_window(&win, false); if let Some(output) = win.output(&self.pinnacle) { - if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { + if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots.flatten() { output.with_state_mut(|state| { state.new_wait_layout_transaction( self.pinnacle.loop_handle.clone(), diff --git a/src/layout.rs b/src/layout.rs index 0879add..7e9f8fe 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -267,7 +267,7 @@ impl State { .fulfilled_requests .insert(output.clone(), current_pending); - let (fs_and_up_snapshots, under_fs_snapshots) = self.backend.with_renderer(|renderer| { + let snapshots = self.backend.with_renderer(|renderer| { capture_snapshots_on_output(&mut self.pinnacle, renderer, &output, []) }); @@ -278,7 +278,7 @@ impl State { output.with_state_mut(|state| { if let Some(ts) = state.layout_transaction.as_mut() { ts.update_pending(pending_windows); - } else { + } else if let Some((fs_and_up_snapshots, under_fs_snapshots)) = snapshots { state.layout_transaction = Some(LayoutTransaction::new( self.pinnacle.loop_handle.clone(), fs_and_up_snapshots,