Skip to content

Commit

Permalink
Clean up Apple cfg's
Browse files Browse the repository at this point in the history
Use target_vendor = "apple" where to cover all Apple OS, and exclude ios for event pumping.
  • Loading branch information
tronical committed Dec 13, 2024
1 parent da7ba2f commit bfdf0e2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/backends/winit/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
cfg_aliases! {
enable_skia_renderer: { any(feature = "renderer-skia", feature = "renderer-skia-opengl", feature = "renderer-skia-vulkan")},
enable_accesskit: { all(feature = "accessibility", not(target_arch = "wasm32")) },
supports_opengl: { any(enable_skia_renderer, feature = "renderer-femtovg")}
supports_opengl: { all(any(enable_skia_renderer, feature = "renderer-femtovg"), not(target_os = "ios")) }
}
// This uses `web_sys_unstable_api`, which is typically set via `RUST_FLAGS`
println!("cargo:rustc-check-cfg=cfg(web_sys_unstable_apis)");
Expand Down
14 changes: 7 additions & 7 deletions internal/backends/winit/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl NotRunningEventLoop {
let mut builder =
builder.unwrap_or_else(|| winit::event_loop::EventLoop::with_user_event());

#[cfg(all(unix, not(target_os = "macos")))]
#[cfg(all(unix, not(target_vendor = "apple")))]
{
#[cfg(feature = "wayland")]
{
Expand Down Expand Up @@ -126,7 +126,7 @@ impl EventLoopInterface for NotRunningEventLoop {
fn event_loop(&self) -> ActiveOrInactiveEventLoop<'_> {
ActiveOrInactiveEventLoop::Inactive(&self.instance)
}
#[cfg(all(unix, not(target_os = "macos"), feature = "wayland"))]
#[cfg(all(unix, not(target_vendor = "apple"), feature = "wayland"))]
fn is_wayland(&self) -> bool {
use winit::platform::wayland::EventLoopExtWayland;
return self.instance.is_wayland();
Expand All @@ -143,7 +143,7 @@ impl<'a> EventLoopInterface for RunningEventLoop<'a> {
fn event_loop(&self) -> ActiveOrInactiveEventLoop<'_> {
ActiveOrInactiveEventLoop::Active(self.active_event_loop)
}
#[cfg(all(unix, not(target_os = "macos"), feature = "wayland"))]
#[cfg(all(unix, not(target_vendor = "apple"), feature = "wayland"))]
fn is_wayland(&self) -> bool {
use winit::platform::wayland::ActiveEventLoopExtWayland;
return self.active_event_loop.is_wayland();
Expand Down Expand Up @@ -352,7 +352,7 @@ impl winit::application::ApplicationHandler<SlintUserEvent> for EventLoopState {
WindowEvent::KeyboardInput { event, is_synthetic, .. } => {
let key_code = event.logical_key;
// For now: Match Qt's behavior of mapping command to control and control to meta (LWin/RWin).
#[cfg(target_os = "macos")]
#[cfg(target_vendor = "apple")]
let key_code = match key_code {
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Control) => {
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Super)
Expand Down Expand Up @@ -690,7 +690,7 @@ impl EventLoopState {

let mut winit_loop = not_running_loop_instance.instance;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios")))]
{
use winit::platform::run_on_demand::EventLoopExtRunOnDemand as _;
winit_loop
Expand All @@ -714,7 +714,7 @@ impl EventLoopState {
Ok(self)
}

#[cfg(target_arch = "wasm32")]
#[cfg(any(target_arch = "wasm32", target_os = "ios"))]
{
winit_loop
.run_app(&mut ActiveEventLoopSetterDuringEventProcessing(&mut self))
Expand All @@ -726,7 +726,7 @@ impl EventLoopState {

/// Runs the event loop and renders the items in the provided `component` in its
/// own window.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios")))]
pub fn pump_events(
mut self,
timeout: Option<std::time::Duration>,
Expand Down
4 changes: 2 additions & 2 deletions internal/backends/winit/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl BackendBuilder {
}
#[cfg(enable_skia_renderer)]
(Some("skia"), None) => renderer::skia::WinitSkiaRenderer::new_suspended,
#[cfg(enable_skia_renderer)]
#[cfg(all(enable_skia_renderer, supports_opengl))]
(Some("skia-opengl"), _) | (Some("skia"), Some(_)) => {
renderer::skia::WinitSkiaRenderer::new_opengl_suspended
}
Expand Down Expand Up @@ -452,7 +452,7 @@ impl i_slint_core::platform::Platform for Backend {
Ok(())
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios")))]
fn process_events(
&self,
timeout: core::time::Duration,
Expand Down
1 change: 1 addition & 0 deletions internal/backends/winit/renderer/skia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl WinitSkiaRenderer {
})
}

#[cfg(not(target_os = "ios"))]
pub fn new_opengl_suspended() -> Box<dyn super::WinitCompatibleRenderer> {
Box::new(Self {
renderer: i_slint_renderer_skia::SkiaRenderer::default_opengl(),
Expand Down
2 changes: 1 addition & 1 deletion internal/backends/winit/winitwindowadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl WinitWindowAdapter {
WinitWindowOrNone::None(attributes) => attributes.borrow().clone(),
};

#[cfg(all(unix, not(target_os = "macos")))]
#[cfg(all(unix, not(target_vendor = "apple")))]
{
if let Some(xdg_app_id) = WindowInner::from_pub(self.window()).xdg_app_id() {
#[cfg(feature = "wayland")]
Expand Down
5 changes: 3 additions & 2 deletions internal/renderers/skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ skia-safe = { version = "0.78.0", features = ["textlayout", "gl"] }
glow = { version = "0.13" }
unicode-segmentation = { version = "1.8.0" }

glutin = { workspace = true, default-features = false, features = ["egl", "wgl"] }

ash = { version = "^0.37.2", optional = true }
vulkano = { version = "0.34.0", optional = true, default-features = false }

[target.'cfg(not(target_os = "ios"))'.dependencies]
glutin = { workspace = true, default-features = false, features = ["egl", "wgl"] }

[target.'cfg(not(target_os = "android"))'.dependencies]
# software renderer fallback
softbuffer = { workspace = true, default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions internal/renderers/skia/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use cfg_aliases::cfg_aliases;
fn main() {
// Setup cfg aliases
cfg_aliases! {
skia_backend_opengl: { any(feature = "opengl", not(any(target_os = "macos", target_family = "windows", target_arch = "wasm32"))) },
skia_backend_metal: { all(target_os = "macos", not(feature = "opengl")) },
skia_backend_opengl: { any(feature = "opengl", not(any(target_vendor = "apple", target_family = "windows", target_arch = "wasm32"))) },
skia_backend_metal: { all(target_vendor = "apple", not(feature = "opengl")) },
skia_backend_d3d: { all(target_family = "windows", not(feature = "opengl")) },
skia_backend_vulkan: { feature = "vulkan" },
skia_backend_software: { not(target_os = "android") },
Expand Down
4 changes: 3 additions & 1 deletion internal/renderers/skia/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod textlayout;
#[cfg(skia_backend_software)]
pub mod software_surface;

#[cfg(target_os = "macos")]
#[cfg(target_vendor = "apple")]
pub mod metal_surface;

#[cfg(target_family = "windows")]
Expand All @@ -45,6 +45,7 @@ pub mod d3d_surface;
#[cfg(skia_backend_vulkan)]
pub mod vulkan_surface;

#[cfg(not(target_os = "ios"))]
pub mod opengl_surface;

use i_slint_core::items::TextWrap;
Expand Down Expand Up @@ -163,6 +164,7 @@ impl SkiaRenderer {
}
}

#[cfg(not(target_os = "ios"))]
/// Creates a new SkiaRenderer that will always use Skia's OpenGL renderer.
pub fn default_opengl() -> Self {
let (partial_rendering_state, visualize_dirty_region) = create_partial_renderer_state();
Expand Down

0 comments on commit bfdf0e2

Please sign in to comment.