Merge pull request #240 from Kethku/switch-to-upstream-skulpin

progress toward switching to upstream skulpin
macos-click-through
Keith Simmons 5 years ago committed by GitHub
commit e943381b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

589
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,7 @@ 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 = { git = "https://github.com/kethku/skulpin", branch = "windows-dpi-fix", features = ["skulpin_sdl2"] }
# skulpin = { path = "../skulpin" }
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"] }
@ -38,6 +36,10 @@ winapi = "0.3.8"
[build-dependencies] [build-dependencies]
winres = "0.1.11" winres = "0.1.11"
sdl2-sys = { git = "https://github.com/Rust-SDL2/rust-sdl2", default-features = false, features = ["bundled", "static-link"] }
[patch.crates-io]
sdl2 = { git = "https://github.com/Rust-SDL2/rust-sdl2", default-features = false }
[profile.release] [profile.release]
debug = true debug = true

@ -6,10 +6,12 @@ use log::{debug, error, info, trace};
use skulpin::sdl2; 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::{FullscreenType, 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::{
use skulpin::{LogicalSize, PhysicalSize}; CoordinateSystem, LogicalSize, PhysicalSize, PresentMode, Renderer as SkulpinRenderer,
RendererBuilder, Sdl2Window, Window,
};
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 +47,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: (u32, u32), cached_size: (u32, u32),
@ -134,7 +135,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()
@ -144,21 +145,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,
@ -167,8 +169,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),
@ -278,16 +279,13 @@ 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;
let physical_size = PhysicalSize::new(
if let Ok(new_mouse_position) = LogicalSize::from_physical_size_tuple(
(
(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 = new_mouse_position;
let sdl_window_wrapper = Sdl2Window::new(&self.window);
self.mouse_position = physical_size.to_logical(sdl_window_wrapper.scale_factor());
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,
@ -295,7 +293,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 {
@ -359,26 +356,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");
@ -389,10 +372,10 @@ impl WindowWrapper {
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