1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Tweak to the way TopLevelWindow detects focus

This commit is contained in:
jules 2014-05-23 21:52:29 +01:00
parent 90d317a74a
commit 867585701b

View file

@ -27,7 +27,6 @@ class TopLevelWindowManager : private Timer,
private DeletedAtShutdown
{
public:
//==============================================================================
TopLevelWindowManager() : currentActive (nullptr)
{
}
@ -48,33 +47,15 @@ public:
{
startTimer (jmin (1731, getTimerInterval() * 2));
TopLevelWindow* active = nullptr;
TopLevelWindow* newActive = findCurrentlyActiveWindow();
if (Process::isForegroundProcess())
if (newActive != currentActive)
{
active = currentActive;
Component* const c = Component::getCurrentlyFocusedComponent();
TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
if (tlw == nullptr && c != nullptr)
tlw = c->findParentComponentOfClass<TopLevelWindow>();
if (tlw != nullptr)
active = tlw;
}
if (active != currentActive)
{
currentActive = active;
currentActive = newActive;
for (int i = windows.size(); --i >= 0;)
{
TopLevelWindow* const tlw = windows.getUnchecked (i);
tlw->setWindowActive (isWindowActive (tlw));
i = jmin (i, windows.size() - 1);
}
if (TopLevelWindow* tlw = windows[i])
tlw->setWindowActive (isWindowActive (tlw));
Desktop::getInstance().triggerFocusCallback();
}
@ -101,7 +82,7 @@ public:
deleteInstance();
}
Array <TopLevelWindow*> windows;
Array<TopLevelWindow*> windows;
private:
TopLevelWindow* currentActive;
@ -119,6 +100,26 @@ private:
&& tlw->isShowing();
}
TopLevelWindow* findCurrentlyActiveWindow() const
{
if (Process::isForegroundProcess())
{
Component* const focusedComp = Component::getCurrentlyFocusedComponent();
TopLevelWindow* w = dynamic_cast<TopLevelWindow*> (focusedComp);
if (w == nullptr && focusedComp != nullptr)
w = focusedComp->findParentComponentOfClass<TopLevelWindow>();
if (w == nullptr)
w = currentActive;
if (w != nullptr && w->isShowing())
return w;
}
return nullptr;
}
JUCE_DECLARE_NON_COPYABLE (TopLevelWindowManager)
};
@ -187,12 +188,11 @@ bool TopLevelWindow::isUsingNativeTitleBar() const noexcept
void TopLevelWindow::visibilityChanged()
{
if (isShowing()
&& (getPeer()->getStyleFlags() & (ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses)) == 0)
{
toFront (true);
}
if (isShowing())
if (ComponentPeer* p = getPeer())
if ((p->getStyleFlags() & (ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses)) == 0)
toFront (true);
}
void TopLevelWindow::parentHierarchyChanged()