Skip to content

Commit

Permalink
fix(wm): pass *const u8 to enum_display_devices
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Dec 23, 2023
1 parent 657ac44 commit d3bc780
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion komorebi/src/windows_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}', "");

Expand Down

0 comments on commit d3bc780

Please sign in to comment.