Browse Source

Changes to improve AU, VST and RTAS key forwarding on the Mac

tags/2021-05-28
Julian Storer 16 years ago
parent
commit
48bacabcff
11 changed files with 1101 additions and 1059 deletions
  1. +13
    -2
      extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm
  2. +34
    -0
      extras/audio plugins/wrapper/RTAS/juce_RTAS_MacUtilities.mm
  3. +1003
    -996
      extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp
  4. +11
    -4
      extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp
  5. +8
    -0
      extras/audio plugins/wrapper/VST/juce_VST_Wrapper.mm
  6. +23
    -45
      juce_amalgamated.cpp
  7. +2
    -4
      src/gui/components/controls/juce_TreeView.cpp
  8. +2
    -1
      src/gui/components/mouse/juce_DragAndDropContainer.cpp
  9. +2
    -1
      src/gui/components/special/juce_DropShadower.cpp
  10. +2
    -1
      src/gui/components/windows/juce_TooltipWindow.cpp
  11. +1
    -5
      src/native/mac/juce_mac_NSViewComponentPeer.mm

+ 13
- 2
extras/audio plugins/wrapper/AU/juce_AU_Wrapper.mm View File

@@ -948,7 +948,6 @@ public:
#if ! JucePlugin_EditorRequiresKeyboardFocus #if ! JucePlugin_EditorRequiresKeyboardFocus
setWantsKeyboardFocus (false); setWantsKeyboardFocus (false);
#else #else
setComponentProperty ("juce_disallowFocus", true);
setWantsKeyboardFocus (true); setWantsKeyboardFocus (true);
#endif #endif
} }
@@ -1230,7 +1229,6 @@ private:
#if ! JucePlugin_EditorRequiresKeyboardFocus #if ! JucePlugin_EditorRequiresKeyboardFocus
addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses); addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
setWantsKeyboardFocus (false); setWantsKeyboardFocus (false);
setComponentProperty ("juce_disallowFocus", true);
#else #else
addToDesktop (ComponentPeer::windowIsTemporary); addToDesktop (ComponentPeer::windowIsTemporary);
setWantsKeyboardFocus (true); setWantsKeyboardFocus (true);
@@ -1339,6 +1337,19 @@ private:
recursive = false; recursive = false;
} }
} }
bool keyPressed (const KeyPress& kp)
{
if (! kp.getModifiers().isCommandDown())
{
// If we have an unused keypress, move the key-focus to a host window
// and re-inject the event..
[[hostWindow parentWindow] makeKeyWindow];
[NSApp postEvent: [NSApp currentEvent] atStart: YES];
}
return false;
}
private: private:
HIViewRef parentView; HIViewRef parentView;


+ 34
- 0
extras/audio plugins/wrapper/RTAS/juce_RTAS_MacUtilities.mm View File

@@ -110,4 +110,38 @@ void removeSubWindow (void* nsWindow, Component* comp)
[hostWindow release]; [hostWindow release];
} }
static bool isJuceWindow (WindowRef w) throw()
{
for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
{
ComponentPeer* peer = ComponentPeer::getPeer(i);
NSView* view = (NSView*) peer->getNativeHandle();
if ([[view window] windowRef] == w)
return true;
}
return false;
}
void forwardCurrentKeyEventToHostWindow()
{
WindowRef w = FrontNonFloatingWindow();
WindowRef original = w;
while (IsValidWindowPtr (w) && isJuceWindow (w))
{
w = GetNextWindowOfClass (w, kDocumentWindowClass, true);
if (w == original)
break;
}
if (! isJuceWindow (w))
{
ActivateWindow (w, true);
[NSApp postEvent: [NSApp currentEvent] atStart: YES];
}
}
#endif #endif

+ 1003
- 996
extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp
File diff suppressed because it is too large
View File


+ 11
- 4
extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp View File

