mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-23 18:01:12 +01:00
fix(wm): pass *const u8 to enum_display_devices
Thanks to @ids1024 for pointing out that the failing system calls were likely due to optimizations being made with the release profile's opt-level=3 and to @saethlin for pointing out that in the previous commit I was returning a pointer to a temporary that was about to be deallocated. https://fosstodon.org/@ids1024/111627094548141620 https://hachyderm.io/@saethlin/111627135615930244 With this commit, the display ids are now successfully returned from calls to EnumDisplayDevicesA on release builds.
This commit is contained in:
@@ -242,13 +242,12 @@ impl WindowsApi {
|
||||
|
||||
pub fn enum_display_devices(
|
||||
index: u32,
|
||||
lp_device: Option<[u8; 32]>,
|
||||
lp_device: Option<*const u8>,
|
||||
) -> Result<DISPLAY_DEVICEA> {
|
||||
#[allow(clippy::option_if_let_else)]
|
||||
let lp_device = if let Some(lp_device) = lp_device {
|
||||
PCSTR::from_raw(lp_device.as_ptr())
|
||||
} else {
|
||||
PCSTR::null()
|
||||
let lp_device = match lp_device {
|
||||
None => PCSTR::null(),
|
||||
Some(lp_device) => PCSTR(lp_device),
|
||||
};
|
||||
|
||||
let mut display_device = DISPLAY_DEVICEA {
|
||||
|
||||
@@ -85,7 +85,8 @@ pub extern "system" fn enum_display_monitor(
|
||||
.to_string();
|
||||
|
||||
if clean_name.eq(m.name()) {
|
||||
if let Ok(device) = WindowsApi::enum_display_devices(0, Some(d.DeviceName)) {
|
||||
if let Ok(device) = WindowsApi::enum_display_devices(0, Some(d.DeviceName.as_ptr()))
|
||||
{
|
||||
let id = String::from_utf8_lossy(&device.DeviceID);
|
||||
let clean_id = id.replace('\u{0000}', "");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user