From 3f6a1f758b0d324c76f6812aae9cd44add644255 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 23 Feb 2018 00:10:42 -0800 Subject: [PATCH] restore original window position when exiting fullscreen We do some bookkeeping of our own because the get_position() method appears to return stale data on Linux. --- src/gliumwindows.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index 5317a4804..fdaf69af0 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -66,7 +66,10 @@ pub struct TerminalWindow { last_mouse_coords: (f64, f64), last_modifiers: KeyModifiers, wakeup_receiver: Receiver, - is_fullscreen: bool, + window_position: Option<(i32, i32)>, + /// is is_some, holds position to be restored after exiting + /// fullscreen mode. + is_fullscreen: Option<(i32, i32)>, } impl TerminalWindow { @@ -107,6 +110,7 @@ impl TerminalWindow { }; host.display.gl_window().set_cursor(MouseCursor::Text); + let window_position = host.display.gl_window().get_position(); let renderer = Renderer::new(&host.display, width, height, fonts, palette)?; let cell_height = cell_height.ceil() as usize; @@ -124,7 +128,8 @@ impl TerminalWindow { last_mouse_coords: (0.0, 0.0), last_modifiers: Default::default(), wakeup_receiver, - is_fullscreen: false, + window_position, + is_fullscreen: None, }) } @@ -427,6 +432,12 @@ impl TerminalWindow { } => { self.resize_surfaces(width as u16, height as u16)?; } + Event::WindowEvent { + event: WindowEvent::Moved(x, y), + .. + } => { + self.window_position = Some((x, y)); + } Event::WindowEvent { event: WindowEvent::ReceivedCharacter(c), .. @@ -434,13 +445,17 @@ impl TerminalWindow { // Primitive Alt-Enter fullscreen shortcut if c == '\r' && self.last_modifiers.contains(KeyModifiers::ALT) { let window = self.host.display.gl_window(); - let (monitor, enabled) = if self.is_fullscreen { - (None, false) + let pos = self.is_fullscreen.take(); + if let Some((x, y)) = pos { + window.set_fullscreen(None); + window.set_position(x, y); } else { - (Some(window.get_current_monitor()), true) - }; - window.set_fullscreen(monitor); - self.is_fullscreen = enabled; + // We use our own idea of the position because get_position() + // appears to only return the initial position of the window + // on Linux. + self.is_fullscreen = self.window_position.take(); + window.set_fullscreen(Some(window.get_current_monitor())); + } } else { self.terminal .key_down(KeyCode::Char(c), self.last_modifiers, &mut self.host)?;