aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2022-08-10 16:48:46 +0400
committerGitHub <noreply@github.com>2022-08-10 16:48:46 +0400
commit7d708d53f7ecb4c64db10ae44e7f4fca47c29a85 (patch)
treece76633d705da9b90e7e0d78afa24cef183ee286 /alacritty/src
parent76c5d01ee2b2178e71df578a109108655a97c24a (diff)
downloadr-alacritty-7d708d53f7ecb4c64db10ae44e7f4fca47c29a85.tar.gz
r-alacritty-7d708d53f7ecb4c64db10ae44e7f4fca47c29a85.tar.bz2
r-alacritty-7d708d53f7ecb4c64db10ae44e7f4fca47c29a85.zip
Bump glutin to 0.29.1
Fixes #6239. Fixes #5975. Fixes #5876. Fixes #5767. Fixes #4484. Fixes #3139.
Diffstat (limited to 'alacritty/src')
-rw-r--r--alacritty/src/config/window.rs18
-rw-r--r--alacritty/src/display/window.rs31
-rw-r--r--alacritty/src/event.rs58
-rw-r--r--alacritty/src/main.rs41
-rw-r--r--alacritty/src/renderer/text/builtin_font.rs4
5 files changed, 105 insertions, 47 deletions
diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs
index 08f38b57..8a59a007 100644
--- a/alacritty/src/config/window.rs
+++ b/alacritty/src/config/window.rs
@@ -31,7 +31,13 @@ pub struct WindowConfig {
pub embed: Option<c_ulong>,
/// GTK theme variant.
- pub gtk_theme_variant: Option<String>,
+ #[config(deprecated = "use window.decorations_theme_variant instead")]
+ gtk_theme_variant: Option<String>,
+
+ /// System decorations theme variant.
+ ///
+ /// Controls GTK theme variant on X11 and winit client side decorations on Wayland.
+ decorations_theme_variant: Option<String>,
/// Spread out additional padding evenly.
pub dynamic_padding: bool,
@@ -61,6 +67,7 @@ impl Default for WindowConfig {
decorations: Default::default(),
startup_mode: Default::default(),
embed: Default::default(),
+ decorations_theme_variant: Default::default(),
gtk_theme_variant: Default::default(),
dynamic_padding: Default::default(),
identity: Identity::default(),
@@ -104,6 +111,15 @@ impl WindowConfig {
}
}
+ #[cfg(not(any(target_os = "macos", windows)))]
+ #[inline]
+ pub fn decorations_theme_variant(&self) -> Option<&str> {
+ self.gtk_theme_variant
+ .as_ref()
+ .or_else(|| 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();
diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs
index 480654cf..0e754ed4 100644
--- a/alacritty/src/display/window.rs
+++ b/alacritty/src/display/window.rs
@@ -13,6 +13,7 @@ use {
wayland_client::protocol::wl_surface::WlSurface,
wayland_client::{Attached, EventQueue, Proxy},
glutin::platform::unix::EventLoopWindowTargetExtUnix,
+ glutin::window::Theme,
};
#[rustfmt::skip]
@@ -60,7 +61,7 @@ use crate::gl;
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
static WINDOW_ICON: &[u8] = include_bytes!("../../alacritty.png");
-/// This should match the definition of IDI_ICON from `windows.rc`.
+/// This should match the definition of IDI_ICON from `alacritty.rc`.
#[cfg(windows)]
const IDI_ICON: WORD = 0x101;
@@ -233,6 +234,9 @@ impl Window {
let current_mouse_cursor = CursorIcon::Text;
windowed_context.window().set_cursor_icon(current_mouse_cursor);
+ // Enable IME.
+ windowed_context.window().set_ime_allowed(true);
+
// Set OpenGL symbol loader. This call MUST be after window.make_current on windows.
gl::load_with(|symbol| windowed_context.get_proc_address(symbol) as *const _);
@@ -323,14 +327,15 @@ impl Window {
#[cfg(feature = "x11")]
let icon = {
let decoder = Decoder::new(Cursor::new(WINDOW_ICON));
- let (info, mut reader) = decoder.read_info().expect("invalid embedded icon");
- let mut buf = vec![0; info.buffer_size()];
+ let mut reader = decoder.read_info().expect("invalid embedded icon");
+ let mut buf = vec![0; reader.output_buffer_size()];
let _ = reader.next_frame(&mut buf);
- Icon::from_rgba(buf, info.width, info.height)
+ Icon::from_rgba(buf, reader.info().width, reader.info().height)
};
let builder = WindowBuilder::new()
.with_title(&identity.title)
+ .with_name(&identity.class.instance, &identity.class.general)
.with_visible(false)
.with_transparent(true)
.with_decorations(window_config.decorations != Decorations::None)
@@ -340,19 +345,19 @@ impl Window {
#[cfg(feature = "x11")]
let builder = builder.with_window_icon(icon.ok());
- #[cfg(feature = "wayland")]
- let builder = builder.with_app_id(identity.class.instance.to_owned());
-
- #[cfg(feature = "x11")]
- let builder = builder
- .with_class(identity.class.instance.to_owned(), identity.class.general.to_owned());
-
#[cfg(feature = "x11")]
- let builder = match &window_config.gtk_theme_variant {
- Some(val) => builder.with_gtk_theme_variant(val.clone()),
+ let builder = match window_config.decorations_theme_variant() {
+ Some(val) => builder.with_gtk_theme_variant(val.to_string()),
None => builder,
};
+ #[cfg(feature = "wayland")]
+ let builder = match window_config.decorations_theme_variant() {
+ Some("light") => builder.with_wayland_csd_theme(Theme::Light),
+ // Prefer dark theme by default, since default alacritty theme is dark.
+ _ => builder.with_wayland_csd_theme(Theme::Dark),
+ };
+
builder
}
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index cfa1c25c..54bb239e 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -13,8 +13,12 @@ use std::time::{Duration, Instant};
use std::{env, f32, mem};
use glutin::dpi::PhysicalSize;
-use glutin::event::{ElementState, Event as GlutinEvent, ModifiersState, MouseButton, WindowEvent};
-use glutin::event_loop::{ControlFlow, EventLoop, EventLoopProxy, EventLoopWindowTarget};
+use glutin::event::{
+ ElementState, Event as GlutinEvent, Ime, ModifiersState, MouseButton, StartCause, WindowEvent,
+};
+use glutin::event_loop::{
+ ControlFlow, DeviceEventFilter, EventLoop, EventLoopProxy, EventLoopWindowTarget,
+};
use glutin::platform::run_return::EventLoopExtRunReturn;
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
use glutin::platform::unix::EventLoopWindowTargetExtUnix;
@@ -1208,6 +1212,13 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
*self.ctx.dirty = true;
}
},
+ WindowEvent::Ime(ime) => {
+ if let Ime::Commit(text) = ime {
+ for ch in text.chars() {
+ self.received_char(ch)
+ }
+ }
+ },
WindowEvent::KeyboardInput { is_synthetic: true, .. }
| WindowEvent::TouchpadPressure { .. }
| WindowEvent::ScaleFactorChanged { .. }
@@ -1218,6 +1229,7 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
| WindowEvent::ThemeChanged(_)
| WindowEvent::HoveredFile(_)
| WindowEvent::Touch(_)
+ | WindowEvent::Occluded(_)
| WindowEvent::Moved(_) => (),
}
},
@@ -1289,9 +1301,16 @@ impl Processor {
}
/// Run the event loop.
- pub fn run(&mut self, mut event_loop: EventLoop<Event>) {
+ ///
+ /// The result is exit code generate from the loop.
+ pub fn run(
+ &mut self,
+ mut event_loop: EventLoop<Event>,
+ initial_window_options: WindowOptions,
+ ) -> Result<(), Box<dyn Error>> {
let proxy = event_loop.create_proxy();
let mut scheduler = Scheduler::new(proxy.clone());
+ let mut initial_window_options = Some(initial_window_options);
// NOTE: Since this takes a pointer to the winit event loop, it MUST be dropped first.
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
@@ -1299,7 +1318,10 @@ impl Processor {
#[cfg(any(not(feature = "wayland"), target_os = "macos", windows))]
let mut clipboard = Clipboard::new();
- event_loop.run_return(|event, event_loop, control_flow| {
+ // Disable all device events, since we don't care about them.
+ event_loop.set_device_event_filter(DeviceEventFilter::Always);
+
+ let exit_code = event_loop.run_return(move |event, event_loop, control_flow| {
if self.config.debug.print_events {
info!("glutin event: {:?}", event);
}
@@ -1310,6 +1332,27 @@ impl Processor {
}
match event {
+ // The event loop just got initialized. Create a window.
+ GlutinEvent::Resumed => {
+ // Creating window inside event loop is required for platforms like macOS to
+ // properly initialize state, like tab management. Othwerwise the first window
+ // won't handle tabs.
+ let initial_window_options = match initial_window_options.take() {
+ Some(initial_window_options) => initial_window_options,
+ None => return,
+ };
+
+ if let Err(err) =
+ self.create_window(event_loop, proxy.clone(), initial_window_options)
+ {
+ // Log the error right away since we can't return it.
+ eprintln!("Error: {}", err);
+ *control_flow = ControlFlow::ExitWithCode(1);
+ return;
+ }
+
+ info!("Initialisation complete");
+ },
// Check for shutdown.
GlutinEvent::UserEvent(Event {
window_id: Some(window_id),
@@ -1428,11 +1471,18 @@ impl Processor {
_ => (),
}
});
+
+ if exit_code == 0 {
+ Ok(())
+ } else {
+ Err(format!("Event loop terminated with code: {}", exit_code).into())
+ }
}
/// Check if an event is irrelevant and can be skipped.
fn skip_event(event: &GlutinEvent<'_, Event>) -> bool {
match event {
+ GlutinEvent::NewEvents(StartCause::Init) => false,
GlutinEvent::WindowEvent { event, .. } => matches!(
event,
WindowEvent::KeyboardInput { is_synthetic: true, .. }
diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs
index a0a98efe..2e7c30a9 100644
--- a/alacritty/src/main.rs
+++ b/alacritty/src/main.rs
@@ -14,13 +14,13 @@ compile_error!(r#"at least one of the "x11"/"wayland" features must be enabled"#
#[cfg(target_os = "macos")]
use std::env;
+use std::error::Error;
use std::fmt::Write as _;
+use std::fs;
use std::io::{self, Write};
use std::path::PathBuf;
-use std::string::ToString;
-use std::{fs, process};
-use glutin::event_loop::EventLoop as GlutinEventLoop;
+use glutin::event_loop::EventLoopBuilder as GlutinEventLoopBuilder;
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
use glutin::platform::unix::EventLoopWindowTargetExtUnix;
use log::info;
@@ -62,7 +62,7 @@ use crate::event::{Event, Processor};
#[cfg(target_os = "macos")]
use crate::macos::locale;
-fn main() {
+fn main() -> Result<(), Box<dyn Error>> {
#[cfg(windows)]
panic::attach_handler();
@@ -78,25 +78,19 @@ fn main() {
let options = Options::new();
#[cfg(unix)]
- let result = match options.subcommands {
+ match options.subcommands {
Some(Subcommands::Msg(options)) => msg(options),
None => alacritty(options),
- };
+ }
#[cfg(not(unix))]
- let result = alacritty(options);
-
- // Handle command failure.
- if let Err(err) = result {
- eprintln!("Error: {}", err);
- process::exit(1);
- }
+ alacritty(options)
}
/// `msg` subcommand entrypoint.
#[cfg(unix)]
-fn msg(options: MessageOptions) -> Result<(), String> {
- ipc::send_message(options.socket, options.message).map_err(|err| err.to_string())
+fn msg(options: MessageOptions) -> Result<(), Box<dyn Error>> {
+ ipc::send_message(options.socket, options.message).map_err(|err| err.into())
}
/// Temporary files stored for Alacritty.
@@ -129,9 +123,9 @@ impl Drop for TemporaryFiles {
///
/// Creates a window, the terminal state, PTY, I/O event loop, input processor,
/// config change monitor, and runs the main display loop.
-fn alacritty(options: Options) -> Result<(), String> {
+fn alacritty(options: Options) -> Result<(), Box<dyn Error>> {
// Setup glutin event loop.
- let window_event_loop = GlutinEventLoop::<Event>::with_user_event();
+ let window_event_loop = GlutinEventLoopBuilder::<Event>::with_user_event().build();
// Initialize the logger as soon as possible as to capture output from other subsystems.
let log_file = logging::initialize(&options, window_event_loop.create_proxy())
@@ -191,16 +185,8 @@ fn alacritty(options: Options) -> Result<(), String> {
let window_options = options.window_options.clone();
let mut processor = Processor::new(config, options, &window_event_loop);
- // Create the first Alacritty window.
- let proxy = window_event_loop.create_proxy();
- processor
- .create_window(&window_event_loop, proxy, window_options)
- .map_err(|err| err.to_string())?;
-
- info!("Initialisation complete");
-
// Start event loop and block until shutdown.
- processor.run(window_event_loop);
+ let result = processor.run(window_event_loop, window_options);
// This explicit drop is needed for Windows, ConPTY backend. Otherwise a deadlock can occur.
// The cause:
@@ -225,7 +211,8 @@ fn alacritty(options: Options) -> Result<(), String> {
}
info!("Goodbye");
- Ok(())
+
+ result
}
fn log_config_path(config: &UiConfig) {
diff --git a/alacritty/src/renderer/text/builtin_font.rs b/alacritty/src/renderer/text/builtin_font.rs
index a4bf65e3..66c5db0f 100644
--- a/alacritty/src/renderer/text/builtin_font.rs
+++ b/alacritty/src/renderer/text/builtin_font.rs
@@ -90,8 +90,8 @@ fn box_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> Raster
left: 0,
height: height as i32,
width: width as i32,
- advance: (0, 0),
buffer,
+ advance: (width as i32, height as i32),
};
},
_ => Canvas::new(width, height),
@@ -486,8 +486,8 @@ fn box_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> Raster
left: 0,
height: height as i32,
width: width as i32,
- advance: (0, 0),
buffer,
+ advance: (width as i32, height as i32),
}
}