diff options
author | Naru <naru@naruaway.com> | 2023-01-07 23:23:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-07 14:23:00 +0000 |
commit | bcd6d0d981fd192f21a2f5142f421f4aa1de1648 (patch) | |
tree | 999bbb4c0123a9865ea824a2ecc3a1f1b732f5b6 | |
parent | 2bd26fbeb0c51cd8a98ae31d58ea105d1274387a (diff) | |
download | alacritty-bcd6d0d981fd192f21a2f5142f421f4aa1de1648.tar.gz alacritty-bcd6d0d981fd192f21a2f5142f421f4aa1de1648.zip |
Use sRGB color space for NSWindow on macOS
Co-authored-by: Christian Duerr <contact@christianduerr.com>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/display/window.rs | 27 |
2 files changed, 23 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 31696c54..dddfcb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - `font.glyph_offset.y` is now applied to underline/strikeout +- Always use sRGB color space on macOS ### Fixed diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 97329d70..6f9e908a 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -26,16 +26,18 @@ use std::sync::atomic::AtomicBool; use std::sync::Arc; #[cfg(target_os = "macos")] -use cocoa::base::{id, NO, YES}; -#[cfg(target_os = "macos")] -use objc::{msg_send, sel, sel_impl}; +use { + cocoa::appkit::NSColorSpace, + cocoa::base::{id, nil, NO, YES}, + objc::{msg_send, sel, sel_impl}, + winit::platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}, +}; + use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use winit::dpi::{PhysicalPosition, PhysicalSize}; use winit::event_loop::EventLoopWindowTarget; use winit::monitor::MonitorHandle; -#[cfg(target_os = "macos")] -use winit::platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}; #[cfg(windows)] use winit::platform::windows::IconExtWindows; use winit::window::{ @@ -164,6 +166,9 @@ impl Window { // Enable IME. window.set_ime_allowed(true); + #[cfg(target_os = "macos")] + use_srgb_color_space(&window); + #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] if !is_wayland { // On X11, embed the window inside another if the parent ID has been set. @@ -460,6 +465,18 @@ fn x_embed_window(window: &WinitWindow, parent_id: std::os::raw::c_ulong) { } } +#[cfg(target_os = "macos")] +fn use_srgb_color_space(window: &WinitWindow) { + let raw_window = match window.raw_window_handle() { + RawWindowHandle::AppKit(handle) => handle.ns_window as id, + _ => return, + }; + + unsafe { + let _: () = msg_send![raw_window, setColorSpace: NSColorSpace::sRGBColorSpace(nil)]; + } +} + #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] unsafe extern "C" fn xembed_error_handler(_: *mut XDisplay, _: *mut XErrorEvent) -> i32 { log::error!("Could not embed into specified window."); |