add fullscreen support

macos-click-through
keith 5 years ago
parent 310a383dd0
commit 7c8e21c504

@ -5,7 +5,7 @@ use log::{info, trace, debug, error};
use skulpin::{LogicalSize, PhysicalSize}; use skulpin::{LogicalSize, PhysicalSize};
use skulpin::sdl2; use skulpin::sdl2;
use skulpin::sdl2::Sdl; use skulpin::sdl2::Sdl;
use skulpin::sdl2::video::Window; use skulpin::sdl2::video::{Window, FullscreenType};
use skulpin::sdl2::event::Event; use skulpin::sdl2::event::Event;
use skulpin::sdl2::keyboard::{Mod, Keycode}; use skulpin::sdl2::keyboard::{Mod, Keycode};
use skulpin::{RendererBuilder, Renderer as SkulpinRenderer, PresentMode, CoordinateSystem, dpis}; use skulpin::{RendererBuilder, Renderer as SkulpinRenderer, PresentMode, CoordinateSystem, dpis};
@ -50,7 +50,8 @@ struct WindowWrapper {
previous_size: LogicalSize, previous_size: LogicalSize,
previous_dpis: (f32, f32), previous_dpis: (f32, f32),
ignore_text_input: bool, ignore_text_input: bool,
transparency: f32 transparency: f32,
fullscreen: bool
} }
impl WindowWrapper { impl WindowWrapper {
@ -114,19 +115,18 @@ impl WindowWrapper {
previous_size, previous_size,
previous_dpis, previous_dpis,
ignore_text_input: false, ignore_text_input: false,
transparency: 1.0 transparency: 1.0,
fullscreen: false
} }
} }
pub fn synchronize_title(&mut self) { pub fn synchronize_settings(&mut self) {
let editor_title = { EDITOR.lock().title.clone() }; let editor_title = { EDITOR.lock().title.clone() };
if self.title != editor_title { if self.title != editor_title {
self.title = editor_title; self.title = editor_title;
self.window.set_title(&self.title).expect("Could not set title"); self.window.set_title(&self.title).expect("Could not set title");
} }
}
pub fn synchronize_transparency(&mut self) {
let transparency = { SETTINGS.get::<WindowSettings>().transparency }; let transparency = { SETTINGS.get::<WindowSettings>().transparency };
if let Ok(opacity) = self.window.opacity() { if let Ok(opacity) = self.window.opacity() {
if opacity != transparency { if opacity != transparency {
@ -134,6 +134,16 @@ impl WindowWrapper {
self.transparency = transparency; self.transparency = transparency;
} }
} }
let fullscreen = { SETTINGS.get::<WindowSettings>().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_key_down(&mut self, keycode: Keycode, modifiers: Mod) { pub fn handle_key_down(&mut self, keycode: Keycode, modifiers: Mod) {
@ -276,23 +286,25 @@ impl WindowWrapper {
#[derive(Clone)] #[derive(Clone)]
struct WindowSettings { struct WindowSettings {
refresh_rate: u64, refresh_rate: u64,
transparency: f32,
no_idle: bool, no_idle: bool,
transparency: f32 fullscreen: bool
} }
pub fn initialize_settings() { pub fn initialize_settings() {
let no_idle = SETTINGS.neovim_arguments.contains(&String::from("--noIdle")); let no_idle = SETTINGS.neovim_arguments.contains(&String::from("--noIdle"));
SETTINGS.set(&WindowSettings { SETTINGS.set(&WindowSettings {
refresh_rate: 60, refresh_rate: 60,
transparency: 1.0,
no_idle, no_idle,
transparency: 1.0 fullscreen: false
}); });
register_nvim_setting!("refresh_rate", WindowSettings::refresh_rate); register_nvim_setting!("refresh_rate", WindowSettings::refresh_rate);
register_nvim_setting!("no_idle", WindowSettings::no_idle);
register_nvim_setting!("transparency", WindowSettings::transparency); register_nvim_setting!("transparency", WindowSettings::transparency);
register_nvim_setting!("no_idle", WindowSettings::no_idle);
register_nvim_setting!("fullscreen", WindowSettings::fullscreen);
} }
pub fn ui_loop() { pub fn ui_loop() {
@ -303,8 +315,7 @@ pub fn ui_loop() {
'running: loop { 'running: loop {
let frame_start = Instant::now(); let frame_start = Instant::now();
window.synchronize_title(); window.synchronize_settings();
window.synchronize_transparency();
for event in event_pump.poll_iter() { for event in event_pump.poll_iter() {
match event { match event {

Loading…
Cancel
Save