pywebview icon indicating copy to clipboard operation
pywebview copied to clipboard

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

Open cervelas opened this issue 5 months ago • 2 comments

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:

https://github.com/r0x0r/pywebview/blob/ca10170daec098ab090b55726f5bb09b8129d553/webview/platforms/winforms.py#L188 https://github.com/r0x0r/pywebview/blob/ca10170daec098ab090b55726f5bb09b8129d553/webview/platforms/winforms.py#L189

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 avatar Sep 11 '24 15:09 cervelas