servo/ports/servoshell/desktop
Mukilan Thiyagarajan ba67a0a4fb
servoshell: fix issues related to HiDPI (#33529)
The current implementation has 3 main issues related to HiDPI:

1. When the window moves from a screen with scale factor of 1.5 to one
   with 1 and back to 1.5, the minibrowser toolbar actually ends up
   being scaled by a factor of 2.25 instead of 1.5. This is because we
   currently use the [set_pixels_per_point] method on egui's Context,
   but calling this with a value of `ppp` will modify egui's internal
   'zoom factor' to be:
   ```
   zoom_factor = ppp / native_points_per_pixel.
   ```
   where `native_points_per_pixel` is the window system scale factor.
   The idea is egui can calculate the final scale factor for translating
   its logical points to physical pixels as:
   ```
   points_per_pixel = zoom_factor * native_points_per_pixel
   ```
   where zoom_factor is a factor used for Ctrl+Plus, Ctrl+Minus
   behaviour. The problem is when we handle the ScaleFactorChanged winit
   event due to window moving between screens, the
   `native_points_per_pixel` still has the value of the previous
   screen's native scaling factor and not the current screen's factor.
   This seems to be the case even if we pass the ScaleFactorChanged
   event to egui before we call `set_pixels_per_point`.
2. The egui logic for handing Ctrl+Plus, Ctrl+Minus and Ctrl+0 doesn't
   interact well with servoshell's device-pixel-ratio CLI argument which
   allows the user to override the HiDPI factor. For example, Ctrl+0
   will cause egui to reset the zoom_factor to 1.0 instead of the
   override we wanted. Another issue is egui's Ctrl+Plus/Ctrl+Minus
   will scale the minibrowser in increments of 0.10 whereas
   Servo's own page zoom doesn't (it keeps multiplying by 1.1, so the
   actual increments are 0.1, 0.21. 0.33 etc)
3. The inital window size calculation on Linux currently assumes a scale
   factor of 1.0. This means the window doesn't have the expected
   default logical size of 1024*740 on HiDPI systems. On a screen with
   HiDPI factor of 1.5, the logical window size ends up being 682x493.

This change addresses all 3 issues:

For 1,  switch to the `set_zoom_factor` method of egui context
to avoid the issue with scaling by incorrect native_points_per_pixel.
To allow for the device-pixel-ratio override to work, we calculate the
actual zoom_factor as `device-pixel-ratio / window's scaling factor`.

For 2, disable egui's handling of Ctrl+Plus, Ctrl+Minus, Ctrl-0
shortcuts. It is unclear whether the current behaviour of scaling
both the toolbar and the web page was intentional, or just an accident.
This behaviour is also different from other browser where page zoom
doesn't scale the GUI, so it doesn't seem like a regression to me.

For 3, use LogicalSize type of winit which lets the physical size
calulation to be handled by winit using the windows's actual HiDPI
factor instead of hardcoded 1.0.

[set_pixels_per_point]: 1603f05818/crates/egui/src/context.rs (L1886)

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-09-24 12:12:23 +00:00
..
protocols Basic tab strip for the minibrowser (#33100) 2024-08-27 20:17:33 +00:00
app.rs servoshell: fix issues related to HiDPI (#33529) 2024-09-24 12:12:23 +00:00
cli.rs Make tracing available on all platforms, with or without perfetto (#33301) 2024-09-04 12:56:29 +00:00
egui_glue.rs Split servoshell into Desktop and common part (#32457) 2024-06-14 06:26:35 +00:00
embedder.rs compositor: Do not parse the Cargo.lock file while building (#33222) 2024-08-28 08:36:54 +00:00
events_loop.rs clippy: fix some warnings in desktop and some components (#32583) 2024-06-25 07:04:23 +00:00
geometry.rs Split servoshell into Desktop and common part (#32457) 2024-06-14 06:26:35 +00:00
headed_window.rs servoshell: fix issues related to HiDPI (#33529) 2024-09-24 12:12:23 +00:00
headless_window.rs Split servoshell into Desktop and common part (#32457) 2024-06-14 06:26:35 +00:00
keyutils.rs servoshell: Clean up keyboard event conversion a little (#32564) 2024-06-19 19:38:56 +00:00
minibrowser.rs servoshell: fix issues related to HiDPI (#33529) 2024-09-24 12:12:23 +00:00
mod.rs make protocol handlers registrable (#33104) 2024-08-22 04:11:16 +00:00
tracing.rs Gamepad: Implement GamepadHapticActuator (#32046) 2024-07-20 06:29:27 +00:00
webview.rs clippy: Fix suggestions in script, libservo, and servoshell (#33453) 2024-09-14 08:41:13 +00:00
window_trait.rs Split servoshell into Desktop and common part (#32457) 2024-06-14 06:26:35 +00:00