Hello folks!

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

tests

To note that first and second test were run using a different pc so no the same graphical card was used.

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.

Q1 - do you have back correct mm measures using the above perl code?

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.

Q2 - what about the $widget->scaling()?

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?

conclusions

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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Tk screen and monitor size in mm, DPI and scaling by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.