Skip to content

Commit

Permalink
Windows: fix initial window size when display scaling != 100%
Browse files Browse the repository at this point in the history
The heart of this issue was that the resize callbacks have two
layers of state; one in the low level window and one in the application
level window.

On Windows, the system triggers the low level callback prior to
opengl being initialized.  Since the application level depends on
the opengl state, there are some code paths where it NOPs and
returns early if opengl isn't yet initialized.

When the system-wide display scaling is set to say 200%, the application
layer can't know the effective DPI of the window it is creating because
it doesn't know which monitor will be used or what its DPI will be.

New windows are created at the default DPI of 96, and we rely on the
resize events to detect the actual DPI and adjust the scaling in
the window.

The early call of the resize callback meant that the low level and
application level size/dpi state was out of sync and the result was
that the window had half as many pixels as it should, but that the
terminal model was still sized as though it had the correct amount
(twice as many as visible).  This resulted in the window being too
small for the viewport.

The resolution is simple: we now suppress emitting the resize processing
until opengl has been initialized.

The test scenario for this is:

* Set system scaling to 100%
* Launch wezterm
* Set system scaling to 200%
* Observe that wezterm scales to match
* Press CTRL-SHIFT-N to spawn a new window
* Observe that the new window size matches the other window (previously
  this one would be half the size)

While I was looking at this, I noticed that the manifest didn't
match the DPI awareness that we have in the code, so update that.

refs: #427
  • Loading branch information
wez committed Jan 18, 2021
1 parent 83dbf03 commit aee3778
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/windows/manifest.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<dpiAwareness>PerMonitorV2, unaware</dpiAwareness>
<dpiAwareness>PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
1 change: 1 addition & 0 deletions docs/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ brief notes about them may accumulate here.
* Setting a really large or really small font scale (using CTRL +/-) no longer causes a panic [#428](https://github.com/wez/wezterm/issues/428)
* Fixed an issue where the mouse wheel wasn't mapped to cursor up/down when the alternate screen was active [#429](https://github.com/wez/wezterm/issues/429)
* Fixed `ToggleFullScreen` not working on macOS and X11. It still doesn't function on Windows. `native_macos_fullscreen_mode = false` uses a fast full-screen window on macOS. Set it to `true` to use the slower macOS native "Spaces" style fullscreen mode. [#177](https://github.com/wez/wezterm/issues/177)
* Windows: fix an issue where the initial window size didn't factor the correct DPI when the system-wide display scaling was not 100%. [#427](https://github.com/wez/wezterm/issues/427)

### 20201101-103216-403d002d

Expand Down
10 changes: 10 additions & 0 deletions window/src/os/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ impl WindowInner {
/// Calls resize if needed.
/// Returns true if we did.
fn check_and_call_resize_if_needed(&mut self) -> bool {
if self.gl_state.is_none() {
// Don't cache state or generate resize callbacks until
// we've set up opengl, otherwise we can miss propagating
// some state during the initial window setup that results
// in the window dimensions being out of sync with the dpi
// when eg: the system display settings are set to 200%
// scale factor.
return false;
}

let mut rect = RECT {
left: 0,
bottom: 0,
Expand Down

0 comments on commit aee3778

Please # to comment.