Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: Cursor motion blur transparency
Richie McIlroy0671cd281e5e
diff --git a/apps/desktop/src-tauri/src/cursor.rs b/apps/desktop/src-tauri/src/cursor.rsindex e1d19c369..8a1f5e82f 100644--- a/apps/desktop/src-tauri/src/cursor.rs+++ b/apps/desktop/src-tauri/src/cursor.rs@@ -185,15 +185,15 @@ fn get_cursor_image_data() -> Option<Vec<u8>> {#[cfg(windows)]fn get_cursor_image_data() -> Option<Vec<u8>> {- use windows::Win32::UI::WindowsAndMessaging::{GetCursorInfo, CURSORINFO, CURSORINFO_FLAGS};- use windows::Win32::UI::WindowsAndMessaging::{GetIconInfo, ICONINFO};+ use windows::Win32::Foundation::{BOOL, HWND, POINT};use windows::Win32::Graphics::Gdi::{- CreateCompatibleBitmap, CreateCompatibleDC, CreateDIBSection, DeleteDC, DeleteObject,- GetDC, GetObjectA, ReleaseDC, SelectObject, BITMAP, BITMAPINFO, BITMAPINFOHEADER,- DIB_RGB_COLORS, SRCCOPY, BitBlt,+ BitBlt, CreateCompatibleBitmap, CreateCompatibleDC, CreateDIBSection, DeleteDC,+ DeleteObject, GetDC, GetObjectA, ReleaseDC, SelectObject, BITMAP, BITMAPINFO,+ BITMAPINFOHEADER, DIB_RGB_COLORS, SRCCOPY,};- use windows::Win32::Foundation::{BOOL, POINT, HWND};-+ use windows::Win32::UI::WindowsAndMessaging::{GetCursorInfo, CURSORINFO, CURSORINFO_FLAGS};+ use windows::Win32::UI::WindowsAndMessaging::{GetIconInfo, ICONINFO};+unsafe {// Get cursor infolet mut cursor_info = CURSORINFO {@@ -202,7 +202,7 @@ fn get_cursor_image_data() -> Option<Vec<u8>> {hCursor: Default::default(),ptScreenPos: POINT::default(),};-+// Handle Result return typeif GetCursorInfo(&mut cursor_info).is_err() {return None;@@ -226,14 +226,15 @@ fn get_cursor_image_data() -> Option<Vec<u8>> {icon_info.hbmColor,std::mem::size_of::<BITMAP>() as i32,Some(&mut bitmap as *mut _ as *mut _),- ) == 0 {+ ) == 0+ {return None;}// Create compatible DClet screen_dc = GetDC(HWND(0));let mem_dc = CreateCompatibleDC(screen_dc);-+// Create bitmap info headerlet bi = BITMAPINFOHEADER {biSize: std::mem::size_of::<BITMAPINFOHEADER>() as u32,@@ -256,14 +257,7 @@ fn get_cursor_image_data() -> Option<Vec<u8>> {// Create DIB sectionlet mut bits: *mut std::ffi::c_void = std::ptr::null_mut();- let dib = CreateDIBSection(- mem_dc,- &bitmap_info,- DIB_RGB_COLORS,- &mut bits,- None,- 0,- );+ let dib = CreateDIBSection(mem_dc, &bitmap_info, DIB_RGB_COLORS, &mut bits, None, 0);if dib.is_err() {return None;@@ -285,7 +279,9 @@ fn get_cursor_image_data() -> Option<Vec<u8>> {cursor_info.ptScreenPos.x,cursor_info.ptScreenPos.y,SRCCOPY,- ).is_err() {+ )+ .is_err()+ {return None;}@@ -303,14 +299,16 @@ fn get_cursor_image_data() -> Option<Vec<u8>> {DeleteObject(icon_info.hbmMask);// Convert to PNG format- let image = image::RgbaImage::from_raw(- bitmap.bmWidth as u32,- bitmap.bmHeight as u32,- image_data,- )?;+ let image =+ image::RgbaImage::from_raw(bitmap.bmWidth as u32, bitmap.bmHeight as u32, image_data)?;let mut png_data = Vec::new();- image.write_to(&mut std::io::Cursor::new(&mut png_data), image::ImageFormat::Png).ok()?;+ image+ .write_to(+ &mut std::io::Cursor::new(&mut png_data),+ image::ImageFormat::Png,+ )+ .ok()?;Some(png_data)}diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rsindex f4f12b610..591cd12c2 100644--- a/apps/desktop/src-tauri/src/recording.rs+++ b/apps/desktop/src-tauri/src/recording.rs@@ -263,8 +263,18 @@ pub async fn start(let stop_signal = Arc::new(AtomicBool::new(false));- let (mouse_moves, mouse_clicks) =- spawn_cursor_recorder(stop_signal.clone(), screen_bounds, content_dir, cursors_dir);+ // Initialize default values for cursor channels+ let (mouse_moves, mouse_clicks) = if FLAGS.record_mouse {+ spawn_cursor_recorder(stop_signal.clone(), screen_bounds, content_dir, cursors_dir)+ } else {+ // Create dummy channels that will never receive data+ let (move_tx, move_rx) = oneshot::channel();+ let (click_tx, click_rx) = oneshot::channel();+ // Send empty vectors immediately+ move_tx.send(vec![]).unwrap();+ click_tx.send(vec![]).unwrap();+ (move_rx, click_rx)+ };Ok(InProgressRecording {id,diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex 519e376c9..f4eb341a1 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -1113,8 +1113,8 @@ fn draw_cursor(],screen_bounds: uniforms.display.target_bounds,cursor_size: cursor_size_percentage,- last_click_time: last_click_time.min(0.5),- velocity: [0.0, 0.0],+ last_click_time,+ velocity,motion_blur_amount,_alignment: [0.0; 7],};diff --git a/crates/rendering/src/shaders/cursor.wgsl b/crates/rendering/src/shaders/cursor.wgslindex f894adc7c..2e2b17e73 100644--- a/crates/rendering/src/shaders/cursor.wgsl+++ b/crates/rendering/src/shaders/cursor.wgsl@@ -68,7 +68,8 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {// Increase number of samples for smoother blurlet num_samples = 12;- var color = vec4<f32>(0.0);+ var color_sum = vec4<f32>(0.0);+ var weight_sum = 0.0;// Calculate blur direction from velocitylet velocity_dir = normalize(uniforms.velocity);@@ -76,30 +77,29 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {// Increase the blur trail lengthlet blur_strength = uniforms.motion_blur_amount * 2.0;- // Track total weight for normalization- var total_weight = 0.0;-// Sample in both directions from the centerfor (var i = 0; i < num_samples; i++) {// Adjusted sampling pattern for longer trailslet t = (f32(i) / f32(num_samples - 1)) * 2.0 - 1.0; // Range from -1 to 1let weight = 1.0 - abs(t); // Higher weight in the center- total_weight += weight;// Calculate sample offset with increased rangelet offset = velocity_dir * blur_strength * t;let sample_uv = input.uv + offset * uniforms.velocity / uniforms.output_size.xy;- // Apply weighted sample- color += textureSample(t_cursor, s_cursor, sample_uv) * weight;+ // Sample the texture+ let sample = textureSample(t_cursor, s_cursor, sample_uv);++ // Accumulate weighted color including alpha+ color_sum += sample * weight;+ weight_sum += weight;}// Normalize by total weight- color = color / total_weight;-- // Adjust alpha falloff for stronger trails- let alpha_scale = 1.0 - uniforms.motion_blur_amount * 0.2;- color.a *= alpha_scale;+ var final_color = vec4<f32>(0.0);+ if (weight_sum > 0.0) {+ final_color = color_sum / weight_sum;+ }- return color;+ return final_color;}