feat(player): add click-on-video for play/pause and double-click for fullscreen

This commit is contained in:
accusys
2026-03-19 02:24:14 +08:00
parent f6fc120bbd
commit 72187a45a4

View File

@@ -75,6 +75,9 @@ fn run(config: &Config) -> Result<()> {
let mut search_query = String::new(); let mut search_query = String::new();
let mut search_results: Vec<SearchResult> = Vec::new(); let mut search_results: Vec<SearchResult> = Vec::new();
let mut show_help = false; 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 { if let Some(ref video_path) = config.video {
info!("Loading video: {:?}", video_path); info!("Loading video: {:?}", video_path);
@@ -442,6 +445,8 @@ fn run(config: &Config) -> Result<()> {
sdl2::event::Event::MouseButtonDown { x, y, .. } => { sdl2::event::Event::MouseButtonDown { x, y, .. } => {
let progress_y = config.height as i32 - progress_height + 5; let progress_y = config.height as i32 - progress_height + 5;
let bar_height = 20i32; let bar_height = 20i32;
let header_bottom = 60i32;
if y >= progress_y if y >= progress_y
&& y <= progress_y + bar_height && y <= progress_y + bar_height
&& player_state.total_frames > 0 && 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 { .. } => { sdl2::event::Event::MouseButtonUp { .. } => {
@@ -887,6 +936,13 @@ fn run(config: &Config) -> Result<()> {
"1-6 Jump to result", "1-6 Jump to result",
"Esc Close panel", "Esc Close panel",
"", "",
"=== Mouse ===",
"Click video Play / Pause",
"Double-click video Fullscreen",
"Click bar Seek",
"Drag bar Scrub",
"Scroll Zoom",
"",
"=== Other ===", "=== Other ===",
"H Toggle this help", "H Toggle this help",
"Esc Exit", "Esc Exit",