Skip to content

Add ability to customize STARTUPINFO structure in Command API #562

Closed
@federico-terzi

Description

@federico-terzi

Proposal

Problem statement

I need a way to customize the STARTUPINFO structure when spawning a new Command on Windows

Motivating examples or use cases

I'm working on a desktop application which needs to often spawn sub-processes as part of its regular operation. The Command API works well in general, but there's a problem: by default, on Windows every sub-process causes the parent window to display a "spinner" (aka feedback) cursor until the sub-process displays a window. This becomes problematic when the sub-processes are worker processes that will never display a window, as it makes the parent app appear unresponsive due to the spinning cursor.

In Windows land, this is easily solvable by passing the STARTF_FORCEOFFFEEDBACK flag to the STARTUPINFO struct, which is then passed to the CreateProcessW (see SO question)

Unfortunately, while the Command API exposes a creation_flags parameter, this only influences the CreateProcessW flags, not the STARTUPINFO flags.

Solution sketch

Ideally, the Command API should expose some methods to configure the startupinfo_flags individually. After a discussion, we propose to expose the following methods:

// Controls STARTF_RUNFULLSCREEN
fn startupinfo_fullscreen(&mut self, enabled: bool)

// Controls STARTF_UNTRUSTEDSOURCE
fn startupinfo_untrusted_source(&mut self, enabled: bool)

// Controls STARTF_FORCEONFEEDBACK and STARTF_FORCEOFFFEEDBACK
fn startupinfo_force_feedback(&mut self, enabled: Option<bool>)

The STARTUPINFO struct accepts also other flags, but their use is less straightforward as they have side-effects and relationships with other fields, so they can't be changed in isolation (see follow-up comment from @joshtriplett for more details).

Alternatives

For this specific problem, I'm using a workaround to post a dummy message on the sub-process (see SO question). This unfortunately still causes the loading cursor to appear for a fraction of a second, so it's not a solution.

Links and related work

I believe this would be a great addition to the standard library, as it's similar to the existing creation_flags argument

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions