Skip to content
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

Detecting wrong DPI while switching between monitors #1763

Open
Srele-krele opened this issue Feb 13, 2023 · 6 comments
Open

Detecting wrong DPI while switching between monitors #1763

Srele-krele opened this issue Feb 13, 2023 · 6 comments

Comments

@Srele-krele
Copy link

Srele-krele commented Feb 13, 2023

I have noticed a problem while moving main windows from one monitor to other.
My main monitor have scaling set to 100% and second monitor is on 125%.

When I open HeidiSQL on main monitor in console window I see:
/* Scaling controls to screen DPI: 100% */
And when I then move window to second monitor I see:
/* Scaling controls to screen DPI: 125% */
But when I move window back to the main monitor I got this:
/* Scaling controls to screen DPI: 80% */
It should be 100% not 80%.

Why is this a problem? Because when HeidiSQL starts on second monitor (I don't know why it starts on second monitor because I didn't close it on second monitor, but that is other bug that I will submit later) fonts are small - smaller then how I set them, and when I move window to the main monitor fonts are still small and DPI is set to 80%. Then I must close HeidiSQL on main monitor for it to start it again on main monitor to bring back original font size.

My HeidiSQL version is: 12.3.0.6589 (64bit).
My Windows is: Windows 10, version 22H2 (OS Build 19045.2486)

Please fix this.

@janmyszkier
Copy link

Also affected: UI eventually ends up like this when we move the window back and forth:
Zrzut ekranu 2023-06-22 082220

Version: 12.5.0.6677
OS: Windows 11 Home 22H2, (OS Build 22621.1848)

@igitur
Copy link
Contributor

igitur commented May 10, 2024

Same issue here.

@ansgarbecker Can you try to hook onto WM_DISPLAYCHANGE and recalibrate by calling TMainForm.FormBeforeMonitorDpiChanged ? You'll have to get the DPI from somewhere, though.

@igitur
Copy link
Contributor

igitur commented May 10, 2024

ChatGPT says:

uses
  Winapi.Windows, Shcore;

function GetMonitorDPI: UINT;
var
  Monitor: HMONITOR;
  DPIX, DPIY: UINT;
begin
  // Get handle to the primary monitor
  Monitor := MonitorFromWindow(GetDesktopWindow, MONITOR_DEFAULTTOPRIMARY);
  // Retrieve DPI of the monitor
  GetDpiForMonitor(Monitor, MONITOR_DPI_TYPE_EFFECTIVE, DPIX, DPIY);
  Result := DPIX; // You can return DPIY if you need vertical DPI
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  DPI: UINT;
begin
  // Get DPI of the current monitor
  DPI := GetMonitorDPI;
  // Display DPI
  ShowMessage('DPI: ' + IntToStr(DPI));
end;

ansgarbecker added a commit that referenced this issue May 10, 2024
@ansgarbecker
Copy link
Collaborator

Using the OnBeforeMonitorDpiChanged event, the new and the old DPI value are passed to this event, so there is no need to retrieve it separately.

The wrong percentage shown in the log panel is only cosmetic, and fixed in the next build 6852. Also the wrong height of the donate button in the upper right corner. Please test with the next build available in an hour.

Apart from that I cannot reproduce any obvious issue with the newest release, no matter how often I move HeidiSQL from one screen to another.
On which DPIs are you running your screens?

@igitur
Copy link
Contributor

igitur commented May 10, 2024

So my situation is weird/exotic, but it's like this:

I run HeidiSQL on a desktop PC in my office.

When I work in the office, I have 2 1080p displays, 100% scaling factor, 96 dpi.

When I work at home, I remote (via RDP) into my office PC and continue working. At home I have 2 monitors, one 1080p (100% scaling and one with a higher scaling of 125%).

HeidiSQL's controls' scaling gets messed up if I move from one location to the other.

@igitur
Copy link
Contributor

igitur commented May 16, 2024

After a few commutes between work and home, my HeidiSQL now looks like this. It's not unworkable, but the controls definitely look different, with smaller padding between labels and smaller text.

image

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

No branches or pull requests

4 participants