1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2025-07-31 22:03:40 -04:00

Use sRGB color space for NSWindow on macOS

Co-authored-by: Christian Duerr <contact@christianduerr.com>
This commit is contained in:
Naru 2023-01-07 23:23:00 +09:00 committed by GitHub
parent 2bd26fbeb0
commit bcd6d0d981
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View file

@ -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

View file

@ -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.");