Skip to content

Instantly share code, notes, and snippets.

@NyCodeGHG
Last active January 29, 2023 21:07
Show Gist options
  • Save NyCodeGHG/a316d185f2a66da25700c878157efe1f to your computer and use it in GitHub Desktop.
Save NyCodeGHG/a316d185f2a66da25700c878157efe1f to your computer and use it in GitHub Desktop.
windows display upside down toggle in rust (πŸš€)
/// Windows Display Upside down toggle
/// Made with <3 by Marie
use std::{mem::MaybeUninit, time::Duration};
use windows::Win32::Graphics::Gdi::{
ChangeDisplaySettingsA, EnumDisplaySettingsA, DEVMODEA, DMDO_180, DMDO_DEFAULT,
DM_DISPLAYORIENTATION, ENUM_CURRENT_SETTINGS,
};
fn main() {
toggle_display();
std::thread::sleep(Duration::from_secs(5));
toggle_display();
}
fn toggle_display() {
let mut mode: MaybeUninit<DEVMODEA> = MaybeUninit::uninit();
unsafe {
EnumDisplaySettingsA(None, ENUM_CURRENT_SETTINGS, mode.as_mut_ptr());
}
let mut mode = unsafe { mode.assume_init() };
if (mode.dmFields | DM_DISPLAYORIENTATION).0 != 0 {
mode.Anonymous1.Anonymous2.dmDisplayOrientation =
if unsafe { mode.Anonymous1.Anonymous2.dmDisplayOrientation } == DMDO_DEFAULT {
DMDO_180
} else {
DMDO_DEFAULT
};
unsafe {
ChangeDisplaySettingsA(
Some(&mode as *const _),
windows::Win32::Graphics::Gdi::CDS_TYPE(0),
)
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment