Monitor DPI for Windows and Mac?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Monitor DPI for Windows and Mac?

Post by FourthWorld » Wed Apr 03, 2024 10:20 pm

LC has a way to obtain DPI (pixel density) on mobile, but I don't believe there's anything in the engine to get that info for desktop platforms. I have a case where on-screen display needs to be of a specific real-world size in inches. I can dig up the AppleScript/Powershell combos needed for stuff like that, but before I spend the time it seemed worth asking:

Anyone here seen a Builder script or other LC extension to obtain DPI for desktop monitors?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Monitor DPI for Windows and Mac?

Post by dunbarx » Wed Apr 03, 2024 10:54 pm

Richard.

You mean the "mobilePixelDensity()"?

Can't you use the screen/card dimensions to determine the number of X and Y pixels on each axis? And if you have that, doesn't that give you the "desktop pixel density"?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Monitor DPI for Windows and Mac?

Post by dunbarx » Wed Apr 03, 2024 11:01 pm

Ah, I see. You do not want to have to rely on using a caliper to measure the actual size of either the screen or the card window dimensions.

Aha.

Craig

stam
Posts: 2688
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Monitor DPI for Windows and Mac?

Post by stam » Thu Apr 04, 2024 12:57 am

FourthWorld wrote:
Wed Apr 03, 2024 10:20 pm
LC has a way to obtain DPI (pixel density) on mobile, but I don't believe there's anything in the engine to get that info for desktop platforms. I have a case where on-screen display needs to be of a specific real-world size in inches. I can dig up the AppleScript/Powershell combos needed for stuff like that, but before I spend the time it seemed worth asking:

Anyone here seen a Builder script or other LC extension to obtain DPI for desktop monitors?
Is pixelScale, systemPixelScale, screenPixelScale or screenPixelScales helpful for this?
Seems like it should be? For multiple monitors the last one seems most appropriate?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Monitor DPI for Windows and Mac?

Post by FourthWorld » Thu Apr 04, 2024 1:12 am

Thanks, but those don't return DPI, just multipliers for pixel doubling on high-res displays.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2688
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Monitor DPI for Windows and Mac?

Post by stam » Thu Apr 04, 2024 7:23 am

According to https://superuser.com/questions/1085734 ... top-screen:

Code: Select all

PPI = sqrt((pixels_horizontal^2 + pixels_vertical^2) / inches_diagonal)
i guess you need a way to get the diagonal dimensions of the screen and know the pixel doubling.

Not sure if that helps?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Monitor DPI for Windows and Mac?

Post by richmond62 » Thu Apr 04, 2024 7:45 am

Here's something as crude as a crude thing.

Code: Select all

on mouseUp
   put item 3 of the screenRect into WIDD
   put item 4 of the screenRect into HITE
   put the pixelScale into sFACTOR
   put WIDD && "x" && HITE into fld "f1"
   put WIDD * sFACTOR into vWIDD
   put HITE * sFACTOR into vHITE
   put vWIDD && "x" && vHITE into fld "f2"
end mouseUp
-
SShot 2024-04-04 at 9.43.15.png
-
Only any good for a machine with a single monitor.
Attachments
SCREENER.livecode.zip
Stack.
(1.07 KiB) Downloaded 10 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Monitor DPI for Windows and Mac?

Post by richmond62 » Thu Apr 04, 2024 9:22 am

Slightly refined (but probably not up to the standard to put in the tank of your HumVee):

Code: Select all

on mouseUp
   put empty into fld "f1"
   put empty into fld "f2"
   put the screenPixelScales into fld "f4"
   put the screenRects into fld "f3"
   put the number of lines in fld "f3" into nSCREENS
   put 1 into SCREAMS
   repeat until SCREAMS > nSCREENS
      put item 3 of line SCREAMS of fld "f3" into WIDD
      put item 4 of line SCREAMS of fld "f3" into HITE
      put line SCREAMS of fld "f4" into sFACTOR
      put WIDD && "x" && HITE into line SCREAMS of fld "f1"
      put WIDD * sFACTOR into vWIDD
      put HITE * sFACTOR into vHITE
      put vWIDD && "x" && vHITE into line SCREAMS of fld "f2"
      add 1 to SCREAMS
   end repeat
end mouseUp
Currently at work, where I have no machine connected to more than 1 monitor . . .

