progress toward switching to upstream skulpin

macos-click-through
keith 5 years ago
parent 3da11e09d8
commit 7b9963652e

2129
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -7,8 +7,7 @@ build = "build.rs"
description = "A simple GUI for Neovim." description = "A simple GUI for Neovim."
[features] [features]
default = ["sdl2-static-link", "embed-fonts"] default = ["embed-fonts"]
sdl2-static-link = ["skulpin/sdl2-static-link"]
embed-fonts = [] embed-fonts = []
[dependencies] [dependencies]
@ -16,8 +15,8 @@ euclid = "0.20.7"
font-kit = "0.6.0" font-kit = "0.6.0"
skribo = { git = "https://github.com/linebender/skribo" } skribo = { git = "https://github.com/linebender/skribo" }
lru = "0.4.3" lru = "0.4.3"
skulpin = { git = "https://github.com/Kethku/skulpin", branch = "sdl2" } skulpin = { version = "0.9.0", features=["skulpin_sdl2"] }
# skulpin = { path = "../skulpin" } sdl2 = { version = ">=0.33", features = ["bundled", "static-link"] }
derive-new = "0.5" derive-new = "0.5"
rmpv = "0.4.4" rmpv = "0.4.4"
rust-embed = { version = "5.2.0", features = ["debug-embed"] } rust-embed = { version = "5.2.0", features = ["debug-embed"] }

