-
Notifications
You must be signed in to change notification settings - Fork 20
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
Windows: Implement resolution
#147
base: main
Are you sure you want to change the base?
Windows: Implement resolution
#147
Conversation
Why
While |
Because I didn't know it existed. The Win32 API is such a chaotic mess of useful functions that something always seems to slip by. |
This is an example that fetchs both pixel resolutions, scaled resolutions and refresh rates. |
There are other interesting things. For example: fetching OS caption without querying WMI: https://github.com/LinusDierheimer/fastfetch/blob/b3da6b0e89c0decb9ea648e1d98a75fa6ac40225/src/detection/os/os_windows.cpp#L34 |
I got an implementation working, thanks for the tip though
Yeah, there are a lot of things that most programs default to calling WMI for that can be found by just using the registry. That's one thing I intend on working on While working on the new implementation, I discovered that |
Implementation Speeds:
Plugged in:
On Battery life:
When heavily throttled (used power plans to downclock CPU to 1.06 GHz to simulate a slow computer)
|
Besides being slow, WMI |
Yeah, I probably should've checked for that before adding it. I've removed the WMI implementation in the most recent commit |
@grtcdr I don't think I'm qualified to review this. I don't have enough experience with windows to comment on this. |
Neither am I, that's okay. I'd appreciate it if someone else (@CarterLi, perhaps) gave a final review before merging. |
Sorry, but I'm not familiar with rust. This is what I got on my MBP
|
Yeah, I probably should've checked the current formatting when implementing it. I've changed the formatting of the output to match the rest of the program.
I can remove the second implementation if you wish, but I don't think it complicates the code much due to the clear separator between the implementations.
A vector has to be used in the selected location due to the need for a while statement instead of an iterator. I was able to use an iterator instead of a vector for the resolution variable, but I found that the implementation caused a significant decrease in readability with no tangible speed improvement. |
It's useless. That's all.
It has nothing to do with vectors or iterators. You call |
src/windows/mod.rs
Outdated
return Ok(resolutions | ||
.iter() | ||
.map( | ||
|resolution| match (resolution.dmDisplayFrequency, resolution.dmLogPixels) { |
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.
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.
Did you test multiple monitors?
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.
Did you try updating the scale factor of your monitors? For me,
dmLogPixels
won't be updated before I restarting my laptap.In addition, according to MSDN,
EnumDisplaySettings
sets only these 5 DEMMODE members.
I didn't before now, and I can confirm that the issue exists for me as well. Along with that, I found that the current implementation doesn't properly get the scale for a second monitor even after a restart. I see a few options moving forward:
- Only show the scaled resolution of the primary monitor and have the bug where it doesn't update as a known issue
- Don't show a scaled resolution
- Do what Fastfetch does and merge the two implementations into a single one that uses
EnumDisplaySettingsW
to get the resolution and refresh rate and usesEnumDisplayMonitors
withoutSetProcessDpiAwareness
to get the scaled resolution. This would likely be about twice as slow, but would add a maximum of a few milliseconds.
I'm going to try implementing option 3 and see how much slower it is.
Did you test multiple monitors?
When a monitor is added or removed, the output correctly updates
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.
There is actually another method by using HDC and GetDeviceCaps.
CarterLi/fastfetch@4d7cb25#diff-1f993416a36137ee7af25d94be4928701d89ca08d9ab322fcb3eb0b5ec6d80b6R39
I dont know if it is faster than EnumDisplayMonitors. The code is much simplier at least.
|resolution| match (resolution.dmDisplayFrequency, resolution.dmLogPixels) { | ||
(0, 0) => format!("{}x{}", resolution.dmPelsWidth, resolution.dmPelsHeight), | ||
(0, _) => format!( | ||
"{}x{} (as {}x{})", |
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.
If the resolution is not scaled. Don't print (as {}x{})
src/windows/mod.rs
Outdated
PCWSTR::null(), | ||
index as u32, | ||
&mut devices[index], | ||
EDD_GET_DEVICE_INTERFACE_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.
If you don't use DISPLAY_DEVICE::DeviceID
, don't set EDD_GET_DEVICE_INTERFACE_NAME
I see what you mean now, I have no idea why I didn't do it like that in the first place. |
I created an implementation of this and the
That also should be fixed now |
No. Although fastfetch has switched to DISPLAY_DEVICEW displayDevice;
//...
HDC hdc = CreateICW(displayDevice.DeviceName, NULL, NULL, NULL);
int width = GetDeviceCaps(hdc, HORZRES);
int height = GetDeviceCaps(hdc, VERTRES);
DeleteDC(hdc); fastfetch has switched to If you don't need these features, you don't need |
Hello, I'm a contributor to https://github.com/lptstr/winfetch (you've talked to the maintainer in #112), and would like to start applying some of the experience I gained there to this project.
SetProcessDpiAwareness
tells the OS to give the program the "real" resolution of each monitor instead of the scaled resolutionEnumDisplayMonitors
to get the information of each monitorGetMonitorInfoW
and store the result in a vectorTODO:
[ ] Implement my method in Fix Resolution Bug lptstr/winfetch#156Only works in admin instances of PowerShell, but I need to test if it's the same for RustIt is the same in Rust, and it seems that the crate WinReg does not anticipate a registry key requiring special permissions as it is not working properly