move osx only code

This commit is contained in:
2019-11-27 01:28:25 +01:00
parent 20fbf5586f
commit 7701e6771b
3 changed files with 42 additions and 42 deletions

View File

@@ -12,6 +12,7 @@
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include <CoreVideo/CoreVideo.h> #include <CoreVideo/CoreVideo.h>
#include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
#import <Carbon/Carbon.h>
#import "objc_utils.h" #import "objc_utils.h"
#include <deque> #include <deque>
@@ -21,6 +22,46 @@
@import AppCenterAnalytics; @import AppCenterAnalytics;
@import AppCenterCrashes; @import AppCenterCrashes;
NSString* keyCodeToString(NSUInteger keyCode, NSUInteger mods)
{
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
CFDataRef uchr =
(CFDataRef)TISGetInputSourceProperty(currentKeyboard,
kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout *keyboardLayout =
(const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
if(keyboardLayout)
{
UInt32 deadKeyState = 0;
UniCharCount maxStringLength = 255;
UniCharCount actualStringLength = 0;
UniChar unicodeString[maxStringLength];
OSStatus status = UCKeyTranslate(keyboardLayout,
keyCode, kUCKeyActionDown, mods,
LMGetKbdType(), 0,
&deadKeyState,
maxStringLength,
&actualStringLength, unicodeString);
if (actualStringLength == 0 && deadKeyState)
{
status = UCKeyTranslate(keyboardLayout,
kVK_Space, kUCKeyActionDown, mods,
LMGetKbdType(), 0,
&deadKeyState,
maxStringLength,
&actualStringLength, unicodeString);
}
if(actualStringLength > 0 && status == noErr)
return [[NSString stringWithCharacters:unicodeString
length:(NSUInteger)actualStringLength] lowercaseString];
}
return nil;
}
@implementation View @implementation View
{ {
NSSharingService *airdrop_service; NSSharingService *airdrop_service;

View File

@@ -6,7 +6,6 @@
#include <iomanip> #include <iomanip>
#include <ctime> #include <ctime>
#include <sstream> #include <sstream>
#import <Carbon/Carbon.h>
#ifdef __OBJC__ #ifdef __OBJC__
#import <Photos/Photos.h> #import <Photos/Photos.h>
@@ -57,46 +56,6 @@ NSString* StringWToNSString ( const std::wstring& Str )
return pString; return pString;
} }
NSString* keyCodeToString(CGKeyCode keyCode, NSUInteger mods)
{
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
CFDataRef uchr =
(CFDataRef)TISGetInputSourceProperty(currentKeyboard,
kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout *keyboardLayout =
(const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
if(keyboardLayout)
{
UInt32 deadKeyState = 0;
UniCharCount maxStringLength = 255;
UniCharCount actualStringLength = 0;
UniChar unicodeString[maxStringLength];
OSStatus status = UCKeyTranslate(keyboardLayout,
keyCode, kUCKeyActionDown, mods,
LMGetKbdType(), 0,
&deadKeyState,
maxStringLength,
&actualStringLength, unicodeString);
if (actualStringLength == 0 && deadKeyState)
{
status = UCKeyTranslate(keyboardLayout,
kVK_Space, kUCKeyActionDown, mods,
LMGetKbdType(), 0,
&deadKeyState,
maxStringLength,
&actualStringLength, unicodeString);
}
if(actualStringLength > 0 && status == noErr)
return [[NSString stringWithCharacters:unicodeString
length:(NSUInteger)actualStringLength] lowercaseString];
}
return nil;
}
std::string base_address; std::string base_address;
std::atomic_flag handler_executed; std::atomic_flag handler_executed;

View File

@@ -16,6 +16,6 @@ void delete_all_files_in_path(const std::string& source_path);
void export_mp4(const std::string& rec_path, int width, int height, int tot, void(^progress_callback)(float)); void export_mp4(const std::string& rec_path, int width, int height, int tot, void(^progress_callback)(float));
void save_image_library(const std::string& path); void save_image_library(const std::string& path);
bool apple_create_dir(const std::string& path); bool apple_create_dir(const std::string& path);
NSString* keyCodeToString(CGKeyCode keyCode, NSUInteger mods); NSString* keyCodeToString(NSUInteger keyCode, NSUInteger mods);
std::wstring NSStringToStringW(NSString* Str); std::wstring NSStringToStringW(NSString* Str);
NSString* StringWToNSString(const std::wstring& Str); NSString* StringWToNSString(const std::wstring& Str);