aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--ports/servoshell/Cargo.toml12
-rw-r--r--ports/servoshell/desktop/headed_window.rs25
3 files changed, 38 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 48098f4964f..c3ca6e3f2e3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6930,6 +6930,8 @@ dependencies = [
"net",
"net_traits",
"nix",
+ "objc2-app-kit",
+ "objc2-foundation",
"ohos-ime",
"ohos-ime-sys",
"ohos-vsync",
diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml
index 4b3cf46a4dc..7566721145f 100644
--- a/ports/servoshell/Cargo.toml
+++ b/ports/servoshell/Cargo.toml
@@ -131,3 +131,15 @@ sig = "1.0"
[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { workspace = true, features = ["Win32_Graphics_Gdi"] }
libservo = { path = "../../components/servo", features = ["no-wgl"] }
+
+[target.'cfg(target_os = "macos")'.dependencies]
+objc2-app-kit = { version = "0.2.2", default-features = false, features = [
+ "std",
+ "NSColorSpace",
+ "NSResponder",
+ "NSView",
+ "NSWindow",
+] }
+objc2-foundation = { version = "0.2.2", default-features = false, features = [
+ "std",
+] }
diff --git a/ports/servoshell/desktop/headed_window.rs b/ports/servoshell/desktop/headed_window.rs
index 001e82b831c..ae741586be0 100644
--- a/ports/servoshell/desktop/headed_window.rs
+++ b/ports/servoshell/desktop/headed_window.rs
@@ -13,7 +13,7 @@ use std::time::Duration;
use euclid::{Angle, Length, Point2D, Rotation3D, Scale, Size2D, UnknownUnit, Vector2D, Vector3D};
use keyboard_types::{Modifiers, ShortcutMatcher};
use log::{debug, info};
-use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
+use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle};
use servo::compositing::windowing::{
AnimationState, EmbedderCoordinates, WebRenderDebugOption, WindowMethods,
};
@@ -37,6 +37,11 @@ use winit::event_loop::ActiveEventLoop;
use winit::keyboard::{Key as LogicalKey, ModifiersState, NamedKey};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use winit::window::Icon;
+#[cfg(target_os = "macos")]
+use {
+ objc2_app_kit::{NSColorSpace, NSView},
+ objc2_foundation::MainThreadMarker,
+};
use super::app_state::RunningAppState;
use super::geometry::{winit_position_to_euclid_point, winit_size_to_euclid_size};
@@ -101,6 +106,8 @@ impl Window {
winit_window.set_window_icon(Some(load_icon(icon_bytes)));
}
+ Window::force_srgb_color_space(winit_window.window_handle().unwrap().as_raw());
+
let monitor = winit_window
.current_monitor()
.or_else(|| winit_window.available_monitors().nth(0))
@@ -420,6 +427,22 @@ impl Window {
pub(crate) fn offscreen_rendering_context(&self) -> Rc<OffscreenRenderingContext> {
self.rendering_context.clone()
}
+
+ #[allow(unused_variables)]
+ fn force_srgb_color_space(window_handle: RawWindowHandle) {
+ #[cfg(target_os = "macos")]
+ {
+ if let RawWindowHandle::AppKit(handle) = window_handle {
+ assert!(MainThreadMarker::new().is_some());
+ unsafe {
+ let view = handle.ns_view.cast::<NSView>().as_ref();
+ view.window()
+ .unwrap()
+ .setColorSpace(Some(&NSColorSpace::sRGBColorSpace()));
+ }
+ }
+ }
+ }
}
impl WindowPortsMethods for Window {