xref: /aosp_15_r20/external/crosvm/base/src/sys/windows/foreground_window.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use winapi::shared::minwindef::DWORD;
6 use winapi::um::winuser::AllowSetForegroundWindow;
7 
8 use crate::errno_result;
9 use crate::Result;
10 
11 /// Grants the given process id temporary permission to foreground another window. This succeeds
12 /// only when the emulator is in the foreground, and will persist only until the next user
13 /// interaction with the window
give_foregrounding_permission(process_id: DWORD) -> Result<()>14 pub fn give_foregrounding_permission(process_id: DWORD) -> Result<()> {
15     // SAFETY:
16     // Safe because this API does not modify memory, and process_id remains in scope for
17     // the duration of the call.
18     match unsafe { AllowSetForegroundWindow(process_id) } {
19         0 => errno_result(),
20         _ => Ok(()),
21     }
22 }
23