mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Make use of glutin wayland/x11 features
This should allow users that are not using Wayland/X11 to reduce the resulted binary size and compilation times.
This commit is contained in:
parent
56e0f5bb05
commit
721f789b5f
7 changed files with 98 additions and 68 deletions
|
@ -12,10 +12,16 @@ sources:
|
||||||
tasks:
|
tasks:
|
||||||
- rustup: |
|
- rustup: |
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
|
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
|
||||||
- 1-43-1: |
|
|
||||||
$HOME/.cargo/bin/rustup toolchain install --profile minimal 1.43.1
|
$HOME/.cargo/bin/rustup toolchain install --profile minimal 1.43.1
|
||||||
|
- 1-43-1: |
|
||||||
cd alacritty
|
cd alacritty
|
||||||
$HOME/.cargo/bin/cargo +1.43.1 test
|
$HOME/.cargo/bin/cargo +1.43.1 test
|
||||||
|
- 1-43-1-wayland: |
|
||||||
|
cd alacritty/alacritty
|
||||||
|
$HOME/.cargo/bin/cargo +1.43.1 test --no-default-features --features=wayland
|
||||||
|
- 1-43-1-x11: |
|
||||||
|
cd alacritty/alacritty
|
||||||
|
$HOME/.cargo/bin/cargo +1.43.1 test --no-default-features --features=x11
|
||||||
- stable: |
|
- stable: |
|
||||||
cd alacritty
|
cd alacritty
|
||||||
$HOME/.cargo/bin/cargo +stable test
|
$HOME/.cargo/bin/cargo +stable test
|
||||||
|
|
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -847,9 +847,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glutin"
|
name = "glutin"
|
||||||
version = "0.25.0"
|
version = "0.25.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed94c05751b6948879d2b15d49930e16ecc0144e51fcb8cd873686d6c4b5ebed"
|
checksum = "d8bae26a39a728b003e9fad473ea89527de0de050143b4df866f18bb154bc86e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android_glue",
|
"android_glue",
|
||||||
"cgl",
|
"cgl",
|
||||||
|
|
|
@ -21,7 +21,7 @@ fnv = "1"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.8"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
glutin = { version = "0.25.0", features = ["serde"] }
|
glutin = { version = "0.25.1", default-features = false, features = ["serde"] }
|
||||||
notify = "4"
|
notify = "4"
|
||||||
parking_lot = "0.11.0"
|
parking_lot = "0.11.0"
|
||||||
crossfont = { version = "0.1.0", features = ["force_system_fontconfig"] }
|
crossfont = { version = "0.1.0", features = ["force_system_fontconfig"] }
|
||||||
|
@ -47,8 +47,8 @@ objc = "0.2.2"
|
||||||
dirs = "2.0.2"
|
dirs = "2.0.2"
|
||||||
|
|
||||||
[target.'cfg(not(any(target_os="windows", target_os="macos")))'.dependencies]
|
[target.'cfg(not(any(target_os="windows", target_os="macos")))'.dependencies]
|
||||||
x11-dl = "2"
|
x11-dl = { version = "2", optional = true }
|
||||||
wayland-client = { version = "0.28.0", features = ["dlopen"] }
|
wayland-client = { version = "0.28.0", features = ["dlopen"], optional = true }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3.7", features = ["impl-default", "wincon"]}
|
winapi = { version = "0.3.7", features = ["impl-default", "wincon"]}
|
||||||
|
@ -58,8 +58,8 @@ embed-resource = "1.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wayland", "x11", "winpty"]
|
default = ["wayland", "x11", "winpty"]
|
||||||
x11 = ["copypasta/x11"]
|
x11 = ["copypasta/x11", "glutin/x11", "x11-dl"]
|
||||||
wayland = ["copypasta/wayland"]
|
wayland = ["copypasta/wayland", "glutin/wayland", "wayland-client"]
|
||||||
winpty = ["alacritty_terminal/winpty"]
|
winpty = ["alacritty_terminal/winpty"]
|
||||||
# Enabling this feature makes shaders automatically reload when changed
|
# Enabling this feature makes shaders automatically reload when changed
|
||||||
live-shader-reload = []
|
live-shader-reload = []
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::fmt::{self, Formatter};
|
use std::fmt::{self, Formatter};
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use glutin::window::CursorIcon;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use parking_lot::MutexGuard;
|
use parking_lot::MutexGuard;
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
use wayland_client::{Display as WaylandDisplay, EventQueue};
|
use wayland_client::{Display as WaylandDisplay, EventQueue};
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -154,14 +154,15 @@ pub struct Display {
|
||||||
/// Currently highlighted URL.
|
/// Currently highlighted URL.
|
||||||
pub highlighted_url: Option<Url>,
|
pub highlighted_url: Option<Url>,
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
pub wayland_event_queue: Option<EventQueue>,
|
pub wayland_event_queue: Option<EventQueue>,
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "macos", windows)))]
|
||||||
|
pub is_x11: bool,
|
||||||
|
|
||||||
renderer: QuadRenderer,
|
renderer: QuadRenderer,
|
||||||
glyph_cache: GlyphCache,
|
glyph_cache: GlyphCache,
|
||||||
meter: Meter,
|
meter: Meter,
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
|
||||||
is_x11: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display {
|
impl Display {
|
||||||
|
@ -184,11 +185,11 @@ impl Display {
|
||||||
debug!("Estimated window size: {:?}", estimated_size);
|
debug!("Estimated window size: {:?}", estimated_size);
|
||||||
debug!("Estimated cell size: {} x {}", cell_width, cell_height);
|
debug!("Estimated cell size: {} x {}", cell_width, cell_height);
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
let mut wayland_event_queue = None;
|
let mut wayland_event_queue = None;
|
||||||
|
|
||||||
// Initialize Wayland event queue, to handle Wayland callbacks.
|
// Initialize Wayland event queue, to handle Wayland callbacks.
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
if let Some(display) = event_loop.wayland_display() {
|
if let Some(display) = event_loop.wayland_display() {
|
||||||
let display = unsafe { WaylandDisplay::from_external_display(display as _) };
|
let display = unsafe { WaylandDisplay::from_external_display(display as _) };
|
||||||
wayland_event_queue = Some(display.create_event_queue());
|
wayland_event_queue = Some(display.create_event_queue());
|
||||||
|
@ -199,7 +200,7 @@ impl Display {
|
||||||
event_loop,
|
event_loop,
|
||||||
&config,
|
&config,
|
||||||
estimated_size,
|
estimated_size,
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
wayland_event_queue.as_ref(),
|
wayland_event_queue.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -253,8 +254,10 @@ impl Display {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
set_font_smoothing(config.ui_config.font.use_thin_strokes());
|
set_font_smoothing(config.ui_config.font.use_thin_strokes());
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
let is_x11 = event_loop.is_x11();
|
let is_x11 = event_loop.is_x11();
|
||||||
|
#[cfg(not(any(feature = "x11", target_os = "macos", windows)))]
|
||||||
|
let is_x11 = false;
|
||||||
|
|
||||||
// On Wayland we can safely ignore this call, since the window isn't visible until you
|
// On Wayland we can safely ignore this call, since the window isn't visible until you
|
||||||
// actually draw something into it and commit those changes.
|
// actually draw something into it and commit those changes.
|
||||||
|
@ -296,7 +299,7 @@ impl Display {
|
||||||
highlighted_url: None,
|
highlighted_url: None,
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(not(any(target_os = "macos", windows)))]
|
||||||
is_x11,
|
is_x11,
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
wayland_event_queue,
|
wayland_event_queue,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -582,12 +585,12 @@ impl Display {
|
||||||
|
|
||||||
// Frame event should be requested before swaping buffers, since it requires surface
|
// Frame event should be requested before swaping buffers, since it requires surface
|
||||||
// `commit`, which is done by swap buffers under the hood.
|
// `commit`, which is done by swap buffers under the hood.
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
self.request_frame(&self.window);
|
self.request_frame(&self.window);
|
||||||
|
|
||||||
self.window.swap_buffers();
|
self.window.swap_buffers();
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
if self.is_x11 {
|
if self.is_x11 {
|
||||||
// On X11 `swap_buffers` does not block for vsync. However the next OpenGl command
|
// On X11 `swap_buffers` does not block for vsync. However the next OpenGl command
|
||||||
// will block to synchronize (this is `glClear` in Alacritty), which causes a
|
// will block to synchronize (this is `glClear` in Alacritty), which causes a
|
||||||
|
@ -662,7 +665,7 @@ impl Display {
|
||||||
|
|
||||||
/// Requst a new frame for a window on Wayland.
|
/// Requst a new frame for a window on Wayland.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
fn request_frame(&self, window: &Window) {
|
fn request_frame(&self, window: &Window) {
|
||||||
let surface = match window.wayland_surface() {
|
let surface = match window.wayland_surface() {
|
||||||
Some(surface) => surface,
|
Some(surface) => surface,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use glutin::dpi::PhysicalSize;
|
||||||
use glutin::event::{ElementState, Event as GlutinEvent, ModifiersState, MouseButton, WindowEvent};
|
use glutin::event::{ElementState, Event as GlutinEvent, ModifiersState, MouseButton, WindowEvent};
|
||||||
use glutin::event_loop::{ControlFlow, EventLoop, EventLoopProxy, EventLoopWindowTarget};
|
use glutin::event_loop::{ControlFlow, EventLoop, EventLoopProxy, EventLoopWindowTarget};
|
||||||
use glutin::platform::desktop::EventLoopExtDesktop;
|
use glutin::platform::desktop::EventLoopExtDesktop;
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
use glutin::platform::unix::EventLoopWindowTargetExtUnix;
|
use glutin::platform::unix::EventLoopWindowTargetExtUnix;
|
||||||
use log::info;
|
use log::info;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
|
@ -749,7 +749,7 @@ impl<N: Notify + OnResize> Processor<N> {
|
||||||
|
|
||||||
/// Return `true` if `event_queue` is empty, `false` otherwise.
|
/// Return `true` if `event_queue` is empty, `false` otherwise.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
fn event_queue_empty(&mut self) -> bool {
|
fn event_queue_empty(&mut self) -> bool {
|
||||||
let wayland_event_queue = match self.display.wayland_event_queue.as_mut() {
|
let wayland_event_queue = match self.display.wayland_event_queue.as_mut() {
|
||||||
Some(wayland_event_queue) => wayland_event_queue,
|
Some(wayland_event_queue) => wayland_event_queue,
|
||||||
|
@ -767,7 +767,7 @@ impl<N: Notify + OnResize> Processor<N> {
|
||||||
|
|
||||||
/// Return `true` if `event_queue` is empty, `false` otherwise.
|
/// Return `true` if `event_queue` is empty, `false` otherwise.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(any(target_os = "macos", windows))]
|
#[cfg(any(target_os = "macos", windows, not(feature = "wayland")))]
|
||||||
fn event_queue_empty(&mut self) -> bool {
|
fn event_queue_empty(&mut self) -> bool {
|
||||||
self.event_queue.is_empty()
|
self.event_queue.is_empty()
|
||||||
}
|
}
|
||||||
|
@ -863,7 +863,7 @@ impl<N: Notify + OnResize> Processor<N> {
|
||||||
|
|
||||||
// Skip rendering on Wayland until we get frame event from compositor.
|
// Skip rendering on Wayland until we get frame event from compositor.
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(not(any(target_os = "macos", windows)))]
|
||||||
if event_loop.is_wayland() && !self.display.window.should_draw.load(Ordering::Relaxed) {
|
if !self.display.is_x11 && !self.display.window.should_draw.load(Ordering::Relaxed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1114,7 +1114,7 @@ impl<N: Notify + OnResize> Processor<N> {
|
||||||
processor.ctx.window.set_title(&config.ui_config.window.title);
|
processor.ctx.window.set_title(&config.ui_config.window.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
if processor.ctx.event_loop.is_wayland() {
|
if processor.ctx.event_loop.is_wayland() {
|
||||||
processor.ctx.window.set_wayland_theme(&config.colors);
|
processor.ctx.window.set_wayland_theme(&config.colors);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ mod scheduler;
|
||||||
mod url;
|
mod url;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
mod wayland_theme;
|
mod wayland_theme;
|
||||||
|
|
||||||
mod gl {
|
mod gl {
|
||||||
|
@ -160,10 +160,7 @@ fn run(
|
||||||
// The PTY forks a process to run the shell on the slave side of the
|
// The PTY forks a process to run the shell on the slave side of the
|
||||||
// pseudoterminal. A file descriptor for the master side is retained for
|
// pseudoterminal. A file descriptor for the master side is retained for
|
||||||
// reading/writing to the shell.
|
// reading/writing to the shell.
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
|
||||||
let pty = tty::new(&config, &display.size_info, display.window.x11_window_id());
|
let pty = tty::new(&config, &display.size_info, display.window.x11_window_id());
|
||||||
#[cfg(any(target_os = "macos", windows))]
|
|
||||||
let pty = tty::new(&config, &display.size_info, None);
|
|
||||||
|
|
||||||
// Create the pseudoterminal I/O loop.
|
// Create the pseudoterminal I/O loop.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(not(any(target_os = "macos", windows)))]
|
||||||
use {
|
use {
|
||||||
std::ffi::c_void,
|
|
||||||
std::os::raw::c_ulong,
|
|
||||||
std::sync::atomic::AtomicBool,
|
std::sync::atomic::AtomicBool,
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
|
|
||||||
glutin::platform::unix::{EventLoopWindowTargetExtUnix, WindowBuilderExtUnix, WindowExtUnix},
|
glutin::platform::unix::{EventLoopWindowTargetExtUnix, WindowBuilderExtUnix, WindowExtUnix},
|
||||||
image::ImageFormat,
|
image::ImageFormat,
|
||||||
log::error,
|
};
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
|
use {
|
||||||
wayland_client::protocol::wl_surface::WlSurface,
|
wayland_client::protocol::wl_surface::WlSurface,
|
||||||
wayland_client::{Attached, EventQueue, Proxy},
|
wayland_client::{Attached, EventQueue, Proxy},
|
||||||
x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib},
|
|
||||||
|
|
||||||
alacritty_terminal::config::Colors,
|
alacritty_terminal::config::Colors,
|
||||||
|
|
||||||
crate::wayland_theme::AlacrittyWaylandTheme,
|
crate::wayland_theme::AlacrittyWaylandTheme,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
|
use x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib};
|
||||||
|
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
|
||||||
use glutin::dpi::{PhysicalPosition, PhysicalSize};
|
use glutin::dpi::{PhysicalPosition, PhysicalSize};
|
||||||
|
@ -134,7 +138,7 @@ pub struct Window {
|
||||||
pub should_draw: Arc<AtomicBool>,
|
pub should_draw: Arc<AtomicBool>,
|
||||||
|
|
||||||
/// Attached Wayland surface to request new frame events.
|
/// Attached Wayland surface to request new frame events.
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
pub wayland_surface: Option<Attached<WlSurface>>,
|
pub wayland_surface: Option<Attached<WlSurface>>,
|
||||||
|
|
||||||
/// Cached DPR for quickly scaling pixel sizes.
|
/// Cached DPR for quickly scaling pixel sizes.
|
||||||
|
@ -153,20 +157,23 @@ impl Window {
|
||||||
event_loop: &EventLoop<E>,
|
event_loop: &EventLoop<E>,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
size: Option<PhysicalSize<u32>>,
|
size: Option<PhysicalSize<u32>>,
|
||||||
#[cfg(not(any(target_os = "macos", windows)))] wayland_event_queue: Option<&EventQueue>,
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
|
wayland_event_queue: Option<&EventQueue>,
|
||||||
) -> Result<Window> {
|
) -> Result<Window> {
|
||||||
let window_config = &config.ui_config.window;
|
let window_config = &config.ui_config.window;
|
||||||
let window_builder = Window::get_platform_window(&window_config.title, &window_config);
|
let window_builder = Window::get_platform_window(&window_config.title, &window_config);
|
||||||
|
|
||||||
// Disable vsync on Wayland.
|
// Check if we're running Wayland to disable vsync.
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
let vsync = !event_loop.is_wayland();
|
let is_wayland = event_loop.is_wayland();
|
||||||
#[cfg(any(target_os = "macos", windows))]
|
#[cfg(any(target_os = "macos", windows, not(feature = "wayland")))]
|
||||||
let vsync = true;
|
let is_wayland = false;
|
||||||
|
|
||||||
let windowed_context =
|
let windowed_context =
|
||||||
create_gl_window(window_builder.clone(), &event_loop, false, vsync, size)
|
create_gl_window(window_builder.clone(), &event_loop, false, !is_wayland, size)
|
||||||
.or_else(|_| create_gl_window(window_builder, &event_loop, true, vsync, size))?;
|
.or_else(|_| {
|
||||||
|
create_gl_window(window_builder, &event_loop, true, !is_wayland, size)
|
||||||
|
})?;
|
||||||
|
|
||||||
// Text cursor.
|
// Text cursor.
|
||||||
let current_mouse_cursor = CursorIcon::Text;
|
let current_mouse_cursor = CursorIcon::Text;
|
||||||
|
@ -175,16 +182,19 @@ impl Window {
|
||||||
// Set OpenGL symbol loader. This call MUST be after window.make_current on windows.
|
// 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 _);
|
gl::load_with(|symbol| windowed_context.get_proc_address(symbol) as *const _);
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
let mut wayland_surface = None;
|
let mut wayland_surface = None;
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
if event_loop.is_x11() {
|
if !is_wayland {
|
||||||
// On X11, embed the window inside another if the parent ID has been set.
|
// On X11, embed the window inside another if the parent ID has been set.
|
||||||
if let Some(parent_window_id) = window_config.embed {
|
if let Some(parent_window_id) = window_config.embed {
|
||||||
x_embed_window(windowed_context.window(), parent_window_id);
|
x_embed_window(windowed_context.window(), parent_window_id);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
|
if is_wayland {
|
||||||
// Apply client side decorations theme.
|
// Apply client side decorations theme.
|
||||||
let theme = AlacrittyWaylandTheme::new(&config.colors);
|
let theme = AlacrittyWaylandTheme::new(&config.colors);
|
||||||
windowed_context.window().set_wayland_theme(theme);
|
windowed_context.window().set_wayland_theme(theme);
|
||||||
|
@ -203,7 +213,7 @@ impl Window {
|
||||||
windowed_context,
|
windowed_context,
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(not(any(target_os = "macos", windows)))]
|
||||||
should_draw: Arc::new(AtomicBool::new(true)),
|
should_draw: Arc::new(AtomicBool::new(true)),
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
wayland_surface,
|
wayland_surface,
|
||||||
dpr,
|
dpr,
|
||||||
})
|
})
|
||||||
|
@ -254,22 +264,26 @@ impl Window {
|
||||||
|
|
||||||
let class = &window_config.class;
|
let class = &window_config.class;
|
||||||
|
|
||||||
let mut builder = WindowBuilder::new()
|
let builder = WindowBuilder::new()
|
||||||
.with_title(title)
|
.with_title(title)
|
||||||
.with_visible(false)
|
.with_visible(false)
|
||||||
.with_transparent(true)
|
.with_transparent(true)
|
||||||
.with_decorations(window_config.decorations != Decorations::None)
|
.with_decorations(window_config.decorations != Decorations::None)
|
||||||
.with_maximized(window_config.maximized())
|
.with_maximized(window_config.maximized())
|
||||||
.with_fullscreen(window_config.fullscreen())
|
.with_fullscreen(window_config.fullscreen())
|
||||||
.with_window_icon(icon.ok())
|
.with_window_icon(icon.ok());
|
||||||
// X11.
|
|
||||||
.with_class(class.instance.clone(), class.general.clone())
|
|
||||||
// Wayland.
|
|
||||||
.with_app_id(class.instance.clone());
|
|
||||||
|
|
||||||
if let Some(ref val) = window_config.gtk_theme_variant {
|
#[cfg(feature = "wayland")]
|
||||||
builder = builder.with_gtk_theme_variant(val.clone())
|
let builder = builder.with_app_id(class.instance.clone());
|
||||||
}
|
|
||||||
|
#[cfg(feature = "x11")]
|
||||||
|
let builder = builder.with_class(class.instance.clone(), class.general.clone());
|
||||||
|
|
||||||
|
#[cfg(feature = "x11")]
|
||||||
|
let builder = match &window_config.gtk_theme_variant {
|
||||||
|
Some(val) => builder.with_gtk_theme_variant(val.clone()),
|
||||||
|
None => builder,
|
||||||
|
};
|
||||||
|
|
||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
@ -312,7 +326,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
pub fn set_urgent(&self, is_urgent: bool) {
|
pub fn set_urgent(&self, is_urgent: bool) {
|
||||||
self.window().set_urgent(is_urgent);
|
self.window().set_urgent(is_urgent);
|
||||||
}
|
}
|
||||||
|
@ -326,18 +340,23 @@ impl Window {
|
||||||
self.window().request_user_attention(RequestUserAttentionType::Critical);
|
self.window().request_user_attention(RequestUserAttentionType::Critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(any(windows, not(feature = "x11")))]
|
||||||
pub fn set_urgent(&self, _is_urgent: bool) {}
|
pub fn set_urgent(&self, _is_urgent: bool) {}
|
||||||
|
|
||||||
pub fn set_outer_position(&self, pos: PhysicalPosition<i32>) {
|
pub fn set_outer_position(&self, pos: PhysicalPosition<i32>) {
|
||||||
self.window().set_outer_position(pos);
|
self.window().set_outer_position(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
pub fn x11_window_id(&self) -> Option<usize> {
|
pub fn x11_window_id(&self) -> Option<usize> {
|
||||||
self.window().xlib_window().map(|xlib_window| xlib_window as usize)
|
self.window().xlib_window().map(|xlib_window| xlib_window as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", windows, not(feature = "x11")))]
|
||||||
|
pub fn x11_window_id(&self) -> Option<usize> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn window_id(&self) -> WindowId {
|
pub fn window_id(&self) -> WindowId {
|
||||||
self.window().id()
|
self.window().id()
|
||||||
}
|
}
|
||||||
|
@ -374,17 +393,22 @@ impl Window {
|
||||||
self.window().set_simple_fullscreen(simple_fullscreen);
|
self.window().set_simple_fullscreen(simple_fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
pub fn wayland_display(&self) -> Option<*mut c_void> {
|
pub fn wayland_display(&self) -> Option<*mut std::ffi::c_void> {
|
||||||
self.window().wayland_display()
|
self.window().wayland_display()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
#[cfg(any(not(feature = "wayland"), any(target_os = "macos", windows)))]
|
||||||
|
pub fn wayland_display(&self) -> Option<*mut std::ffi::c_void> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
pub fn wayland_surface(&self) -> Option<&Attached<WlSurface>> {
|
pub fn wayland_surface(&self) -> Option<&Attached<WlSurface>> {
|
||||||
self.wayland_surface.as_ref()
|
self.wayland_surface.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
||||||
pub fn set_wayland_theme(&mut self, colors: &Colors) {
|
pub fn set_wayland_theme(&mut self, colors: &Colors) {
|
||||||
self.window().set_wayland_theme(AlacrittyWaylandTheme::new(colors));
|
self.window().set_wayland_theme(AlacrittyWaylandTheme::new(colors));
|
||||||
}
|
}
|
||||||
|
@ -415,8 +439,8 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
fn x_embed_window(window: &GlutinWindow, parent_id: c_ulong) {
|
fn x_embed_window(window: &GlutinWindow, parent_id: std::os::raw::c_ulong) {
|
||||||
let (xlib_display, xlib_window) = match (window.xlib_display(), window.xlib_window()) {
|
let (xlib_display, xlib_window) = match (window.xlib_display(), window.xlib_window()) {
|
||||||
(Some(display), Some(window)) => (display, window),
|
(Some(display), Some(window)) => (display, window),
|
||||||
_ => return,
|
_ => return,
|
||||||
|
@ -449,8 +473,8 @@ fn x_embed_window(window: &GlutinWindow, parent_id: c_ulong) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", windows)))]
|
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
|
||||||
unsafe extern "C" fn xembed_error_handler(_: *mut XDisplay, _: *mut XErrorEvent) -> i32 {
|
unsafe extern "C" fn xembed_error_handler(_: *mut XDisplay, _: *mut XErrorEvent) -> i32 {
|
||||||
error!("Could not embed into specified window.");
|
log::error!("Could not embed into specified window.");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue