Hide the menubar only when going fullscreen.

This commit is contained in:
Paul Chote
2011-01-27 20:12:34 +13:00
parent 746c3d068c
commit 38b98bf358
6 changed files with 51 additions and 44 deletions

View File

@@ -22,4 +22,5 @@
- (BOOL)initMono; - (BOOL)initMono;
- (void)runUtilityWithArgs:(NSArray *)arg; - (void)runUtilityWithArgs:(NSArray *)arg;
- (void)utilityResponded:(NSNotification *)n; - (void)utilityResponded:(NSNotification *)n;
- (BOOL)shouldHideMenubar;
@end @end

View File

@@ -5,7 +5,6 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see LICENSE. * see LICENSE.
*/ */
#import "main.h"
#import "Controller.h" #import "Controller.h"
@implementation Controller @implementation Controller
@@ -17,16 +16,12 @@
forKey:@"gamepath"]]; forKey:@"gamepath"]];
} }
extern char **environ;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{ {
gamePath = [[NSUserDefaults standardUserDefaults] stringForKey:@"gamepath"];
NSArray *args = [[NSProcessInfo processInfo] arguments]; NSArray *args = [[NSProcessInfo processInfo] arguments];
gamePath = [[NSUserDefaults standardUserDefaults] stringForKey:@"gamepath"];
// Ingame requests for native dialogs
if ([args containsObject:@"--display-filepicker"])
[self launchFilePicker:args];
// Try and launch the game // Try and launch the game
if (![self initMono]) if (![self initMono])
{ {
@@ -42,16 +37,21 @@
[[NSApplication sharedApplication] terminate:self]; [[NSApplication sharedApplication] terminate:self];
} }
// Ingame requests for native dialogs
if ([args containsObject:@"--display-filepicker"])
[self launchFilePicker:args];
// Extract a zip file // Extract a zip file
if ([args containsObject:@"--extract-zip"]) else if ([args containsObject:@"--extract-zip"])
[self extractZip:args]; [self extractZip:args];
// Install ra packages from cd // Install ra packages from cd
if ([args containsObject:@"--install-ra-packages"]) else if ([args containsObject:@"--install-ra-packages"])
[self installRAPackages:args]; [self installRAPackages:args];
else
[self launchMod:@"cnc"];
[self launchMod:@"cnc"];
[NSApp terminate: nil]; [NSApp terminate: nil];
} }
@@ -72,8 +72,10 @@
- (void)launchFilePicker:(NSArray *)args - (void)launchFilePicker:(NSArray *)args
{ {
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
hide_menubar_if_necessary();
if ([self shouldHideMenubar])
[NSMenu setMenuBarVisible:NO];
NSOpenPanel *op = [NSOpenPanel openPanel]; NSOpenPanel *op = [NSOpenPanel openPanel];
[op setLevel:CGShieldingWindowLevel()]; [op setLevel:CGShieldingWindowLevel()];
[op setAllowsMultipleSelection:NO]; [op setAllowsMultipleSelection:NO];
@@ -88,6 +90,28 @@
[NSApp terminate: nil]; [NSApp terminate: nil];
} }
- (BOOL)shouldHideMenubar
{
NSTask *task = [[[NSTask alloc] init] autorelease];
NSPipe *pipe = [NSPipe pipe];
NSMutableArray *taskArgs = [NSMutableArray arrayWithObjects:@"OpenRA.Utility.exe",
@"--settings-value",
[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath],
@"Graphics.Mode", nil];
[task setCurrentDirectoryPath:gamePath];
[task setLaunchPath:monoPath];
[task setArguments:taskArgs];
[task setStandardOutput:pipe];
NSFileHandle *readHandle = [pipe fileHandleForReading];
[task launch];
[task waitUntilExit];
NSString *response = [[[NSString alloc] initWithData:[readHandle readDataToEndOfFile]
encoding: NSUTF8StringEncoding] autorelease];
return ![response isEqualToString:@"Windowed\n"];
}
-(void)launchMod:(NSString *)mod -(void)launchMod:(NSString *)mod
{ {
// Use LaunchServices because neither NSTask or NSWorkspace support Info.plist _and_ arguments pre-10.6 // Use LaunchServices because neither NSTask or NSWorkspace support Info.plist _and_ arguments pre-10.6
@@ -95,12 +119,14 @@
// First argument is the directory to run in // First argument is the directory to run in
// Second...Nth arguments are passed to OpenRA.Game.exe // Second...Nth arguments are passed to OpenRA.Game.exe
// Launcher wrapper sets mono --debug, gl renderer and support dir. // Launcher wrapper sets mono --debug, gl renderer and support dir.
NSArray *args = [NSArray arrayWithObjects:@"--launch", gamePath, monoPath, NSArray *args = [NSArray arrayWithObjects:@"--launch",
[self shouldHideMenubar] ? @"--hide-menubar" : @"--no-hide-menubar",
gamePath,
monoPath,
[NSString stringWithFormat:@"UtilityPath=%@", [[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], [NSString stringWithFormat:@"UtilityPath=%@", [[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]],
[NSString stringWithFormat:@"SupportDir=%@",[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath]], [NSString stringWithFormat:@"SupportDir=%@",[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath]],
[NSString stringWithFormat:@"Game.Mods=%@",mod], [NSString stringWithFormat:@"Game.Mods=%@",mod],
nil]; nil];
FSRef appRef; FSRef appRef;
CFURLGetFSRef((CFURLRef)[NSURL URLWithString:[[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], &appRef); CFURLGetFSRef((CFURLRef)[NSURL URLWithString:[[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], &appRef);

View File

@@ -27,7 +27,6 @@
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
8D1107310486CEB800E47090 /* OpenRA-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OpenRA-Info.plist"; sourceTree = "<group>"; }; 8D1107310486CEB800E47090 /* OpenRA-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OpenRA-Info.plist"; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* OpenRA.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRA.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D1107320486CEB800E47090 /* OpenRA.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRA.app; sourceTree = BUILT_PRODUCTS_DIR; };
DA134CC412E6F131009AA0EF /* main.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = main.h; sourceTree = "<group>"; };
DA81FA801290F5C800C48F2F /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; }; DA81FA801290F5C800C48F2F /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
DA81FA811290F5C800C48F2F /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; }; DA81FA811290F5C800C48F2F /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
DA81FBDB12910E4900C48F2F /* OpenRA.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = OpenRA.icns; sourceTree = "<group>"; }; DA81FBDB12910E4900C48F2F /* OpenRA.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = OpenRA.icns; sourceTree = "<group>"; };
@@ -100,7 +99,6 @@
children = ( children = (
256AC3F00F4B6AF500CF3369 /* OpenRA_Prefix.pch */, 256AC3F00F4B6AF500CF3369 /* OpenRA_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */, 29B97316FDCFA39411CA2CEA /* main.m */,
DA134CC412E6F131009AA0EF /* main.h */,
); );
name = "Other Sources"; name = "Other Sources";
sourceTree = "<group>"; sourceTree = "<group>";

View File

@@ -1,10 +0,0 @@
/*
* main.h
* OpenRA
*
* Created by Paul Chote on 19/01/11.
* Copyright 2011 OpenRA. All rights reserved.
*
*/
void hide_menubar_if_necessary();

View File

@@ -7,48 +7,48 @@
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "main.h"
extern char **environ; extern char **environ;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* When launching a mod, the arguments are of the form /* When launching a mod, the arguments are of the form
* --launch <game dir> <mono path> <utility path> <support dir option> <mod option> */ * --launch <game dir> <mono path> <utility path> <support dir option> <mod option> */
if (argc >= 6 && strcmp(argv[1], "--launch") == 0) if (argc >= 8 && strcmp(argv[1], "--launch") == 0)
{ {
/* Change into the game dir */ /* Change into the game dir */
chdir(argv[2]); chdir(argv[3]);
/* Command line args for mono */ /* Command line args for mono */
char *args[] = { char *args[] = {
argv[3], argv[4],
"--debug", "--debug",
"OpenRA.Game.exe", "OpenRA.Game.exe",
argv[4],
argv[5], argv[5],
argv[6], argv[6],
argv[7],
NULL NULL
}; };
/* add game dir to DYLD_LIBRARY_PATH */ /* add game dir to DYLD_LIBRARY_PATH */
char *old = getenv("DYLD_LIBRARY_PATH"); char *old = getenv("DYLD_LIBRARY_PATH");
if (old == NULL) if (old == NULL)
setenv("DYLD_LIBRARY_PATH", argv[2], 1); setenv("DYLD_LIBRARY_PATH", argv[3], 1);
else else
{ {
char buf[512]; char buf[512];
int len = strlen(argv[2]) + strlen(old) + 2; int len = strlen(argv[3]) + strlen(old) + 2;
if (len > 512) if (len > 512)
{ {
NSLog(@"Insufficient DYLD_LIBRARY_PATH buffer length. Wanted %d, had 512", len); NSLog(@"Insufficient DYLD_LIBRARY_PATH buffer length. Wanted %d, had 512", len);
exit(1); exit(1);
} }
sprintf(buf,"%s:%s",argv[2], old); sprintf(buf,"%s:%s",argv[3], old);
setenv("DYLD_LIBRARY_PATH", buf, 1); setenv("DYLD_LIBRARY_PATH", buf, 1);
} }
if (strcmp(argv[2], "--hide-menubar") == 0)
hide_menubar_if_necessary(); [NSMenu setMenuBarVisible:NO];
/* Exec mono */ /* Exec mono */
execve(args[0], args, environ); execve(args[0], args, environ);
} }
@@ -56,11 +56,3 @@ int main(int argc, char *argv[])
/* Else, start the launcher */ /* Else, start the launcher */
return NSApplicationMain(argc, (const char **) argv); return NSApplicationMain(argc, (const char **) argv);
} }
// Hide the menubar and dock if we are running fullscreen
void hide_menubar_if_necessary()
{
// TODO: HACK: Parse the settings.yaml / commandline args for fullscreen options
if (YES)
[NSMenu setMenuBarVisible:NO];
}