Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ncvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ bool wxNcVisApp::OnInit() {
}
}

// Create main frame
wxNcVisFrame * frame =
new wxNcVisFrame(
"NcVis",
wxPoint(50, 50),
wxSize(842, 462),
wxSize(1050, 605),
wxstrNcVisResourceDir,
mapOptions,
vecFilenames);
Expand Down
47 changes: 47 additions & 0 deletions src/wxImagePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@
#include <wx/kbdstate.h>

#include <map>
#include <cstdlib>
#include <cstring>
#include <cstdio>

////////////////////////////////////////////////////////////////////////////////

/*
* Workaround for XQuartz display refresh bug on macOS Tahoe (26.x).
* See: https://github.com/XQuartz/XQuartz/issues/438
* wxWidgets applications fail to refresh properly on window resize because
* expose events are not generated correctly. Set NCVIS_FORCE_EXPOSE_FIX to a
* nonzero value (for example, NCVIS_FORCE_EXPOSE_FIX=1) to force redraws on
* resize events; leave it unset or set it to 0 to disable this workaround.
*/
static int expose_fix_checked = 0;
static int expose_fix_enabled = 0;

static int check_expose_fix(void)
{
if (expose_fix_checked)
return expose_fix_enabled;

expose_fix_checked = 1;
expose_fix_enabled = 0;

const char *env = std::getenv("NCVIS_FORCE_EXPOSE_FIX");
if (env != NULL && std::strcmp(env, "0") != 0) {
expose_fix_enabled = 1;
std::fprintf(stderr, "ncvis: NCVIS_FORCE_EXPOSE_FIX set, enabling XQuartz refresh workaround\n");
}

return expose_fix_enabled;
}

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -130,6 +163,10 @@ wxImagePanel::wxImagePanel(
SetMinSize(wxSize(wxs.GetWidth(), wxs.GetHeight()));
SetCoordinateRange(0.0, 1.0, 0.0, 1.0);

// XQuartz workaround: Check if expose fix is needed (NCVIS_FORCE_EXPOSE_FIX=1)
// See: https://github.com/XQuartz/XQuartz/issues/438
check_expose_fix();

// Initialize font information
m_sftTitleBar.xScale = TITLE_FONTHEIGHT;
m_sftTitleBar.yScale = TITLE_FONTHEIGHT;
Expand Down Expand Up @@ -277,6 +314,11 @@ void wxImagePanel::OnSize(wxSizeEvent & evt) {
std::cout << "RESIZE " << wxs.GetWidth() << " " << wxs.GetHeight() << std::endl;
}
m_fResize = true;

// XQuartz workaround: Force refresh on resize to work around expose event bug
if (expose_fix_enabled) {
this->Refresh();
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1544,6 +1586,11 @@ void wxImagePanel::PaintNow() {
////////////////////////////////////////////////////////////////////////////////

void wxImagePanel::Render(wxDC & dc) {
// XQuartz workaround: Clear background before drawing to prevent black windows
if (expose_fix_enabled) {
dc.SetBackground(wxBrush(GetBackgroundColour()));
dc.Clear();
}
dc.DrawBitmap(m_image, 0, 0, false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/wxNcVisFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ void wxNcVisFrame::InitializeWindow() {

// Variable controls
m_rightsizer = new wxStaticBoxSizer(wxVERTICAL, this);
m_rightsizer->SetMinSize(660,220);
m_rightsizer->SetMinSize(790,265);

m_ctrlsizer->Add(menusizer, 0);
m_ctrlsizer->Add(m_rightsizer, 0, wxEXPAND);
Expand Down