From 09b25bd6362bab9090f0c9f91277319a140e9eba Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Tue, 14 Apr 2020 14:36:42 +0200 Subject: [PATCH 1/7] Fixed win32 input for Danish keyboard layout --- src/bridge/layouts/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bridge/layouts/mod.rs b/src/bridge/layouts/mod.rs index 6d91d69..e53e9d0 100644 --- a/src/bridge/layouts/mod.rs +++ b/src/bridge/layouts/mod.rs @@ -64,20 +64,20 @@ fn append_modifiers( if result == "<" { result = "lt".to_string(); special = true; - } + } if shift { special = true; result = format!("S-{}", result); } - if ctrl { + if ctrl && !alt { special = true; result = format!("C-{}", result); } - if alt { + if alt && !ctrl { special = true; result = format!("M-{}", result); - } + } if cfg!(not(target_os = "windows")) && gui { special = true; result = format!("D-{}", result); From db3d8ef1794109a4978bef076a568f88480c52f3 Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Tue, 14 Apr 2020 18:30:44 +0200 Subject: [PATCH 2/7] Made fullscreen toggleable with Alt+Enter --- src/window.rs | 66 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/src/window.rs b/src/window.rs index dff20d0..691d125 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,8 +5,8 @@ use std::time::{Duration, Instant}; use log::{debug, error, info, trace}; use skulpin::sdl2; use skulpin::sdl2::event::{Event, WindowEvent}; -use skulpin::sdl2::keyboard::Keycode; -use skulpin::sdl2::video::{FullscreenType, Window}; +use skulpin::sdl2::keyboard::{Keycode, Mod}; +use skulpin::sdl2::video::{Window}; use skulpin::sdl2::Sdl; use skulpin::{dpis, CoordinateSystem, PresentMode, Renderer as SkulpinRenderer, RendererBuilder}; use skulpin::{LogicalSize, PhysicalSize}; @@ -55,6 +55,9 @@ struct WindowWrapper { previous_dpis: (f32, f32), transparency: f32, fullscreen: bool, + cached_width: i32, + cached_height: i32, + cached_position: (i32, i32) } pub fn window_geometry() -> Result<(u64, u64), String> { @@ -133,7 +136,6 @@ impl WindowWrapper { let window = video_subsystem .window("Neovide", logical_size.width, logical_size.height) - .position_centered() .allow_highdpi() .resizable() .vulkan() @@ -141,6 +143,7 @@ impl WindowWrapper { .expect("Failed to create window"); info!("window created"); + let skulpin_renderer = RendererBuilder::new() .prefer_integrated_gpu() .use_vulkan_debug_layer(true) @@ -168,7 +171,44 @@ impl WindowWrapper { previous_dpis, transparency: 1.0, fullscreen: false, + cached_width: 0, + cached_height: 0, + cached_position: (0, 0) + } + } + + pub fn toggle_fullscreen(&mut self) { + unsafe { + let raw_handle = self.window.raw(); + let display_index = sdl2::sys::SDL_GetWindowDisplayIndex(raw_handle); + + if let Ok(rect) = self.window.subsystem().display_bounds(display_index) { + if self.fullscreen { + // Set window back to resizable + sdl2::sys::SDL_SetWindowResizable(raw_handle, sdl2::sys::SDL_bool::SDL_TRUE); + + // Use cached size and position + self.window.set_size(self.cached_width as u32, self.cached_height as u32).unwrap(); + self.window.set_position( + sdl2::video::WindowPos::Positioned(self.cached_position.0), + sdl2::video::WindowPos::Positioned(self.cached_position.1) + ); + self.window.set_bordered(true); + } + else { + // Cache the size and position + sdl2::sys::SDL_GetWindowSize(raw_handle, &mut self.cached_width, &mut self.cached_height); + sdl2::sys::SDL_GetWindowPosition(raw_handle, &mut self.cached_position.0, &mut self.cached_position.1); + sdl2::sys::SDL_SetWindowResizable(raw_handle, sdl2::sys::SDL_bool::SDL_FALSE); + + // Set window to fullscreen + self.window.set_size(rect.width(), rect.height()).unwrap(); + self.window.set_position(sdl2::video::WindowPos::Positioned(0), sdl2::video::WindowPos::Positioned(0)); + self.window.set_bordered(true); + } + } } + self.fullscreen = !self.fullscreen; } pub fn synchronize_settings(&mut self) { @@ -187,16 +227,6 @@ impl WindowWrapper { self.transparency = transparency; } } - - let fullscreen = { SETTINGS.get::().fullscreen }; - if self.fullscreen != fullscreen { - let state = match fullscreen { - true => FullscreenType::Desktop, - false => FullscreenType::Off, - }; - self.window.set_fullscreen(state).ok(); - self.fullscreen = fullscreen; - } } pub fn handle_quit(&mut self) { @@ -206,6 +236,12 @@ impl WindowWrapper { pub fn handle_keyboard_input(&mut self, keycode: Option, text: Option) { let modifiers = self.context.keyboard().mod_state(); + if let Some(key) = keycode { + if key == Keycode::Return && modifiers.contains(Mod::LALTMOD) { + self.toggle_fullscreen(); + } + } + if keycode.is_some() || text.is_some() { trace!( "Keyboard Input Received: keycode-{:?} modifiers-{:?} text-{:?}", @@ -373,6 +409,10 @@ pub fn initialize_settings() { pub fn ui_loop() { let mut window = WindowWrapper::new(); + + if SETTINGS.get::().fullscreen { + window.toggle_fullscreen(); + } info!("Starting window event loop"); let mut event_pump = window From 628c06077c1cca57dffc2d050f957e0417be8df1 Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Tue, 14 Apr 2020 18:36:57 +0200 Subject: [PATCH 3/7] Fixed display relative top-left coordinates --- src/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.rs b/src/window.rs index 691d125..e76adb2 100644 --- a/src/window.rs +++ b/src/window.rs @@ -203,7 +203,7 @@ impl WindowWrapper { // Set window to fullscreen self.window.set_size(rect.width(), rect.height()).unwrap(); - self.window.set_position(sdl2::video::WindowPos::Positioned(0), sdl2::video::WindowPos::Positioned(0)); + self.window.set_position(sdl2::video::WindowPos::Positioned(rect.x()), sdl2::video::WindowPos::Positioned(rect.y())); self.window.set_bordered(true); } } From 18b8c65835be81a3eab763ac53a3c0e22f99c07d Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Tue, 14 Apr 2020 18:56:45 +0200 Subject: [PATCH 4/7] Return after toggle fullscreen (avoids extraneous enter processed by vim) --- src/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/window.rs b/src/window.rs index e76adb2..5198447 100644 --- a/src/window.rs +++ b/src/window.rs @@ -239,6 +239,7 @@ impl WindowWrapper { if let Some(key) = keycode { if key == Keycode::Return && modifiers.contains(Mod::LALTMOD) { self.toggle_fullscreen(); + return; } } From 5286df954dc2352ccd6bab25f31db3ae8bc4aa7c Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Wed, 15 Apr 2020 00:09:13 +0200 Subject: [PATCH 5/7] Reverted keybind changes for this branch --- src/bridge/layouts/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bridge/layouts/mod.rs b/src/bridge/layouts/mod.rs index e53e9d0..d1907b8 100644 --- a/src/bridge/layouts/mod.rs +++ b/src/bridge/layouts/mod.rs @@ -70,14 +70,14 @@ fn append_modifiers( special = true; result = format!("S-{}", result); } - if ctrl && !alt { + if ctrl { special = true; result = format!("C-{}", result); } - if alt && !ctrl { + if alt { special = true; result = format!("M-{}", result); - } + } if cfg!(not(target_os = "windows")) && gui { special = true; result = format!("D-{}", result); From fefce19262cc0f91b115f06e25661b26f4ec4b72 Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Wed, 15 Apr 2020 00:24:07 +0200 Subject: [PATCH 6/7] Integrated the toggle with the existing vim settings variable --- src/window.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/window.rs b/src/window.rs index 5198447..b7c7149 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,7 +5,7 @@ use std::time::{Duration, Instant}; use log::{debug, error, info, trace}; use skulpin::sdl2; use skulpin::sdl2::event::{Event, WindowEvent}; -use skulpin::sdl2::keyboard::{Keycode, Mod}; +use skulpin::sdl2::keyboard::{Keycode}; use skulpin::sdl2::video::{Window}; use skulpin::sdl2::Sdl; use skulpin::{dpis, CoordinateSystem, PresentMode, Renderer as SkulpinRenderer, RendererBuilder}; @@ -55,8 +55,7 @@ struct WindowWrapper { previous_dpis: (f32, f32), transparency: f32, fullscreen: bool, - cached_width: i32, - cached_height: i32, + cached_size: (i32, i32), cached_position: (i32, i32) } @@ -171,8 +170,7 @@ impl WindowWrapper { previous_dpis, transparency: 1.0, fullscreen: false, - cached_width: 0, - cached_height: 0, + cached_size: (0, 0), cached_position: (0, 0) } } @@ -188,7 +186,7 @@ impl WindowWrapper { sdl2::sys::SDL_SetWindowResizable(raw_handle, sdl2::sys::SDL_bool::SDL_TRUE); // Use cached size and position - self.window.set_size(self.cached_width as u32, self.cached_height as u32).unwrap(); + self.window.set_size(self.cached_size.0 as u32, self.cached_size.1 as u32).unwrap(); self.window.set_position( sdl2::video::WindowPos::Positioned(self.cached_position.0), sdl2::video::WindowPos::Positioned(self.cached_position.1) @@ -197,7 +195,7 @@ impl WindowWrapper { } else { // Cache the size and position - sdl2::sys::SDL_GetWindowSize(raw_handle, &mut self.cached_width, &mut self.cached_height); + sdl2::sys::SDL_GetWindowSize(raw_handle, &mut self.cached_size.0, &mut self.cached_size.1); sdl2::sys::SDL_GetWindowPosition(raw_handle, &mut self.cached_position.0, &mut self.cached_position.1); sdl2::sys::SDL_SetWindowResizable(raw_handle, sdl2::sys::SDL_bool::SDL_FALSE); @@ -227,6 +225,11 @@ impl WindowWrapper { self.transparency = transparency; } } + + let fullscreen = { SETTINGS.get::().fullscreen }; + if self.fullscreen != fullscreen { + self.toggle_fullscreen(); + } } pub fn handle_quit(&mut self) { @@ -236,13 +239,6 @@ impl WindowWrapper { pub fn handle_keyboard_input(&mut self, keycode: Option, text: Option) { let modifiers = self.context.keyboard().mod_state(); - if let Some(key) = keycode { - if key == Keycode::Return && modifiers.contains(Mod::LALTMOD) { - self.toggle_fullscreen(); - return; - } - } - if keycode.is_some() || text.is_some() { trace!( "Keyboard Input Received: keycode-{:?} modifiers-{:?} text-{:?}", @@ -411,10 +407,6 @@ pub fn initialize_settings() { pub fn ui_loop() { let mut window = WindowWrapper::new(); - if SETTINGS.get::().fullscreen { - window.toggle_fullscreen(); - } - info!("Starting window event loop"); let mut event_pump = window .context From 7d7483352911f2e7f4ae9c19855669a5880246e9 Mon Sep 17 00:00:00 2001 From: Rasmus Michelsen Date: Wed, 15 Apr 2020 01:01:26 +0200 Subject: [PATCH 7/7] Reinserted call to position_centered() --- src/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.rs b/src/window.rs index b7c7149..effa6f8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -135,6 +135,7 @@ impl WindowWrapper { let window = video_subsystem .window("Neovide", logical_size.width, logical_size.height) + .position_centered() .allow_highdpi() .resizable() .vulkan() @@ -142,7 +143,6 @@ impl WindowWrapper { .expect("Failed to create window"); info!("window created"); - let skulpin_renderer = RendererBuilder::new() .prefer_integrated_gpu() .use_vulkan_debug_layer(true)