Skip to content

Commit

Permalink
Merge pull request #379 from kas-gui/work2
Browse files Browse the repository at this point in the history
Update winit, wgpu, dark-light, window_clipboard
  • Loading branch information
dhardy committed Feb 10, 2023
2 parents 2d44664 + 9a5fcb1 commit d5d19af
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 21 deletions.
10 changes: 7 additions & 3 deletions crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ serde_json = { version = "1.0.61", optional = true }
serde_yaml = { version = "0.9.9", optional = true }
ron = { version = "0.8.0", package = "ron", optional = true }
num_enum = "0.5.6"
dark-light = { version = "0.2.2", optional = true }
dark-light = { version = "1.0", optional = true }
raw-window-handle = "0.5.0"
window_clipboard = { version = "0.2.0", optional = true }
async-global-executor = { version = "2.3.1", optional = true }
cfg-if = "1.0.0"

Expand All @@ -100,6 +99,11 @@ version = "0.5.0" # used in doc links

[dependencies.winit]
# Provides translations for several winit types
version = "0.27"
version = "0.28.1"
optional = true
default-features = false

[dependencies.window_clipboard]
git = "https://github.com/TobTobXX/window_clipboard.git"
rev = "1392da8339c8aebb9849d00eb7383a73ed076f1d"
optional = true
4 changes: 3 additions & 1 deletion crates/kas-core/src/shell/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ pub trait WindowSurface {
shared: &mut Self::Shared,
size: Size,
window: W,
) -> Self;
) -> Result<Self>
where
Self: Sized;

/// Get current surface size
fn size(&self) -> Size;
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-core/src/shell/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<'a> PlatformWrapper<'a> {
{
cfg_if::cfg_if! {
if #[cfg(all(feature = "wayland", feature = "x11"))] {
use winit::platform::unix::EventLoopWindowTargetExtUnix;
use winit::platform::wayland::EventLoopWindowTargetExtWayland;
return if self.0.is_wayland() {
Platform::Wayland
} else {
Expand Down
5 changes: 2 additions & 3 deletions crates/kas-core/src/shell/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use kas::theme::{Theme, Window as _};
use kas::{Action, Layout, WidgetCore, WidgetExt, Window as _, WindowId};
use std::mem::take;
use std::time::Instant;
use winit::error::OsError;
use winit::event::WindowEvent;
use winit::event_loop::EventLoopWindowTarget;
use winit::window::WindowBuilder;
Expand All @@ -43,7 +42,7 @@ impl<S: WindowSurface, T: Theme<S::Shared>> Window<S, T> {
elwt: &EventLoopWindowTarget<ProxyAction>,
window_id: WindowId,
widget: Box<dyn kas::Window>,
) -> Result<Self, OsError> {
) -> super::Result<Self> {
let time = Instant::now();

let mut widget = kas::RootWidget::new(widget);
Expand Down Expand Up @@ -114,7 +113,7 @@ impl<S: WindowSurface, T: Theme<S::Shared>> Window<S, T> {
solve_cache.invalidate_rule_cache();
}

let surface = S::new(&mut shared.draw.draw, size, &window);
let surface = S::new(&mut shared.draw.draw, size, &window)?;

let mut r = Window {
widget,
Expand Down
5 changes: 3 additions & 2 deletions crates/kas-core/src/theme/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ impl From<ColorsLinear> for ColorsSrgb {
impl Default for ColorsLinear {
#[cfg(feature = "dark-light")]
fn default() -> Self {
use dark_light::Mode;
match dark_light::detect() {
dark_light::Mode::Dark => ColorsSrgb::dark().into(),
dark_light::Mode::Light => ColorsSrgb::light().into(),
Mode::Dark => ColorsSrgb::dark().into(),
Mode::Light | Mode::Default => ColorsSrgb::light().into(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ proc-macro-error = "1.0"
bitflags = "1.3.1"

[dependencies.impl-tools-lib]
version = "0.7.0" # version used in doc links
version = "0.8.0" # version used in doc links

[dependencies.syn]
version = "1.0.14"
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-resvg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ svg = ["dep:resvg", "dep:usvg"]

[dependencies]
tiny-skia = { version = "0.8.2" }
resvg = { version = "0.28.0", optional = true }
usvg = { version = "0.28.0", optional = true }
resvg = { version = "0.29.0", optional = true }
usvg = { version = "0.29.0", optional = true }
once_cell = "1.17.0"
thiserror = "1.0.23"

Expand Down
1 change: 0 additions & 1 deletion crates/kas-resvg/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn load(data: &[u8], resources_dir: Option<&Path>) -> Result<Tree, usvg::Error>
shape_rendering: usvg::ShapeRendering::default(),
text_rendering: usvg::TextRendering::default(),
image_rendering: usvg::ImageRendering::default(),
keep_named_groups: false,
default_size: usvg::Size::new(100.0, 100.0).unwrap(),
image_href_resolver: Default::default(),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ raster = ["kas-text/raster"]
bytemuck = "1.7.0"
futures-lite = "1.12"
log = "0.4"
wgpu = { version = "0.14.0", features = ["spirv"] }
wgpu = { version = "0.15.0", features = ["spirv"] }
thiserror = "1.0.23"
guillotiere = "0.6.0"
rustc-hash = "1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/kas-wgpu/src/draw/atlases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl Atlas {
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});

let view = tex.create_view(&wgpu::TextureViewDescriptor::default());
Expand Down
5 changes: 4 additions & 1 deletion crates/kas-wgpu/src/draw/draw_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl<C: CustomPipe> DrawPipe<C> {
options: &Options,
raster_config: &kas::theme::RasterConfig,
) -> Result<Self, Error> {
let instance = wgpu::Instance::new(options.backend());
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: options.backend(),
..Default::default()
});
let adapter_options = options.adapter_options();
let req = instance.request_adapter(&adapter_options);
let adapter = match block_on(req) {
Expand Down
12 changes: 7 additions & 5 deletions crates/kas-wgpu/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use kas::cast::Cast;
use kas::draw::color::Rgba;
use kas::draw::{DrawIface, WindowCommon};
use kas::geom::Size;
use kas::shell::{raw_window_handle as raw, WindowSurface};
use kas::shell::{raw_window_handle as raw, Error, WindowSurface};
use std::time::Instant;

/// Per-window data
Expand All @@ -27,11 +27,12 @@ impl<C: CustomPipe> WindowSurface for Surface<C> {
shared: &mut Self::Shared,
size: Size,
window: W,
) -> Self {
) -> Result<Self, Error> {
let mut draw = shared.new_window();
shared.resize(&mut draw, size);

let surface = unsafe { shared.instance.create_surface(&window) };
let surface = unsafe { shared.instance.create_surface(&window) }
.map_err(|e| Error::Graphics(Box::new(e)))?;
let sc_desc = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: crate::draw::RENDER_TEX_FORMAT,
Expand All @@ -43,14 +44,15 @@ impl<C: CustomPipe> WindowSurface for Surface<C> {
// a sub-set of modes are supported (depending on target).
// Currently it's unclear how to handle this properly.
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
};
surface.configure(&shared.device, &sc_desc);

Surface {
Ok(Surface {
surface,
sc_desc,
draw,
}
})
}

fn size(&self) -> Size {
Expand Down

0 comments on commit d5d19af

Please sign in to comment.