From e2272b539493b35660f3168911d9ac8890637d35 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 16 Jun 2023 17:53:17 +0200 Subject: [PATCH] try to preserve window position when playing multiple files --- videoplayer/src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index a3c7f43..bc453c3 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -246,6 +246,8 @@ struct Player { sdl_context: sdl2::Sdl, vsystem: sdl2::VideoSubsystem, asystem: sdl2::AudioSubsystem, + xpos: Option, + ypos: Option, acontrol: AudioControl, vcontrol: VideoControl, @@ -284,6 +286,8 @@ impl Player { let vcontrol = VideoControl::new(None, 0, 0, 0, 0); Self { sdl_context, asystem, vsystem, + xpos: None, + ypos: None, acontrol, vcontrol, @@ -643,8 +647,12 @@ impl Player { } else { "NihAV player".to_owned() }; - let window = self.vsystem.window(&wname, width as u32, height as u32) - .position_centered().build().unwrap(); + let mut builder = self.vsystem.window(&wname, width as u32, height as u32); + let window = if let (Some(xpos), Some(ypos)) = (self.xpos, self.ypos) { + builder.position(xpos, ypos).build().unwrap() + } else { + builder.position_centered().build().unwrap() + }; let mut canvas = window.into_canvas().build().unwrap(); let texture_creator = canvas.texture_creator(); let mut disp_q = DispQueue::new(&texture_creator, width, height, if self.has_video { FRAME_QUEUE_LEN } else { 0 }); @@ -757,6 +765,9 @@ impl Player { thread::sleep(Duration::from_millis(20)); } } + let (xpos, ypos) = canvas.into_window().position(); + self.xpos = Some(xpos); + self.ypos = Some(ypos); println!(); std::mem::swap(&mut self.vcontrol, &mut new_vcontrol); new_vcontrol.finish(); -- 2.30.2