diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-01-29 22:41:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-29 22:41:15 +0000 |
commit | 73759da0f52f7186181f7284a4c9cb9db0798d59 (patch) | |
tree | f8755ed3d22583b2eaab9c994e5ccc48540e1fde | |
parent | cb46f0e1ac3baf54b15951762bdf8ffaa38d36c3 (diff) | |
download | r-alacritty-73759da0f52f7186181f7284a4c9cb9db0798d59.tar.gz r-alacritty-73759da0f52f7186181f7284a4c9cb9db0798d59.tar.bz2 r-alacritty-73759da0f52f7186181f7284a4c9cb9db0798d59.zip |
Fix segmentation fault on shutdown with Wayland
Fixes #4702.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/clipboard.rs | 42 | ||||
-rw-r--r-- | alacritty/src/display/window.rs | 10 | ||||
-rw-r--r-- | alacritty/src/event.rs | 15 |
4 files changed, 29 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d31bf64c..68b8a16c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Crash due to assertion failure on 32-bit architectures +- Segmentation fault on shutdown with Wayland ### Removed diff --git a/alacritty/src/clipboard.rs b/alacritty/src/clipboard.rs index b9708d6f..dd0a8348 100644 --- a/alacritty/src/clipboard.rs +++ b/alacritty/src/clipboard.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] use std::ffi::c_void; use log::{debug, warn}; @@ -7,9 +7,9 @@ use alacritty_terminal::term::ClipboardType; #[cfg(any(test, not(any(feature = "x11", target_os = "macos", windows))))] use copypasta::nop_clipboard::NopClipboardContext; -#[cfg(all(not(any(target_os = "macos", windows)), feature = "wayland"))] +#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] use copypasta::wayland_clipboard; -#[cfg(all(not(any(target_os = "macos", windows)), feature = "x11"))] +#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] use copypasta::x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext}; #[cfg(any(feature = "x11", target_os = "macos", windows))] use copypasta::ClipboardContext; @@ -21,28 +21,21 @@ pub struct Clipboard { } impl Clipboard { - #[cfg(any(target_os = "macos", windows))] + #[cfg(any(not(feature = "wayland"), target_os = "macos", windows))] pub fn new() -> Self { Self::default() } - #[cfg(not(any(target_os = "macos", windows)))] - pub fn new(_display: Option<*mut c_void>) -> Self { - #[cfg(feature = "wayland")] - if let Some(display) = _display { - let (selection, clipboard) = - unsafe { wayland_clipboard::create_clipboards_from_external(display) }; - return Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) }; + #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] + pub unsafe fn new(display: Option<*mut c_void>) -> Self { + match display { + Some(display) => { + let (selection, clipboard) = + wayland_clipboard::create_clipboards_from_external(display); + Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) } + }, + None => Self::default(), } - - #[cfg(feature = "x11")] - return Self { - clipboard: Box::new(ClipboardContext::new().unwrap()), - selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())), - }; - - #[cfg(not(feature = "x11"))] - return Self::new_nop(); } /// Used for tests and to handle missing clipboard provider when built without the `x11` @@ -55,8 +48,15 @@ impl Clipboard { impl Default for Clipboard { fn default() -> Self { - #[cfg(any(feature = "x11", target_os = "macos", windows))] + #[cfg(any(target_os = "macos", windows))] return Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: None }; + + #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] + return Self { + clipboard: Box::new(ClipboardContext::new().unwrap()), + selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())), + }; + #[cfg(not(any(feature = "x11", target_os = "macos", windows)))] return Self::new_nop(); } diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index b500e8f2..1bd3525a 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -400,16 +400,6 @@ impl Window { } #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] - pub fn wayland_display(&self) -> Option<*mut std::ffi::c_void> { - self.window().wayland_display() - } - - #[cfg(not(any(feature = "wayland", 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>> { self.wayland_surface.as_ref() } diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 0e9ab655..f3fbc699 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -928,7 +928,6 @@ pub struct Processor<N> { mouse: Mouse, received_count: usize, suppress_chars: bool, - clipboard: Clipboard, modifiers: ModifiersState, config: Config, message_buffer: MessageBuffer, @@ -951,11 +950,6 @@ impl<N: Notify + OnResize> Processor<N> { display: Display, cli_options: CLIOptions, ) -> Processor<N> { - #[cfg(not(any(target_os = "macos", windows)))] - let clipboard = Clipboard::new(display.window.wayland_display()); - #[cfg(any(target_os = "macos", windows))] - let clipboard = Clipboard::new(); - Processor { notifier, mouse: Default::default(), @@ -967,7 +961,6 @@ impl<N: Notify + OnResize> Processor<N> { message_buffer, display, event_queue: Vec::new(), - clipboard, search_state: SearchState::new(), cli_options, dirty: false, @@ -1012,6 +1005,12 @@ impl<N: Notify + OnResize> Processor<N> { self.event_queue.push(event.into()); } + // 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))))] + let mut clipboard = unsafe { Clipboard::new(event_loop.wayland_display()) }; + #[cfg(any(not(feature = "wayland"), target_os = "macos", windows))] + let mut clipboard = Clipboard::new(); + event_loop.run_return(|event, event_loop, control_flow| { if self.config.ui_config.debug.print_events { info!("glutin event: {:?}", event); @@ -1067,7 +1066,7 @@ impl<N: Notify + OnResize> Processor<N> { terminal: &mut terminal, notifier: &mut self.notifier, mouse: &mut self.mouse, - clipboard: &mut self.clipboard, + clipboard: &mut clipboard, received_count: &mut self.received_count, suppress_chars: &mut self.suppress_chars, modifiers: &mut self.modifiers, |