Implement set_maximized, get_current_monitor, set_fullscreen and set_decorations for windows (#457)
* Implement set_fullscreen for windows * Implement get_current_monitor for windows * Implement set_maximized * Implement set_decorations for windows * Update CHANGELOG.md * Fixed minor syntax bug for stable rust version * Added support for WindowBuilder::with_maximized * Move all window sized related functions to main thread * Refactor and formatting force_window_active * Remove unused code * Update CHANGELOG.md * Refactor and change keyboard handling code * Reformatting and refactoring * Added back missing link for comment * Fixed set_maximized and set_fullscreen wrong order bug * Call ShowWindow(SW_RESTORE) when restore_saved_window * Sync system maximized status when set_fullscreen * Fixed wrong function name
This commit is contained in:
parent
457c0b7208
commit
bdc01fee1a
7 changed files with 536 additions and 100 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use winapi::ctypes::wchar_t;
|
||||
use winapi::shared::minwindef::{DWORD, LPARAM, BOOL, TRUE};
|
||||
use winapi::shared::windef::{HMONITOR, HDC, LPRECT};
|
||||
use winapi::shared::windef::{HMONITOR, HDC, LPRECT, HWND};
|
||||
use winapi::um::winuser;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
|
@ -87,6 +87,37 @@ impl EventsLoop {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_current_monitor(handle: HWND) -> MonitorId {
|
||||
unsafe {
|
||||
let mut monitor_info: winuser::MONITORINFOEXW = mem::zeroed();
|
||||
monitor_info.cbSize = mem::size_of::<winuser::MONITORINFOEXW>() as DWORD;
|
||||
|
||||
let hmonitor = winuser::MonitorFromWindow(handle, winuser::MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
winuser::GetMonitorInfoW(
|
||||
hmonitor,
|
||||
&mut monitor_info as *mut winuser::MONITORINFOEXW as *mut winuser::MONITORINFO,
|
||||
);
|
||||
|
||||
let place = monitor_info.rcMonitor;
|
||||
let position = (place.left as i32, place.top as i32);
|
||||
let dimensions = (
|
||||
(place.right - place.left) as u32,
|
||||
(place.bottom - place.top) as u32,
|
||||
);
|
||||
|
||||
MonitorId {
|
||||
adapter_name: monitor_info.szDevice,
|
||||
hmonitor: super::monitor::HMonitor(hmonitor),
|
||||
monitor_name: wchar_as_string(&monitor_info.szDevice),
|
||||
primary: monitor_info.dwFlags & winuser::MONITORINFOF_PRIMARY != 0,
|
||||
position,
|
||||
dimensions,
|
||||
hidpi_factor: 1.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_primary_monitor(&self) -> MonitorId {
|
||||
// we simply get all available monitors and return the one with the `MONITORINFOF_PRIMARY` flag
|
||||
// TODO: it is possible to query the win32 API for the primary monitor, this should be done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue