diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-02-02 11:30:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-02 11:30:23 +0300 |
commit | 1c878a0476257d328113efcd7088f1aa53f42e56 (patch) | |
tree | b4ba30e6b9549965387330f9eb7111c95795de69 /alacritty/src | |
parent | 246ec8945d84f658fc88d02a33c3590ef4a92e0f (diff) | |
download | r-alacritty-1c878a0476257d328113efcd7088f1aa53f42e56.tar.gz r-alacritty-1c878a0476257d328113efcd7088f1aa53f42e56.tar.bz2 r-alacritty-1c878a0476257d328113efcd7088f1aa53f42e56.zip |
Update winit to 0.28
Fixes #6644.
Fixes #6615.
Fixes #6558.
Fixes #6515.
Fixes #3187.
Fixes #62.
Diffstat (limited to 'alacritty/src')
-rw-r--r-- | alacritty/src/config/ui_config.rs | 6 | ||||
-rw-r--r-- | alacritty/src/config/window.rs | 29 | ||||
-rw-r--r-- | alacritty/src/display/window.rs | 73 | ||||
-rw-r--r-- | alacritty/src/event.rs | 5 | ||||
-rw-r--r-- | alacritty/src/input.rs | 6 | ||||
-rw-r--r-- | alacritty/src/main.rs | 2 | ||||
-rw-r--r-- | alacritty/src/renderer/platform.rs | 4 | ||||
-rw-r--r-- | alacritty/src/window_context.rs | 10 |
8 files changed, 65 insertions, 70 deletions
diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index f58097cf..29ff2c4c 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -44,7 +44,9 @@ pub struct UiConfig { pub debug: Debug, /// Send escape sequences using the alt key. - pub alt_send_esc: bool, + #[config(removed = "It's now always set to 'true'. If you're on macOS use \ + 'window.option_as_alt' to alter behavior of Option")] + pub alt_send_esc: Option<bool>, /// Live config reload. pub live_config_reload: bool, @@ -88,7 +90,7 @@ impl Default for UiConfig { fn default() -> Self { Self { live_config_reload: true, - alt_send_esc: true, + alt_send_esc: Default::default(), #[cfg(unix)] ipc_socket: true, font: Default::default(), diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs index f1a74232..476172d1 100644 --- a/alacritty/src/config/window.rs +++ b/alacritty/src/config/window.rs @@ -4,7 +4,10 @@ use std::os::raw::c_ulong; use log::{error, warn}; use serde::de::{self, MapAccess, Visitor}; use serde::{Deserialize, Deserializer, Serialize}; -use winit::window::Fullscreen; +use winit::window::{Fullscreen, Theme}; + +#[cfg(target_os = "macos")] +use winit::platform::macos::OptionAsAlt; use alacritty_config_derive::{ConfigDeserialize, SerdeReplace}; use alacritty_terminal::config::{Percentage, LOG_TARGET_CONFIG}; @@ -30,14 +33,8 @@ pub struct WindowConfig { #[config(skip)] pub embed: Option<c_ulong>, - /// GTK theme variant. - #[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>, + pub decorations_theme_variant: Option<Theme>, /// Spread out additional padding evenly. pub dynamic_padding: bool, @@ -52,6 +49,10 @@ pub struct WindowConfig { /// Background opacity from 0.0 to 1.0. pub opacity: Percentage, + /// Controls which `Option` key should be treated as `Alt`. + #[cfg(target_os = "macos")] + pub option_as_alt: OptionAsAlt, + /// Pixel padding. padding: Delta<u8>, @@ -68,12 +69,13 @@ impl Default for WindowConfig { startup_mode: Default::default(), embed: Default::default(), decorations_theme_variant: Default::default(), - gtk_theme_variant: Default::default(), dynamic_padding: Default::default(), identity: Identity::default(), opacity: Default::default(), padding: Default::default(), dimensions: Default::default(), + #[cfg(target_os = "macos")] + option_as_alt: Default::default(), } } } @@ -111,15 +113,6 @@ 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(self.decorations_theme_variant.as_ref()) - .map(|theme| theme.as_str()) - } - #[inline] pub fn padding(&self, scale_factor: f32) -> (f32, f32) { let padding_x = (f32::from(self.padding.x) * scale_factor).floor(); diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 6f9e908a..1aee00e4 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -1,20 +1,20 @@ -#[cfg(not(any(target_os = "macos", windows)))] -use winit::platform::unix::{WindowBuilderExtUnix, WindowExtUnix}; - #[rustfmt::skip] #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] use { wayland_client::protocol::wl_surface::WlSurface, wayland_client::{Attached, EventQueue, Proxy}, - winit::platform::unix::EventLoopWindowTargetExtUnix, - winit::window::Theme, + winit::platform::wayland::{EventLoopWindowTargetExtWayland, WindowExtWayland}, }; +#[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))] +use winit::platform::wayland::WindowBuilderExtWayland; + #[rustfmt::skip] #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] use { std::io::Cursor, + winit::platform::x11::{WindowExtX11, WindowBuilderExtX11}, glutin::platform::x11::X11VisualInfo, x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib}, winit::window::Icon, @@ -30,7 +30,7 @@ use { cocoa::appkit::NSColorSpace, cocoa::base::{id, nil, NO, YES}, objc::{msg_send, sel, sel_impl}, - winit::platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}, + winit::platform::macos::{OptionAsAlt, WindowBuilderExtMacOS, WindowExtMacOS}, }; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; @@ -41,7 +41,8 @@ use winit::monitor::MonitorHandle; #[cfg(windows)] use winit::platform::windows::IconExtWindows; use winit::window::{ - CursorIcon, Fullscreen, UserAttentionType, Window as WinitWindow, WindowBuilder, WindowId, + CursorIcon, Fullscreen, ImePurpose, UserAttentionType, Window as WinitWindow, WindowBuilder, + WindowId, }; use alacritty_terminal::index::Point; @@ -151,7 +152,14 @@ impl Window { .with_position(PhysicalPosition::<i32>::from((position.x, position.y))); } - let window = window_builder.build(event_loop)?; + let window = window_builder + .with_title(&identity.title) + .with_theme(config.window.decorations_theme_variant) + .with_visible(false) + .with_transparent(true) + .with_maximized(config.window.maximized()) + .with_fullscreen(config.window.fullscreen()) + .build(event_loop)?; // Check if we're running Wayland to disable vsync. #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] @@ -165,6 +173,10 @@ impl Window { // Enable IME. window.set_ime_allowed(true); + window.set_ime_purpose(ImePurpose::Terminal); + + // Set initial transparency hint. + window.set_transparent(config.window_opacity() < 1.); #[cfg(target_os = "macos")] use_srgb_color_space(&window); @@ -276,61 +288,33 @@ impl Window { }; let builder = WindowBuilder::new() - .with_title(&identity.title) .with_name(&identity.class.general, &identity.class.instance) - .with_visible(false) - .with_transparent(true) - .with_decorations(window_config.decorations != Decorations::None) - .with_maximized(window_config.maximized()) - .with_fullscreen(window_config.fullscreen()); + .with_decorations(window_config.decorations != Decorations::None); #[cfg(feature = "x11")] let builder = builder.with_window_icon(Some(icon)); #[cfg(feature = "x11")] - let builder = match window_config.decorations_theme_variant() { - Some(val) => builder.with_gtk_theme_variant(val.to_string()), - None => builder, - }; - - #[cfg(feature = "x11")] let builder = match x11_visual { Some(visual) => builder.with_x11_visual(visual.into_raw()), 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 } #[cfg(windows)] - pub fn get_platform_window(identity: &Identity, window_config: &WindowConfig) -> WindowBuilder { + pub fn get_platform_window(_: &Identity, window_config: &WindowConfig) -> WindowBuilder { let icon = winit::window::Icon::from_resource(IDI_ICON, None); WindowBuilder::new() - .with_title(&identity.title) - .with_visible(false) .with_decorations(window_config.decorations != Decorations::None) - .with_transparent(true) - .with_maximized(window_config.maximized()) - .with_fullscreen(window_config.fullscreen()) .with_window_icon(icon.ok()) } #[cfg(target_os = "macos")] - pub fn get_platform_window(identity: &Identity, window_config: &WindowConfig) -> WindowBuilder { - let window = WindowBuilder::new() - .with_title(&identity.title) - .with_visible(false) - .with_transparent(true) - .with_maximized(window_config.maximized()) - .with_fullscreen(window_config.fullscreen()); + pub fn get_platform_window(_: &Identity, window_config: &WindowConfig) -> WindowBuilder { + let window = WindowBuilder::new().with_option_as_alt(window_config.option_as_alt); match window_config.decorations { Decorations::Full => window, @@ -357,6 +341,10 @@ impl Window { self.window.id() } + pub fn set_transparent(&self, transparent: bool) { + self.window.set_transparent(transparent); + } + pub fn set_maximized(&self, maximized: bool) { self.window.set_maximized(maximized); } @@ -380,6 +368,11 @@ impl Window { self.set_simple_fullscreen(!self.window.simple_fullscreen()); } + #[cfg(target_os = "macos")] + pub fn set_option_as_alt(&self, option_as_alt: OptionAsAlt) { + self.window.set_option_as_alt(option_as_alt); + } + pub fn set_fullscreen(&self, fullscreen: bool) { if fullscreen { self.window.set_fullscreen(Some(Fullscreen::Borderless(None))); diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 9388b8a9..768b7a47 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -26,7 +26,7 @@ use winit::event_loop::{ }; use winit::platform::run_return::EventLoopExtRunReturn; #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] -use winit::platform::unix::EventLoopWindowTargetExtUnix; +use winit::platform::wayland::EventLoopWindowTargetExtWayland; use winit::window::WindowId; use crossfont::{self, Size}; @@ -1280,6 +1280,9 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> { }, WindowEvent::KeyboardInput { is_synthetic: true, .. } | WindowEvent::TouchpadPressure { .. } + | WindowEvent::TouchpadMagnify { .. } + | WindowEvent::TouchpadRotate { .. } + | WindowEvent::SmartMagnify { .. } | WindowEvent::ScaleFactorChanged { .. } | WindowEvent::CursorEntered { .. } | WindowEvent::AxisMotion { .. } diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 33be1bf3..d27a8ca7 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -868,11 +868,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { let mut bytes = vec![0; utf8_len]; c.encode_utf8(&mut bytes[..]); - if self.ctx.config().alt_send_esc - && *self.ctx.received_count() == 0 - && self.ctx.modifiers().alt() - && utf8_len == 1 - { + if *self.ctx.received_count() == 0 && self.ctx.modifiers().alt() && utf8_len == 1 { bytes.insert(0, b'\x1b'); } diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 3514b84e..d9d26022 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -25,7 +25,7 @@ use log::info; use windows_sys::Win32::System::Console::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS}; use winit::event_loop::EventLoopBuilder as WinitEventLoopBuilder; #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] -use winit::platform::unix::EventLoopWindowTargetExtUnix; +use winit::platform::x11::EventLoopWindowTargetExtX11; use alacritty_terminal::tty; diff --git a/alacritty/src/renderer/platform.rs b/alacritty/src/renderer/platform.rs index 0a8263c1..77826100 100644 --- a/alacritty/src/renderer/platform.rs +++ b/alacritty/src/renderer/platform.rs @@ -14,7 +14,7 @@ use glutin::surface::{Surface, SurfaceAttributesBuilder, WindowSurface}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; use winit::dpi::PhysicalSize; #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] -use winit::platform::unix; +use winit::platform::x11; /// Create the GL display. pub fn create_gl_display( @@ -28,7 +28,7 @@ pub fn create_gl_display( let preference = DisplayApiPreference::Wgl(Some(_raw_window_handle.unwrap())); #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] - let preference = DisplayApiPreference::GlxThenEgl(Box::new(unix::register_xlib_error_hook)); + let preference = DisplayApiPreference::GlxThenEgl(Box::new(x11::register_xlib_error_hook)); #[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))] let preference = DisplayApiPreference::Egl; diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index 79bc918b..6680f583 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -332,9 +332,17 @@ impl WindowContext { self.display.window.set_title(self.config.window.identity.title.clone()); } + let opaque = self.config.window_opacity() >= 1.; + // Disable shadows for transparent windows on macOS. #[cfg(target_os = "macos")] - self.display.window.set_has_shadow(self.config.window_opacity() >= 1.0); + self.display.window.set_has_shadow(opaque); + + #[cfg(target_os = "macos")] + self.display.window.set_option_as_alt(self.config.window.option_as_alt); + + // Change opacity state. + self.display.window.set_transparent(!opaque); // Update hint keys. self.display.hint_state.update_alphabet(self.config.hints.alphabet()); |