Add DPI scaling to KIPLATFORM

GTK needs to check current scaling but wx doesn't provide this
functionality in 3.0, so we can bypass by going straight to the source.
This commit is contained in:
Seth Hillbrand 2021-02-22 17:38:27 -08:00
parent 2013a801d1
commit 507ca9bc73
5 changed files with 36 additions and 1 deletions

View File

@ -28,6 +28,7 @@
#include <env_vars.h>
#include <pgm_base.h>
#include <settings/common_settings.h>
#include <kiplatform/ui.h>
#include <wx/log.h>
@ -117,7 +118,7 @@ double DPI_SCALING::GetScaleFactor() const
// Use the native WX reporting.
// On Linux, this will not work until WX 3.2 and GTK >= 3.10
// Otherwise it returns 1.0
val = m_window->GetContentScaleFactor();
val = KIPLATFORM::UI::GetSystemScaleFactor( m_window );
wxLogTrace( traceHiDpi, "Scale factor (WX): %f", *val );
}

View File

@ -91,3 +91,16 @@ void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
// Only the list of cells must be freed, the renderer isn't ours to free
g_list_free( cells );
}
double KIPLATFORM::UI::GetSystemScaleFactor( const wxWindow* aWindow )
{
double val = 1.0;
GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
if( widget && gtk_check_version( 3, 10, 0 ) == NULL )
val = gtk_widget_get_scale_factor( widget );
return val;
}

View File

@ -85,6 +85,14 @@ namespace KIPLATFORM
* @param aChoice is the choice box to ellipsize
*/
void EllipsizeChoiceBox( wxChoice* aChoice );
/**
* Tries to determine the system scaling factor currently in use for the window. Under wx3.0, GTK
* fails to properly detect the scale factor.
* @param aWindow pointer to the window to check
* @return System scale factor in use, defaulting to the wxWidgets method
*/
double GetSystemScaleFactor( const wxWindow* aWindow );
}
}

View File

@ -95,3 +95,9 @@ void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
{
// Not implemented
}
double KIPLATFORM::UI::GetSystemScaleFactor( const wxWindow* aWindow )
{
return aWindow->GetContentScaleFactor();
}

View File

@ -25,6 +25,7 @@
#include <wx/nonownedwnd.h>
#include <wx/toplevel.h>
#include <wx/button.h>
#include <wx/window.h>
bool KIPLATFORM::UI::IsDarkTheme()
@ -91,3 +92,9 @@ void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
{
// Not implemented
}
double KIPLATFORM::UI::GetSystemScaleFactor( const wxWindow* aWindow )
{
return aWindow->GetContentScaleFactor();
}