diff options
author | Casper Rogild Storm <2248455+casperstorm@users.noreply.github.com> | 2020-05-17 23:14:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 21:14:13 +0000 |
commit | ab1f173ccd20001aafe2f5b3268423861b0ecdfe (patch) | |
tree | d71c0990b1dd1fef80787a64fb553cf18393a983 /font/src | |
parent | 395fee2b01d0fe59f5502402e102f50ebfd88cd1 (diff) | |
download | alacritty-ab1f173ccd20001aafe2f5b3268423861b0ecdfe.tar.gz alacritty-ab1f173ccd20001aafe2f5b3268423861b0ecdfe.zip |
Add subpixel anti-aliasing support on macOS 10.14+
Diffstat (limited to 'font/src')
-rw-r--r-- | font/src/darwin/mod.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 19371c9b..f7bf6c82 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -38,6 +38,9 @@ use core_text::font_descriptor::kCTFontVerticalOrientation; use core_text::font_descriptor::SymbolicTraitAccessors; use core_text::font_descriptor::{CTFontDescriptor, CTFontOrientation}; +use cocoa::base::{id, nil, NO}; +use cocoa::foundation::{NSOperatingSystemVersion, NSProcessInfo, NSString, NSUserDefaults}; + use euclid::{Point2D, Rect, Size2D}; use log::{trace, warn}; @@ -278,6 +281,31 @@ pub struct Font { unsafe impl Send for Font {} + +/// Set subpixel anti-aliasing on macOS. +/// +/// Sub-pixel anti-aliasing has been disabled since macOS Mojave by default. This function allows +/// overriding the global `CGFontRenderingFontSmoothingDisabled` setting on a per-application basis +/// to re-enable it. +/// +/// This is a no-op on systems running High Sierra or earlier (< 10.14.0). +pub fn set_font_smoothing(enable: bool) { + let min_macos_version = NSOperatingSystemVersion::new(10, 14, 0); + unsafe { + // Check that we're running at least Mojave (10.14.0+). + if !NSProcessInfo::processInfo(nil).isOperatingSystemAtLeastVersion(min_macos_version) { + return + } + + let key = NSString::alloc(nil).init_str("CGFontRenderingFontSmoothingDisabled"); + if enable { + id::standardUserDefaults().setBool_forKey_(NO, key); + } else { + id::standardUserDefaults().removeObject_forKey_(key); + } + } +} + /// List all family names. pub fn get_family_names() -> Vec<String> { // CFArray of CFStringRef. |