summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2022-11-03 19:37:54 +0300
committerGitHub <noreply@github.com>2022-11-03 19:37:54 +0300
commit0e418bc2f761617455cc58aaabc375055dfe4284 (patch)
treefc15d2260404914e21297d392f7f9c32a5f2bffc
parent578e08486dfcdee0b2cd0e7a66752ff50edc46b8 (diff)
Update glutin to 0.30.0
The glutin 0.30.0 update decouples glutin from winit which provides us with basis for a multithreaded renderer. This also improves robustness of our configuration picking, context creation, and surface handling. As an example we're now able to start on systems without a vsync, we don't try to build lots of contexts to check if some config works, and so on. That also brings us possibility to handle context losses, but that's a future work. Fixes #1268.
-rw-r--r--.builds/freebsd.yml4
-rw-r--r--.builds/linux.yml4
-rw-r--r--.github/workflows/ci.yml2
-rw-r--r--CHANGELOG.md6
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--Cargo.lock93
-rw-r--r--alacritty/Cargo.toml19
-rw-r--r--alacritty/src/config/bindings.rs8
-rw-r--r--alacritty/src/config/monitor.rs2
-rw-r--r--alacritty/src/config/ui_config.rs2
-rw-r--r--alacritty/src/config/window.rs10
-rw-r--r--alacritty/src/display/damage.rs24
-rw-r--r--alacritty/src/display/hint.rs2
-rw-r--r--alacritty/src/display/mod.rs451
-rw-r--r--alacritty/src/display/window.rs310
-rw-r--r--alacritty/src/event.rs130
-rw-r--r--alacritty/src/input.rs34
-rw-r--r--alacritty/src/ipc.rs4
-rw-r--r--alacritty/src/logging.rs2
-rw-r--r--alacritty/src/main.rs10
-rw-r--r--alacritty/src/renderer/mod.rs21
-rw-r--r--alacritty/src/renderer/platform.rs116
-rw-r--r--alacritty/src/scheduler.rs6
-rw-r--r--alacritty/src/window_context.rs128
-rw-r--r--alacritty_config/Cargo.toml2
-rw-r--r--alacritty_config_derive/Cargo.toml2
-rw-r--r--alacritty_terminal/Cargo.toml2
27 files changed, 774 insertions, 622 deletions
diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml
index 3cd2a60d..4aa4113b 100644
--- a/.builds/freebsd.yml
+++ b/.builds/freebsd.yml
@@ -24,8 +24,8 @@ tasks:
cargo test
- oldstable: |
cd alacritty
- rustup toolchain install --profile minimal 1.57.0
- rustup default 1.57.0
+ rustup toolchain install --profile minimal 1.60.0
+ rustup default 1.60.0
cargo test
- clippy: |
cd alacritty
diff --git a/.builds/linux.yml b/.builds/linux.yml
index a61afd3a..4e6e0a0b 100644
--- a/.builds/linux.yml
+++ b/.builds/linux.yml
@@ -27,8 +27,8 @@ tasks:
cargo +nightly fmt -- --check
- oldstable: |
cd alacritty
- rustup toolchain install --profile minimal 1.57.0
- rustup default 1.57.0
+ rustup toolchain install --profile minimal 1.60.0
+ rustup default 1.60.0
cargo test
- clippy: |
cd alacritty
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index dea6dd4a..652e65aa 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -19,7 +19,7 @@ jobs:
run: cargo test
- name: Oldstable
run: |
- rustup default 1.57.0
+ rustup default 1.60.0
cargo test
- name: Clippy
run: |
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bc9fe55..7a3cfe0e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Packaging
+- Minimum Rust version has been bumped to 1.60.0
+
+## 0.11.0
+
+### Packaging
+
- Minimum Rust version has been bumped to 1.57.0
- Renamed `io.alacritty.Alacritty.appdata.xml` to `org.alacritty.Alacritty.appdata.xml`
- Renamed `io.alacritty` to `org.alacritty` for `Alacritty.app`
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index bd2dbd77..65879dbd 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -42,7 +42,7 @@ and
[easy](https://github.com/alacritty/alacritty/issues?q=is%3Aopen+is%3Aissue+label%3A%22D+-+easy%22)
issues.
-Please note that the minimum supported version of Alacritty is Rust 1.57.0. All patches are expected
+Please note that the minimum supported version of Alacritty is Rust 1.60.0. All patches are expected
to work with the minimum supported version.
Since `alacritty_terminal`'s version always tracks the next release, make sure that the version is
diff --git a/Cargo.lock b/Cargo.lock
index a545c28d..fa2eac1d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -40,6 +40,7 @@ dependencies = [
"unicode-width",
"wayland-client",
"windows-sys",
+ "winit",
"x11-dl",
"xdg",
]
@@ -185,6 +186,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
+name = "cfg_aliases"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
+
+[[package]]
name = "cgl"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -660,55 +667,42 @@ dependencies = [
[[package]]
name = "glutin"
-version = "0.29.1"
+version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "444c9ad294fdcaf20ccf6726b78f380b5450275540c9b68ab62f49726ad1c713"
+checksum = "34acbf502536f1d125f0fc09b6ad8824e93e6da7b99e86d3383e6b8310ba3554"
dependencies = [
+ "bitflags",
+ "cfg_aliases",
"cgl",
"cocoa",
"core-foundation",
"glutin_egl_sys",
- "glutin_gles2_sys",
"glutin_glx_sys",
"glutin_wgl_sys",
"libloading",
- "log",
"objc",
"once_cell",
- "osmesa-sys",
- "parking_lot 0.12.1",
"raw-window-handle 0.5.0",
- "wayland-client",
- "wayland-egl",
- "winapi 0.3.9",
- "winit",
+ "wayland-sys 0.30.0-beta.12",
+ "windows-sys",
+ "x11-dl",
]
[[package]]
name = "glutin_egl_sys"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "68900f84b471f31ea1d1355567eb865a2cf446294f06cef8d653ed7bcf5f013d"
-dependencies = [
- "gl_generator",
- "winapi 0.3.9",
-]
-
-[[package]]
-name = "glutin_gles2_sys"
-version = "0.1.5"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e8094e708b730a7c8a1954f4f8a31880af00eb8a1c5b5bf85d28a0a3c6d69103"
+checksum = "2c3c95a2d7a54bab0c74759794efb5cd63470d4504cbe85ed4114dc82c98bdc1"
dependencies = [
"gl_generator",
- "objc",
+ "windows-sys",
]
[[package]]
name = "glutin_glx_sys"
-version = "0.1.8"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d93d0575865098580c5b3a423188cd959419912ea60b1e48e8b3b526f6d02468"
+checksum = "947c4850c58211c9627969c2b4e2674764b81ae5b47bab2c9a477d7942f96e0f"
dependencies = [
"gl_generator",
"x11-dl",
@@ -716,9 +710,9 @@ dependencies = [
[[package]]
name = "glutin_wgl_sys"
-version = "0.1.5"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3da5951a1569dbab865c6f2a863efafff193a93caf05538d193e9e3816d21696"
+checksum = "20c33975a6c9d49d72c8f032a60079bf8df536954fbf9e4cee90396ace815c57"
dependencies = [
"gl_generator",
]
@@ -1206,15 +1200,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
-name = "osmesa-sys"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b"
-dependencies = [
- "shared_library",
-]
-
-[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1529,16 +1514,6 @@ dependencies = [
]
[[package]]
-name = "shared_library"
-version = "0.1.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
-dependencies = [
- "lazy_static",
- "libc",
-]
-
-[[package]]
name = "signal-hook"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1868,7 +1843,7 @@ dependencies = [
"scoped-tls",
"wayland-commons",
"wayland-scanner",
- "wayland-sys",
+ "wayland-sys 0.29.5",
]
[[package]]
@@ -1880,7 +1855,7 @@ dependencies = [
"nix",
"once_cell",
"smallvec",
- "wayland-sys",
+ "wayland-sys 0.29.5",
]
[[package]]
@@ -1895,16 +1870,6 @@ dependencies = [
]
[[package]]
-name = "wayland-egl"
-version = "0.29.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "402de949f81a012926d821a2d659f930694257e76dd92b6e0042ceb27be4107d"
-dependencies = [
- "wayland-client",
- "wayland-sys",
-]
-
-[[package]]
name = "wayland-protocols"
version = "0.29.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1939,6 +1904,18 @@ dependencies = [
]
[[package]]
+name = "wayland-sys"
+version = "0.30.0-beta.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1117fe4570fe063122ba2b1b1e39e56fb1a73921d395f9288af06af0dd1c7f55"
+dependencies = [
+ "dlib",
+ "lazy_static",
+ "log",
+ "pkg-config",
+]
+
+[[package]]
name = "web-sys"
version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/alacritty/Cargo.toml b/alacritty/Cargo.toml
index 4ca77b11..c414e766 100644
--- a/alacritty/Cargo.toml
+++ b/alacritty/Cargo.toml
@@ -7,7 +7,7 @@ description = "A fast, cross-platform, OpenGL terminal emulator"
readme = "README.md"
homepage = "https://github.com/alacritty/alacritty"
edition = "2021"
-rust-version = "1.57.0"
+rust-version = "1.60.0"
[dependencies.alacritty_terminal]
path = "../alacritty_terminal"
@@ -29,11 +29,13 @@ fnv = "1"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.8"
serde_json = "1"
-glutin = { version = "0.29.1", default-features = false, features = ["serde"] }
+glutin = { version = "0.30.0", default-features = false, features = ["egl", "wgl"] }
+winit = { version = "0.27.4", default-features = false, features = ["serde"] }
notify = "4"
parking_lot = "0.12.0"
crossfont = { version = "0.5.0", features = ["force_system_fontconfig"] }
copypasta = { version = "0.8.1", default-features = false }
+raw-window-handle = "0.5.0"
libc = "0.2"
unicode-width = "0.1"
bitflags = "1"
@@ -74,11 +76,18 @@ embed-resource = "1.7.2"
[features]
default = ["wayland", "x11"]
-x11 = ["copypasta/x11", "glutin/x11", "x11-dl", "png"]
+x11 = [
+ "copypasta/x11",
+ "winit/x11",
+ "glutin/x11",
+ "glutin/glx",
+ "x11-dl",
+ "png"]
wayland = [
"copypasta/wayland",
"glutin/wayland",
- "glutin/wayland-dlopen",
- "glutin/wayland-csd-adwaita",
+ "winit/wayland",
+ "winit/wayland-dlopen",
+ "winit/wayland-csd-adwaita",
"wayland-client"]
nightly = []
diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs
index 3aae25ed..7b654b66 100644
--- a/alacritty/src/config/bindings.rs
+++ b/alacritty/src/config/bindings.rs
@@ -3,11 +3,11 @@
use std::fmt::{self, Debug, Display};
use bitflags::bitflags;
-use glutin::event::VirtualKeyCode::*;
-use glutin::event::{ModifiersState, MouseButton, VirtualKeyCode};
use serde::de::{self, Error as SerdeError, MapAccess, Unexpected, Visitor};
use serde::{Deserialize, Deserializer};
use serde_yaml::Value as SerdeValue;
+use winit::event::VirtualKeyCode::*;
+use winit::event::{ModifiersState, MouseButton, VirtualKeyCode};
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
@@ -1187,7 +1187,7 @@ impl<'a> Deserialize<'a> for KeyBinding {
}
}
-/// Newtype for implementing deserialize on glutin Mods.
+/// Newtype for implementing deserialize on winit Mods.
///
/// Our deserialize impl wouldn't be covered by a derive(Deserialize); see the
/// impl below.
@@ -1242,7 +1242,7 @@ impl<'a> de::Deserialize<'a> for ModsWrapper {
mod tests {
use super::*;
- use glutin::event::ModifiersState;
+ use winit::event::ModifiersState;
type MockBinding = Binding<usize>;
diff --git a/alacritty/src/config/monitor.rs b/alacritty/src/config/monitor.rs
index 8981570c..f6d52e2f 100644
--- a/alacritty/src/config/monitor.rs
+++ b/alacritty/src/config/monitor.rs
@@ -2,9 +2,9 @@ use std::path::PathBuf;
use std::sync::mpsc;
use std::time::Duration;
-use glutin::event_loop::EventLoopProxy;
use log::{debug, error};
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
+use winit::event_loop::EventLoopProxy;
use alacritty_terminal::thread;
diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs
index a332b737..f58097cf 100644
--- a/alacritty/src/config/ui_config.rs
+++ b/alacritty/src/config/ui_config.rs
@@ -3,11 +3,11 @@ use std::fmt::{self, Formatter};
use std::path::PathBuf;
use std::rc::Rc;
-use glutin::event::{ModifiersState, VirtualKeyCode};
use log::error;
use serde::de::{Error as SerdeError, MapAccess, Visitor};
use serde::{self, Deserialize, Deserializer};
use unicode_width::UnicodeWidthChar;
+use winit::event::{ModifiersState, VirtualKeyCode};
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
use alacritty_terminal::config::{
diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs
index 5d63d60f..f1a74232 100644
--- a/alacritty/src/config/window.rs
+++ b/alacritty/src/config/window.rs
@@ -1,10 +1,10 @@
use std::fmt::{self, Formatter};
use std::os::raw::c_ulong;
-use glutin::window::Fullscreen;
use log::{error, warn};
use serde::de::{self, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
+use winit::window::Fullscreen;
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
use alacritty_terminal::config::{Percentage, LOG_TARGET_CONFIG};
@@ -116,14 +116,14 @@ impl WindowConfig {
pub fn decorations_theme_variant(&self) -> Option<&str> {
self.gtk_theme_variant
.as_ref()
- .or_else(|| self.decorations_theme_variant.as_ref())
+ .or(self.decorations_theme_variant.as_ref())
.map(|theme| theme.as_str())
}
#[inline]
- pub fn padding(&self, scale_factor: f64) -> (f32, f32) {
- let padding_x = (f32::from(self.padding.x) * scale_factor as f32).floor();
- let padding_y = (f32::from(self.padding.y) * scale_factor as f32).floor();
+ pub fn padding(&self, scale_factor: f32) -> (f32, f32) {
+ let padding_x = (f32::from(self.padding.x) * scale_factor).floor();
+ let padding_y = (f32::from(self.padding.y) * scale_factor).floor();
(padding_x, padding_y)
}
diff --git a/alacritty/src/display/damage.rs b/alacritty/src/display/damage.rs
index d9b271c5..380a2f63 100644
--- a/alacritty/src/display/damage.rs
+++ b/alacritty/src/display/damage.rs
@@ -1,7 +1,7 @@
use std::cmp;
use std::iter::Peekable;
-use glutin::Rect;
+use glutin::surface::Rect;
use alacritty_terminal::term::{LineDamageBounds, TermDamageIterator};
@@ -25,17 +25,23 @@ impl<'a> RenderDamageIterator<'a> {
let x = size_info.padding_x() + line_damage.left as u32 * size_info.cell_width();
let y = y_top - (line_damage.line + 1) as u32 * size_info.cell_height();
let width = (line_damage.right - line_damage.left + 1) as u32 * size_info.cell_width();
- Rect { x, y, height: size_info.cell_height(), width }
+ Rect::new(x as i32, y as i32, width as i32, size_info.cell_height() as i32)
}
// Make sure to damage near cells to include wide chars.
#[inline]
fn overdamage(&self, mut rect: Rect) -> Rect {
let size_info = &self.size_info;
- rect.x = rect.x.saturating_sub(size_info.cell_width());
- rect.width = cmp::min(size_info.width() - rect.x, rect.width + 2 * size_info.cell_width());
- rect.y = rect.y.saturating_sub(size_info.cell_height() / 2);
- rect.height = cmp::min(size_info.height() - rect.y, rect.height + size_info.cell_height());
+ rect.x = rect.x.saturating_sub(size_info.cell_width() as i32);
+ rect.width = cmp::min(
+ size_info.width() as i32 - rect.x,
+ rect.width + 2 * size_info.cell_width() as i32,
+ );
+ rect.y = rect.y.saturating_sub(size_info.cell_height() as i32 / 2);
+ rect.height = cmp::min(
+ size_info.height() as i32 - rect.y,
+ rect.height + size_info.cell_height() as i32,
+ );
rect
}
@@ -63,7 +69,7 @@ impl<'a> Iterator for RenderDamageIterator<'a> {
}
}
-/// Check if two given [`glutin::Rect`] overlap.
+/// Check if two given [`glutin::surface::Rect`] overlap.
fn rects_overlap(lhs: Rect, rhs: Rect) -> bool {
!(
// `lhs` is left of `rhs`.
@@ -77,12 +83,12 @@ fn rects_overlap(lhs: Rect, rhs: Rect) -> bool {
)
}
-/// Merge two [`glutin::Rect`] by producing the smallest rectangle that contains both.
+/// Merge two [`glutin::surface::Rect`] by producing the smallest rectangle that contains both.
#[inline]
fn merge_rects(lhs: Rect, rhs: Rect) -> Rect {
let left_x = cmp::min(lhs.x, rhs.x);
let right_x = cmp::max(lhs.x + lhs.width, rhs.x + rhs.width);
let y_top = cmp::max(lhs.y + lhs.height, rhs.y + rhs.height);
let y_bottom = cmp::min(lhs.y, rhs.y);
- Rect { x: left_x, y: y_bottom, width: right_x - left_x, height: y_top - y_bottom }
+ Rect::new(left_x, y_bottom, right_x - left_x, y_top - y_bottom)
}
diff --git a/alacritty/src/display/hint.rs b/alacritty/src/display/hint.rs
index 8d374bdb..202b8f97 100644
--- a/alacritty/src/display/hint.rs
+++ b/alacritty/src/display/hint.rs
@@ -2,7 +2,7 @@ use std::cmp::Reverse;
use std::collections::HashSet;
use std::iter;
-use glutin::event::ModifiersState;
+use winit::event::ModifiersState;
use alacritty_terminal::grid::{BidirectionalIterator, Dimensions};
use alacritty_terminal::index::{Boundary, Column, Direction, Line, Point};
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs
index c17d8aa7..ed1b1fc5 100644
--- a/alacritty/src/display/mod.rs
+++ b/alacritty/src/display/mod.rs
@@ -1,23 +1,24 @@
//! The display subsystem including window management, font rasterization, and
//! GPU drawing.
+use std::cmp;
use std::fmt::{self, Formatter};
+use std::mem::{self, ManuallyDrop};
+use std::num::NonZeroU32;
+use std::ops::{Deref, DerefMut};
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
use std::sync::atomic::Ordering;
-use std::{cmp, mem};
-
-use glutin::dpi::PhysicalSize;
-use glutin::event::ModifiersState;
-use glutin::event_loop::EventLoopWindowTarget;
-#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
-use glutin::platform::unix::EventLoopWindowTargetExtUnix;
-use glutin::window::CursorIcon;
-use glutin::Rect as DamageRect;
-use log::{debug, info};
+
+use glutin::context::{NotCurrentContext, PossiblyCurrentContext};
+use glutin::prelude::*;
+use glutin::surface::{Rect as DamageRect, Surface, SwapInterval, WindowSurface};
+
+use log::{debug, info, warn};
use parking_lot::MutexGuard;
use serde::{Deserialize, Serialize};
-#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
-use wayland_client::EventQueue;
+use winit::dpi::PhysicalSize;
+use winit::event::ModifiersState;
+use winit::window::CursorIcon;
use crossfont::{self, Rasterize, Rasterizer};
use unicode_width::UnicodeWidthChar;
@@ -33,9 +34,9 @@ use alacritty_terminal::term::color::Rgb;
use alacritty_terminal::term::{self, Term, TermDamage, TermMode, MIN_COLUMNS, MIN_SCREEN_LINES};
use crate::config::font::Font;
+use crate::config::window::Dimensions;
#[cfg(not(windows))]
use crate::config::window::StartupMode;
-use crate::config::window::{Dimensions, Identity};
use crate::config::UiConfig;
use crate::display::bell::VisualBell;
use crate::display::color::List;
@@ -84,8 +85,8 @@ pub enum Error {
/// Error in renderer.
Render(renderer::Error),
- /// Error during buffer swap.
- Context(glutin::ContextError),
+ /// Error during context operations.
+ Context(glutin::error::Error),
}
impl std::error::Error for Error {
@@ -128,8 +129,8 @@ impl From<renderer::Error> for Error {
}
}
-impl From<glutin::ContextError> for Error {
- fn from(val: glutin::ContextError) -> Self {
+impl From<glutin::error::Error> for Error {
+ fn from(val: glutin::error::Error) -> Self {
Error::Context(val)
}
}
@@ -334,17 +335,17 @@ impl DisplayUpdate {
/// The display wraps a window, font rasterizer, and GPU renderer.
pub struct Display {
- pub size_info: SizeInfo,
pub window: Window,
+ pub size_info: SizeInfo,
+
/// Hint highlighted by the mouse.
pub highlighted_hint: Option<HintMatch>,
/// Hint highlighted by the vi mode cursor.
pub vi_highlighted_hint: Option<HintMatch>,
- #[cfg(not(any(target_os = "macos", windows)))]
- pub is_x11: bool,
+ pub is_wayland: bool,
/// UI cursor visibility for blinking.
pub cursor_hidden: bool,
@@ -369,161 +370,57 @@ pub struct Display {
// Mouse point position when highlighting hints.
hint_mouse_point: Option<Point>,
- is_damage_supported: bool,
+ renderer: ManuallyDrop<Renderer>,
+
+ surface: ManuallyDrop<Surface<WindowSurface>>,
+
+ context: ManuallyDrop<Replaceable<PossiblyCurrentContext>>,
+
debug_damage: bool,
damage_rects: Vec<DamageRect>,
next_frame_damage_rects: Vec<DamageRect>,
- renderer: Renderer,
glyph_cache: GlyphCache,
meter: Meter,
}
-/// Input method state.
-#[derive(Debug, Default)]
-pub struct Ime {
- /// Whether the IME is enabled.
- enabled: bool,
-
- /// Current IME preedit.
- preedit: Option<Preedit>,
-}
-
-impl Ime {
- pub fn new() -> Self {
- Default::default()
- }
-
- #[inline]
- pub fn set_enabled(&mut self, is_enabled: bool) {
- if is_enabled {
- self.enabled = is_enabled
- } else {
- // Clear state when disabling IME.
- *self = Default::default();
- }
- }
-
- #[inline]
- pub fn is_enabled(&self) -> bool {
- self.enabled
- }
-
- #[inline]
- pub fn set_preedit(&mut self, preedit: Option<Preedit>) {
- self.preedit = preedit;
- }
-
- #[inline]
- pub fn preedit(&self) -> Option<&Preedit> {
- self.preedit.as_ref()
- }
-}
-
-#[derive(Debug, Default, PartialEq, Eq)]
-pub struct Preedit {
- /// The preedit text.
- text: String,
-
- /// Byte offset for cursor start into the preedit text.
- ///
- /// `None` means that the cursor is invisible.
- cursor_byte_offset: Option<usize>,
-
- /// The cursor offset from the end of the preedit in char width.
- cursor_end_offset: Option<usize>,
-}
-
-impl Preedit {
- pub fn new(text: String, cursor_byte_offset: Option<usize>) -> Self {
- let cursor_end_offset = if let Some(byte_offset) = cursor_byte_offset {
- // Convert byte offset into char offset.
- let cursor_end_offset =
- text[byte_offset..].chars().fold(0, |acc, ch| acc + ch.width().unwrap_or(1));
-
- Some(cursor_end_offset)
- } else {
- None
- };
-
- Self { text, cursor_byte_offset, cursor_end_offset }
- }
-}
-
-/// Pending renderer updates.
-///
-/// All renderer updates are cached to be applied just before rendering, to avoid platform-specific
-/// rendering issues.
-#[derive(Debug, Default, Copy, Clone)]
-pub struct RendererUpdate {
- /// Should resize the window.
- resize: bool,
-
- /// Clear font caches.
- clear_font_cache: bool,
-}
-
impl Display {
- pub fn new<E>(
+ pub fn new(
+ window: Window,
+ gl_context: NotCurrentContext,
config: &UiConfig,
- event_loop: &EventLoopWindowTarget<E>,
- identity: &Identity,
- #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
- wayland_event_queue: Option<&EventQueue>,
) -> Result<Display, Error> {
- #[cfg(any(not(feature = "x11"), target_os = "macos", windows))]
- let is_x11 = false;
- #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
- let is_x11 = event_loop.is_x11();
+ #[cfg(any(not(feature = "wayland"), target_os = "macos", windows))]
+ let is_wayland = false;
+ #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
+ let is_wayland = window.wayland_surface().is_some();
- // Guess scale_factor based on first monitor. On Wayland the initial frame always renders at
- // a scale factor of 1.
- let estimated_scale_factor = if cfg!(any(target_os = "macos", windows)) || is_x11 {
- event_loop.available_monitors().next().map_or(1., |m| m.scale_factor())
- } else {
- 1.
- };
+ let scale_factor = window.scale_factor as f32;
+ let rasterizer = Rasterizer::new(scale_factor)?;
- // Guess the target window dimensions.
debug!("Loading \"{}\" font", &config.font.normal().family);
- let font = &config.font;
- let rasterizer = Rasterizer::new(estimated_scale_factor as f32)?;
- let mut glyph_cache = GlyphCache::new(rasterizer, font)?;
+ let mut glyph_cache = GlyphCache::new(rasterizer, &config.font)?;
+
let metrics = glyph_cache.font_metrics();
let (cell_width, cell_height) = compute_cell_size(config, &metrics);
- // Guess the target window size if the user has specified the number of lines/columns.
- let dimensions = config.window.dimensions();
- let estimated_size = dimensions.map(|dimensions| {
- window_size(config, dimensions, cell_width, cell_height, estimated_scale_factor)
- });
+ // Resize the window to account for the user configured size.
+ if let Some(dimensions) = config.window.dimensions() {
+ let size = window_size(config, dimensions, cell_width, cell_height, scale_factor);
+ window.set_inner_size(size);
+ }
- debug!("Estimated scaling factor: {}", estimated_scale_factor);
- debug!("Estimated window size: {:?}", estimated_size);
- debug!("Estimated cell size: {} x {}", cell_width, cell_height);
-
- // Spawn the Alacritty window.
- let window = Window::new(
- event_loop,
- config,
- identity,
- estimated_size,
- #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
- wayland_event_queue,
+ // Create the GL surface to draw into.
+ let surface = renderer::platform::create_gl_surface(
+ &gl_context,
+ window.inner_size(),
+ window.raw_window_handle(),
)?;
- // Create renderer.
- let mut renderer = Renderer::new()?;
-
- let scale_factor = window.scale_factor;
- info!("Display scale factor: {}", scale_factor);
+ // Make the context current.
+ let context = gl_context.make_current(&surface)?;
- // If the scaling factor changed update the glyph cache and mark for resize.
- let should_resize = (estimated_scale_factor - window.scale_factor).abs() > f64::EPSILON;
- let (cell_width, cell_height) = if should_resize {
- Self::update_font_size(&mut glyph_cache, scale_factor, config, font)
- } else {
- (cell_width, cell_height)
- };
+ // Create renderer.
+ let mut renderer = Renderer::new(&context)?;
// Load font common glyphs to accelerate rendering.
debug!("Filling glyph cache with com