From 9722a0582096d07fc472afde862208d676d2487a Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 21 Mar 2022 16:44:28 -0700 Subject: [PATCH] Attempt to fix the Mac DPI grid mixing When moving windows between monitors on Mac that changes the DPI, we observe incorrect re-sizing of columns and rows. This attempts to rectify the situation by avoiding DPI changes for Mac builds. Fixes https://gitlab.com/kicad/code/kicad/issues/10586 --- common/widgets/wx_grid.cpp | 21 +++++++++++++++++++++ include/widgets/wx_grid.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/common/widgets/wx_grid.cpp b/common/widgets/wx_grid.cpp index bdcdc59302..5d9a396ff4 100644 --- a/common/widgets/wx_grid.cpp +++ b/common/widgets/wx_grid.cpp @@ -40,6 +40,11 @@ WX_GRID::WX_GRID( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxS // Make sure the GUI font scales properly on GTK SetDefaultCellFont( KIUI::GetControlFont( this ) ); + +#if wxCHECK_VERSION( 3, 1, 0 ) + Connect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this ); +#endif + } @@ -47,9 +52,25 @@ WX_GRID::~WX_GRID() { if( m_weOwnTable ) DestroyTable( GetTable() ); + +#if wxCHECK_VERSION( 3, 1, 0 ) + Disconnect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this ); +#endif + } +#if wxCHECK_VERSION( 3, 1, 0 ) +void WX_GRID::onDPIChanged(wxDPIChangedEvent& aEvt) +{ + /// This terrible hack is a way to avoid the incredibly disruptive resizing of grids that happens on Macs + /// when moving a window between monitors of different DPIs. +#ifndef __WXMAC__ + aEvt.Skip(); +#endif +} +#endif + void WX_GRID::SetColLabelSize( int aHeight ) { if( aHeight == 0 ) diff --git a/include/widgets/wx_grid.h b/include/widgets/wx_grid.h index fa528ea770..4fc8cd7ed2 100644 --- a/include/widgets/wx_grid.h +++ b/include/widgets/wx_grid.h @@ -24,7 +24,10 @@ #ifndef KICAD_WX_GRID_H #define KICAD_WX_GRID_H +#include #include +#include + class WX_GRID : public wxGrid { @@ -119,6 +122,10 @@ protected: void onGridColMove( wxGridEvent& aEvent ); void onGridCellSelect( wxGridEvent& aEvent ); +#if wxCHECK_VERSION( 3, 1, 0 ) + void onDPIChanged(wxDPIChangedEvent& event); +#endif + bool m_weOwnTable; };