Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a mac implementation for next_keyboard_layout() function, now the get_voice_name() function, on macOS will also return its language code #116

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4e05d24
Added TTSVoice class for macOS.
GruiaChiscop Jun 19, 2024
1fec133
Finishes fitting this class into nvgt's codebase
samtupy Jun 20, 2024
06078f6
Merge branch 'samtupy:main' into macOSEnhancements
GruiaChiscop Jun 20, 2024
2d86157
Added ave_file_dialog and open_file dialog functions
GruiaChiscop Jun 22, 2024
8621e40
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jun 22, 2024
5414c0a
Add the open_file_dialog and save_file_dialog functions
GruiaChiscop Jun 22, 2024
b946cc7
Now the functions are registered correctly on the script, added tests…
GruiaChiscop Jun 22, 2024
5e793d7
Added tests for save and open file dialogs
GruiaChiscop Jun 22, 2024
19f02b9
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jun 24, 2024
64c07ba
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jun 27, 2024
675d54e
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jun 29, 2024
59dbd9b
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jul 2, 2024
a139e1e
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jul 6, 2024
fa42217
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Jul 22, 2024
e9bfd75
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Sep 1, 2024
54d68ff
Solved conflicts with the upstream repo
GruiaChiscop Sep 23, 2024
dfc2b0c
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Sep 24, 2024
e9900a7
Resolved conflicts
GruiaChiscop Sep 30, 2024
4622c34
Fixed errors in ui.cpp
GruiaChiscop Sep 30, 2024
2f1f6a0
commit
GruiaChiscop Oct 2, 2024
e6daec8
Merge branch 'samtupy:main' into Tessera's-enhancements
GruiaChiscop Oct 2, 2024
d5cf689
commit#2
GruiaChiscop Oct 2, 2024
b53b369
Now getVoiceName in AVTTSVoice will also return the language code. Th…
GruiaChiscop Oct 6, 2024
cd15451
Implemented next_keyboard_layout() function for macOS
GruiaChiscop Oct 7, 2024
a674154
Merge branch 'samtupy:main' into GruiaChiscopEnhancements
GruiaChiscop Oct 7, 2024
2763c68
Removed debugging code
GruiaChiscop Oct 7, 2024
5fe45df
Merge branch 'GruiaChiscopEnhancements' of github.com:GruiaChiscop/nv…
GruiaChiscop Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"files.associations": {
"__bit_reference": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"execution": "cpp",
"memory": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"print": "cpp",
"queue": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"variant": "cpp",
"vector": "cpp",
"algorithm": "cpp"
}
}
Empty file modified build/build_macos.sh
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions src/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include <windows.h>
#include <commdlg.h>
#include "InputBox.h"
#elif defined(__APPLE__)
#include <IOKit/IOKitLib.h>
Expand All @@ -30,6 +31,7 @@
#endif
#ifndef _WIN32
#include <sys/time.h>

#endif
#include <SDL3/SDL.h>
#include <obfuscate.h>
Expand Down Expand Up @@ -187,6 +189,8 @@ bool urlopen(const std::string& url) {
void next_keyboard_layout() {
#ifdef _WIN32
ActivateKeyboardLayout((HKL)HKL_NEXT, 0);
#elif defined(__APPLE__)
nextMacInputSource();
#endif
}
std::string input_box(const std::string& title, const std::string& text, const std::string& default_value) {
Expand Down Expand Up @@ -331,6 +335,7 @@ void refresh_window() {
post_events.clear();
}
}

void wait(int ms) {
if (!g_WindowHandle || g_WindowThreadId != thread_current_thread_id()) {
Poco::Thread::sleep(ms);
Expand All @@ -349,6 +354,7 @@ void wait(int ms) {
}



// The following function contributed to NVGT by silak
uint64_t idle_ticks() {
#ifdef _WIN32
Expand Down
2 changes: 2 additions & 0 deletions src/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ bool DestroyNVGTWindow();
bool WindowIsFocused();
void refresh_window();
void wait(int ms);
//std::string open_fileDialog(const std::string& title);
//std::string save_file_dialog(const std::string& title, const std::string& filename);
void RegisterUI(asIScriptEngine* engine);
2 changes: 2 additions & 0 deletions src/apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ bool voice_over_speak(const std::string& message, bool interrupt = true);
void voice_over_window_created();
void voice_over_speech_shutdown();
std::string apple_input_box(const std::string& title, const std::string& message, const std::string& default_value = "", bool secure = false, bool readonly = false);
std::string apple_requested_file();
void nextMacInputSource();

// Definition for AVTTSVoice class created by Gruia Chiscop on 6/6/24.
class AVTTSVoice {
Expand Down
1 change: 1 addition & 0 deletions src/apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ NSUInteger getVoicesCount() const {
//this method returns the index of the voice, using its name. If more than a voice has the same name, like alex from eSpeak and Alex from Apple, the first voice index will be returned.
int getVoiceIndex(const std::string& name) {
NSArray<AVSpeechSynthesisVoice *> *voices = [AVSpeechSynthesisVoice speechVoices];
NSString *nsname = [NSString stringWithUTF8String:name.c_str()];
AVSpeechSynthesisVoice *voice = getVoiceObject([NSString stringWithUTF8String:name.c_str()]);
if (voice) {
NSUInteger result = [voices indexOfObject:voice];
Expand Down
25 changes: 25 additions & 0 deletions src/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#import <AppKit/AppKit.h>
#import <Carbon/Carbon.h>
#include <string>
#include <Poco/Event.h>
#include <Poco/Mutex.h>
Expand Down Expand Up @@ -93,3 +94,27 @@ void voice_over_speech_shutdown() {
else if (result == NSAlertSecondButtonReturn) return "\xff"; // nvgt value for cancel for the moment.
return "\xff"; // Either an error or we can't determine what was pressed. Should we throw an exception or something?
}

void nextMacInputSource() {
CFArrayRef inputSources = TISCreateInputSourceList(NULL, false);
TISInputSourceRef currentInput = TISCopyCurrentKeyboardInputSource();
NSInteger count = CFArrayGetCount(inputSources);
NSInteger currentIndex = -1;
for(int i=0; i<count; i++) {
TISInputSourceRef k = (TISInputSourceRef)CFArrayGetValueAtIndex(inputSources, i);
if(CFEqual(k, currentInput)) {
currentIndex = i;
break;
}
}
if(currentIndex==-1) {
CFRelease(currentInput);
CFRelease(inputSources);
return;
}
NSInteger nextIndex = (currentIndex+1)%count;
TISInputSourceRef nextInput = (TISInputSourceRef)CFArrayGetValueAtIndex(inputSources, nextIndex);
TISSelectInputSource(nextInput);
CFRelease(currentInput);
CFRelease(inputSources);
}
4 changes: 4 additions & 0 deletions test/quick/keyboard_layout.nvgt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void main()
{
next_keyboard_layout();
}