Dark mode 3.1.3 macOS Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
72deluxe
Experienced Solver
Experienced Solver
Posts: 87
Joined: Tue May 20, 2008 10:55 pm

Dark mode 3.1.3 macOS

Post by 72deluxe » Mon Nov 18, 2019 11:01 am

Hello

I have seen that support for dark mode has been added in 3.1.3. I tried adding a comment on the page http://wxwidgets.org/news/2019/10/wxwid ... -released/ but it seems to have been marked as spam.

I have built this under Mojave and tried the following:

Code: Select all

Bind(wxEVT_SYS_COLOUR_CHANGED, &myFrame::OnSystemColourChanged, this);

void myFrame::OnSystemColourChanged(wxSysColourChangedEvent &event)
{
  wxSystemAppearance s = wxSystemSettings::GetAppearance();
  wxString dark = s.IsDark() ? "it's dark" : "it's light";
  wxString m("System colour changed - ");
  m += dark;
  ::wxMessageBox(m);
  event.Skip();
}
but this is not getting hit or fired at all. I am using System Preferences > General to change the mode from light to dark and vice versa but this is never getting hit??

I see that the widgets in the app (eg. list control, buttons) are correctly somehow being informed that the system colour has changed as they are changing but I cannot get my handler to hit.

Am I missing something obvious?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4360
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Dark mode 3.1.3 macOS

Post by ONEEYEMAN » Mon Nov 18, 2019 3:54 pm

Hi,
Where is the call to Bind() being executed?

Also according to documentation its implemented for Windows only.

You can try to bug the developers in the wx-users ML or try to implement it yourself and submit as a patch/PR.

Thank you.

72deluxe
Experienced Solver
Experienced Solver
Posts: 87
Joined: Tue May 20, 2008 10:55 pm

Re: Dark mode 3.1.3 macOS

Post by 72deluxe » Mon Nov 18, 2019 4:10 pm

The call to Bind is being called in the constructor of myFrame.

I think the documentation is wrong because the release notes for 3.1.3 (https://raw.githubusercontent.com/wxWid ... hanges.txt) specifically mentions "Support for macOS Mojave and later dark mode." for wxOSX. Also "dark mode" is a recent Windows 10 feature for non-Win32 apps (viewtopic.php?t=45869).

I will try the mailing lists, thanks - where is wx-users again?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4360
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Dark mode 3.1.3 macOS

Post by ONEEYEMAN » Mon Nov 18, 2019 4:16 pm

Hi,
Mailing lists.

Thank you.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2512
Joined: Sun Jan 03, 2010 5:45 pm

Re: Dark mode 3.1.3 macOS

Post by PB » Mon Nov 18, 2019 4:53 pm

I know nothing about macOS, but according to this complaint in the related commit, the event does arrive:
https://github.com/wxWidgets/wxWidgets/ ... t-30315261

72deluxe
Experienced Solver
Experienced Solver
Posts: 87
Joined: Tue May 20, 2008 10:55 pm

Re: Dark mode 3.1.3 macOS

Post by 72deluxe » Mon Nov 18, 2019 10:55 pm

Thanks for that tip. I had a look through the code to see where it is handled and there's some code in the carbon directory but only mention of it once in cocoa. I managed to get it working anyway.
I debugged it by adding a wxApp-level HandleEvent override function to see what events were being handled by the application (yes all events go through here):

Code: Select all

void myApp::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& event) const
{
  wxApp::HandleEvent(handler, func, event);
}
wxSysColourChanged events are indeed passing through this.

I managed to get my main frame's handler to hit by hooking up differently. Instead of

Code: Select all

Bind(wxEVT_SYS_COLOUR_CHANGED, &myFrame::OnSystemColourChanged, this);
I used this instead:

Code: Select all

Bind(wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler(myFrame::OnSystemColourChanged), this);
I have no idea why &myFrame::OnSystemColourChanged wouldn't be recognised. Also, I could not get any message boxes to show up in my event handler. ::wxMessageBox and wxMessageDialog did not show. cout output did show up but no popup GUI dialogs. I am not going to be showing message boxes in this handler anyway so it isn't a problem but was trying to show a message for debugging/testing purposes.

I posted a question on Stackoverflow about this (https://stackoverflow.com/questions/58920057) and have answered my own question there.
Thanks for all your help and suggestions.

Post Reply