Skip to content

screen.scaleFactor always returns 1 for 125% DPI #6571

Closed

Description

@Mossop
  • Electron version: 1.2.8
  • Operating system: Windows

I have a hidpi screen on my laptop and a normal main monitor that has some scaling applied through windows' display properties. In both cases the following code returns 1 even though I would expect something larger:

require('electron').screen.getPrimaryDisplay().scaleFactor

Activity

  1. zcbenz commented on Jul 25, 2016

    @zcbenz
    Contributor

    getPrimaryDisplay() probably didn't return the display you expected, it returns the display that the system considers primary, which may not be your laptop's screen. You should use APIs like getDisplayNearestPoint() to get the scale factor for current display.

  2. Mossop commented on Jul 25, 2016

    @Mossop
    ContributorAuthor

    I've tried to use the APIs to find the current screen and it still returns a scaleFactor of 1 despite the OS being set to scale to 125%. Also screen.getAllDisplays() returns just a single display regardless of whether I'm using my laptop screen or my external monitor (my laptop screen is disabled in that case so that is to be expected).

    Is it possible that scaleFactor only supports integer values?

  3. zcbenz commented on Jul 26, 2016

    @zcbenz
    Contributor

    Thanks for the information, after testing I found that screen.scaleFactor returns 1 when DPI is 125%, however DPI 150% can work.

  4. reopened this on Jul 26, 2016
  5. changed the title [-]screen.scaleFactor always returns 1[/-] [+]screen.scaleFactor always returns 1 for 125% DPI[/+] on Jul 26, 2016
  6. virifi commented on Jul 26, 2016

    @virifi

    Chromium has this issue from two years ago, but it has been fixed a few days ago.
    See https://bugs.chromium.org/p/chromium/issues/detail?id=410696

  7. bsclifton commented on Jan 20, 2017

    @bsclifton
    Contributor

    Just a heads up that I believe this is going to have a large impact

    Because folks at 125% will finally get properly scaled content, everything will appear to be much larger for them. If those people are upset and don't like this, it can be worked around by passing two additional flags to the base::CommandLine class (you should be able to append via the command line):
    --high-dpi-support=1 --force-device-scale-factor=1

  8. zxc23 commented on Sep 4, 2017

    @zxc23

    @bsclifton I've been looking everywhere for this information, and I finally found it here. Thank you very much for that.

    I got my electron app to ignore the desktop display scaling with this in the main process:

    app.commandLine.appendSwitch('high-dpi-support', 1)
    app.commandLine.appendSwitch('force-device-scale-factor', 1)
    
  9. sirgru commented on Oct 20, 2017

    @sirgru

    Thanks @zxc23 for posting that solution. My application started scaling after I've npm installed electron (with global install there was no scaling). After adding those lines, the body of the application looks correct, but the top menu bar (on Windows) is scaled down. Any solution for this?

  10. HaulinOats commented on Jul 23, 2019

    @HaulinOats

    Should these flags be added to the official documentation as valid command line switches, since they work?

  11. MarshallOfSound commented on Jul 24, 2019

    @MarshallOfSound
    Member

    @HaulinOats There are hundreds of potential chromium CLI switches. We can't (and won't) document all of them especially as we can't guarantee there continued existence

  12. HaulinOats commented on Jul 24, 2019

    @HaulinOats

    Ah, I follow. Wasn't aware it was that complicated. I'm still learning. Appreciate the response.

  13. gsbnlda commented on Jun 25, 2023

    @gsbnlda

    @bsclifton I've been looking everywhere for this information, and I finally found it here. Thank you very much for that.

    I got my electron app to ignore the desktop display scaling with this in the main process:

    app.commandLine.appendSwitch('high-dpi-support', 1)
    app.commandLine.appendSwitch('force-device-scale-factor', 1)
    

    How it will work for Microsoft edge browser? edge menu tab font seems very small.

  14. gsbnlda commented on Jun 25, 2023

    @gsbnlda

    Just a heads up that I believe this is going to have a large impact

    Because folks at 125% will finally get properly scaled content, everything will appear to be much larger for them. If those people are upset and don't like this, it can be worked around by passing two additional flags to the base::CommandLine class (you should be able to append via the command line): --high-dpi-support=1 --force-device-scale-factor=1

    Microsoft edge browser menu tab font seems very small . How it works for ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions