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

Wrong windows location if main screen is not the first one. #1468

Open
cervelas opened this issue Sep 11, 2024 · 1 comment
Open

Wrong windows location if main screen is not the first one. #1468

cervelas opened this issue Sep 11, 2024 · 1 comment

Comments

@cervelas
Copy link

Specification

  • pywebview version: 5.2
  • operating system: Windows 11
  • web renderer: WinForms

Description

On a multi monitor setup, set the main default screen to a monitor that is not the first one (i.e. center screen on a 3 monitors setup).
When creating a window for each monitor, if the screen.frame.X value is <= 0, the windows is not visible because X Location value is miscaculated.

test code:

import time
import webview
from webview.platforms.winforms import BrowserView

def print_views():
    time.sleep(1)
    for k, v in BrowserView.instances.items():
        print(k, v.Location)

for i, screen in enumerate(webview.screens):
    print(screen.frame)
    webview.create_window(f"Window {i}", screen=screen)

webview.start(print_views)

wrong result:

{X=2048,Y=0,Width=1463,Height=775}
{X=-2048,Y=0,Width=1707,Height=912}
{X=0,Y=0,Width=2048,Height=1104}
master {X=2974,Y=139}
child_bcda924d {X=-3626,Y=225} <-- WRONG !
child_ba5741a1 {X=780,Y=345}

right results:

{X=2048,Y=0,Width=1463,Height=775}
{X=-2048,Y=0,Width=1707,Height=912}
{X=0,Y=0,Width=2048,Height=1104}
master {X=2974,Y=139}
child_36a86f35 {X=-1993,Y=225}
child_0554c898 {X=780,Y=345}

Fix

The error is in BrowserForm.init() method, X location value is miscaulated, it's working without thoses two lines:

if window.screen.frame.X >= 0

else window.screen.frame.X * self.scale_factor - window.screen.width * self.scale_factor / 2

I'm not sure about windows version here, so more test are needed on other windows versions and maybe monitor setups.

Practicalities

  • YES I am willing to work on this issue myself, this soft is awesome.

  • NO I am prepared to support this issue financially, i'm a freelancer.

@cervelas cervelas changed the title Wrong placement of windows if main screen is not the first one. Wrong windows location if main screen is not the first one. Sep 11, 2024
@r0x0r
Copy link
Owner

r0x0r commented Sep 17, 2024

Thanks for investigating this. Feel free to submit a PR.

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

No branches or pull requests

2 participants