|
|
@ -13,7 +13,7 @@ use std::{
|
|
|
|
|
|
|
|
|
|
|
|
use glutin::{
|
|
|
|
use glutin::{
|
|
|
|
self,
|
|
|
|
self,
|
|
|
|
dpi::{LogicalSize, PhysicalSize},
|
|
|
|
dpi::PhysicalSize,
|
|
|
|
event::{Event, WindowEvent},
|
|
|
|
event::{Event, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::{self, Fullscreen, Icon},
|
|
|
|
window::{self, Fullscreen, Icon},
|
|
|
@ -25,8 +25,9 @@ use glutin::platform::unix::WindowBuilderExtUnix;
|
|
|
|
|
|
|
|
|
|
|
|
use super::{handle_new_grid_size, settings::WindowSettings};
|
|
|
|
use super::{handle_new_grid_size, settings::WindowSettings};
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
bridge::UiCommand, channel_utils::*, cmd_line::CmdLineSettings, editor::WindowCommand,
|
|
|
|
bridge::UiCommand, channel_utils::*, cmd_line::CmdLineSettings, editor::DrawCommand,
|
|
|
|
redraw_scheduler::REDRAW_SCHEDULER, renderer::Renderer, settings::SETTINGS,
|
|
|
|
editor::WindowCommand, redraw_scheduler::REDRAW_SCHEDULER, renderer::Renderer,
|
|
|
|
|
|
|
|
settings::SETTINGS,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use image::{load_from_memory, GenericImageView, Pixel};
|
|
|
|
use image::{load_from_memory, GenericImageView, Pixel};
|
|
|
|
use keyboard_manager::KeyboardManager;
|
|
|
|
use keyboard_manager::KeyboardManager;
|
|
|
@ -149,36 +150,25 @@ impl GlutinWindowWrapper {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn draw_frame(&mut self, dt: f32) {
|
|
|
|
pub fn draw_frame(&mut self, dt: f32) {
|
|
|
|
let window = self.windowed_context.window();
|
|
|
|
let window = self.windowed_context.window();
|
|
|
|
let scaling = window.scale_factor();
|
|
|
|
|
|
|
|
let current_size = window.inner_size();
|
|
|
|
let current_size = window.inner_size();
|
|
|
|
let previous_size = self.saved_inner_size;
|
|
|
|
let previous_size = self.saved_inner_size;
|
|
|
|
|
|
|
|
|
|
|
|
if previous_size != current_size {
|
|
|
|
if previous_size != current_size {
|
|
|
|
self.saved_inner_size = current_size;
|
|
|
|
self.saved_inner_size = current_size;
|
|
|
|
handle_new_grid_size(
|
|
|
|
handle_new_grid_size(current_size, &self.renderer, &self.ui_command_sender);
|
|
|
|
current_size.to_logical(scaling),
|
|
|
|
|
|
|
|
&self.renderer,
|
|
|
|
|
|
|
|
&self.ui_command_sender,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
self.skia_renderer.resize(&self.windowed_context);
|
|
|
|
self.skia_renderer.resize(&self.windowed_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let ui_command_sender = self.ui_command_sender.clone();
|
|
|
|
let ui_command_sender = self.ui_command_sender.clone();
|
|
|
|
|
|
|
|
|
|
|
|
if REDRAW_SCHEDULER.should_draw() || SETTINGS.get::<WindowSettings>().no_idle {
|
|
|
|
if REDRAW_SCHEDULER.should_draw() || SETTINGS.get::<WindowSettings>().no_idle {
|
|
|
|
log::debug!("Render triggered using scale factor: {}", scaling);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let renderer = &mut self.renderer;
|
|
|
|
let renderer = &mut self.renderer;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let canvas = self.skia_renderer.canvas();
|
|
|
|
let canvas = self.skia_renderer.canvas();
|
|
|
|
|
|
|
|
|
|
|
|
if renderer.draw_frame(canvas, dt, scaling as f32) {
|
|
|
|
if renderer.draw_frame(canvas, dt) {
|
|
|
|
handle_new_grid_size(
|
|
|
|
handle_new_grid_size(current_size, renderer, &ui_command_sender);
|
|
|
|
current_size.to_logical(scaling),
|
|
|
|
|
|
|
|
renderer,
|
|
|
|
|
|
|
|
&ui_command_sender,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -189,11 +179,11 @@ impl GlutinWindowWrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn start_loop(
|
|
|
|
pub fn start_loop(
|
|
|
|
|
|
|
|
batched_draw_command_receiver: Receiver<Vec<DrawCommand>>,
|
|
|
|
window_command_receiver: Receiver<WindowCommand>,
|
|
|
|
window_command_receiver: Receiver<WindowCommand>,
|
|
|
|
ui_command_sender: LoggingTx<UiCommand>,
|
|
|
|
ui_command_sender: LoggingTx<UiCommand>,
|
|
|
|
running: Arc<AtomicBool>,
|
|
|
|
running: Arc<AtomicBool>,
|
|
|
|
logical_size: (u64, u64),
|
|
|
|
initial_size: (u64, u64),
|
|
|
|
renderer: Renderer,
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let icon = {
|
|
|
|
let icon = {
|
|
|
|
let icon_data = Asset::get("neovide.ico").expect("Failed to read icon data");
|
|
|
|
let icon_data = Asset::get("neovide.ico").expect("Failed to read icon data");
|
|
|
@ -208,11 +198,9 @@ pub fn start_loop(
|
|
|
|
log::info!("icon created");
|
|
|
|
log::info!("icon created");
|
|
|
|
|
|
|
|
|
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
let (width, height) = logical_size;
|
|
|
|
|
|
|
|
let logical_size: LogicalSize<u32> = (width as u32, height as u32).into();
|
|
|
|
|
|
|
|
let winit_window_builder = window::WindowBuilder::new()
|
|
|
|
let winit_window_builder = window::WindowBuilder::new()
|
|
|
|
.with_title("Neovide")
|
|
|
|
.with_title("Neovide")
|
|
|
|
.with_inner_size(logical_size)
|
|
|
|
|
|
|
|
.with_window_icon(Some(icon))
|
|
|
|
.with_window_icon(Some(icon))
|
|
|
|
.with_maximized(SETTINGS.get::<CmdLineSettings>().maximized)
|
|
|
|
.with_maximized(SETTINGS.get::<CmdLineSettings>().maximized)
|
|
|
|
.with_decorations(!SETTINGS.get::<CmdLineSettings>().frameless);
|
|
|
|
.with_decorations(!SETTINGS.get::<CmdLineSettings>().frameless);
|
|
|
@ -229,11 +217,25 @@ pub fn start_loop(
|
|
|
|
.build_windowed(winit_window_builder, &event_loop)
|
|
|
|
.build_windowed(winit_window_builder, &event_loop)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
let windowed_context = unsafe { windowed_context.make_current().unwrap() };
|
|
|
|
let windowed_context = unsafe { windowed_context.make_current().unwrap() };
|
|
|
|
let initial_size = windowed_context.window().inner_size();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log::info!("window created");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let skia_renderer = SkiaRenderer::new(&windowed_context);
|
|
|
|
let skia_renderer = SkiaRenderer::new(&windowed_context);
|
|
|
|
|
|
|
|
let scale_factor = windowed_context.window().scale_factor();
|
|
|
|
|
|
|
|
let renderer = Renderer::new(batched_draw_command_receiver, scale_factor);
|
|
|
|
|
|
|
|
let window = windowed_context.window();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let initial_inner_size =
|
|
|
|
|
|
|
|
get_initial_window_size(initial_size, (renderer.font_width, renderer.font_height));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.set_inner_size(initial_inner_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log::info!(
|
|
|
|
|
|
|
|
"window created (scale_factor: {}, font_size: {}x{})",
|
|
|
|
|
|
|
|
scale_factor,
|
|
|
|
|
|
|
|
renderer.font_width,
|
|
|
|
|
|
|
|
renderer.font_height,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let saved_inner_size = window.inner_size();
|
|
|
|
|
|
|
|
|
|
|
|
let mut window_wrapper = GlutinWindowWrapper {
|
|
|
|
let mut window_wrapper = GlutinWindowWrapper {
|
|
|
|
windowed_context,
|
|
|
|
windowed_context,
|
|
|
@ -243,7 +245,7 @@ pub fn start_loop(
|
|
|
|
mouse_manager: MouseManager::new(ui_command_sender.clone()),
|
|
|
|
mouse_manager: MouseManager::new(ui_command_sender.clone()),
|
|
|
|
title: String::from("Neovide"),
|
|
|
|
title: String::from("Neovide"),
|
|
|
|
fullscreen: false,
|
|
|
|
fullscreen: false,
|
|
|
|
saved_inner_size: initial_size,
|
|
|
|
saved_inner_size,
|
|
|
|
ui_command_sender,
|
|
|
|
ui_command_sender,
|
|
|
|
window_command_receiver,
|
|
|
|
window_command_receiver,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -274,3 +276,12 @@ pub fn start_loop(
|
|
|
|
*control_flow = ControlFlow::WaitUntil(previous_frame_start + frame_duration)
|
|
|
|
*control_flow = ControlFlow::WaitUntil(previous_frame_start + frame_duration)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_initial_window_size(
|
|
|
|
|
|
|
|
dimensions: (u64, u64),
|
|
|
|
|
|
|
|
font_dimesions: (u64, u64),
|
|
|
|
|
|
|
|
) -> PhysicalSize<u32> {
|
|
|
|
|
|
|
|
let (width, height) = dimensions;
|
|
|
|
|
|
|
|
let (font_width, font_height) = font_dimesions;
|
|
|
|
|
|
|
|
PhysicalSize::new((width * font_width) as u32, (height * font_height) as u32)
|
|
|
|
|
|
|
|
}
|
|
|
|