Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-10-25 07:25:26 +0300
committerCampbell Barton <campbell@blender.org>2022-10-25 07:56:09 +0300
commit059d9631924366ba66b0cacf50cb5dad95889fe2 (patch)
tree84ca3db1eb41156cda7002aebaf9ecb3e9dd7151 /intern/ghost/intern/GHOST_WindowWayland.cpp
parentdd08b490afc9224d700eb08c39a4a1a5aa2317a9 (diff)
GHOST/Wayland: store fractional scaling in each window instead of DPI
This makes it possible to access the fractional scaling for a window, there is no need to store the DPI which can be returned by getDPIHint().
Diffstat (limited to 'intern/ghost/intern/GHOST_WindowWayland.cpp')
-rw-r--r--intern/ghost/intern/GHOST_WindowWayland.cpp51
1 files changed, 22 insertions, 29 deletions
diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp
index f9d7f5c25e2..edcbcc14a37 100644
--- a/intern/ghost/intern/GHOST_WindowWayland.cpp
+++ b/intern/ghost/intern/GHOST_WindowWayland.cpp
@@ -90,13 +90,8 @@ struct GWL_Window {
/** The scale value written to #wl_surface_set_buffer_scale. */
int scale = 0;
- /**
- * The DPI, either:
- * - `scale * base_dpi`
- * - `wl_fixed_to_int(scale_fractional * base_dpi)`
- * When fractional scaling is available.
- */
- uint32_t dpi = 0;
+ /** The fractional scale used to calculate the DPI. */
+ wl_fixed_t scale_fractional = 0;
#ifdef WITH_GHOST_WAYLAND_LIBDECOR
WGL_LibDecor_Window *libdecor = nullptr;
@@ -147,7 +142,7 @@ static int output_scale_cmp(const GWL_Output *output_a, const GWL_Output *output
static int outputs_max_scale_or_default(const std::vector<GWL_Output *> &outputs,
const int32_t scale_default,
- uint32_t *r_dpi)
+ wl_fixed_t *r_scale_fractional)
{
const GWL_Output *output_max = nullptr;
for (const GWL_Output *reg_output : outputs) {
@@ -157,18 +152,16 @@ static int outputs_max_scale_or_default(const std::vector<GWL_Output *> &outputs
}
if (output_max) {
- if (r_dpi) {
- *r_dpi = output_max->has_scale_fractional ?
- /* Fractional DPI. */
- wl_fixed_to_int(output_max->scale_fractional * base_dpi) :
- /* Simple non-fractional DPI. */
- (output_max->scale * base_dpi);
+ if (r_scale_fractional) {
+ *r_scale_fractional = output_max->has_scale_fractional ?
+ output_max->scale_fractional :
+ wl_fixed_from_int(output_max->scale);
}
return output_max->scale;
}
- if (r_dpi) {
- *r_dpi = scale_default * base_dpi;
+ if (r_scale_fractional) {
+ *r_scale_fractional = wl_fixed_from_int(scale_default);
}
return scale_default;
}
@@ -479,7 +472,7 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system,
*
* Using the maximum scale is best as it results in the window first being smaller,
* avoiding a large window flashing before it's made smaller. */
- window_->scale = outputs_max_scale_or_default(system_->outputs(), 1, &window_->dpi);
+ window_->scale = outputs_max_scale_or_default(system_->outputs(), 1, &window_->scale_fractional);
/* Window surfaces. */
window_->wl_surface = wl_compositor_create_surface(system_->wl_compositor());
@@ -751,7 +744,9 @@ GHOST_WindowWayland::~GHOST_WindowWayland()
uint16_t GHOST_WindowWayland::getDPIHint()
{
- return window_->dpi;
+ /* Using the physical DPI will cause wrong scaling of the UI
+ * use a multiplier for the default DPI as a workaround. */
+ return wl_fixed_to_int(window_->scale_fractional * base_dpi);
}
GHOST_TSuccess GHOST_WindowWayland::setWindowCursorVisibility(bool visible)
@@ -962,14 +957,14 @@ GHOST_Context *GHOST_WindowWayland::newDrawingContext(GHOST_TDrawingContextType
* Expose some members via methods.
* \{ */
-uint16_t GHOST_WindowWayland::dpi() const
+int GHOST_WindowWayland::scale() const
{
- return window_->dpi;
+ return window_->scale;
}
-int GHOST_WindowWayland::scale() const
+wl_fixed_t GHOST_WindowWayland::scale_fractional() const
{
- return window_->scale;
+ return window_->scale_fractional;
}
wl_surface *GHOST_WindowWayland::wl_surface() const
@@ -1035,13 +1030,13 @@ GHOST_TSuccess GHOST_WindowWayland::notify_size()
*/
bool GHOST_WindowWayland::outputs_changed_update_scale()
{
- uint32_t dpi_next;
- const int scale_next = outputs_max_scale_or_default(outputs(), 0, &dpi_next);
+ wl_fixed_t scale_fractional_next = 0;
+ const int scale_next = outputs_max_scale_or_default(outputs(), 0, &scale_fractional_next);
if (UNLIKELY(scale_next == 0)) {
return false;
}
- const uint32_t dpi_curr = window_->dpi;
+ const wl_fixed_t scale_fractional_curr = window_->scale_fractional;
const int scale_curr = window_->scale;
bool changed = false;
@@ -1055,10 +1050,8 @@ bool GHOST_WindowWayland::outputs_changed_update_scale()
changed = true;
}
- if (dpi_next != dpi_curr) {
- /* Using the real DPI will cause wrong scaling of the UI
- * use a multiplier for the default DPI as workaround. */
- window_->dpi = dpi_next;
+ if (scale_fractional_next != scale_fractional_curr) {
+ window_->scale_fractional = scale_fractional_next;
changed = true;
/* As this is a low-level function, we might want adding this event to be optional,