r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.73k stars 554 forks source link

CEF High DPI issue (probably) - window inside window #613

Closed bekatd closed 3 years ago

bekatd commented 4 years ago

Specification

Description

I am facing window inside window issue on some machines. image After some research I found that it should be High DPI related issue, and tried to create manifest files for main executable app.exe and subprocess.exe files with dpiaware settings true, but it caused blank screen upon launch.

Practicalities

r0x0r commented 4 years ago

This issue was fixed here https://github.com/r0x0r/pywebview/issues/331 Has it resurfaced?

bekatd commented 4 years ago

Unfortunately yes. In order to reproduce issue you can change scaling in windows while application is already running image

bekatd commented 4 years ago

And also. I don't understand how manifest files work. I created files but they have no effect at all.

bekatd commented 4 years ago

I tested and its completely cefpython related issue, since mshtml is rednering everything correctly when changing scale

r0x0r commented 4 years ago

I don’t understand manifest files either.

One thing that I can think of is the path to subprocess.exe set by pywebview is not correct. As result it fails to apply correct DPI settings.

bekatd commented 4 years ago

I looked at your changes and seems it expects subprocess file to be in the cefpython package right? image

r0x0r commented 4 years ago

Either cefpython package or bundled along with pyinstaller

On 12. Oct 2020, at 22.58, bekatd notifications@github.com wrote:

I looked at you changes and seems it expects subprocess file to be in the cefpython package right? https://user-images.githubusercontent.com/6948919/95785437-cb6f1c00-0ce6-11eb-86a9-43c3058f3be7.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/r0x0r/pywebview/issues/613#issuecomment-707317084, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAL2KWPXHDXJKP2U4WI2FXDSKNNWRANCNFSM4SNCWCRA.

bekatd commented 4 years ago

I use cx-freeze, since with pyinstaller I get trojan virus alerts on windows machines. Issue exists for both installers, as its completely cefpython related issue not freezers

r0x0r commented 4 years ago

I have no experience with cxfreeze. Feel free to contribute a patch.

bekatd commented 4 years ago

Results of my little investigations that might be helpful. I tried to set different scale options image and eventually I got it working if BOTH app.exe (executable of application) and subprocess.exe have the same scale settings, BUT with small bug - window content remains unchanged, until forcefully cause repaint (for example, slightly changing size of window) and whoala everything in its place again.

The problem now is that main executable can't set own scale settings after running :(

any thoughts?

PS: Pywebview expects subprocess.exe to be inside cefpython package, and this might be something that needs to be changed too.

bekatd commented 4 years ago

@r0x0r I found solution, it so simple. Just set DPI scale mode programmatically before invoking window with ctypes:

ctypes.windll.user32.SetProcessDpiAwarenessContext(-4)

link to description

list of options:

bekatd commented 4 years ago

@r0x0r Would be great if you inject this ctypes.windll.user32.SetProcessDpiAwarenessContext(-4) before window initialization and also ensure that subprocess.exe file is discovered in case it's not inside cefpython package folder.

For some reason cx_Freeze needs to place subprocess.exe (and all other cefpython files, except cefpython_XX.pyd and __init__.py files) alongside main executable (outside of cefpython directory) and I manually fixed the correct reference to it

r0x0r commented 4 years ago

Does this setting replace the registry hack in place?

bekatd commented 4 years ago

Does this setting replace the registry hack in place?

Unfortunately no. Only combination of those two (main.exe and subprocess.exe) dpi settings does the job

r0x0r commented 4 years ago

To support cx_freeze there should be a way to detect that program is run under cx_freeze (like with pyinstaller’s sys._MEIPASS) and set the subprocess.exe path accordingly.

bekatd commented 4 years ago

To support cx_freeze there should be a way to detect that program is run under cx_freeze (like with pyinstaller’s sys._MEIPASS) and set the subprocess.exe path accordingly.

I think its sys.frozen for cxfreeze

cxfreeze using data files

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 3 years ago

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.