Skip to content

Commit 03912f4

Browse files
authored
Rollup merge of #141013 - federico-terzi:feat/command_startupinfo_windows, r=joboet
Implement methods to set STARTUPINFO flags for Command API on Windows Implements #141010
2 parents 9808b07 + e0b6363 commit 03912f4

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

library/std/src/os/windows/process.rs

+36
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,27 @@ pub trait CommandExt: Sealed {
344344
&mut self,
345345
attribute_list: &ProcThreadAttributeList<'_>,
346346
) -> io::Result<process::Child>;
347+
348+
/// When true, sets the `STARTF_RUNFULLSCREEN` flag on the [STARTUPINFO][1] struct before passing it to `CreateProcess`.
349+
///
350+
/// [1]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfoa
351+
#[unstable(feature = "windows_process_extensions_startupinfo", issue = "141010")]
352+
fn startupinfo_fullscreen(&mut self, enabled: bool) -> &mut process::Command;
353+
354+
/// When true, sets the `STARTF_UNTRUSTEDSOURCE` flag on the [STARTUPINFO][1] struct before passing it to `CreateProcess`.
355+
///
356+
/// [1]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfoa
357+
#[unstable(feature = "windows_process_extensions_startupinfo", issue = "141010")]
358+
fn startupinfo_untrusted_source(&mut self, enabled: bool) -> &mut process::Command;
359+
360+
/// When specified, sets the following flags on the [STARTUPINFO][1] struct before passing it to `CreateProcess`:
361+
/// - If `Some(true)`, sets `STARTF_FORCEONFEEDBACK`
362+
/// - If `Some(false)`, sets `STARTF_FORCEOFFFEEDBACK`
363+
/// - If `None`, does not set any flags
364+
///
365+
/// [1]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfoa
366+
#[unstable(feature = "windows_process_extensions_startupinfo", issue = "141010")]
367+
fn startupinfo_force_feedback(&mut self, enabled: Option<bool>) -> &mut process::Command;
347368
}
348369

349370
#[stable(feature = "windows_process_extensions", since = "1.16.0")]
@@ -385,6 +406,21 @@ impl CommandExt for process::Command {
385406
.spawn_with_attributes(sys::process::Stdio::Inherit, true, Some(attribute_list))
386407
.map(process::Child::from_inner)
387408
}
409+
410+
fn startupinfo_fullscreen(&mut self, enabled: bool) -> &mut process::Command {
411+
self.as_inner_mut().startupinfo_fullscreen(enabled);
412+
self
413+
}
414+
415+
fn startupinfo_untrusted_source(&mut self, enabled: bool) -> &mut process::Command {
416+
self.as_inner_mut().startupinfo_untrusted_source(enabled);
417+
self
418+
}
419+
420+
fn startupinfo_force_feedback(&mut self, enabled: Option<bool>) -> &mut process::Command {
421+
self.as_inner_mut().startupinfo_force_feedback(enabled);
422+
self
423+
}
388424
}
389425

390426
#[unstable(feature = "windows_process_extensions_main_thread_handle", issue = "96723")]

library/std/src/sys/process/windows.rs

+36
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ pub struct Command {
155155
stdout: Option<Stdio>,
156156
stderr: Option<Stdio>,
157157
force_quotes_enabled: bool,
158+
startupinfo_fullscreen: bool,
159+
startupinfo_untrusted_source: bool,
160+
startupinfo_force_feedback: Option<bool>,
158161
}
159162

160163
pub enum Stdio {
@@ -186,6 +189,9 @@ impl Command {
186189
stdout: None,
187190
stderr: None,
188191
force_quotes_enabled: false,
192+
startupinfo_fullscreen: false,
193+
startupinfo_untrusted_source: false,
194+
startupinfo_force_feedback: None,
189195
}
190196
}
191197

@@ -222,6 +228,18 @@ impl Command {
222228
self.args.push(Arg::Raw(command_str_to_append.to_os_string()))
223229
}
224230

231+
pub fn startupinfo_fullscreen(&mut self, enabled: bool) {
232+
self.startupinfo_fullscreen = enabled;
233+
}
234+
235+
pub fn startupinfo_untrusted_source(&mut self, enabled: bool) {
236+
self.startupinfo_untrusted_source = enabled;
237+
}
238+
239+
pub fn startupinfo_force_feedback(&mut self, enabled: Option<bool>) {
240+
self.startupinfo_force_feedback = enabled;
241+
}
242+
225243
pub fn get_program(&self) -> &OsStr {
226244
&self.program
227245
}
@@ -343,6 +361,24 @@ impl Command {
343361
si.wShowWindow = cmd_show;
344362
}
345363

364+
if self.startupinfo_fullscreen {
365+
si.dwFlags |= c::STARTF_RUNFULLSCREEN;
366+
}
367+
368+
if self.startupinfo_untrusted_source {
369+
si.dwFlags |= c::STARTF_UNTRUSTEDSOURCE;
370+
}
371+
372+
match self.startupinfo_force_feedback {
373+
Some(true) => {
374+
si.dwFlags |= c::STARTF_FORCEONFEEDBACK;
375+
}
376+
Some(false) => {
377+
si.dwFlags |= c::STARTF_FORCEOFFFEEDBACK;
378+
}
379+
None => {}
380+
}
381+
346382
let si_ptr: *mut c::STARTUPINFOW;
347383

348384
let mut si_ex;

0 commit comments

Comments
 (0)