-
Notifications
You must be signed in to change notification settings - Fork 950
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
Expose get_physical_extents for the MonitorId #442
Conversation
Sorry for the wait.
|
@francesca64 I'm working on the windows thing.
I'll test X11 and Wayland on a VM, just to be sure that the implementation is correct. Working on a windows fix. |
Also relevant: https://ofekshilon.com/2011/11/13/reading-monitor-physical-dimensions-or-getting-the-edid-the-right-way/ Windows "smartly" enlarges the monitors size in order to correct for the distance of the eye to the monitor. Which is - in my opinion - a complete shitpile of design. It may work, it may not work. Reading the EDID data from the windows registry seems to be the only proper way to do it, as ridicoulous as this may sound. Note: this function is named |
It seems that this is GLFW's solution: if (IsWindows8Point1OrGreater()) {
widthMM = GetDeviceCaps(dc, HORZSIZE);
heightMM = GetDeviceCaps(dc, VERTSIZE);
} else {
widthMM = (int) (dm.dmPelsWidth * 25.4f / GetDeviceCaps(dc, LOGPIXELSX));
heightMM = (int) (dm.dmPelsHeight * 25.4f / GetDeviceCaps(dc, LOGPIXELSY));
} |
I've verified that this works as expected on macOS. For Windows, I assume that's not finished yet. |
Yeah, I haven't had much time to work on this... I'm basically trying to port the solution presented here: https://ofekshilon.com/2014/06/19/reading-specific-monitor-dimensions/ - this way it'll work on all versions on Windows and with multiple monitors, too. |
55299ce
to
95e7c01
Compare
DO NOT MERGE THIS YET
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.
Two minor nits ^^
|
||
#[inline] | ||
pub fn get_physical_extents(&self) -> Option<(u64, u64)> { | ||
match self { |
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.
Should match on *self
// Find the display_device with the correct monitor name | ||
let display_device = get_display_device_from_monitor_name(monitor_name)?; | ||
let device_id = wchar_as_string(&display_device.DeviceID[..]); | ||
println!("device id - {:?}, monitor name: {:?}", device_id, monitor_name); |
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.
Should be removed or replaced by logging.
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.
Thanks for helping out, but this PR is WIP, so I don't think this is pertinent.
(Also, winit has no logging infrastructure whatsoever, so your proposed alternative would be something of an undertaking. If you want winit to have logging sooner, then I recommend opening an issue so everyone has a chance to argue about whether or not to use slog
. It's something I've been meaning to do, but I've been busy.)
let app: id = msg_send![Class::get("UIApplication")?, sharedApplication]; | ||
let delegate: id = msg_send![app, delegate]; | ||
let state: *mut c_void = *(&*delegate).get_ivar("glutinState"); | ||
let state = state as *mut DelegateState; |
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.
Okay, I've had a chance to work on iOS now. I don't believe this needs to be wrapped in setjmp
, and you can just use self.delegate_state
instead of re-retrieving everything.
let scale = (*state).scale; | ||
let width = (*state).size.0; | ||
let height = (*state).size.1; | ||
Some(((width as f32 * scale) as u64, (height as f32 * scale) as u64)) |
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.
and note that converting a float to an integer doesn't automatically round. Is this what you wanted?
@@ -86,6 +89,7 @@ pub fn get_available_monitors(x: &Arc<XConnection>) -> Vec<MonitorId> { | |||
dimensions: ((*crtc).width as u32, (*crtc).height as u32), | |||
position: ((*crtc).x as i32, (*crtc).y as i32), | |||
primary: true, | |||
extents_mm: (x_mm as u64, y_mm as u64), |
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.
Fun fact: these can sometimes be 0. #543
I'm not sure if you've lost patience with us yet, but proper multi-plat DPI support will be landing soon so you'll be in for a bit of a rebase. By "proper", I mean "proper except for Android", since it doesn't look like I can get access to the DPI factor without rust-mobile/android-rs-glue#116... if I'm wrong, please let me know. |
Oh I haven't, it's just that the reason why I needed this in the first place, which is webrender, has "fixed itself" because I noticed that I mixed up pixels and points: servo/webrender#2596 (comment) So for my use-case, I don't really need it anymore... I'll definitely wait until proper DPI is done, then maybe I can get some redundancy out. |
Proper DPI is over here #548, so it will probably be out in a week or so (though I should know better than to say things like that). |
This PR hasn't had any activity for over a year! If this is still relevant, please rebase this PR against master and reopen it. Thanks! |
At least on Windows, X11, Wayland, macOS and iOS, this new function returns the physical size of the screen in millimeter. On Android, I can't implement it because there is no way for me to the access to the JavaVM. This is waiting on rust-mobile/android-rs-glue#116. I need this for two reasons:
I haven't tested that the function actually returns the value in millimeter, though, just that it compiles.