Skip to content

Commit

Permalink
#43 GetDisplays
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Nov 28, 2024
1 parent 8eb09dd commit 1c53924
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/sdl3/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,23 @@ impl VideoSubsystem {
}
}

#[doc(alias = "SDL_GetDisplays")]
pub fn displays(&self) -> Result<Vec<sys::video::SDL_DisplayID>, String> {
unsafe {
let mut count: c_int = 0;
let displays_ptr = sys::video::SDL_GetDisplays(&mut count);
if displays_ptr.is_null() {
return Err(get_error());
}

let displays_slice = std::slice::from_raw_parts(displays_ptr, count as usize);
let displays_vec = displays_slice.to_vec();
SDL_free(displays_ptr as *mut c_void);

Ok(displays_vec)
}
}

/// Get the name of the display at the index `display_name`.
///
/// Will return an error if the index is out of bounds or if SDL experienced a failure; inspect
Expand Down

0 comments on commit 1c53924

Please sign in to comment.