-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screen Module, window titlebar, position, size, DPI #1037
Changes from 1 commit
5fc5bb8
0c677ef
81412f1
e6aa4d4
98e823d
22b755d
3d52493
6c8ba46
262abc7
69fddf5
196fbe9
adcac2d
11838fc
ecdf087
0e9dbac
0f3f319
e7f0b56
8444bfc
83b2759
ffb743f
bc1f83a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,6 @@ use std::mem::size_of; | |
use crate::screen::Monitor; | ||
use crate::kurbo::Rect; | ||
|
||
static mut MONITORS : Vec<Monitor> = Vec::new(); | ||
|
||
unsafe extern "system" fn monitorenumproc(hmonitor : HMONITOR, _hdc : HDC, _lprect : LPRECT, _lparam : LPARAM) -> BOOL { | ||
let rect = RECT { left: 0, top: 0, right: 0, bottom: 0}; | ||
let mut info = MONITORINFO { cbSize : size_of::<MONITORINFO>() as u32, rcMonitor : rect, rcWork : rect, dwFlags : 0}; | ||
|
@@ -41,21 +39,21 @@ unsafe extern "system" fn monitorenumproc(hmonitor : HMONITOR, _hdc : HDC, _lpre | |
let primary = info.dwFlags == MONITORINFOF_PRIMARY; | ||
let rect = Rect::new(info.rcMonitor.left as f64, info.rcMonitor.top as f64, info.rcMonitor.right as f64, info.rcMonitor.bottom as f64); | ||
let work_rect = Rect::new(info.rcWork.left as f64, info.rcWork.top as f64, info.rcWork.right as f64, info.rcWork.bottom as f64); | ||
let m = Monitor::new(primary, rect, work_rect); | ||
MONITORS.push(m); | ||
let monitors = _lparam as *mut Vec::<Monitor>; | ||
(*monitors).push(Monitor::new(primary, rect, work_rect)); | ||
TRUE | ||
} | ||
|
||
|
||
pub(crate) fn get_monitors() -> Vec<Monitor> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe there is a safety issue here due to the use of static mutable global state, and the fact that this function is exposed up to the user through the Another possibility for the safety concern is to use a Mutex. But that in turn requires once_cell (or lazy_static, we have deps on both), so it's a little long-winded. |
||
unsafe { | ||
MONITORS = Vec::new(); | ||
if EnumDisplayMonitors(null_mut(), null_mut(), Some(monitorenumproc), 0) == 0{ | ||
let monitors = Vec::<Monitor>::new(); | ||
let ptr = &monitors as *const Vec::<Monitor>; | ||
if EnumDisplayMonitors(null_mut(), null_mut(), Some(monitorenumproc), ptr as isize) == 0{ | ||
warn!( | ||
"Failed to Enumerate Display Monitors: {}", | ||
Error::Hr(HRESULT_FROM_WIN32(GetLastError())) | ||
); | ||
}; | ||
MONITORS.clone() | ||
monitors | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,7 @@ pub(crate) fn recti_to_rect(rect: RECT) -> Rect { | |
type GetDpiForSystem = unsafe extern "system" fn() -> UINT; | ||
type GetDpiForWindow = unsafe extern "system" fn(HWND) -> UINT; | ||
type SetProcessDpiAwarenessContext = unsafe extern "system" fn(winapi::shared::windef::DPI_AWARENESS_CONTEXT) -> BOOL; | ||
type GetSystemMetricsForDpi = unsafe extern "system" fn(winapi::ctypes::c_int, UINT) -> winapi::ctypes::c_int; | ||
// from shcore.dll | ||
type GetDpiForMonitor = unsafe extern "system" fn(HMONITOR, MONITOR_DPI_TYPE, *mut UINT, *mut UINT); | ||
type SetProcessDpiAwareness = unsafe extern "system" fn(PROCESS_DPI_AWARENESS) -> HRESULT; | ||
|
@@ -150,6 +151,7 @@ pub struct OptionalFunctions { | |
pub SetProcessDpiAwarenessContext: Option<SetProcessDpiAwarenessContext>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to suggest cleaning this up a bit, but now I'm not sure. We don't currently use |
||
pub GetDpiForMonitor: Option<GetDpiForMonitor>, | ||
pub SetProcessDpiAwareness: Option<SetProcessDpiAwareness>, | ||
pub GetSystemMetricsForDpi: Option<GetSystemMetricsForDpi>, | ||
pub DCompositionCreateDevice2: Option<DCompositionCreateDevice2>, | ||
pub CreateDXGIFactory2: Option<CreateDXGIFactory2>, | ||
} | ||
|
@@ -205,6 +207,7 @@ fn load_optional_functions() -> OptionalFunctions { | |
let mut GetDpiForWindow = None; | ||
let mut SetProcessDpiAwarenessContext = None; | ||
let mut SetProcessDpiAwareness = None; | ||
let mut GetSystemMetricsForDpi = None; | ||
let mut DCompositionCreateDevice2 = None; | ||
let mut CreateDXGIFactory2 = None; | ||
|
||
|
@@ -221,6 +224,7 @@ fn load_optional_functions() -> OptionalFunctions { | |
load_function!(user32, GetDpiForSystem, "10"); | ||
load_function!(user32, GetDpiForWindow, "10"); | ||
load_function!(user32, SetProcessDpiAwarenessContext, "10"); | ||
load_function!(user32, GetSystemMetricsForDpi, "10"); | ||
} | ||
|
||
if !dcomp.is_null() { | ||
|
@@ -237,6 +241,7 @@ fn load_optional_functions() -> OptionalFunctions { | |
SetProcessDpiAwarenessContext, | ||
GetDpiForMonitor, | ||
SetProcessDpiAwareness, | ||
GetSystemMetricsForDpi, | ||
DCompositionCreateDevice2, | ||
CreateDXGIFactory2, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My experience is that putting any additional functionality in the runloop is problematic. The logic doesn't get invoked when the system is using its own runloop, which happens on live resize and also while a file dialog is open. Also, if and when we ever run as a guest (for example as a VST plugin), then we'll also be at the mercy of the host's runloop. But if we use the function sparingly, maybe we're ok.
Also, I think the name "DS_HANDLE_DROPPED" is confusing and should be changed to "BLOCKED" to be consistent with other functions.
See below where I suggest a comment to add.