@@ -154,6 +154,7 @@ BEGIN_JUCE_NAMESPACE
extern void detachComponentFromWindowRef (Component* component, void* nsWindow); extern void detachComponentFromWindowRef (Component* component, void* nsWindow);
extern void setNativeHostWindowSize (void* nsWindow, Component* editorComp, int newWidth, int newHeight); extern void setNativeHostWindowSize (void* nsWindow, Component* editorComp, int newWidth, int newHeight);
extern void checkWindowVisibility (void* nsWindow, Component* component); extern void checkWindowVisibility (void* nsWindow, Component* component);
extern void forwardCurrentKeyEventToHost (Component* component);
#endif #endif
#if JUCE_LINUX #if JUCE_LINUX
@@ -279,10 +280,6 @@ public:
editor->setTopLeftPosition (0, 0); editor->setTopLeftPosition (0, 0);
addAndMakeVisible (editor); addAndMakeVisible (editor);
#if ! JucePlugin_EditorRequiresKeyboardFocus
setComponentProperty ("juce_disallowFocus", true);
#endif
#if JUCE_WIN32 #if JUCE_WIN32
addMouseListener (this, true); addMouseListener (this, true);
#endif #endif
@@ -306,6 +303,16 @@ public:
triggerAsyncUpdate(); triggerAsyncUpdate();
} }
#if JUCE_MAC
bool keyPressed (const KeyPress& kp)
{
// If we have an unused keypress, move the key-focus to a host window
// and re-inject the event..
forwardCurrentKeyEventToHost (this);
return true;
}
#endif
AudioProcessorEditor* getEditorComp() const AudioProcessorEditor* getEditorComp() const
{ {
return dynamic_cast <AudioProcessorEditor*> (getChildComponent (0)); return dynamic_cast <AudioProcessorEditor*> (getChildComponent (0));


+ 8
- 0
extras/audio plugins/wrapper/VST/juce_VST_Wrapper.mm View File

@@ -240,6 +240,14 @@ void checkWindowVisibility (void* nsWindow, Component* comp)
comp->setVisible ([hostWindow isVisible]); comp->setVisible ([hostWindow isVisible]);
} }
void forwardCurrentKeyEventToHost (Component* comp)
{
NSWindow* win = [(NSView*) comp->getWindowHandle() window];
[[win parentWindow] makeKeyWindow];
[NSApp postEvent: [NSApp currentEvent] atStart: YES];
}
END_JUCE_NAMESPACE END_JUCE_NAMESPACE
#endif #endif

+ 23
- 45
juce_amalgamated.cpp View File

@@ -51812,14 +51812,12 @@ public:


