summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--alacritty.yml12
-rw-r--r--alacritty/src/display.rs6
-rw-r--r--alacritty/src/event.rs8
-rw-r--r--font/Cargo.toml1
-rw-r--r--font/src/darwin/mod.rs28
6 files changed, 47 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d79b6638..661f2a21 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -331,7 +331,7 @@ dependencies = [
[[package]]
name = "cocoa"
-version = "0.20.0"
+version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -597,6 +597,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "font"
version = "0.1.0"
dependencies = [
+ "cocoa 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2204,7 +2205,7 @@ version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "cocoa 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cocoa 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-video-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2367,7 +2368,7 @@ dependencies = [
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum cmake 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "49f97562167906afc51aa3fd7e6c83c10a5c96d33bd18f98a4c06a1413134caa"
"checksum cocoa 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f29f7768b2d1be17b96158e3285951d366b40211320fb30826a76cb7a0da6400"
-"checksum cocoa 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0a4736c86d51bd878b474400d9ec888156f4037015f5d09794fab9f26eab1ad4"
+"checksum cocoa 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8f7b6f3f7f4f0b3ec5c5039aaa9e8c3cef97a7a480a400fd62944841314f293d"
"checksum constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
"checksum copypasta 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "865e9675691e2a7dfc806b16ef2dd5dd536e26ea9b8046519767d79be03aeb6a"
"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d"
diff --git a/alacritty.yml b/alacritty.yml
index bf2b4048..d9054b04 100644
--- a/alacritty.yml
+++ b/alacritty.yml
@@ -153,17 +153,7 @@
# Thin stroke font rendering (macOS only)
#
# Thin strokes are suitable for retina displays, but for non-retina screens
- # it is recommended to set `use_thin_strokes` to `false`
- #
- # macOS >= 10.14.x:
- #
- # If the font quality on non-retina display looks bad then set
- # `use_thin_strokes` to `true` and enable font smoothing by running the
- # following command:
- # `defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO`
- #
- # This is a global setting and will require a log out or restart to take
- # effect.
+ # it is recommended to set `use_thin_strokes` to `false`.
#use_thin_strokes: true
# If `true`, bold text is drawn using the bright color variants.
diff --git a/alacritty/src/display.rs b/alacritty/src/display.rs
index f081e054..fcb87604 100644
--- a/alacritty/src/display.rs
+++ b/alacritty/src/display.rs
@@ -32,6 +32,8 @@ use parking_lot::MutexGuard;
use wayland_client::{Display as WaylandDisplay, EventQueue};
use font::{self, Rasterize};
+#[cfg(target_os = "macos")]
+use font::set_font_smoothing;
use alacritty_terminal::config::{Font, StartupMode};
use alacritty_terminal::event::{Event, OnResize};
@@ -225,6 +227,10 @@ impl Display {
api.clear(background_color);
});
+ // Set subpixel anti-aliasing.
+ #[cfg(target_os = "macos")]
+ set_font_smoothing(config.font.use_thin_strokes());
+
#[cfg(not(any(target_os = "macos", windows)))]
let is_x11 = event_loop.is_x11();
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index 9a625a91..8ec2b839 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -22,7 +22,9 @@ use glutin::platform::unix::EventLoopWindowTargetExtUnix;
use log::{debug, info, warn};
use serde_json as json;
-use font::Size;
+use font::{self, Size};
+#[cfg(target_os = "macos")]
+use font::set_font_smoothing;
use alacritty_terminal::clipboard::ClipboardType;
use alacritty_terminal::config::Font;
@@ -726,6 +728,10 @@ impl<N: Notify + OnResize> Processor<N> {
}
}
+ // Set subpixel anti-aliasing.
+ #[cfg(target_os = "macos")]
+ set_font_smoothing(config.font.use_thin_strokes());
+
*processor.ctx.config = config;
processor.ctx.terminal.dirty = true;
diff --git a/font/Cargo.toml b/font/Cargo.toml
index 1c546f40..6b5825c4 100644
--- a/font/Cargo.toml
+++ b/font/Cargo.toml
@@ -17,6 +17,7 @@ servo-fontconfig = "0.5.0"
freetype-rs = "0.25"
[target.'cfg(target_os = "macos")'.dependencies]
+cocoa = "0.20.1"
core-foundation = "0.7"
core-text = "15"
core-graphics = "0.19"
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.