Setting focus in juce_dispatchNextMessageOnSystemQueue


#1

Is the following code in juce_dispatchNextMessageOnSystemQueue important? It is causing plugins the run in my app to crash, I guess they aren’t expecting the focus to change.

if (GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber) { // if it's someone else's window being clicked on, give it the kb focus if (m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN) SetFocus (m.hwnd); }


#2

What if I change it so it’s like this, so GetFocus() only gets called if it’s going from no focus to non juce window focus or juce window to non juce window. But if the focus is already on a non juce window, and another non juce window gets clicks, the focus doesn’t get changed.

if (GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber) { // if it's someone else's window being clicked on, give it the kb focus if (m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN) { HWND currFocus = GetFocus(); if (currFocus == NULL || GetWindowLong(currFocus, GWLP_USERDATA) == improbableWindowNumber) SetFocus (m.hwnd); } }


#3

Well it must be there for a good reason, but it’s a long time since I added it, and I actually can’t remember why… (It could actually be because other plugins were failing to get focus when they need it).

I’m tempted to say that the whole section could be deleted, but your test looks like a good compromise until I can figure out what it’s there for…


#4