Skip to content

Commit

Permalink
macOS: fix integration, menu bar now works as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpapersonic committed Nov 30, 2022
1 parent 890955e commit 06a86c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions schism/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,11 @@ void schism_exit(int status)

extern void vis_init(void);

#ifdef MACOSX
int SDL_main(int argc, char** argv)
#else
int main(int argc, char **argv)
#endif
{
if (! SDL_VERSION_ATLEAST(2,0,5)) {
SDL_Log("SDL_VERSION %i.%i.%i less than required!", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
Expand Down
30 changes: 23 additions & 7 deletions sys/macosx/macosx-sdlmain.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam

#define KEQ_FN(n) [NSString stringWithFormat:@"%C", NSF##n##FunctionKey]

@interface SDLApplication : NSApplication
@interface SDL_SchismTracker : NSApplication
@end

@interface NSApplication(OtherMacOSXExtensions)
-(void)setAppleMenu:(NSMenu*)m;
@end

@implementation SDLApplication
@implementation SDL_SchismTracker
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
Expand Down Expand Up @@ -410,7 +410,7 @@ static void CustomApplicationMain (int argc, char **argv)
CPSProcessSerNum PSN;

/* Ensure the application object is initialised */
[SDLApplication sharedApplication];
[SDL_SchismTracker sharedApplication];

/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN)) {
Expand All @@ -419,7 +419,7 @@ static void CustomApplicationMain (int argc, char **argv)
}
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[SDLApplication sharedApplication];
[SDL_SchismTracker sharedApplication];
}

/* Set up the menubar */
Expand Down Expand Up @@ -447,7 +447,7 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note
[self setupWorkingDirectory:gFinderLaunch];

/* Hand off to main application code */
status = SDL_Init (gArgv);
status = SDL_main (gArgc, gArgv);

/* We're done, thank you for playing */
exit(status);
Expand Down Expand Up @@ -502,8 +502,7 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString


/* Main entry point to executable - should *not* be SDL_main! */
/* JK LOL... SDL2 */
int SDL_main (int argc, char **argv)
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
Expand Down Expand Up @@ -547,6 +546,23 @@ void macosx_clippy_put(const char *buf)
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pb setString:contents forType:NSStringPboardType];
}
// ktt appears to be 1/60th of a second?
unsigned int key_repeat_rate(void)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int ktt = [defaults integerForKey:@"KeyRepeat"];
if (!ktt || ktt < 0) ktt = 4; // eh?
ktt = (ktt * 1000) / 60;
return (unsigned)ktt;
}
unsigned int key_repeat_delay(void)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int ktt = [defaults integerForKey:@"InitialKeyRepeat"];
if (!ktt || ktt < 0) ktt = 35;
ktt = (ktt * 1000) / 60;
return (unsigned)ktt;
}
int key_scancode_lookup(int k, int def)
{
switch (k & 127) {
Expand Down

0 comments on commit 06a86c1

Please sign in to comment.