windows: get pid with win32 api (#8785)

Ezekiel Warren created

While trying to get mouse/keyboard support in for Windows I ran into a
stack overflow issue related to the pid being `-1`. Getting the proper
process ID seems to fix it.

Release Notes:

- Fixed stack overflow on Windows

Change summary

Cargo.lock                      | 1 +
crates/terminal/Cargo.toml      | 6 ++++++
crates/terminal/src/terminal.rs | 2 +-
3 files changed, 8 insertions(+), 1 deletion(-)

Detailed changes

Cargo.lock 🔗

@@ -9463,6 +9463,7 @@ dependencies = [
  "theme",
  "thiserror",
  "util",
+ "windows 0.53.0",
 ]
 
 [[package]]

crates/terminal/Cargo.toml 🔗

@@ -30,5 +30,11 @@ theme.workspace = true
 thiserror.workspace = true
 util.workspace = true
 
+[target.'cfg(windows)'.dependencies.windows]
+version = "0.53.0"
+features = [
+    "Win32_System_Threading",
+]
+
 [dev-dependencies]
 rand.workspace = true

crates/terminal/src/terminal.rs 🔗

@@ -670,7 +670,7 @@ impl Terminal {
         let mut pid = unsafe { libc::tcgetpgrp(self.shell_fd as i32) };
         // todo("windows")
         #[cfg(windows)]
-        let mut pid = -1;
+        let mut pid = unsafe { windows::Win32::System::Threading::GetCurrentProcessId() } as i32;
         if pid < 0 {
             pid = self.shell_pid as i32;
         }