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."
[features]
default = ["sdl2-static-link", "embed-fonts"]
sdl2-static-link = ["skulpin/sdl2-static-link"]
default = ["embed-fonts"]
embed-fonts = []
[dependencies]
@ -16,8 +15,7 @@ euclid = "0.20.7"
font-kit = "0.6.0"
skribo = { git = "https://github.com/linebender/skribo" }
lru = "0.4.3"
skulpin = { git = "https://github.com/Kethku/skulpin", branch = "sdl2" }
# skulpin = { path = "../skulpin" }
skulpin = { git = "https://github.com/kethku/skulpin", branch = "windows-dpi-fix", features = ["skulpin_sdl2"] }
derive-new = "0.5"
rmpv = "0.4.4"
rust-embed = { version = "5.2.0", features = ["debug-embed"] }
@ -38,6 +36,10 @@ winapi = "0.3.8"
[build-dependencies]
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]
debug = true

@ -6,10 +6,12 @@ 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::video::FullscreenType;
use skulpin::sdl2::Sdl;
use skulpin::{dpis, CoordinateSystem, PresentMode, Renderer as SkulpinRenderer, RendererBuilder};
use skulpin::{LogicalSize, PhysicalSize};
use skulpin::{
CoordinateSystem, LogicalSize, PhysicalSize, PresentMode, Renderer as SkulpinRenderer,
RendererBuilder, Sdl2Window, Window,
};
use crate::bridge::{produce_neovim_keybinding_string, UiCommand, BRIDGE};
use crate::editor::EDITOR;
@ -45,14 +47,13 @@ fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer) {
struct WindowWrapper {
context: Sdl,
window: Window,
window: sdl2::video::Window,
skulpin_renderer: SkulpinRenderer,
renderer: Renderer,
mouse_down: bool,
mouse_position: LogicalSize,
title: String,
previous_size: LogicalSize,
previous_dpis: (f32, f32),
transparency: f32,
fullscreen: bool,
cached_size: (u32, u32),
@ -134,7 +135,7 @@ impl WindowWrapper {
// };
// info!("icon created");
let window = video_subsystem
let sdl_window = video_subsystem
.window("Neovide", logical_size.width, logical_size.height)
.position_centered()
.allow_highdpi()
@ -144,21 +145,22 @@ impl WindowWrapper {
.expect("Failed to create window");
info!("window created");
let skulpin_renderer = RendererBuilder::new()
.prefer_integrated_gpu()
.use_vulkan_debug_layer(true)
.present_mode_priority(vec![PresentMode::Immediate])
.coordinate_system(CoordinateSystem::Logical)
.build(&window)
.expect("Failed to create renderer");
info!("renderer created");
let skulpin_renderer = {
let sdl_window_wrapper = Sdl2Window::new(&sdl_window);
RendererBuilder::new()
.prefer_integrated_gpu()
.use_vulkan_debug_layer(true)
.present_mode_priority(vec![PresentMode::Immediate])
.coordinate_system(CoordinateSystem::Logical)
.build(&sdl_window_wrapper)
.expect("Failed to create renderer")
};
let previous_size = LogicalSize::new(&window).unwrap();
let previous_dpis = dpis(&window).unwrap();
info!("renderer created");
WindowWrapper {
context,
window,
window: sdl_window,
skulpin_renderer,
renderer,
mouse_down: false,
@ -167,8 +169,7 @@ impl WindowWrapper {
height: 0,
},
title: String::from("Neovide"),
previous_size,
previous_dpis,
previous_size: logical_size,
transparency: 1.0,
fullscreen: false,
cached_size: (0, 0),
@ -278,22 +279,18 @@ impl WindowWrapper {
pub fn handle_pointer_motion(&mut self, x: i32, y: i32) {
let previous_position = self.mouse_position;
if let Ok(new_mouse_position) = LogicalSize::from_physical_size_tuple(
(
(x as f32 / self.renderer.font_width) as u32,
(y as f32 / self.renderer.font_height) as u32,
),
&self.window,
) {
self.mouse_position = new_mouse_position;
if self.mouse_down && previous_position != self.mouse_position {
BRIDGE.queue_command(UiCommand::Drag(
self.mouse_position.width,
self.mouse_position.height,
));
}
let physical_size = PhysicalSize::new(
(x as f32 / self.renderer.font_width) as u32,
(y as f32 / self.renderer.font_height) as u32,
);
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 {
BRIDGE.queue_command(UiCommand::Drag(
self.mouse_position.width,
self.mouse_position.height,
));
}
}
@ -359,25 +356,11 @@ impl WindowWrapper {
return false;
}
if let Ok(new_size) = LogicalSize::new(&self.window) {
if self.previous_size != new_size {
handle_new_grid_size(new_size, &self.renderer);
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;
}
let sdl_window_wrapper = Sdl2Window::new(&self.window);
let new_size = sdl_window_wrapper.logical_size();
if self.previous_size != new_size {
handle_new_grid_size(new_size, &self.renderer);
self.previous_size = new_size;
}
debug!("Render Triggered");
@ -389,10 +372,10 @@ impl WindowWrapper {
if self
.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);
if renderer.draw(canvas, coordinate_system_helper, dt) {
if renderer.draw(canvas, &coordinate_system_helper, dt) {
handle_new_grid_size(current_size, &renderer)
}
})

Loading…
Cancel
Save