Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
I'm playing again with Tk and I needed to grab the screen size and I found how to do it in the Tk::Widget documentation. Unfortunately my eyes spotted the screenmmwidth method which aims to Returns a decimal string giving the width of $widget's screen, in millimeters
I found it interesting but also proved to give me erroneous results. I tested it with the following code:
use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $name = $mw->screen; my $height = $mw->screenheight; my $width = $mw->screenwidth; my $scaling = $mw->scaling; my $heightmm = $mw->screenmmheight; my $widthmm = $mw->screenmmwidth; print <<EOT; screen name $name pixel width $width pixel height $height scaling $scaling mm width $widthmm mm height $heightmm EOT MainLoop;
The outputs on my win7 box is:
screen name :0.0 pixel width 1920 pixel height 1080 scaling 1.33333333333333 mm width 508 # <--- wrong! mm height 286 # <--- wrong!
Everything is correct but last two measures: infact the current monitor where the above mainwindow was displayed is (using the ruler) width 480mm height 270mm
Also to note that on the win10 box a powershell command (apparently not available in win7) gives correct measures:
Get-WmiObject -Namespace root\WMI -ComputerName localhost -Query "sel +ect InstanceName, MaxHorizontalImagesize, MaxVerticalImageSize from W +miMoninitorBasicDisplayParams" ... MaxHorizontalImageSize : 48 MaxVerticalImageSize : 27
UPDATE as vr noted below the above powershell code is mispelled: MaxvwerticalImageSize for MaxVerticalImageSize and now is corrected.
While investigating the issue I discovered that while GetSystemMetrics is available in perl via the Win32 module, in the meantime they invented the DPI Awareness Mode exposed by the call (not available in perl) GetSystemMetricsForDpi
I must also add that my desktop is configured as an extended one covering the big monitor and the laptop one but 508 is not correct anyway even adding the two monitors width.
I'd like to know from you if you get correct mm measures from the above code and on which OS the test was run and with which eventual scaling effect applied.
The Tk::Widget documentation tell about the scaling and the dreadful DPI, 1/72 of inch and whatever:
> A ``point'' is a unit of measurement equal to 1/72 inch. A scaling factor of 1.0 corresponds to 1 pixel per point, which is equivalent to a standard 72 dpi monitor. A scaling factor of 1.25 would mean 1.25 pixels per point, which is the setting for a 90 dpi monitor; setting the scaling factor to 1.25 on a 72 dpi monitor would cause everything in the application to be displayed 1.25 times as large as normal.
Everywhere in my tests I got back a scaling factor of 1.3333333 and if I understand it correctly it means I have 1.33333 points every 1/72 of an inch ( 0,35277777777777775 mm). Again: if I do: total pixels / $widget->scaling() * 0,35277777777777775 I get back my, wrong 508
So: might be this scaling value the root cause of the wrong results I get? It is possible to get a correct meausre?
Well.. I can live without mm measures using only pxels as I have ever done but I'm interested to see if there is a possibility to use screenmmwidth correctly.
In my new application I will disable mm measures by default and let the user able to enable it only using a command line switch and forcing them to read a big warning on screen and, obviously, documenting it.
Thanks for reading
L*
|
|---|