From 72187a45a4d335c05780c1dfbe1867f30aeb1e9c Mon Sep 17 00:00:00 2001 From: accusys Date: Thu, 19 Mar 2026 02:24:14 +0800 Subject: [PATCH] feat(player): add click-on-video for play/pause and double-click for fullscreen --- src/main.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/main.rs b/src/main.rs index 30e79cc..69a2305 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,6 +75,9 @@ fn run(config: &Config) -> Result<()> { let mut search_query = String::new(); let mut search_results: Vec = Vec::new(); let mut show_help = false; + let mut last_click_time: u64 = 0; + let mut last_click_x: i32 = 0; + let mut last_click_y: i32 = 0; if let Some(ref video_path) = config.video { info!("Loading video: {:?}", video_path); @@ -442,6 +445,8 @@ fn run(config: &Config) -> Result<()> { sdl2::event::Event::MouseButtonDown { x, y, .. } => { let progress_y = config.height as i32 - progress_height + 5; let bar_height = 20i32; + + let header_bottom = 60i32; if y >= progress_y && y <= progress_y + bar_height && player_state.total_frames > 0 @@ -468,6 +473,50 @@ fn run(config: &Config) -> Result<()> { } } } + } else if y > header_bottom && y < progress_y - 5 { + let now = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_millis() as u64) + .unwrap_or(0); + let dx = (x - last_click_x).abs(); + let dy = (y - last_click_y).abs(); + let is_double_click = dx < 10 && dy < 10 && (now - last_click_time) < 300; + + if is_double_click { + is_fullscreen = !is_fullscreen; + info!( + "Double-click: fullscreen {}", + if is_fullscreen { "ON" } else { "OFF" } + ); + } else { + player_state.playback = + if player_state.playback == PlaybackState::Playing { + PlaybackState::Paused + } else { + PlaybackState::Playing + }; + if let Some(ref mut audio) = audio_player { + if player_state.playback == PlaybackState::Playing { + if !player_state.muted { + audio.resume(); + } + } else { + audio.pause(); + } + } + info!( + "Video click: {}", + if player_state.playback == PlaybackState::Playing { + "PLAY" + } else { + "PAUSE" + } + ); + } + + last_click_time = now; + last_click_x = x; + last_click_y = y; } } sdl2::event::Event::MouseButtonUp { .. } => { @@ -887,6 +936,13 @@ fn run(config: &Config) -> Result<()> { "1-6 Jump to result", "Esc Close panel", "", + "=== Mouse ===", + "Click video Play / Pause", + "Double-click video Fullscreen", + "Click bar Seek", + "Drag bar Scrub", + "Scroll Zoom", + "", "=== Other ===", "H Toggle this help", "Esc Exit",