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

fix: adjust window position for monitor DPI #119

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

JonasWischeropp
Copy link
Contributor

@JonasWischeropp JonasWischeropp commented Oct 1, 2024

  1. Logical needs to be converted into Physical
  2. anchor_<x|y> (line 246) is already a PhysicalPosition

Example:

Monitor: 1600px 900px with 150%

  "defaultPlacements": [
    {
      "anchor": "bottom_left",
      "offsetX": "0px",
      "offsetY": "-24px",
      "width": "100%",
      "height": "24px",
      "monitorSelection": {
        "type": "all"
      }
    }
  ]

Before the y-position was calculated by (1600+-24)*(2/3) and not by 1600+(-24*(3/2)).

I think that #115 might be related to this.

@lars-berger
Copy link
Member

Ay thanks for the PR on this 🙏

It's so close to everything positioning nicely... but I was still able to reproduce a scaling issue with the default starter configs on one of the monitors like so:

Screenshot 2024-10-02 052646

image
image

@lars-berger
Copy link
Member

Seems to work correctly if size/position is set twice:

#[cfg(target_os = "windows")]
{
  let _ = window.set_size(size);
  let _ = window.set_position(position);
  let _ = window.set_size(size);
  let _ = window.set_position(position); // < not sure whether this call is necessary or if it's only size that needs to be set twice
}

We do something similar in GlazeWM where we call SetWindowPos twice when doing cross-monitor moves with different DPI's.

Are you able to reproduce #116 btw? Wonder if this also fixes that issue

@JonasWischeropp
Copy link
Contributor Author

After some testing, I was able to reproduce #116.
The bar was rendered outside of the monitor.

With the adjustments of this PR, the problem no longer occurred (with and without calling window.set_size and window.set_position twice).

@JonasWischeropp
Copy link
Contributor Author

I was unable to reproduce any problems that require to set size and position twice.

@JonasWischeropp
Copy link
Contributor Author

Never mind, I was able to reproduce the same problem you mentioned.
And with set_size and set_position twice it was fixed. Good catch, I would never have thought of that.

@lars-berger
Copy link
Member

After some testing, I was able to reproduce #116. The bar was rendered outside of the monitor.

With the adjustments of this PR, the problem no longer occurred (with and without calling window.set_size and window.set_position twice).

Ay that's great 🙌

BTW, I think we should be scaling only pixel values and leaving % values (e.g. "width": "98%") untouched. Does that sound right? Otherwise, e.g. 98% ends up scaling to the full size of the monitor

@JonasWischeropp
Copy link
Contributor Author

BTW, I think we should be scaling only pixel values and leaving % values (e.g. "width": "98%") untouched. Does that sound right? Otherwise, e.g. 98% ends up scaling to the full size of the monitor

Makes sense, I hadn't thought of that. I will make the change.

@JonasWischeropp
Copy link
Contributor Author

Percentage values are no longer scaled.

@lars-berger lars-berger changed the title fix: monitor scaling fix: adjust window position for monitor DPI Oct 4, 2024
@lars-berger lars-berger merged commit 632f93b into glzr-io:main Oct 4, 2024
1 check passed
Copy link

github-actions bot commented Oct 4, 2024

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants