Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

some editor improvements

Brendan Allan0b04d1344a97
diff --git a/apps/desktop/src-tauri/src/flags.rs b/apps/desktop/src-tauri/src/flags.rs
index f56387e3a..dbc06054b 100644
--- a/apps/desktop/src-tauri/src/flags.rs
+++ b/apps/desktop/src-tauri/src/flags.rs
@@ -9,7 +9,7 @@ pub mod plugin {
Builder::new("cap-flags")
.js_init_script(format!(
"window.FLAGS = {}",
- serde_json::to_string(&FLAGS).unwrap()
+ serde_json::to_string_pretty(&FLAGS).unwrap()
))
.build()
}
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index d5da08b8d..7ea42e3f8 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -438,11 +438,10 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<
window.unminimize().ok();
}
- std::fs::create_dir_all(recording.recording_dir.join("screenshots")).ok();
- let display_screenshot = recording
- .recording_dir
- .join("screenshots")
- .join("display.jpg");
+ let screenshots_dir = recording.recording_dir.join("screenshots");
+ std::fs::create_dir_all(&screenshots_dir).ok();
+
+ let display_screenshot = screenshots_dir.join("display.jpg");
create_screenshot(
recording.display_output_path.clone(),
display_screenshot.clone(),
@@ -450,11 +449,7 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<
)
.await?;
- // Create thumbnail
- let thumbnail = recording
- .recording_dir
- .join("screenshots")
- .join("thumbnail.png");
+ let thumbnail = screenshots_dir.join("thumbnail.png");
create_thumbnail(display_screenshot, thumbnail, (100, 100)).await?;
let recording_dir = recording.recording_dir.clone();
@@ -473,6 +468,8 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<
.emit(&app)
.ok();
+ let recordings = ProjectRecordings::new(&recording.meta);
+
let config = {
let mut segments = vec![];
let mut passed_duration = 0.0;
@@ -482,7 +479,7 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<
passed_duration += recording.segments[i + 1] - recording.segments[i];
segments.push(TimelineSegment {
start,
- end: passed_duration,
+ end: passed_duration.min(recordings.duration()),
timescale: 1.0,
});
}
@@ -496,11 +493,7 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<
}
};
- std::fs::write(
- recording.recording_dir.join("project-config.json"),
- serde_json::to_string_pretty(&json!(&config)).unwrap(),
- )
- .unwrap();
+ config.write(&recording.recording_dir).unwrap();
AppSounds::StopRecording.play();
@@ -1581,7 +1574,7 @@ fn close_previous_recordings_window(app: AppHandle) {
#[tauri::command(async)]
#[specta::specta]
fn focus_captures_panel(app: AppHandle) {
- if let Ok(panel) = app.get_webview_panel(&CapWindow::PrevRecordings.label()) {
+ if let Ok(panel) = app.get_webview_panel(&CapWindowId::PrevRecordings.label()) {
panel.make_key_window();
}
}
@@ -1651,11 +1644,7 @@ async fn set_playhead_position(app: AppHandle, video_id: String, frame_number: u
async fn set_project_config(app: AppHandle, video_id: String, config: ProjectConfiguration) {
let editor_instance = upsert_editor_instance(&app, video_id).await;
- std::fs::write(
- editor_instance.project_path.join("project-config.json"),
- serde_json::to_string_pretty(&json!(config)).unwrap(),
- )
- .unwrap();
+ config.write(&editor_instance.project_path).unwrap();
editor_instance.project_config.0.send(config).ok();
}
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index 6478fa8db..a781592b1 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -1,7 +1,7 @@
use cap_flags::FLAGS;
use cap_media::{encoders::*, feeds::*, filters::*, pipeline::*, sources::*, MediaError};
-use cap_project::CursorEvent;
-use device_query::{DeviceQuery, DeviceState};
+use cap_project::{CursorEvent, RecordingMeta};
+use device_query::{DeviceEvents, DeviceQuery, DeviceState};
use serde::Serialize;
use specta::Type;
use std::collections::HashMap;
@@ -85,6 +85,7 @@ pub struct CompletedRecording {
pub audio_output_path: Option<PathBuf>,
pub display_source: ScreenCaptureTarget,
pub segments: Vec<f64>,
+ pub meta: RecordingMeta,
}
impl InProgressRecording {
@@ -148,7 +149,7 @@ impl InProgressRecording {
if FLAGS.record_mouse {
// Save mouse events to files
let mut file = File::create(self.recording_dir.join("cursor.json")).unwrap();
- serde_json::to_writer(
+ serde_json::to_writer_pretty(
&mut file,
&CursorData {
clicks: self.cursor_clicks.await.unwrap(),
@@ -168,6 +169,7 @@ impl InProgressRecording {
audio_output_path: self.audio_output_path,
display_source: self.display_source,
segments: self.segments,
+ meta,
}
}
@@ -341,7 +343,8 @@ pub async fn start(
moves.push(mouse_event);
}
- if mouse_state.button_pressed[0] && !last_mouse_state.button_pressed[0] {
+ // cursor 0 doesn't do anything
+ if mouse_state.button_pressed[1] && !last_mouse_state.button_pressed[1] {
let mouse_event = CursorEvent {
active_modifiers: vec![],
cursor_id,
@@ -367,7 +370,7 @@ pub async fn start(
let cursor_json_path = content_dir.join("cursor.json");
println!("Saving cursor data to: {:?}", cursor_json_path);
if let Ok(mut file) = File::create(&cursor_json_path) {
- if let Err(e) = serde_json::to_writer(&mut file, &cursor_data) {
+ if let Err(e) = serde_json::to_writer_pretty(&mut file, &cursor_data) {
eprintln!("Failed to save cursor data: {}", e);
} else {
println!("Successfully saved cursor data");
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index 594995835..bdb6efcf5 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -5,13 +5,14 @@ use tauri::{
AppHandle, LogicalPosition, Manager, WebviewUrl, WebviewWindow, WebviewWindowBuilder, Wry,
};
+#[derive(Clone)]
pub enum CapWindow {
Main,
Settings { page: Option<String> },
Editor { project_id: String },
Permissions,
PrevRecordings,
- Notifications,
+ // Notifications,
WindowCaptureOccluder,
Camera { ws_port: u16 },
InProgressRecording { position: Option<(f64, f64)> },
@@ -20,13 +21,14 @@ pub enum CapWindow {
Changelog,
}
+#[derive(Clone)]
pub enum CapWindowId {
Main,
Settings,
Editor { project_id: String },
Permissions,
PrevRecordings,
- Notifications,
+ // Notifications,
WindowCaptureOccluder,
Camera,
InProgressRecording,
@@ -44,7 +46,7 @@ impl CapWindowId {
"window-capture-occluder" => Self::WindowCaptureOccluder,
"in-progress-recording" => Self::InProgressRecording,
"prev-recordings" => Self::PrevRecordings,
- "notifications" => Self::Notifications,
+ // "notifications" => Self::Notifications,
"permissions" => Self::Permissions,
"feedback" => Self::Feedback,
"upgrade" => Self::Upgrade,
@@ -64,7 +66,7 @@ impl CapWindowId {
Self::WindowCaptureOccluder => "window-capture-occluder".to_string(),
Self::InProgressRecording => "in-progress-recording".to_string(),
Self::PrevRecordings => "prev-recordings".to_string(),
- Self::Notifications => "notifications".to_string(),
+ // Self::Notifications => "notifications".to_string(),
Self::Editor { project_id } => format!("editor-{}", project_id),
Self::Permissions => "permissions".to_string(),
Self::Feedback => "feedback".to_string(),
@@ -79,7 +81,7 @@ impl CapWindowId {
Self::WindowCaptureOccluder => "Cap Window Capture Occluder".to_string(),
Self::InProgressRecording => "Cap In Progress Recording".to_string(),
Self::Editor { .. } => "Cap Editor".to_string(),
- Self::Notifications => "Cap Notifications".to_string(),
+ // Self::Notifications => "Cap Notifications".to_string(),
Self::Permissions => "Cap Permissions".to_string(),
Self::Changelog => "Cap Changelog".to_string(),
_ => "Cap".to_string(),
@@ -88,14 +90,14 @@ impl CapWindowId {
pub fn activates_dock(&self) -> bool {
match self {
- Self::Main => true,
- Self::Editor { .. } => true,
- Self::Settings => true,
- Self::Notifications => true,
- Self::Permissions => true,
- Self::Feedback => true,
- Self::Upgrade => true,
- Self::Changelog => true,
+ Self::Main
+ | Self::Editor { .. }
+ | Self::Settings
+ // | Self::Notifications
+ | Self::Permissions
+ | Self::Feedback
+ | Self::Upgrade
+ | Self::Changelog => true,
_ => false,
}
}
@@ -104,75 +106,23 @@ impl CapWindowId {
let label = self.label();
app.get_webview_window(&label)
}
-}
-
-impl CapWindow {
- pub fn from_label(label: &str) -> Self {
- match label {
- "main" => Self::Main,
- "settings" => Self::Settings { page: None },
- "camera" => Self::Camera { ws_port: 0 },
- "window-capture-occluder" => Self::WindowCaptureOccluder,
- "in-progress-recording" => Self::InProgressRecording { position: None },
- "prev-recordings" => Self::PrevRecordings,
- "notifications" => Self::Notifications,
- "permissions" => Self::Permissions,
- "feedback" => Self::Feedback,
- "upgrade" => Self::Upgrade,
- "changelog" => Self::Changelog,
- s if s.starts_with("editor-") => Self::Editor {
- project_id: s.replace("editor-", ""),
- },
- _ => unreachable!("unknown window label: {}", label),
- }
- }
- pub fn label(&self) -> String {
+ pub fn traffic_lights_position(&self) -> Option<Option<LogicalPosition<f64>>> {
match self {
- Self::Main => "main".to_string(),
- Self::Settings { .. } => "settings".to_string(),
- Self::Camera { .. } => "camera".to_string(),
- Self::WindowCaptureOccluder => "window-capture-occluder".to_string(),
- Self::InProgressRecording { .. } => "in-progress-recording".to_string(),
- Self::PrevRecordings => "prev-recordings".to_string(),
- Self::Notifications => "notifications".to_string(),
- Self::Editor { project_id } => format!("editor-{}", project_id),
- Self::Permissions => "permissions".to_string(),
- Self::Feedback => "feedback".to_string(),
- Self::Upgrade => "upgrade".to_string(),
- Self::Changelog => "changelog".to_string(),
- }
- }
-
- pub fn title(&self) -> String {
- match self {
- Self::Settings { .. } => "Cap Settings".to_string(),
- Self::WindowCaptureOccluder => "Cap Window Capture Occluder".to_string(),
- Self::InProgressRecording { .. } => "Cap In Progress Recording".to_string(),
- Self::Editor { .. } => "Cap Editor".to_string(),
- Self::Notifications => "Cap Notifications".to_string(),
- Self::Permissions => "Cap Permissions".to_string(),
- Self::Changelog => "Cap Changelog".to_string(),
- _ => "Cap".to_string(),
- }
- }
-
- pub fn activates_dock(&self) -> bool {
- match self {
- CapWindow::Main => true,
- CapWindow::Editor { .. } => true,
- CapWindow::Settings { .. } => true,
- CapWindow::Notifications => true,
- CapWindow::Permissions => true,
- CapWindow::Feedback => true,
- CapWindow::Upgrade => true,
- CapWindow::Changelog => true,
- _ => false,
+ Self::Camera
+ | Self::InProgressRecording
+ | Self::WindowCaptureOccluder
+ | Self::PrevRecordings => None,
+ // | Self::Notifications => None,
+ Self::Editor { .. } => Some(Some(LogicalPosition::new(20.0, 48.0))),
+ _ => Some(None),
}
}
+}
+impl CapWindow {
pub fn get(&self, app: &AppHandle<Wry>) -> Option<WebviewWindow> {
- let label = self.label();
+ let label = self.id().label();
app.get_webview_window(&label)
}
@@ -184,9 +134,11 @@ impl CapWindow {
return Ok(window);
}
+ let id = self.id();
+
let monitor = app.primary_monitor()?.unwrap();
- Ok(match self {
+ let window = match self {
Self::Main => {
let mut window_builder = self
.window_builder(app, "/")
@@ -197,25 +149,12 @@ impl CapWindow {
.theme(Some(tauri::Theme::Light))
.shadow(true);
- #[cfg(target_os = "macos")]
- {
- window_builder = window_builder
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay)
- .shadow(true);
- }
-
#[cfg(target_os = "windows")]
{
window_builder = window_builder.decorations(false).shadow(false);
}
- let window = window_builder.build()?;
-
- #[cfg(target_os = "macos")]
- setup_delegates(&window, None);
-
- window
+ window_builder.build()?
}
Self::Settings { page } => {
let mut window_builder = self
@@ -228,11 +167,6 @@ impl CapWindow {
.maximized(false)
.transparent(true);
- #[cfg(target_os = "windows")]
- {
- window_builder = window_builder.decorations(false).shadow(false);
- }
-
#[cfg(target_os = "macos")]
{
window_builder = window_builder
@@ -241,13 +175,79 @@ impl CapWindow {
.shadow(true);
}
- let window = window_builder.build()?;
+ window_builder.build()?
+ }
+ Self::Editor { project_id } => {
+ let mut window_builder = self
+ .window_builder(app, format!("/editor?id={project_id}"))
+ .inner_size(1150.0, 800.0)
+ .hidden_title(true)
+ .title_bar_style(tauri::TitleBarStyle::Overlay)
+ .theme(Some(tauri::Theme::Light));
- #[cfg(target_os = "macos")]
- setup_delegates(&window, None);
+ window_builder.build()?
+ }
+ Self::Permissions => {
+ let mut window_builder = self
+ .window_builder(app, "/permissions")
+ .inner_size(500.0, 425.0)
+ .resizable(false)
+ .maximized(false)
+ .shadow(true)
+ .transparent(true);
+
+ #[cfg(target_os = "windows")]
+ {
+ window_builder = window_builder.decorations(false);
+ }
+
+ window_builder.build()?
+ }
+ Self::Feedback => {
+ let mut window_builder = self
+ .window_builder(app, "/feedback")
+ .inner_size(400.0, 400.0)
+ .resizable(false)
+ .maximized(false)
+ .shadow(true)
+ .transparent(true);
+
+ #[cfg(target_os = "windows")]
+ {
+ window_builder = window_builder.decorations(false);
+ }
+
+ window_builder.build()?
+ }
+ Self::Upgrade => {
+ let mut window_builder = self
+ .window_builder(app, "/upgrade")
+ .inner_size(800.0, 850.0)
+ .resizable(false)
+ .maximized(false)
+ .shadow(true)
+ .transparent(true);
+
+ let window = window_builder.build()?;
window
}
+ Self::Changelog => {
+ let mut window_builder = self
+ .window_builder(app, "/changelog")
+ .inner_size(600.0, 450.0)
+ .resizable(true)
+ .maximized(false)
+ .shadow(true)
+ .transparent(true);
+
+ #[cfg(target_os = "windows")]
+ {
+ window_builder = window_builder.decorations(false);
+ }
+
+ window_builder.build()?
+ }
Self::Camera { ws_port } => {
const WINDOW_SIZE: f64 = 230.0 * 2.0;
@@ -322,7 +322,6 @@ impl CapWindow {
let height = 40.0;
self.window_builder(app, "/in-progress-recording")
- .title(self.title())
.maximized(false)
.resizable(false)
.fullscreen(false)
@@ -340,31 +339,31 @@ impl CapWindow {
.visible(false)
.build()?
}
- Self::Notifications => {
- let window = self
- .window_builder(app, "/notifications")
- .maximized(false)
- .transparent(true)
- .resizable(false)
- .fullscreen(false)
- .decorations(false)
- .shadow(false)
- .always_on_top(true)
- .visible_on_all_workspaces(true)
- .content_protected(true)
- .inner_size(350.0, 350.0)
- .skip_taskbar(true)
- .position(
- (monitor.size().width as f64) / monitor.scale_factor() - 350.0,
- 0.0,
- )
- .build()?;
-
- // Make window non-interactive
- window.set_ignore_cursor_events(true)?;
-
- window
- }
+ // Self::Notifications => {
+ // let window = self
+ // .window_builder(app, "/notifications")
+ // .maximized(false)
+ // .transparent(true)
+ // .resizable(false)
+ // .fullscreen(false)
+ // .decorations(false)
+ // .shadow(false)
+ // .always_on_top(true)
+ // .visible_on_all_workspaces(true)
+ // .content_protected(true)
+ // .inner_size(350.0, 350.0)
+ // .skip_taskbar(true)
+ // .position(
+ // (monitor.size().width as f64) / monitor.scale_factor() - 350.0,
+ // 0.0,
+ // )
+ // .build()?;
+
+ // // Make window non-interactive
+ // window.set_ignore_cursor_events(true)?;
+
+ // window
+ // }
Self::PrevRecordings => {
let mut window_builder = self
.window_builder(app, "/prev-recordings")
@@ -415,141 +414,13 @@ impl CapWindow {
window
}
- Self::Editor { project_id } => {
- let mut window_builder = self
- .window_builder(app, format!("/editor?id={project_id}"))
- .inner_size(1150.0, 800.0)
- .title(self.title())
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay)
- .theme(Some(tauri::Theme::Light));
-
- #[cfg(target_os = "macos")]
- {
- window_builder = window_builder
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay);
- }
-
- let window = window_builder.build()?;
-
- #[cfg(target_os = "macos")]
- setup_delegates(&window, Some(LogicalPosition::new(20.0, 48.0)));
-
- window
- }
- Self::Permissions => {
- let mut window_builder = self
- .window_builder(app, "/permissions")
- .title(self.title())
- .inner_size(500.0, 425.0)
- .resizable(false)
- .maximized(false)
- .shadow(true)
- .transparent(true);
-
- #[cfg(target_os = "macos")]
- {
- window_builder = window_builder
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay);
- }
-
- #[cfg(target_os = "windows")]
- {
- window_builder = window_builder.decorations(false);
- }
-
- let window = window_builder.build()?;
-
- #[cfg(target_os = "macos")]
- setup_delegates(&window, None);
-
- window
- }
- Self::Feedback => {
- let mut window_builder = self
- .window_builder(app, "/feedback")
- .title(self.title())
- .inner_size(400.0, 400.0)
- .resizable(false)
- .maximized(false)
- .shadow(true)
- .transparent(true);
-
- #[cfg(target_os = "macos")]
- {
- window_builder = window_builder
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay);
- }
-
- #[cfg(target_os = "windows")]
- {
- window_builder = window_builder.decorations(false);
- }
+ };
- let window = window_builder.build()?;
-
- #[cfg(target_os = "macos")]
- setup_delegates(&window, None);
-
- window
- }
- Self::Upgrade => {
- let mut window_builder = self
- .window_builder(app, "/upgrade")
- .title(self.title())
- .inner_size(800.0, 850.0)
- .resizable(false)
- .maximized(false)
- .shadow(true)
- .transparent(true);
-
- #[cfg(target_os = "macos")]
- {
- window_builder = window_builder
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay);
- }
-
- let window = window_builder.build()?;
-
- #[cfg(target_os = "macos")]
- setup_delegates(&window, None);
-
- window
- }
- Self::Changelog => {
- let mut window_builder = self
- .window_builder(app, "/changelog")
- .title(self.title())
- .inner_size(600.0, 450.0)
- .resizable(true)
- .maximized(false)
- .shadow(true)
- .transparent(true);
-
- #[cfg(target_os = "macos")]
- {
- window_builder = window_builder
- .hidden_title(true)
- .title_bar_style(tauri::TitleBarStyle::Overlay);
- }
-
- #[cfg(target_os = "windows")]
- {
- window_builder = window_builder.decorations(false);
- }
-
- let window = window_builder.build()?;
-
- #[cfg(target_os = "macos")]
- setup_delegates(&window, None);
+ if let Some(position) = id.traffic_lights_position() {
+ add_traffic_lights(&window, position);
+ }
- window
- }
- })
+ Ok(window)
}
fn window_builder<'a>(
@@ -557,39 +428,73 @@ impl CapWindow {
app: &'a AppHandle<Wry>,
url: impl Into<PathBuf>,
) -> WebviewWindowBuilder<'a, Wry, AppHandle<Wry>> {
- WebviewWindow::builder(app, self.label(), WebviewUrl::App(url.into()))
- .title(self.title())
+ let id = self.id();
+
+ let mut builder = WebviewWindow::builder(app, id.label(), WebviewUrl::App(url.into()))
+ .title(id.title())
.visible(false)
- .accept_first_mouse(true)
+ .accept_first_mouse(true);
+
+ #[cfg(target_os = "macos")]
+ {
+ if id.traffic_lights_position().is_some() {
+ builder = builder
+ .hidden_title(true)
+ .title_bar_style(tauri::TitleBarStyle::Overlay)
+ .shadow(true);
+ }
+ }
+
+ builder
}
-}
-#[cfg(target_os = "macos")]
-fn setup_delegates(window: &WebviewWindow<Wry>, controls_inset: Option<LogicalPosition<f64>>) {
- use crate::platform::delegates;
-
- let target_window = window.clone();
- window
- .run_on_main_thread(move || {
- delegates::setup(
- target_window.as_ref().window(),
- controls_inset.unwrap_or(LogicalPosition::new(14.0, 22.0)),
- );
-
- let c_win = target_window.clone();
- target_window.on_window_event(move |event| match event {
- tauri::WindowEvent::ThemeChanged(..) => {
- delegates::position_window_controls(
- delegates::UnsafeWindowHandle(
- c_win
- .ns_window()
- .expect("Failed to get native window handle"),
- ),
- &controls_inset.unwrap_or(LogicalPosition::new(14.0, 22.0)),
- );
- }
- _ => (),
- });
- })
- .ok();
+ pub fn id(&self) -> CapWindowId {
+ match self {
+ CapWindow::Main => CapWindowId::Main,
+ CapWindow::Settings { .. } => CapWindowId::Settings,
+ CapWindow::Editor { project_id } => CapWindowId::Editor {
+ project_id: project_id.clone(),
+ },
+ CapWindow::Permissions => CapWindowId::Permissions,
+ CapWindow::PrevRecordings => CapWindowId::PrevRecordings,
+ // CapWindow::Notifications => CapWindowId::Notifications,
+ CapWindow::WindowCaptureOccluder => CapWindowId::WindowCaptureOccluder,
+ CapWindow::Camera { .. } => CapWindowId::Camera,
+ CapWindow::InProgressRecording { .. } => CapWindowId::InProgressRecording,
+ CapWindow::Feedback => CapWindowId::Feedback,
+ CapWindow::Upgrade => CapWindowId::Upgrade,
+ CapWindow::Changelog => CapWindowId::Changelog,
+ }
+ }
+}
+fn add_traffic_lights(window: &WebviewWindow<Wry>, controls_inset: Option<LogicalPosition<f64>>) {
+ #[cfg(target_os = "macos")]
+ {
+ use crate::platform::delegates;
+
+ let target_window = window.clone();
+ window
+ .run_on_main_thread(move || {
+ delegates::setup(
+ target_window.as_ref().window(),
+ controls_inset.unwrap_or(LogicalPosition::new(14.0, 22.0)),
+ );
+
+ let c_win = target_window.clone();
+ target_window.on_window_event(move |event| match event {
+ tauri::WindowEvent::ThemeChanged(..) => {
+ delegates::position_window_controls(
+ delegates::UnsafeWindowHandle(
+ c_win
+ .ns_window()
+ .expect("Failed to get native window handle"),
+ ),
+ &controls_inset.unwrap_or(LogicalPosition::new(14.0, 22.0)),
+ );
+ }
+ _ => (),
+ });
+ })
+ .ok();
+ }
}
diff --git a/apps/desktop/src/routes/(window-chrome).tsx b/apps/desktop/src/routes/(window-chrome).tsx
index a3a89eb9a..c8f446223 100644
--- a/apps/desktop/src/routes/(window-chrome).tsx
+++ b/apps/desktop/src/routes/(window-chrome).tsx
@@ -1,6 +1,7 @@
import type { RouteSectionProps } from "@solidjs/router";
import { onMount, ParentProps, Suspense } from "solid-js";
import { getCurrentWindow } from "@tauri-apps/api/window";
+import { Transition } from "solid-transition-group";
import Header from "../components/Header";
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
index ebd18f745..9424e1be3 100644
--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
@@ -573,7 +573,7 @@ export function ConfigSidebar() {
return (
<div
data-visible={state.timelineSelection?.type === "zoom"}
- class="absolute inset-0 p-[0.75rem] text-[0.875rem] space-y-4 bg-gray-50 z-50"
+ class="absolute inset-0 p-[0.75rem] text-[0.875rem] space-y-4 bg-gray-50 z-50 animate-in slide-in-from-bottom-2 fade-in"
>
<div class="flex flex-row justify-between">
<EditorButton
diff --git a/apps/desktop/src/routes/editor/Timeline.tsx b/apps/desktop/src/routes/editor/Timeline.tsx
index 2c45b7abb..4175195b2 100644
--- a/apps/desktop/src/routes/editor/Timeline.tsx
+++ b/apps/desktop/src/routes/editor/Timeline.tsx
@@ -12,16 +12,22 @@ import {
} from "solid-js";
import { createEventListenerMap } from "@solid-primitives/event-listener";
import { cx } from "cva";
-import { produce } from "solid-js/store";
+import { createStore, produce } from "solid-js/store";
import { mergeRefs } from "@solid-primitives/refs";
+import { createContextProvider } from "@solid-primitives/context";
import { commands } from "~/utils/tauri";
import { useEditorContext } from "./context";
import { formatTime } from "./utils";
-const TimelineContext = createContext<{ duration: Accessor<number> }>({
- duration: () => 0,
-});
+const [TimelineContextProvider, useTimelineContext] = createContextProvider(
+ (props: { duration: number }) => {
+ return {
+ duration: () => props.duration,
+ };
+ },
+ null!
+);
export function Timeline() {
const {
@@ -68,17 +74,14 @@ export function Timeline() {
project.timeline ??= {
segments: [{ start: 0, end: duration(), timescale: 1 }],
};
- // project.timeline.zoomSegments = [
- // { start: 0, end: duration(), amount: 1 },
- // ];
})
);
}
return (
- <TimelineContext.Provider value={{ duration }}>
+ <TimelineContextProvider duration={duration()}>
<div
- class="py-[2rem] relative overflow-hidden space-y-2"
+ class="py-[2rem] relative overflow-hidden"
style={{
"padding-left": `${xPadding}px`,
"padding-right": `${xPadding}px`,
@@ -313,261 +316,282 @@ export function Timeline() {
const [hoveredTime, setHoveredTime] = createSignal<number>();
return (
- <TrackRoot
- isFreeForm
- onMouseMove={(e) => {
- if (hoveringSegment()) {
- setHoveredTime(undefined);
- return;
- }
-
- const bounds = e.target.getBoundingClientRect()!;
-
- let time =
- ((e.clientX - bounds.left) / bounds.width) * duration();
-
- const prevSegmentIndex =
- project.timeline?.zoomSegments?.findIndex(
- (s) => s.end < time
- );
+ <>
+ <div class="h-2 w-full" />
+
+ <TrackRoot
+ isFreeForm
+ onMouseMove={(e) => {
+ if (hoveringSegment()) {
+ setHoveredTime(undefined);
+ return;
+ }
- const nextSegmentIndex =
- project.timeline?.zoomSegments?.findIndex(
- (s) => time < s.start
- );
+ const bounds = e.target.getBoundingClientRect()!;
- if (nextSegmentIndex !== undefined) {
- const nextSegment =
- project.timeline?.zoomSegments?.[nextSegmentIndex];
+ let time =
+ ((e.clientX - bounds.left) / bounds.width) * duration();
- if (prevSegmentIndex !== undefined && nextSegment) {
- const prevSegment =
- project.timeline?.zoomSegments?.[prevSegmentIndex];
+ const prevSegmentIndex =
+ project.timeline?.zoomSegments?.findIndex(
+ (s) => s.end < time
+ );
+
+ const nextSegmentIndex =
+ project.timeline?.zoomSegments?.findIndex(
+ (s) => time < s.start
+ );
- if (prevSegment) {
- const availableTime =
- nextSegment?.start - prevSegment?.end;
+ if (nextSegmentIndex !== undefined) {
+ const nextSegment =
+ project.timeline?.zoomSegments?.[nextSegmentIndex];
- if (availableTime < 1) return;
+ if (prevSegmentIndex !== undefined && nextSegment) {
+ const prevSegment =
+ project.timeline?.zoomSegments?.[prevSegmentIndex];
+
+ if (prevSegment) {
+ const availableTime =
+ nextSegment?.start - prevSegment?.end;
+
+ if (availableTime < 1) return;
+ }
}
- }
- if (nextSegment && nextSegment.start - time < 1) {
- time = nextSegment.start - 1;
+ if (nextSegment && nextSegment.start - time < 1) {
+ time = nextSegment.start - 1;
+ }
}
- }
- setHoveredTime(Math.min(time, duration() - 1));
- }}
- onMouseLeave={(e) => setHoveredTime()}
- onClick={(e) => {
- const time = hoveredTime();
- if (time === undefined) return;
-
- e.stopPropagation();
- setProject(
- "timeline",
- "zoomSegments",
- produce((zoomSegments) => {
- zoomSegments ??= [];
- zoomSegments.push({
- start: time,
- end: time + 1,
- amount: 1.5,
- });
- })
- );
- }}
- >
- <Show when={hoveredTime()}>
- {(time) => (
- <SegmentRoot
- class="border-red-300 group pointer-events-none opacity-70"
- innerClass="ring-red-300"
- segment={{
- start: time(),
- end: time() + 1,
- }}
- >
- <SegmentHandle class="bg-red-300" />
- <SegmentContent class="bg-red-50" />
- <SegmentHandle class="bg-red-300" />
- </SegmentRoot>
- )}
- </Show>
- <For each={project.timeline?.zoomSegments}>
- {(segment, i) => (
- <SegmentRoot
- class="border-red-300 group"
- innerClass="ring-red-300"
- segment={segment}
- onMouseEnter={() => {
- setHoveringSegment(true);
- }}
- onMouseLeave={() => {
- setHoveringSegment(false);
- }}
- >
- <SegmentHandle
- class="bg-red-300 group-hover:bg-opacity-80 transition-colors"
- onMouseDown={(downEvent) => {
- const start = segment.start;
-
- const maxDuration =
- editorInstance.recordingDuration -
- segments().reduce(
- (acc, segment, segmentI) =>
- segmentI === i()
- ? acc
- : acc +
- (segment.end - segment.start) /
- segment.timescale,
- 0
- );
-
- function update(event: MouseEvent) {
- const { width } = timelineBounds;
-
- const newStart =
- start +
- ((event.clientX - downEvent.clientX) / width!) *
- duration();
-
- setProject(
- "timeline",
- "zoomSegments",
- i(),
- "start",
- Math.min(
- Math.max(
- newStart,
- // Math.max(newStart, 0),
- segment.end - maxDuration
- ),
- segment.end - 1
- )
- );
- }
-
- const resumeHistory = history.pause();
- createRoot((dispose) => {
- createEventListenerMap(window, {
- mousemove: update,
- mouseup: (e) => {
- dispose();
- resumeHistory();
- update(e);
- },
- });
- });
- }}
- onClick={(e) => {
- e.stopPropagation();
- }}
- />
- <SegmentContent
- class="bg-red-50 cursor-pointer group-hover:bg-opacity-80 transition-colors"
- onClick={(e) => {
- setState("timelineSelection", {
- type: "zoom",
- index: i(),
- });
- e.stopPropagation();
+ setHoveredTime(Math.min(time, duration() - 1));
+ }}
+ onMouseLeave={(e) => setHoveredTime()}
+ onClick={(e) => {
+ const time = hoveredTime();
+ if (time === undefined) return;
+
+ e.stopPropagation();
+ setProject(
+ "timeline",
+ "zoomSegments",
+ produce((zoomSegments) => {
+ zoomSegments ??= [];
+ zoomSegments.push({
+ start: time,
+ end: time + 1,
+ amount: 1.5,
+ });
+ })
+ );
+ }}
+ >
+ <Show
+ when={
+ !useTrackContext().trackState.draggingHandle &&
+ hoveredTime()
+ }
+ >
+ {(time) => (
+ <SegmentRoot
+ class="border-red-300 group pointer-events-none opacity-70"
+ innerClass="ring-red-300"
+ segment={{
+ start: time(),
+ end: time() + 1,
}}
>
- {/*<button
- onClick={() => {
- // setProject(
- // "timeline",
- // "zoomSegments",
- // produce((segments) => {
- // segments.splice(i(), 1);
- // })
- // );
- }}
- class="size-7 opacity-0 group/button group-hover:opacity-100 transition-opacity bg-gray-50 rounded-full flex flex-col items-center justify-center"
- >
- <IconCapTrash class="size-4 text-gray-400 group-hover/button:text-gray-500 transition-colors" />
- </button>*/}
- </SegmentContent>
- <SegmentHandle
- class="bg-red-300 group-hover:bg-opacity-80 transition-colors"
- onMouseDown={(downEvent) => {
- const end = segment.end;
-
- const maxDuration =
- editorInstance.recordingDuration -
- segments().reduce(
- (acc, segment, segmentI) =>
- segmentI === i()
- ? acc
- : acc +
- (segment.end - segment.start) /
- segment.timescale,
- 0
- );
-
- function update(event: MouseEvent) {
- const { width } = timelineBounds;
-
- const newEnd =
- end +
- ((event.clientX - downEvent.clientX) / width!) *
- duration();
-
- setProject(
- "timeline",
- "zoomSegments",
- i(),
- "end",
- Math.max(
- Math.min(newEnd, segment.start + maxDuration),
- segment.start + 1
- )
- );
- }
-
- const resumeHistory = history.pause();
- createRoot((dispose) => {
- createEventListenerMap(window, {
- mousemove: update,
- mouseup: (e) => {
- dispose();
- resumeHistory();
- update(e);
- },
- });
- });
- }}
- onClick={(e) => {
- e.stopPropagation();
- }}
- />
- </SegmentRoot>
- )}
- </For>
- </TrackRoot>
+ <SegmentHandle class="bg-red-300" />
+ <SegmentContent class="bg-red-50" />
+ <SegmentHandle class="bg-red-300" />
+ </SegmentRoot>
+ )}
+ </Show>
+ <For each={project.timeline?.zoomSegments}>
+ {(segment, i) => {
+ const { setTrackState } = useTrackContext();
+
+ return (
+ <SegmentRoot
+ class="border-red-300 group"
+ innerClass="ring-red-300"
+ segment={segment}
+ onMouseEnter={() => {
+ setHoveringSegment(true);
+ }}
+ onMouseLeave={() => {
+ setHoveringSegment(false);
+ }}
+ >
+ <SegmentHandle
+ class="bg-red-300 group-hover:bg-opacity-80 transition-colors"
+ onMouseDown={(downEvent) => {
+ const start = segment.start;
+
+ const maxDuration =
+ editorInstance.recordingDuration -
+ segments().reduce(
+ (acc, segment, segmentI) =>
+ segmentI === i()
+ ? acc
+ : acc +
+ (segment.end - segment.start) /
+ segment.timescale,
+ 0
+ );
+
+ function update(event: MouseEvent) {
+ const { width } = timelineBounds;
+
+ const newStart =
+ start +
+ ((event.clientX - downEvent.clientX) /
+ width!) *
+ duration();
+
+ setProject(
+ "timeline",
+ "zoomSegments",
+ i(),
+ "start",
+ Math.min(
+ Math.max(
+ newStart,
+ // Math.max(newStart, 0),
+ segment.end - maxDuration
+ ),
+ segment.end - 1
+ )
+ );
+ }
+
+ setTrackState("draggingHandle", true);
+
+ const resumeHistory = history.pause();
+ createRoot((dispose) => {
+ createEventListenerMap(window, {
+ mousemove: update,
+ mouseup: (e) => {
+ dispose();
+ resumeHistory();
+ update(e);
+ setTrackState("draggingHandle", false);
+ },
+ });
+ });
+ }}
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ />
+ <SegmentContent
+ class="bg-red-50 cursor-pointer group-hover:bg-opacity-80 transition-colors"
+ onClick={(e) => {
+ setState("timelineSelection", {
+ type: "zoom",
+ index: i(),
+ });
+ e.stopPropagation();
+ }}
+ />
+ <SegmentHandle
+ class="bg-red-300 group-hover:bg-opacity-80 transition-colors"
+ onMouseDown={(downEvent) => {
+ const end = segment.end;
+
+ const maxDuration =
+ editorInstance.recordingDuration -
+ segments().reduce(
+ (acc, segment, segmentI) =>
+ segmentI === i()
+ ? acc
+ : acc +
+ (segment.end - segment.start) /
+ segment.timescale,
+ 0
+ );
+
+ function update(event: MouseEvent) {
+ const { width } = timelineBounds;
+
+ const newEnd =
+ end +
+ ((event.clientX - downEvent.clientX) /
+ width!) *
+ duration();
+
+ setProject(
+ "timeline",
+ "zoomSegments",
+ i(),
+ "end",
+ Math.max(
+ Math.min(
+ newEnd,
+ segment.start + maxDuration
+ ),
+ segment.start + 1
+ )
+ );
+ }
+
+ setTrackState("draggingHandle", true);
+
+ const resumeHistory = history.pause();
+ createRoot((dispose) => {
+ createEventListenerMap(window, {
+ mousemove: update,
+ mouseup: (e) => {
+ dispose();
+ resumeHistory();
+ update(e);
+ setTrackState("draggingHandle", false);
+ },
+ });
+ });
+ }}
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ />
+ </SegmentRoot>
+ );
+ }}
+ </For>
+ </TrackRoot>
+ </>
);
}}
</Show>
</div>
- </TimelineContext.Provider>
+ </TimelineContextProvider>
);
}
-const TrackContext = createContext<{
- trackBounds: ReturnType<typeof createElementBounds>;
- isFreeForm: boolean;
-}>();
+const [TrackContextProvider, useTrackContext] = createContextProvider(
+ (props: {
+ ref: Accessor<Element | undefined>;
+ isFreeForm: Accessor<boolean>;
+ }) => {
+ const [trackState, setTrackState] = createStore({
+ draggingHandle: false,
+ });
+ const bounds = createElementBounds(() => props.ref());
+
+ return {
+ trackBounds: bounds,
+ isFreeForm: () => props.isFreeForm(),
+ trackState,
+ setTrackState,
+ };
+ },
+ null!
+);
function TrackRoot(props: ComponentProps<"div"> & { isFreeForm: boolean }) {
const [ref, setRef] = createSignal<HTMLDivElement>();
- const bounds = createElementBounds(ref);
return (
- <TrackContext.Provider
- value={{ trackBounds: bounds, isFreeForm: props.isFreeForm }}
- >
+ <TrackContextProvider ref={ref} isFreeForm={() => props.isFreeForm}>
<div
{...props}
ref={mergeRefs(setRef, props.ref)}
@@ -575,7 +599,7 @@ function TrackRoot(props: ComponentProps<"div"> & { isFreeForm: boolean }) {
>
{props.children}
</div>
- </TrackContext.Provider>
+ </TrackContextProvider>
);
}
@@ -585,8 +609,8 @@ function SegmentRoot(
segment: { start: number; end: number };
}
) {
- const { duration } = useContext(TimelineContext)!;
- const { trackBounds, isFreeForm } = useContext(TrackContext)!;
+ const { duration } = useTimelineContext();
+ const { trackBounds, isFreeForm } = useTrackContext();
return (
<div
@@ -596,7 +620,7 @@ function SegmentRoot(
props.class
)}
style={{
- transform: isFreeForm
+ transform: isFreeForm()
? `translateX(${
(props.segment.start / duration()) * (trackBounds.width ?? 0)
}px)`
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs
index 19a3da1ac..c3260a0b4 100644
--- a/crates/editor/src/editor_instance.rs
+++ b/crates/editor/src/editor_instance.rs
@@ -3,7 +3,7 @@ use crate::editor;
use crate::playback::{self, PlaybackHandle};
use crate::project_recordings::ProjectRecordings;
use cap_ffmpeg::FFmpeg;
-use cap_project::{CursorData, ProjectConfiguration, RecordingMeta};
+use cap_project::{CursorData, ProjectConfiguration, RecordingMeta, XY};
use cap_rendering::decoder::AsyncVideoDecoder;
use cap_rendering::{ProjectUniforms, RecordingDecoders, RenderOptions, RenderVideoConstants};
use std::ops::Deref;
@@ -60,8 +60,11 @@ impl EditorInstance {
let recordings = ProjectRecordings::new(&meta);
let render_options = RenderOptions {
- screen_size: (recordings.display.width, recordings.display.height),
- camera_size: recordings.camera.as_ref().map(|c| (c.width, c.height)),
+ screen_size: XY::new(recordings.display.width, recordings.display.height),
+ camera_size: recordings
+ .camera
+ .as_ref()
+ .map(|c| XY::new(c.width, c.height)),
};
let screen_decoder =
diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rs
index 0a5027a6d..b60981a42 100644
--- a/crates/editor/src/playback.rs
+++ b/crates/editor/src/playback.rs
@@ -119,7 +119,6 @@ impl Playback {
}
}
- println!("playback done");
stop_tx.send(true).ok();
event_tx.send(PlaybackEvent::Stop).ok();
diff --git a/crates/editor/src/project_recordings.rs b/crates/editor/src/project_recordings.rs
index 319d7cb18..e826b9753 100644
--- a/crates/editor/src/project_recordings.rs
+++ b/crates/editor/src/project_recordings.rs
@@ -28,7 +28,7 @@ impl Video {
Video {
width: video_decoder.width(),
height: video_decoder.height(),
- duration: (input.duration() / 1_000_000) as f64,
+ duration: input.duration() as f64 / 1_000_000.0,
fps: frame_rate.numerator() as f32 / frame_rate.denominator() as f32,
}
}
@@ -53,7 +53,7 @@ impl Audio {
.unwrap();
Audio {
- duration: (input.duration() / 1_000_000) as f64,
+ duration: input.duration() as f64 / 1_000_000.0,
sample_rate: video_decoder.rate(),
channels: video_decoder.channels(),
}
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index 74a3f6578..f8f2a13cd 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -1,4 +1,7 @@
-use std::ops::{Add, Div, Mul, Sub};
+use std::{
+ ops::{Add, Div, Mul, Sub},
+ path::Path,
+};
use serde::{Deserialize, Serialize};
use specta::Type;
@@ -328,6 +331,18 @@ pub struct ProjectConfiguration {
}
impl ProjectConfiguration {
+ pub fn load(project_path: impl AsRef<Path>) -> Result<Self, std::io::Error> {
+ std::fs::read_to_string(project_path.as_ref().join("project-config.json"))
+ .map(|s| serde_json::from_str(&s).unwrap_or_default())
+ }
+
+ pub fn write(&self, project_path: impl AsRef<Path>) -> Result<(), std::io::Error> {
+ std::fs::write(
+ project_path.as_ref().join("project-config.json"),
+ serde_json::to_string_pretty(self)?,
+ )
+ }
+
pub fn timeline(&self) -> Option<&TimelineConfiguration> {
self.timeline.as_ref()
}
diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs
index b41642efe..b7a0a37a1 100644
--- a/crates/project/src/lib.rs
+++ b/crates/project/src/lib.rs
@@ -85,10 +85,7 @@ impl RecordingMeta {
}
pub fn project_config(&self) -> ProjectConfiguration {
- std::fs::read_to_string(self.project_path.join("project-config.json"))
- .ok()
- .and_then(|s| serde_json::from_str(&s).ok())
- .unwrap_or_default()
+ ProjectConfiguration::load(&self.project_path).unwrap_or_default()
}
pub fn cursor_data(&self) -> CursorData {
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 2c0e25c3d..df896095c 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -29,13 +29,13 @@ pub use decoder::DecodedFrame;
const STANDARD_CURSOR_HEIGHT: f32 = 50.0; // Standard height for all cursors
-#[derive(Debug, Clone, Serialize, Deserialize, Type)]
+#[derive(Debug, Clone, Type)]
pub struct RenderOptions {
- pub camera_size: Option<(u32, u32)>,
- pub screen_size: (u32, u32),
+ pub camera_size: Option<XY<u32>>,
+ pub screen_size: XY<u32>,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Type)]
+#[derive(Debug, Clone, Type)]
pub struct WebcamStyle {
pub border_radius: f32,
pub shadow_color: [f32; 4],
@@ -100,7 +100,6 @@ impl RecordingDecoders {
self.screen.get_frame(frame_number),
OptionFuture::from(self.camera.as_ref().map(|d| d.get_frame(frame_number)))
);
- println!("-t Got Frame? {frame_number}: {}", &screen_frame.is_some());
screen_frame.map(|f| (f, camera_frame.flatten()))
}
@@ -384,8 +383,8 @@ impl ProjectUniforms {
project.background.crop.unwrap_or(Crop {
position: XY { x: 0, y: 0 },
size: XY {
- x: options.screen_size.0,
- y: options.screen_size.1,
+ x: options.screen_size.x,
+ y: options.screen_size.y,
},
})
}
@@ -453,14 +452,14 @@ impl ProjectUniforms {
let crop = Self::get_crop(options, project);
let zoom_origin = zoom_origin_uv.to_raw_display_space(XY {
- x: options.screen_size.0 as f64,
- y: options.screen_size.1 as f64,
+ x: options.screen_size.x as f64,
+ y: options.screen_size.y as f64,
});
let zoom_origin = zoom_origin.to_cropped_display_space(crop);
let (display, zoom) = {
let output_size = XY::new(output_size.0 as f64, output_size.1 as f64);
- let size = [options.screen_size.0 as f32, options.screen_size.1 as f32];
+ let size = [options.screen_size.x as f32, options.screen_size.y as f32];
let crop_start = Coord::<RawDisplaySpace>::new(XY::new(
crop.position.x as f64,
@@ -538,7 +537,7 @@ impl ProjectUniforms {
.map(|camera_size| {
let output_size = [output_size.0 as f32, output_size.1 as f32];
- let frame_size = [camera_size.0 as f32, camera_size.1 as f32];
+ let frame_size = [camera_size.x as f32, camera_size.y as f32];
let min_axis = output_size[0].min(output_size[1]);
let size = [
@@ -670,8 +669,6 @@ impl ZoomKeyframes {
let t = delta_time / keyframe_length;
let t = t.powf(0.5);
-
-
prev.amount + (next.amount - prev.amount) * t
}
}
@@ -750,8 +747,8 @@ pub async fn produce_frame(
let texture = constants.device.create_texture(
&(wgpu::TextureDescriptor {
size: wgpu::Extent3d {
- width: constants.options.screen_size.0,
- height: constants.options.screen_size.1,
+ width: constants.options.screen_size.x,
+ height: constants.options.screen_size.y,
depth_or_array_layers: 1,
},
mip_level_count: 1,
@@ -778,12 +775,12 @@ pub async fn produce_frame(
screen_frame,
wgpu::ImageDataLayout {
offset: 0,
- bytes_per_row: Some(constants.options.screen_size.0 * 4),
+ bytes_per_row: Some(constants.options.screen_size.x * 4),
rows_per_image: None,
},
wgpu::Extent3d {
- width: frame_size.0,
- height: frame_size.1,
+ width: frame_size.x,
+ height: frame_size.y,
depth_or_array_layers: 1,
},
);
@@ -824,8 +821,8 @@ pub async fn produce_frame(
let texture = constants.device.create_texture(
&(wgpu::TextureDescriptor {
size: wgpu::Extent3d {
- width: camera_size.0,
- height: camera_size.1,
+ width: camera_size.x,
+ height: camera_size.y,
depth_or_array_layers: 1,
},
mip_level_count: 1,
@@ -852,12 +849,12 @@ pub async fn produce_frame(
camera_frame,
wgpu::ImageDataLayout {
offset: 0,
- bytes_per_row: Some(camera_size.0 * 4),
+ bytes_per_row: Some(camera_size.x * 4),
rows_per_image: None,
},
wgpu::Extent3d {
- width: camera_size.0,
- height: camera_size.1,
+ width: camera_size.x,
+ height: camera_size.y,
depth_or_array_layers: 1,
},
);
@@ -980,7 +977,6 @@ fn draw_cursor(
// );
let cursor_event = find_cursor_event(&constants.cursor, time);
- println!("Found cursor event with ID: {}", cursor_event.cursor_id);
let Some(cursor_texture) = constants.cursor_textures.get(&cursor_event.cursor_id) else {
return;
@@ -994,7 +990,6 @@ fn draw_cursor(
} else {
uniforms.cursor_size
};
- let scale_factor = cursor_size_percentage / 100.0;
// Calculate normalized size maintaining aspect ratio
let normalized_size = [
@@ -1002,17 +997,9 @@ fn draw_cursor(
STANDARD_CURSOR_HEIGHT,
];
- println!(
- "Original cursor size: {}x{}, Normalized size: {}x{}",
- cursor_size.width, cursor_size.height, normalized_size[0], normalized_size[1]
- );
-
let position = uniforms.zoom.apply_scale(
cursor_position
- .to_raw_display_space(XY::new(
- constants.options.screen_size.0 as f64,
- constants.options.screen_size.1 as f64,
- ))
+ .to_raw_display_space(constants.options.screen_size.map(|v| v as f64))
.to_cropped_display_space(ProjectUniforms::get_crop(
&constants.options,
&uniforms.project,
@@ -1023,8 +1010,6 @@ fn draw_cursor(
)),
);
- // println!("Screen position: ({}, {})", position.0, position.1);
-
let cursor_uniforms = CursorUniforms {
position: [position.x as f32, position.y as f32, 0.0, 0.0],
size: [normalized_size[0], normalized_size[1], 0.0, 0.0],
@@ -1040,8 +1025,6 @@ fn draw_cursor(
_alignment: [0.0; 4],
};
- println!("Cursor uniforms: {:?}", cursor_uniforms);
-
let cursor_uniform_buffer =
constants
.device
@@ -1096,8 +1079,6 @@ fn draw_cursor(
render_pass.set_pipeline(&constants.cursor_pipeline.render_pipeline);
render_pass.set_bind_group(0, &cursor_bind_group, &[]);
render_pass.draw(0..4, 0..1);
-
- println!("Drew cursor");
}
struct CompositeVideoFramePipeline {
@@ -1516,8 +1497,6 @@ struct CursorUniforms {
fn find_cursor_event(cursor: &CursorData, time: f32) -> &CursorEvent {
let time_ms = time * 1000.0;
- println!("Finding cursor event for time: {}ms", time_ms);
- println!("Total cursor moves: {}", cursor.moves.len());
let event = cursor
.moves
@@ -1529,7 +1508,6 @@ fn find_cursor_event(cursor: &CursorData, time: f32) -> &CursorEvent {
})
.unwrap_or(&cursor.moves[0]);
- println!("Found cursor event: {:?}", event);
event
}