But should (. . . don't hold your breath . . .) give you 'guff' for multiple monitors.
Attachments
SCREENER 2.livecode.zip
Stack.
(1.27 KiB) Downloaded 13 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Monitor DPI for Windows and Mac?

Post by richmond62 » Thu Apr 04, 2024 9:32 am

Of course my stack(s) doesn't provide the DPI, but it does supply the scale factor, and, for the sake of argument, as I have a 27" Retina display iMac with 2 "bog normal" monitors riding 'side-saddle' (one on each side), I expect my stack will return both the real and the virtual screen resolutions of all those displays.

This:

"In the case of a monitor, you take the number of pixels (dots) in one direction, and divide it by the displayable inches in that direction, to get the DPI (dots per inch)."

Is a 'right fudge' as, for instance, my 2015 iMac is described as a 27 inch display: and having fooled around with a measuring tape that seems to be the DIAGONAL measurement: and I can see NO benefit in doing the fancy calculations (which are not 'that' fancy) to work out the width and the height of the ting: the virtual screen resolution should suffice.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Monitor DPI for Windows and Mac?

Post by FourthWorld » Thu Apr 04, 2024 9:53 am

stam wrote:
Thu Apr 04, 2024 7:23 am
According to https://superuser.com/questions/1085734 ... top-screen:

Code: Select all

PPI = sqrt((pixels_horizontal^2 + pixels_vertical^2) / inches_diagonal)
i guess you need a way to get the diagonal dimensions of the screen and know the pixel doubling.

Not sure if that helps?
The arithmetic is good, but this is for a deployment where we can't rely on users inputing the screen diagonal.

There's likely a Powershell script out there for this. I was just hoping someone had made a Builder function.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Monitor DPI for Windows and Mac?

Post by richmond62 » Thu Apr 04, 2024 1:53 pm

In front of me I have a 23 inch monitor (i.e. 22.9 inches diagonally): I don't know how a computer is going to 'know' that.

HOWEVER:

https://www.infobyip.com/detectdisplaysize.php

https://www.whatismyscreenresolution.or ... itor-size/

As you can see, it has a wide variety of resolutions it can display:
-
SShot 2024-04-04 at 15.47.41.png
-
And, as I demonstrated earlier, I can find the current display resolution, and I can find the pixel density, and from that can derive both the real resolution and the virtual resolution.

At home I have a monitor that can also display at a resolution of 1920 x 1080, but it is a 17 inch monitor.

So: those calculations mentioned above are ONLY any use if there is a way to detect the PHYSICAL SIZE of the monitor attached to a computer.
-
SShot 2024-04-04 at 15.57.01.png
SShot 2024-04-04 at 15.57.01.png (23.64 KiB) Viewed 528 times
-
Which really made my underpants revolve at high speed: how the 'fudge' is that done?

C# "freaks" might like this"

Code: Select all

using System;
using System.Management;
 
namespace GetScreenSize
{
    class Program
    {
        static void Main(string[] args)
        {
            //Get monitor data
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\root\wmi", @"SELECT * FROM WmiMonitorBasicDisplayParams");
 
            //Calculate and output size for each monitor
            foreach (ManagementObject managementObject in searcher.Get())
            {
                //Calculate monitor size
                double width = (byte)managementObject["MaxHorizontalImageSize"] / 2.54;
                double height = (byte)managementObject["MaxVerticalImageSize"] / 2.54;
                double diagonal = Math.Sqrt(width * width + height * height);
 
                //Output monitor size
                Console.WriteLine("Monitor Size: {0:F1}\"", diagonal);
            }
 
            Console.ReadLine();
        }
    }
    }
Just all those curly-wurly brackets make my toes curl up.

AND that may only work on Windows.

https://theezitguy.wordpress.com/2016/0 ... matically/
-
cw.jpg
cw.jpg (15.92 KiB) Viewed 527 times
-
That last image might explain part of the reason I was having 'fun' at the dentist, yet again, this morning. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Monitor DPI for Windows and Mac?

Post by richmond62 » Thu Apr 04, 2024 2:20 pm

https://lessons.livecode.com/m/4069/l/2 ... esolutions

I wonder why checkForScreenSize does not seem to be in the LC Dictionar?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Monitor DPI for Windows and Mac: Richmond Finds More Problems.

Post by richmond62 » Fri Apr 05, 2024 8:38 am

So: at home with a triple-monitored 'thing' and:
-
Screenshot 2024-04-05 at 10.36.37.png
Screenshot 2024-04-05 at 10.36.37.png (65.9 KiB) Viewed 450 times
-
And, as you can see, LiveCode is making a right whoreson's out of monitor number 3.

I thought that might be because of the "default" thing:
-
Screenshot 2024-04-05 at 10.39.39.png
-
BUT my stack STILL returns the same info when set differently:
-
Screenshot 2024-04-05 at 10.39.56.png
-
ALL I have "achieved" in this exercise is exposed another problem with screenRects . . .

What this means is that LiveCode seems completely unable to return the dimensions of the third monitor, which is not very useful at all.

Post Reply

Return to “Talking LiveCode”