void updateComponents() void updateComponents()
{ {
int xAdjust = 0, yAdjust = 0;

const int visibleTop = -getY(); const int visibleTop = -getY();
const int visibleBottom = visibleTop + getParentHeight(); const int visibleBottom = visibleTop + getParentHeight();


BitArray itemsToKeep; BitArray itemsToKeep;
TreeViewItem* item = owner->rootItem; TreeViewItem* item = owner->rootItem;
int y = -yAdjust;
int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;


while (item != 0 && y < visibleBottom) while (item != 0 && y < visibleBottom)
{ {
@@ -51865,7 +51863,7 @@ public:
const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i); const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);


Rectangle pos (item->getItemPosition (false)); Rectangle pos (item->getItemPosition (false));
pos.setSize (pos.getWidth() + xAdjust, item->itemHeight);
pos.setSize (pos.getWidth(), item->itemHeight);


if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom) if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
{ {
@@ -66497,7 +66495,8 @@ void DragAndDropContainer::startDragging (const String& sourceDescription,
dic->setOpaque (true); dic->setOpaque (true);


dic->addToDesktop (ComponentPeer::windowIgnoresMouseClicks dic->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary);
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
} }
else else
thisComp->addChildComponent (dic); thisComp->addChildComponent (dic);
@@ -69739,7 +69738,8 @@ public:
{ {
setSize (1, 1); // to keep the OS happy by not having zero-size windows setSize (1, 1); // to keep the OS happy by not having zero-size windows
addToDesktop (ComponentPeer::windowIgnoresMouseClicks addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary);
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
} }
else if (owner_->getParentComponent() != 0) else if (owner_->getParentComponent() != 0)
{ {
@@ -74210,7 +74210,8 @@ void TooltipWindow::showFor (Component* const c, const String& tip)
if (getParentComponent() == 0) if (getParentComponent() == 0)
{ {
addToDesktop (ComponentPeer::windowHasDropShadow addToDesktop (ComponentPeer::windowHasDropShadow
| ComponentPeer::windowIsTemporary);
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
} }


toFront (false); toFront (false);
@@ -231868,21 +231869,14 @@ SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
{ {
switch (info.dwMajorVersion) switch (info.dwMajorVersion)
{ {
case 5:
return (info.dwMinorVersion == 0) ? Win2000 : WinXP;

case 6:
return (info.dwMinorVersion == 0) ? WinVista : Windows7;

default:
jassertfalse // !! not a supported OS!
break;
case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
default: jassertfalse; break; // !! not a supported OS!
} }
} }
else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{ {
jassert (info.dwMinorVersion != 0); // !! still running on Windows 95?? jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??

return Win98; return Win98;
} }


@@ -231895,25 +231889,12 @@ const String SystemStats::getOperatingSystemName() throw()


switch (getOperatingSystemType()) switch (getOperatingSystemType())
{ {
case WinVista:
name = "Windows Vista";
break;

case WinXP:
name = "Windows XP";
break;

case Win2000:
name = "Windows 2000";
break;

case Win98:
name = "Windows 98";
break;

default:
jassertfalse // !! new type of OS?
break;
case Windows7: name = "Windows 7"; break;
case WinVista: name = "Windows Vista"; break;
case WinXP: name = "Windows XP"; break;
case Win2000: name = "Windows 2000"; break;
case Win98: name = "Windows 98"; break;
default: jassertfalse; break; // !! new type of OS?
} }


return name; return name;
@@ -231924,7 +231905,7 @@ bool SystemStats::isOperatingSystem64Bit() throw()
#ifdef _WIN64 #ifdef _WIN64
return true; return true;
#else #else
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);


LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process"); LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");


@@ -231938,9 +231919,10 @@ bool SystemStats::isOperatingSystem64Bit() throw()


int SystemStats::getMemorySizeInMegabytes() throw() int SystemStats::getMemorySizeInMegabytes() throw()
{ {
MEMORYSTATUS mem;
GlobalMemoryStatus (&mem);
return (int) (mem.dwTotalPhys / (1024 * 1024)) + 1;
MEMORYSTATUSEX mem;
mem.dwLength = sizeof (mem);
GlobalMemoryStatusEx (&mem);
return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
} }


int SystemStats::getNumCpus() throw() int SystemStats::getNumCpus() throw()
@@ -259868,11 +259850,7 @@ void NSViewComponentPeer::drawRect (NSRect r)


bool NSViewComponentPeer::canBecomeKeyWindow() bool NSViewComponentPeer::canBecomeKeyWindow()
{ {
// If running as a plugin, let the component decide whether it's going to allow the window to get focused.
return ((getStyleFlags() & juce::ComponentPeer::windowIsTemporary) == 0)
&& (JUCEApplication::getInstance() != 0
|| (isValidPeer (this)
&& ! getComponent()->getComponentPropertyBool ("juce_disallowFocus", false, false)));
return (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0;
} }


bool NSViewComponentPeer::windowShouldClose() bool NSViewComponentPeer::windowShouldClose()


+ 2
- 4
src/gui/components/controls/juce_TreeView.cpp View File

@@ -175,14 +175,12 @@ public:
void updateComponents() void updateComponents()
{ {
int xAdjust = 0, yAdjust = 0;
const int visibleTop = -getY(); const int visibleTop = -getY();
const int visibleBottom = visibleTop + getParentHeight(); const int visibleBottom = visibleTop + getParentHeight();
BitArray itemsToKeep; BitArray itemsToKeep;
TreeViewItem* item = owner->rootItem; TreeViewItem* item = owner->rootItem;
int y = -yAdjust;
int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
while (item != 0 && y < visibleBottom) while (item != 0 && y < visibleBottom)
{ {
@@ -228,7 +226,7 @@ public:
const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i); const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
Rectangle pos (item->getItemPosition (false)); Rectangle pos (item->getItemPosition (false));
pos.setSize (pos.getWidth() + xAdjust, item->itemHeight);
pos.setSize (pos.getWidth(), item->itemHeight);
if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom) if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
{ {


+ 2
- 1
src/gui/components/mouse/juce_DragAndDropContainer.cpp View File

@@ -434,7 +434,8 @@ void DragAndDropContainer::startDragging (const String& sourceDescription,
dic->setOpaque (true); dic->setOpaque (true);
dic->addToDesktop (ComponentPeer::windowIgnoresMouseClicks dic->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary);
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
} }
else else
thisComp->addChildComponent (dic); thisComp->addChildComponent (dic);


+ 2
- 1
src/gui/components/special/juce_DropShadower.cpp View File

@@ -57,7 +57,8 @@ public:
{ {
setSize (1, 1); // to keep the OS happy by not having zero-size windows setSize (1, 1); // to keep the OS happy by not having zero-size windows
addToDesktop (ComponentPeer::windowIgnoresMouseClicks addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary);
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
} }
else if (owner_->getParentComponent() != 0) else if (owner_->getParentComponent() != 0)
{ {


+ 2
- 1
src/gui/components/windows/juce_TooltipWindow.cpp View File

@@ -105,7 +105,8 @@ void TooltipWindow::showFor (Component* const c, const String& tip)
if (getParentComponent() == 0) if (getParentComponent() == 0)
{ {
addToDesktop (ComponentPeer::windowHasDropShadow addToDesktop (ComponentPeer::windowHasDropShadow
| ComponentPeer::windowIsTemporary);
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
} }
toFront (false); toFront (false);


+ 1
- 5
src/native/mac/juce_mac_NSViewComponentPeer.mm View File

@@ -1457,11 +1457,7 @@ void NSViewComponentPeer::drawRect (NSRect r)
bool NSViewComponentPeer::canBecomeKeyWindow() bool NSViewComponentPeer::canBecomeKeyWindow()
{ {
// If running as a plugin, let the component decide whether it's going to allow the window to get focused.
return ((getStyleFlags() & juce::ComponentPeer::windowIsTemporary) == 0)
&& (JUCEApplication::getInstance() != 0
|| (isValidPeer (this)
&& ! getComponent()->getComponentPropertyBool ("juce_disallowFocus", false, false)));
return (getStyleFlags() & juce::ComponentPeer::windowIgnoresKeyPresses) == 0;
} }
bool NSViewComponentPeer::windowShouldClose() bool NSViewComponentPeer::windowShouldClose()


Loading…
Cancel
Save