Skip to content
Permalink
Browse files
Output messages on Mac!
This is done using a wrapper for the OS X accessibility API which posts announcement requested notifications.
Closes #36.
  • Loading branch information
vick08 authored and jcsteh committed Jul 15, 2015
1 parent 6aca22d commit 41217836a50d1f9dff1d561d03ece4fb6bd793f8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
@@ -1,2 +1,2 @@
#!/bin/sh
clang -dynamiclib -o reaper_osara.dylib -current_version 1.0 -compatibility_version 1.0 -fvisibility=hidden -undefined dynamic_lookup -stdlib=libc++ -std=c++11 -I ../include -I ../include/WDL -I ../include/WDL/wdl/swell reaper_osara.cpp
clang++ -dynamiclib -o reaper_osara.dylib -current_version 1.0 -compatibility_version 1.0 -fvisibility=hidden -undefined dynamic_lookup -stdlib=libc++ -std=c++11 -I ../include -I ../include/WDL -I ../include/WDL/wdl/swell reaper_osara.cpp -fobjc-arc -framework Appkit osxa11y.mm
@@ -0,0 +1,40 @@
#import <AppKit/AppKit.h>
#include "osxa11y_wrapper.h"

@interface OSXA11y : NSObject
- (void)announce:(NSString*)message;
@end

@implementation OSXA11y
namespace NSA11yWrapper {
struct osxa11yImpl
{
OSXA11y* pWrapper;
};

void init()
{
impl = new osxa11yImpl;
impl->pWrapper = [[OSXA11y alloc] init];
}

void osxa11y_announce(const std::string& message)
{
NSString* param = [NSString stringWithUTF8String:message.c_str()];
[impl->pWrapper announce:param];
}

void destroy()
{
if (impl != NULL)
delete impl;
}
}

- (void)announce:(NSString*)message {
NSDictionary *announcementInfo = @{NSAccessibilityAnnouncementKey : message,
NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)};

NSAccessibilityPostNotificationWithUserInfo([NSApp mainWindow], NSAccessibilityAnnouncementRequestedNotification, announcementInfo);
}
@end
@@ -0,0 +1,14 @@
#ifndef osxa11y_wrapper_h
#define osxa11y_wrapper_h
#include <iostream>

namespace NSA11yWrapper {
struct osxa11yImpl;
static osxa11yImpl* impl;

void init();
void osxa11y_announce(const std::string& param);
void destroy();
}

#endif
@@ -22,6 +22,8 @@
#ifdef _WIN32
// We only need this on Windows and it apparently causes compilation issues on Mac.
#include <codecvt>
#else
#include "osxa11y_wrapper.h" // NSA11y wrapper for OS X accessibility API
#endif
#define REAPERAPI_MINIMAL
#define REAPERAPI_IMPLEMENT
@@ -136,6 +138,7 @@ void outputMessage(const string& message) {
#else // _WIN32

void outputMessage(const string& message) {
NSA11yWrapper::osxa11y_announce(message);
}

#endif // _WIN32
@@ -1346,6 +1349,8 @@ REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hI
return 0;
guiThread = GetWindowThreadProcessId(mainHwnd, NULL);
winEventHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, hInstance, handleWinEvent, 0, guiThread, WINEVENT_INCONTEXT);
#else
NSA11yWrapper::init();
#endif

for (int i = 0; POST_COMMANDS[i].cmd; ++i)
@@ -1387,6 +1392,8 @@ REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hI
#ifdef _WIN32
UnhookWinEvent(winEventHook);
accPropServices->Release();
#else
NSA11yWrapper::destroy();
#endif
return 0;
}

0 comments on commit 4121783

Please sign in to comment.