@ -7,9 +7,9 @@ use skulpin::sdl2;
use skulpin::sdl2::event::{Event, WindowEvent}; use skulpin::sdl2::event::{Event, WindowEvent};
use skulpin::sdl2::keyboard::Keycode; use skulpin::sdl2::keyboard::Keycode;
use skulpin::sdl2::video::Window; use skulpin::sdl2::video::Window;
use skulpin::sdl2::video::FullscreenType;
use skulpin::sdl2::Sdl; use skulpin::sdl2::Sdl;
use skulpin::{dpis, CoordinateSystem, PresentMode, Renderer as SkulpinRenderer, RendererBuilder}; use skulpin::{Window, CoordinateSystem, PresentMode, Renderer as SkulpinRenderer, RendererBuilder, LogicalSize, PhysicalSize, Sdl2Window};
use skulpin::{LogicalSize, PhysicalSize};
use crate::bridge::{produce_neovim_keybinding_string, UiCommand, BRIDGE}; use crate::bridge::{produce_neovim_keybinding_string, UiCommand, BRIDGE};
use crate::editor::EDITOR; use crate::editor::EDITOR;
@ -45,14 +45,13 @@ fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer) {
struct WindowWrapper { struct WindowWrapper {
context: Sdl, context: Sdl,
window: Window, window: sdl2::video::Window,
skulpin_renderer: SkulpinRenderer, skulpin_renderer: SkulpinRenderer,
renderer: Renderer, renderer: Renderer,
mouse_down: bool, mouse_down: bool,
mouse_position: LogicalSize, mouse_position: LogicalSize,
title: String, title: String,
previous_size: LogicalSize, previous_size: LogicalSize,
previous_dpis: (f32, f32),
transparency: f32, transparency: f32,
fullscreen: bool, fullscreen: bool,
cached_size: (i32, i32), cached_size: (i32, i32),
@ -133,7 +132,7 @@ impl WindowWrapper {
// }; // };
// info!("icon created"); // info!("icon created");
let window = video_subsystem let sdl_window = video_subsystem
.window("Neovide", logical_size.width, logical_size.height) .window("Neovide", logical_size.width, logical_size.height)
.position_centered() .position_centered()
.allow_highdpi() .allow_highdpi()
@ -143,21 +142,22 @@ impl WindowWrapper {
.expect("Failed to create window"); .expect("Failed to create window");
info!("window created"); info!("window created");
let skulpin_renderer = RendererBuilder::new() let skulpin_renderer = {
let sdl_window_wrapper = Sdl2Window::new(&sdl_window);
RendererBuilder::new()
.prefer_integrated_gpu() .prefer_integrated_gpu()
.use_vulkan_debug_layer(true) .use_vulkan_debug_layer(true)
.present_mode_priority(vec![PresentMode::Immediate]) .present_mode_priority(vec![PresentMode::Immediate])
.coordinate_system(CoordinateSystem::Logical) .coordinate_system(CoordinateSystem::Logical)
.build(&window) .build(&sdl_window_wrapper)
.expect("Failed to create renderer"); .expect("Failed to create renderer")
info!("renderer created"); };
let previous_size = LogicalSize::new(&window).unwrap(); info!("renderer created");
let previous_dpis = dpis(&window).unwrap();
WindowWrapper { WindowWrapper {
context, context,
window, window: sdl_window,
skulpin_renderer, skulpin_renderer,
renderer, renderer,
mouse_down: false, mouse_down: false,
@ -166,8 +166,7 @@ impl WindowWrapper {
height: 0, height: 0,
}, },
title: String::from("Neovide"), title: String::from("Neovide"),
previous_size, previous_size: logical_size,
previous_dpis,
transparency: 1.0, transparency: 1.0,
fullscreen: false, fullscreen: false,
cached_size: (0, 0), cached_size: (0, 0),
@ -268,14 +267,12 @@ impl WindowWrapper {
pub fn handle_pointer_motion(&mut self, x: i32, y: i32) { pub fn handle_pointer_motion(&mut self, x: i32, y: i32) {
let previous_position = self.mouse_position; let previous_position = self.mouse_position;
if let Ok(new_mouse_position) = LogicalSize::from_physical_size_tuple( let physical_size = PhysicalSize::new(
(
(x as f32 / self.renderer.font_width) as u32, (x as f32 / self.renderer.font_width) as u32,
(y as f32 / self.renderer.font_height) as u32, (y as f32 / self.renderer.font_height) as u32
), );
&self.window,
) { self.mouse_position = physical_size.to_logical(1.0);
self.mouse_position = new_mouse_position;
if self.mouse_down && previous_position != self.mouse_position { if self.mouse_down && previous_position != self.mouse_position {
BRIDGE.queue_command(UiCommand::Drag( BRIDGE.queue_command(UiCommand::Drag(
self.mouse_position.width, self.mouse_position.width,
@ -283,7 +280,6 @@ impl WindowWrapper {
)); ));
} }
} }
}
pub fn handle_pointer_down(&mut self) { pub fn handle_pointer_down(&mut self) {
BRIDGE.queue_command(UiCommand::MouseButton { BRIDGE.queue_command(UiCommand::MouseButton {
@ -347,25 +343,12 @@ impl WindowWrapper {
return false; return false;
} }
if let Ok(new_size) = LogicalSize::new(&self.window) { let sdl_window_wrapper = Sdl2Window::new(&self.window);
let new_size = sdl_window_wrapper.logical_size();
if self.previous_size != new_size { if self.previous_size != new_size {
handle_new_grid_size(new_size, &self.renderer); handle_new_grid_size(new_size, &self.renderer);
self.previous_size = new_size; self.previous_size = new_size;
} }
}
if let Ok(new_dpis) = dpis(&self.window) {
if self.previous_dpis != new_dpis {
let physical_size = PhysicalSize::new(&self.window);
self.window
.set_size(
(physical_size.width as f32 * new_dpis.0 / self.previous_dpis.0) as u32,
(physical_size.height as f32 * new_dpis.1 / self.previous_dpis.1) as u32,
)
.unwrap();
self.previous_dpis = new_dpis;
}
}
debug!("Render Triggered"); debug!("Render Triggered");
let current_size = self.previous_size; let current_size = self.previous_size;
@ -373,10 +356,10 @@ impl WindowWrapper {
let renderer = &mut self.renderer; let renderer = &mut self.renderer;
if self if self
.skulpin_renderer .skulpin_renderer
.draw(&self.window, |canvas, coordinate_system_helper| { .draw(&sdl_window_wrapper, |canvas, coordinate_system_helper| {
let dt = 1.0 / (SETTINGS.get::<WindowSettings>().refresh_rate as f32); let dt = 1.0 / (SETTINGS.get::<WindowSettings>().refresh_rate as f32);
if renderer.draw(canvas, coordinate_system_helper, dt) { if renderer.draw(canvas, &coordinate_system_helper, dt) {
handle_new_grid_size(current_size, &renderer) handle_new_grid_size(current_size, &renderer)
} }
}) })

Loading…
Cancel
Save