changePosition() doesn't always place window in correct position

Issue Description:
I am trying to right align an in game window to the game window, but sometimes it will not be aligned properly when changePosition is called. Either it will be too far left (there’s a gap between the border and the in game window)

or it’s too far right and the the in game window is cut off. Most of the time though it works and the window is right aligned.

I am getting the in game window’s width with obtainDeclaredWindow() and the game’s logical width with getRunningGameInfo() and storing them in the component state windowWidth and gameLogicalWidth. These two values are used in changePosition() to calculate the left value by doing gameLogicalWidth - windowWidth. changePosition() will be called whenever gameLogicalWidth or windowWidth changes.

The gameLogicalWidth is updated when the game resolution changes (through GameInfoUpdatedEvent event) or when the onGameLaunched event occurs.

The portion of the manifest.json for the window is below.

     "notification": {
        "file": "index.html",
        "clickthrough": true,
        "in_game_only": true,
        "keep_window_location": true,
        "transparent": true,
        "override_on_update": true,
        "size": {
          "width": 330,
          "height": 300
        "min_size": {
          "width": 330,
          "height": 300
        "max_size": {
          "width": 330,
          "height": 300
        "start_position": {
          "top": 50,
          "left": 90000
        "block_top_window_navigation": true,
        "restrict_to_game_bounds": true

Can you reproduce it (exact steps to reproduce):
This doesn’t always happen so I can’t pinpoint what’s causing the issue. I’ll list the cases where I see this happening.

  1. sometimes happens when resolution is changed through in game menu (not all resolutions has this behaviour)
  • open Osu! in window mode with app started.
  • lower the resolution through the in game menu.
  • results in the menu being partially shifted out of the game window (to the right)
  1. sometimes happens when on app launch when switching games
  • run game in windowed mode and have the app running
  • close the game and start a different game (I was switching from Osu! to Hearthstone both in windows mode)
  • the in game window is sometimes shifted left or right.
  1. Sometimes happens when changing resolution by dragging edge of game window
  • open Hearthstone in window mode
  • drag the border to change the resolution of the game
  • in a few cases the in game window will not be position by the game’s right edge.
    • I have the onGameInfoUpdated callback function debounced by 500ms which seems to help, but doesn’t eliminate the issue.

Impact for my app: Blocks new features

Do you currently have a workaround?
No. I can trigger another resolution change while testing which usually realigns the in game window, but it is not something we can expect a user to do.

Additional Info:
My Window scaling is set to 1.25x since I am on a laptop. This info may or may not be useful.

Please reproduce and attach a zip package of your OW client logs
Happens around 3PM on April 5, 2021. I launch Hearthstone and the in game window is shifted to the left leaving a gap between the window and the game border. (1.3 MB)

Because you are on 125% DPI (Windows scaling) - we have a known issue that the width/height returned by |obtainDeclaredWindow| does not include the DPI calculated in them.

This might be the case here - since you’d get a larger window width (without the DPI).

@fgfl We added a feature request on that (make obtainDeclaredWindow() “DPI-aware”.
But meanwhile, please check Tom’s remark and try to workaround it.

If you have any further issues, please let me know.


Hi @eransharv @tom.wolf ,
the changePosition() API should take in DPI unaware values according to the docs, so the values I am using should be correct.

Note: changePosition() calculates DPI before changing position (so you should pass coordinates without calculating their DPI).

To test this, I tried scaling the values passed in and it consistently causes there to be a gap between the in game window and the game border similar to the picture in my first post.

The windowWidth was saved as the width from obtainDeclaredWindow() divided by window.devicePixelRatio, and the gameWidth used the gameInfo.width value from getRunningGameInfo()

When I was testing, I also saw that the window was shifted about 3/4 down the game window even though I pass a constant 50 into the top parameter. This happened once when I restarted the app.

In summary, using DPI scaled values in changePosition() doesn’t move the in game window to the correct position.

Thanks. Let me know if there is something else I can try to get the in game window positioned correctly.

As a side note, I went back to check the image I posted on slack about the DPI and I saw that getCurrentWindows is multiplying the window width by the Windows scaling instead of dividing. According to @tom.wolf 's message, it sounds like it should be dividing instead of multiplying because DPI unaware values should be larger. Correct me if I am wrong.

  1. Regarding your issue - we’ll try to reproduce it.

  2. Regarding obtain vs getCurrentWindow - I mixed the two:
    obtainDeclareWindow (assuming the window is already open) will return the size with DPI scaling (i.e. smaller when on 1.25) - like you’d get from window.screen.availWidth and getCurrentWindow will return the native size (without DPI), like you’d get from window.screen.availWidth*window.devicePixelRatio.
    We will make them both consistent in the upcoming versions.

FYI I added a note in the docs:

Is this the current behaviour? I am on version

I tried instantiating the window manually through the dev console and the width/height values are all set to 0.

After I call restore on the window, my notification window calls obtainDeclareWindow to get its width. The dimensions it returns is 330x300 (first line of picture below) which is the size set in my manifest (so not DPI scaled). I call obtainDeclaredWindow again in the dev console to confirm.

The left and top values are already scaled.
left = (1600 game res - 330 window res) / 1.25 = 1016
top = 50 /1.25 = 40

We will check it and get back to you. Thanks

Hi @fgfl,

This is the expected behavior for the current version.
In OW client v0.170, we will make them both consistent.