diff options
author | killian <killiancharrier8@gmail.com> | 2022-09-30 13:49:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 11:49:02 +0000 |
commit | e9ee8dcd9f53096a0096c01b5027d7584376cbd2 (patch) | |
tree | 4163304f1e99f878bef7ff5a451f88c8c9571548 /alacritty_terminal/src | |
parent | c5ae05e810a5866a9133b2e88edba3a42706319f (diff) | |
download | alacritty-e9ee8dcd9f53096a0096c01b5027d7584376cbd2.tar.gz alacritty-e9ee8dcd9f53096a0096c01b5027d7584376cbd2.zip |
Migrate from winapi to windows-sys
Diffstat (limited to 'alacritty_terminal/src')
-rw-r--r-- | alacritty_terminal/src/tty/windows/child.rs | 23 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/windows/conpty.rs | 48 |
2 files changed, 38 insertions, 33 deletions
diff --git a/alacritty_terminal/src/tty/windows/child.rs b/alacritty_terminal/src/tty/windows/child.rs index fc163600..91dd1725 100644 --- a/alacritty_terminal/src/tty/windows/child.rs +++ b/alacritty_terminal/src/tty/windows/child.rs @@ -4,14 +4,16 @@ use std::sync::atomic::{AtomicPtr, Ordering}; use mio_extras::channel::{channel, Receiver, Sender}; -use winapi::shared::ntdef::{BOOLEAN, HANDLE, PVOID}; -use winapi::um::winbase::{RegisterWaitForSingleObject, UnregisterWait, INFINITE}; -use winapi::um::winnt::{WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE}; +use windows_sys::Win32::Foundation::{BOOLEAN, HANDLE}; +use windows_sys::Win32::System::Threading::{ + RegisterWaitForSingleObject, UnregisterWait, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE, +}; +use windows_sys::Win32::System::WindowsProgramming::INFINITE; use crate::tty::ChildEvent; /// WinAPI callback to run when child process exits. -extern "system" fn child_exit_callback(ctx: PVOID, timed_out: BOOLEAN) { +extern "system" fn child_exit_callback(ctx: *mut c_void, timed_out: BOOLEAN) { if timed_out != 0 { return; } @@ -29,7 +31,7 @@ impl ChildExitWatcher { pub fn new(child_handle: HANDLE) -> Result<ChildExitWatcher, Error> { let (event_tx, event_rx) = channel::<ChildEvent>(); - let mut wait_handle: HANDLE = 0 as HANDLE; + let mut wait_handle: HANDLE = 0; let sender_ref = Box::new(event_tx); let success = unsafe { @@ -37,7 +39,7 @@ impl ChildExitWatcher { &mut wait_handle, child_handle, Some(child_exit_callback), - Box::into_raw(sender_ref) as PVOID, + Box::into_raw(sender_ref).cast(), INFINITE, WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE, ) @@ -46,7 +48,10 @@ impl ChildExitWatcher { if success == 0 { Err(Error::last_os_error()) } else { - Ok(ChildExitWatcher { wait_handle: AtomicPtr::from(wait_handle), event_rx }) + Ok(ChildExitWatcher { + wait_handle: AtomicPtr::from(wait_handle as *mut c_void), + event_rx, + }) } } @@ -58,7 +63,7 @@ impl ChildExitWatcher { impl Drop for ChildExitWatcher { fn drop(&mut self) { unsafe { - UnregisterWait(self.wait_handle.load(Ordering::Relaxed)); + UnregisterWait(self.wait_handle.load(Ordering::Relaxed) as HANDLE); } } } @@ -78,7 +83,7 @@ mod tests { const WAIT_TIMEOUT: Duration = Duration::from_millis(200); let mut child = Command::new("cmd.exe").spawn().unwrap(); - let child_exit_watcher = ChildExitWatcher::new(child.as_raw_handle()).unwrap(); + let child_exit_watcher = ChildExitWatcher::new(child.as_raw_handle() as HANDLE).unwrap(); let mut events = Events::with_capacity(1); let poll = Poll::new().unwrap(); diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs index e856a1b1..3f6349de 100644 --- a/alacritty_terminal/src/tty/windows/conpty.rs +++ b/alacritty_terminal/src/tty/windows/conpty.rs @@ -3,17 +3,17 @@ use std::os::windows::io::IntoRawHandle; use std::{mem, ptr}; use mio_anonymous_pipes::{EventedAnonRead, EventedAnonWrite}; -use winapi::shared::basetsd::{PSIZE_T, SIZE_T}; -use winapi::shared::minwindef::BYTE; -use winapi::shared::ntdef::LPWSTR; -use winapi::shared::winerror::S_OK; -use winapi::um::consoleapi::{ClosePseudoConsole, CreatePseudoConsole, ResizePseudoConsole}; -use winapi::um::processthreadsapi::{ + +use windows_sys::core::PWSTR; +use windows_sys::Win32::Foundation::{HANDLE, S_OK}; +use windows_sys::Win32::System::Console::{ + ClosePseudoConsole, CreatePseudoConsole, ResizePseudoConsole, COORD, HPCON, +}; +use windows_sys::Win32::System::Threading::{ CreateProcessW, InitializeProcThreadAttributeList, UpdateProcThreadAttribute, - PROCESS_INFORMATION, STARTUPINFOW, + EXTENDED_STARTUPINFO_PRESENT, PROCESS_INFORMATION, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, + STARTF_USESTDHANDLES, STARTUPINFOEXW, STARTUPINFOW, }; -use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW}; -use winapi::um::wincontypes::{COORD, HPCON}; use crate::config::PtyConfig; use crate::event::{OnResize, WindowSize}; @@ -39,7 +39,7 @@ impl Drop for Conpty { unsafe impl Send for Conpty {} pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { - let mut pty_handle = 0 as HPCON; + let mut pty_handle: HPCON = 0; // Passing 0 as the size parameter allows the "system default" buffer // size to be used. There may be small performance and memory advantages @@ -52,10 +52,10 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { let result = unsafe { CreatePseudoConsole( window_size.into(), - conin_pty_handle.into_raw_handle(), - conout_pty_handle.into_raw_handle(), + conin_pty_handle.into_raw_handle() as HANDLE, + conout_pty_handle.into_raw_handle() as HANDLE, 0, - &mut pty_handle as *mut HPCON, + &mut pty_handle as *mut _, ) }; @@ -65,11 +65,11 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { // Prepare child process startup info. - let mut size: SIZE_T = 0; + let mut size: usize = 0; - let mut startup_info_ex: STARTUPINFOEXW = Default::default(); + let mut startup_info_ex: STARTUPINFOEXW = unsafe { mem::zeroed() }; - startup_info_ex.StartupInfo.lpTitle = std::ptr::null_mut() as LPWSTR; + startup_info_ex.StartupInfo.lpTitle = std::ptr::null_mut() as PWSTR; startup_info_ex.StartupInfo.cb = mem::size_of::<STARTUPINFOEXW>() as u32; @@ -80,7 +80,7 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { // Create the appropriately sized thread attribute list. unsafe { let failure = - InitializeProcThreadAttributeList(ptr::null_mut(), 1, 0, &mut size as PSIZE_T) > 0; + InitializeProcThreadAttributeList(ptr::null_mut(), 1, 0, &mut size as *mut usize) > 0; // This call was expected to return false. if failure { @@ -88,7 +88,7 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { } } - let mut attr_list: Box<[BYTE]> = vec![0; size].into_boxed_slice(); + let mut attr_list: Box<[u8]> = vec![0; size].into_boxed_slice(); // Set startup info's attribute list & initialize it // @@ -106,7 +106,7 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { startup_info_ex.lpAttributeList, 1, 0, - &mut size as PSIZE_T, + &mut size as *mut usize, ) > 0; if !success { @@ -119,8 +119,8 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { success = UpdateProcThreadAttribute( startup_info_ex.lpAttributeList, 0, - 22 | 0x0002_0000, // PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE. - pty_handle, + PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE as usize, + pty_handle as *mut std::ffi::c_void, mem::size_of::<HPCON>(), ptr::null_mut(), ptr::null_mut(), @@ -134,11 +134,11 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { let cmdline = win32_string(&cmdline(config)); let cwd = config.working_directory.as_ref().map(win32_string); - let mut proc_info: PROCESS_INFORMATION = Default::default(); + let mut proc_info: PROCESS_INFORMATION = unsafe { mem::zeroed() }; unsafe { success = CreateProcessW( ptr::null(), - cmdline.as_ptr() as LPWSTR, + cmdline.as_ptr() as PWSTR, ptr::null_mut(), ptr::null_mut(), false as i32, @@ -158,7 +158,7 @@ pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> { let conout = EventedAnonRead::new(conout); let child_watcher = ChildExitWatcher::new(proc_info.hProcess).unwrap(); - let conpty = Conpty { handle: pty_handle }; + let conpty = Conpty { handle: pty_handle as HPCON }; Some(Pty::new(conpty, conout, conin, child_watcher)) } |