Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Custom cursor size + editor improvements

Richie McIlroy3532ed6f8c31
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 28abe29af..783de7799 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -2263,6 +2263,18 @@ async fn is_camera_window_open(app: AppHandle) -> bool {
CapWindow::Camera { ws_port: 0 }.get(&app).is_some()
}
+#[tauri::command]
+#[specta::specta]
+async fn seek_to(app: AppHandle, video_id: String, frame_number: u32) {
+ let editor_instance = upsert_editor_instance(&app, video_id).await;
+
+ editor_instance
+ .modify_and_emit_state(|state| {
+ state.playhead_position = frame_number;
+ })
+ .await;
+}
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub async fn run() {
let specta_builder = tauri_specta::Builder::new()
@@ -2320,7 +2332,8 @@ pub async fn run() {
delete_auth_open_signin,
reset_camera_permissions,
reset_microphone_permissions,
- is_camera_window_open
+ is_camera_window_open,
+ seek_to
])
.events(tauri_specta::collect_events![
RecordingOptionsChanged,
diff --git a/apps/desktop/src/routes/(window-chrome)/settings.tsx b/apps/desktop/src/routes/(window-chrome)/settings.tsx
index 995c634c6..d031a1e02 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings.tsx
@@ -1,6 +1,6 @@
import { A, type RouteSectionProps, useLocation } from "@solidjs/router";
import { cx } from "cva";
-import { createResource, For, createSignal } from "solid-js";
+import { createResource, For } from "solid-js";
import { Button } from "@cap/ui-solid";
import { commands } from "~/utils/tauri";
import { getVersion } from "@tauri-apps/api/app";
@@ -15,17 +15,6 @@ export default function (props: RouteSectionProps) {
const [version] = createResource(async () => getVersion());
const versionString = () => version() ?? "0";
- const [enableTooltipNotifications, setEnableTooltipNotifications] =
- createSignal(false);
-
- const handleToggleNotifications = () => {
- setEnableTooltipNotifications(!enableTooltipNotifications());
- commands.setGeneralSettings({
- ...options.data,
- enableTooltipNotifications: !enableTooltipNotifications(),
- });
- };
-
return (
<div class="h-[calc(100vh-3rem)] flex flex-row divide-x divide-gray-200 text-[0.875rem] leading-[1.25rem]">
<div class="h-full flex flex-col">
@@ -74,16 +63,6 @@ export default function (props: RouteSectionProps) {
<Button onClick={handleSignOut} variant="secondary" class="w-full">
Sign Out
</Button>
- <div>
- <label>
- <input
- type="checkbox"
- checked={enableTooltipNotifications()}
- onChange={handleToggleNotifications}
- />
- Enable Tooltip Notifications
- </label>
- </div>
</div>
</div>
<div class="flex-1 bg-gray-50">{props.children}</div>
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
index 71ff67c62..36840dd1d 100644
--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
@@ -16,9 +16,9 @@ import {
ComingSoonTooltip,
EditorButton,
Field,
- Slider,
Subfield,
Toggle,
+ Slider,
} from "./ui";
import { DEFAULT_GRADIENT_FROM, DEFAULT_GRADIENT_TO } from "./projectConfig";
@@ -504,17 +504,14 @@ export function ConfigSidebar() {
</Subfield>
</ComingSoonTooltip>
</Field>
- <ComingSoonTooltip>
- <Field name="Size" icon={<IconCapEnlarge />}>
- <Slider
- disabled
- value={[project.cursor.size]}
- onChange={(v) => setProject("cursor", "size", v[0])}
- minValue={0}
- maxValue={100}
- />
- </Field>
- </ComingSoonTooltip>
+ <Field name="Size" icon={<IconCapEnlarge />}>
+ <Slider
+ value={[project.cursor.size]}
+ onChange={(v) => setProject("cursor", "size", v[0])}
+ minValue={100}
+ maxValue={300}
+ />
+ </Field>
<ComingSoonTooltip>
<Field name="Type" icon={<IconCapCursor />}>
<ul class="flex flex-row gap-2 text-gray-400">
diff --git a/apps/desktop/src/routes/editor/Player.tsx b/apps/desktop/src/routes/editor/Player.tsx
index 3f9b49e53..a37f1e577 100644
--- a/apps/desktop/src/routes/editor/Player.tsx
+++ b/apps/desktop/src/routes/editor/Player.tsx
@@ -20,6 +20,7 @@ import {
topLeftAnimateClasses,
} from "./ui";
import { formatTime } from "./utils";
+import { createEventListener } from "@solid-primitives/event-listener";
export function Player() {
const {
@@ -30,6 +31,7 @@ export function Player() {
latestFrame,
setDialog,
playbackTime,
+ setPlaybackTime,
playing,
setPlaying,
split,
@@ -62,6 +64,52 @@ export function Player() {
</EditorButton>
);
+ const totalDuration = () =>
+ project.timeline?.segments.reduce(
+ (acc, s) => acc + (s.end - s.start) / s.timescale,
+ 0
+ ) ?? editorInstance.recordingDuration;
+
+ const isAtEnd = () => {
+ const total = totalDuration();
+ return total > 0 && total - playbackTime() <= 0.1;
+ };
+
+ createEffect(() => {
+ if (isAtEnd() && playing()) {
+ commands.stopPlayback(videoId);
+ setPlaying(false);
+ }
+ });
+
+ const handlePlayPauseClick = async () => {
+ try {
+ if (isAtEnd()) {
+ await commands.stopPlayback(videoId);
+ setPlaybackTime(0);
+ await commands.seekTo(videoId, 0);
+ await commands.startPlayback(videoId);
+ setPlaying(true);
+ } else if (playing()) {
+ await commands.stopPlayback(videoId);
+ setPlaying(false);
+ } else {
+ await commands.startPlayback(videoId);
+ setPlaying(true);
+ }
+ } catch (error) {
+ console.error("Error handling play/pause:", error);
+ setPlaying(false);
+ }
+ };
+
+ createEventListener(document, "keydown", async (e: KeyboardEvent) => {
+ if (e.code === "Space" && e.target === document.body) {
+ e.preventDefault();
+ await handlePlayPauseClick();
+ }
+ });
+
return (
<div class="flex flex-col divide-y flex-1">
<div class="flex flex-row justify-between font-medium p-[0.75rem] text-[0.875rem] z-10 bg-gray-50">
@@ -176,36 +224,21 @@ export function Player() {
<button type="button" disabled>
<IconCapFrameFirst class="size-[1.2rem]" />
</button>
- {!playing() ? (
- <button
- type="button"
- onClick={() =>
- commands.startPlayback(videoId).then(() => setPlaying(true))
- }
- >
+ <button
+ type="button"
+ onClick={handlePlayPauseClick}
+ class="hover:text-black transition-colors"
+ >
+ {!playing() || isAtEnd() ? (
<IconCapPlayCircle class="size-[1.5rem]" />
- </button>
- ) : (
- <button
- type="button"
- onClick={() =>
- commands.stopPlayback(videoId).then(() => setPlaying(false))
- }
- >
+ ) : (
<IconCapStopCircle class="size-[1.5rem]" />
- </button>
- )}
+ )}
+ </button>
<button type="button" disabled>
<IconCapFrameLast class="size-[1rem]" />
</button>
- <span>
- {formatTime(
- project.timeline?.segments.reduce(
- (acc, s) => acc + (s.end - s.start) / s.timescale,
- 0
- ) ?? editorInstance.recordingDuration
- )}
- </span>
+ <span>{formatTime(totalDuration())}</span>
</div>
<div class="flex-1 flex flex-row justify-end">
{window.FLAGS.split ? (
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 08d3454b9..aff15b4a3 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -316,6 +316,9 @@ async resetMicrophonePermissions() : Promise<Result<null, null>> {
},
async isCameraWindowOpen() : Promise<boolean> {
return await TAURI_INVOKE("is_camera_window_open");
+},
+async seekTo(videoId: string, frameNumber: number) : Promise<void> {
+ await TAURI_INVOKE("seek_to", { videoId, frameNumber });
}
}
diff --git a/crates/flags/src/lib.rs b/crates/flags/src/lib.rs
index 86d40bc16..9a1e97e7b 100644
--- a/crates/flags/src/lib.rs
+++ b/crates/flags/src/lib.rs
@@ -11,5 +11,5 @@ pub const FLAGS: Flags = Flags {
record_mouse: cfg!(debug_assertions),
split: false,
pause_resume: false,
- zoom: false,
+ zoom: true,
};
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index ab8418aa9..65b4bb135 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -150,14 +150,24 @@ pub enum CursorType {
Circle,
}
-#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)]
+#[derive(Type, Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CursorConfiguration {
hide_when_idle: bool,
- size: u32,
+ pub size: u32,
r#type: CursorType,
}
+impl Default for CursorConfiguration {
+ fn default() -> Self {
+ Self {
+ hide_when_idle: false,
+ size: 100,
+ r#type: CursorType::default(),
+ }
+ }
+}
+
#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct HotkeysConfiguration {
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index a309ddb76..94c2a6d5b 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -355,6 +355,7 @@ impl RenderVideoConstants {
#[derive(Clone, Debug)]
pub struct ProjectUniforms {
pub output_size: (u32, u32),
+ pub cursor_size: f32,
display: CompositeVideoFrameUniforms,
camera: Option<CompositeVideoFrameUniforms>,
}
@@ -581,6 +582,7 @@ impl ProjectUniforms {
Self {
output_size,
+ cursor_size: project.cursor.size as f32,
display,
camera,
}
@@ -726,7 +728,7 @@ pub async fn produce_frame(
&constants.device,
&GradientOrColorUniforms::from(background).to_buffer(&constants.device),
),
- wgpu::LoadOp::Clear(wgpu::Color::BLACK), // Clear on first pass
+ wgpu::LoadOp::Clear(wgpu::Color::BLACK),
);
output_is_left = !output_is_left;
@@ -871,10 +873,17 @@ pub async fn produce_frame(
let cursor_size = cursor_texture.size();
let aspect_ratio = cursor_size.width as f32 / cursor_size.height as f32;
- // Calculate normalized size maintaining aspect ratio
+ // Use a default cursor size if the uniform value is 0
+ let cursor_size_percentage = if uniforms.cursor_size <= 0.0 {
+ 100.0
+ } else {
+ uniforms.cursor_size
+ };
+ let scale_factor = cursor_size_percentage / 100.0;
+
let normalized_size = [
- STANDARD_CURSOR_HEIGHT * aspect_ratio,
- STANDARD_CURSOR_HEIGHT,
+ STANDARD_CURSOR_HEIGHT * aspect_ratio * scale_factor,
+ STANDARD_CURSOR_HEIGHT * scale_factor,
];
println!(
@@ -889,23 +898,29 @@ pub async fn produce_frame(
println!("Screen position: ({}, {})", screen_x, screen_y);
let cursor_uniforms = CursorUniforms {
- position: [screen_x as f32, screen_y as f32],
- padding1: [0.0; 2],
- size: normalized_size, // Use normalized size instead of original size
- padding2: [0.0; 2],
- output_size: [uniforms.output_size.0 as f32, uniforms.output_size.1 as f32],
- padding3: [0.0; 2],
+ position: [screen_x as f32, screen_y as f32, 0.0, 0.0],
+ size: [normalized_size[0], normalized_size[1], 0.0, 0.0],
+ output_size: [
+ uniforms.output_size.0 as f32,
+ uniforms.output_size.1 as f32,
+ 0.0,
+ 0.0,
+ ],
screen_bounds: uniforms.display.target_bounds,
+ cursor_size: cursor_size_percentage,
+ padding: [0.0; 3],
+ _alignment: [0.0; 4],
};
println!("Cursor uniforms: {:?}", cursor_uniforms);
+ // Create the uniform buffer with the correct size
let cursor_uniform_buffer =
constants
.device
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Cursor Uniform Buffer"),
- contents: bytemuck::cast_slice(&[cursor_uniforms]),
+ contents: bytemuck::cast_slice(&[cursor_uniforms]), // This ensures proper size
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
});
@@ -956,8 +971,6 @@ pub async fn produce_frame(
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");
}
}
}
@@ -1447,16 +1460,16 @@ struct CursorPipeline {
// Add this before the CursorPipeline struct definition
-#[repr(C)]
+#[repr(C, align(16))] // Add align(16) to ensure proper alignment
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
struct CursorUniforms {
- position: [f32; 2], // 8 bytes
- padding1: [f32; 2], // 8 bytes padding to align next field
- size: [f32; 2], // 8 bytes
- padding2: [f32; 2], // 8 bytes padding to align next field
- output_size: [f32; 2], // 8 bytes
- padding3: [f32; 2], // 8 bytes padding to align next field
- screen_bounds: [f32; 4], // 16 bytes
+ position: [f32; 4],
+ size: [f32; 4],
+ output_size: [f32; 4],
+ screen_bounds: [f32; 4],
+ cursor_size: f32,
+ padding: [f32; 3],
+ _alignment: [f32; 4], // Add extra padding to ensure 16-byte alignment
}
// Add this function near the other cursor-related functions
@@ -1492,7 +1505,7 @@ impl CursorPipeline {
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
- min_binding_size: Some(std::num::NonZeroU64::new(64).unwrap()),
+ min_binding_size: Some(std::num::NonZeroU64::new(96).unwrap()),
},
count: None,
},
diff --git a/crates/rendering/src/shaders/cursor.wgsl b/crates/rendering/src/shaders/cursor.wgsl
index 3c283c025..1ee63d1c7 100644
--- a/crates/rendering/src/shaders/cursor.wgsl
+++ b/crates/rendering/src/shaders/cursor.wgsl
@@ -1,11 +1,10 @@
struct Uniforms {
- position: vec2<f32>,
- padding1: vec2<f32>,
- size: vec2<f32>,
- padding2: vec2<f32>,
- output_size: vec2<f32>,
- padding3: vec2<f32>,
+ position: vec4<f32>,
+ size: vec4<f32>,
+ output_size: vec4<f32>,
screen_bounds: vec4<f32>,
+ cursor_size: f32,
+ padding: vec3<f32>,
};
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
@@ -21,14 +20,11 @@ struct VertexOutput {
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
- // Create a quad from two triangles using triangle strip
let x = f32(vertex_index & 1u);
let y = f32((vertex_index >> 1u) & 1u);
- // Calculate position in screen space
- let pos = uniforms.position + vec2<f32>(x * uniforms.size.x, y * uniforms.size.y);
+ let pos = uniforms.position.xy + vec2<f32>(x * uniforms.size.x, y * uniforms.size.y);
- // Convert to clip space (-1 to 1)
let clip_pos = vec2<f32>(
(pos.x / uniforms.output_size.x) * 2.0 - 1.0,
-((pos.y / uniforms.output_size.y) * 2.0 - 1.0)