Skip to content

Remove the DpiAware class and the auto_zooming setting - #771

Merged
cztomczak merged 3 commits into
cztomczak:masterfrom
linesight:remove-dpiaware
Dec 1, 2026
Merged

cztomczak merged 3 commits into
cztomczak:masterfrom
linesight:remove-dpiaware

Conversation

@linesight

Copy link
Copy Markdown
Contributor

Fixes #769 , #530

Chromium has made the browser and GPU processes DPI aware itself since
M108, and CEF 112 removed CefEnableHighDPISupport().
@cztomczak

Copy link
Copy Markdown
Owner

Thanks for working on this PR, but there are several issues that need to be resolved before this can be approved:

  1. No ctypes in unittests – keep the DPI check, but implement it via Cython:
    We want to keep the test verifying that cef.Initialize() successfully sets DPI awareness on Windows, but using ctypes in main_test.py is unacceptable. We use Cython for all C/C++ and native platform APIs. As established previously, ctypes is strictly forbidden in the library core and in unittests (the two isolated instances in examples/ were rare exceptions due to upstream toolkit bugs).
    Instead of using ctypes in main_test.py, please expose a clean helper through Cython in WindowUtils (e.g., WindowUtils.IsProcessDpiAware() in src/window_utils_win.pyx). Then in unittests/main_test.py, simply assert self.assertTrue(cef.WindowUtils.IsProcessDpiAware()).

  2. Do not cherry-pick deletions of historical sections in Migration-guide.md:
    Deleting only ## v49+ High DPI and ## v57.1+ High DPI while leaving other legacy sections creates inconsistent gaps in the changelog. Please restore those two historical sections in this PR so that changes for v147 stay cleanly in the v147 table at the bottom.
    (Note: A dedicated, separate PR that archives all legacy sections (v66 and earlier) into docs/Migration-guide-old.md is welcome, but let's keep that out of this PR).

  3. Inaccurate statement regarding manifests ("no manifest is needed"):
    In Migration-guide.md, stating that "so no manifest is needed" is inaccurate. Windows allows setting process DPI awareness only once. If an application (such as a splash screen, login dialog, or certain host GUI toolkits) initializes or creates a Win32 window prior to cef.Initialize(), the process is permanently locked as DPI-unaware by Windows, causing Chromium's subsequent call to fail.
    Please correct the entry in Migration-guide.md to accurately state that cef.Initialize() automatically sets Per-Monitor V2 awareness, but an application manifest is still required whenever host GUI components initialize before cef.Initialize(). We agree with removing the verbose DPI comments from hello_world.py to keep that minimal example clean, but the behavior must be documented properly.

  4. Add proper High DPI documentation:
    Since api/DpiAware.md is being removed, please add clear documentation for High DPI in the appropriate places:

    • In api/cefpython.md under Initialize: add a concise note that on Windows, cef.Initialize() automatically sets the process to Per-Monitor V2 DPI awareness.
    • In docs/Knowledge-Base.md: add a "High DPI support on Windows" section explaining how High DPI works in CEF Python v147+, noting that cef.Initialize() enables it automatically, but an embedded .exe manifest is still recommended if host GUI components or windows initialize prior to cef.Initialize().

Please update the PR accordingly.

@cztomczak

Copy link
Copy Markdown
Owner

A quick note to clarify the project's policy on ctypes to avoid misunderstandings in future PRs:

I realize there might be an apparent precedent because we have ctypes in two examples (gtk3.py and wxpython.py), but there is a fundamental architectural difference:

  • In examples/, we are integrating with external, third-party GUI toolkits (PyGObject, wxPython). Those two isolated workarounds were accepted only because of missing API bindings inside those third-party packages, and they had to be solved strictly in user-space Python without modifying the CEF Python build.
  • In src/ and unittests/, we are in full control of our own C++ and Cython build. There is never a reason to reach for ctypes here. Any interaction with native Win32/C++ APIs must go through Cython (.pyx / .pxd) so it is type-safe, compiled, and clean.

Let's keep ctypes strictly out of the library and unittests. If we need native calls in CEF Python or its test suite, let's always implement them properly via Cython.

- Add WindowUtils.IsProcessDpiAware() (Windows), implemented in Cython
  with GetProcessDpiAwareness(), and use it in main_test.py instead of
  ctypes.
- Restore the v49+ and v57.1+ High DPI sections of the migration guide,
  turning links to the removed docs into plain text.
- In the v147 DpiAware entry, note that a GUI toolkit initialized before
  cef.Initialize() may size its UI for 96 DPI, and point to
  WindowUtils.IsProcessDpiAware().
- Document High DPI support in api/cefpython.md (Initialize) and the
  Knowledge Base.
@cztomczak

Copy link
Copy Markdown
Owner

Is the new IsProcessDpiAware implementation better than the old one?

The WindowUtils object contains functions related to window management. IsProcessDpiAware is not a good place to put there.

@linesight

Copy link
Copy Markdown
Contributor Author

IsProcessDpiAware function at old implementation, according to https://learn.microsoft.com/is-is/windows/win32/api/winuser/nf-winuser-isprocessdpiaware , is being deprecated. I have changed the implementation to use GetProcessDpiAwareness following microsoft's guideline.

I am not a huge fan of implementing win32 cython binding helper for cefpython's unittest use case. When you insist "keep the DPI check", this is how it looks. I don't strongly feel necessary to perform dpi check at cefpython side, considering cefpython has zero dpi aware pyx/c++ implementation after proposed dpiaware class removal. Much more meaningful dpi check is either at chromium or cef side. I am ready to make further adjustment if necessary.

@cztomczak

Copy link
Copy Markdown
Owner

Since DpiAware class was removed there is not much point of unit testing whether process is dpi aware.

Is High DPI working fine in all examples? Should we add a comment to tkinter_.py example?

With the DpiAware class gone, CEF Python has no DPI code of its own left
to test; Chromium and CEF cover that. Drop the Cython helper, the Shcore
link and the unit test, and point IsProcessDpiAware() users to the Win32
GetProcessDpiAwareness() in the migration guide.

Add a comment to tkinter_.py explaining why Tk is not DPI scaled on
Windows.
@linesight

Copy link
Copy Markdown
Contributor Author

I have pushed linesight/cefpython@6136237 which removes WindowUtils.IsProcessDpiAware() (the Cython helper, the Shcore link and the docs) and the DPI check in main_test.py.

High DPI are working fine in all examples except tkinter_.py. I added a comment above tk.Tk() that explains it and links to the new "High DPI support on Windows" section in the Knowledge Base.

@cztomczak

Copy link
Copy Markdown
Owner

Looks good. Thanks.

@cztomczak
cztomczak merged commit 5f61ad0 into cztomczak:master Dec 1, 2026
39 checks passed
@linesight
linesight deleted the remove-dpiaware branch December 1, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants