Cmd+Q should close client on osx, closes #169. (Thanks AndrewPH)

This commit is contained in:
UnknownShadow200 2016-04-14 11:09:49 +10:00
parent 93c35029a3
commit 08ae814bb2
2 changed files with 13 additions and 7 deletions

View File

@ -288,11 +288,12 @@ namespace ClassicalSharp {
} }
static int[] viewDistances = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; static int[] viewDistances = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
Key lastKey;
void KeyDownHandler( object sender, KeyboardKeyEventArgs e ) { void KeyDownHandler( object sender, KeyboardKeyEventArgs e ) {
Key key = e.Key; Key key = e.Key;
if( SimulateMouse( key, true ) ) return; if( SimulateMouse( key, true ) ) return;
if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) { if( IsShutdown( key ) ) {
game.Exit(); game.Exit();
} else if( key == Keys[KeyBinding.Screenshot] ) { } else if( key == Keys[KeyBinding.Screenshot] ) {
game.screenshotRequested = true; game.screenshotRequested = true;
@ -300,6 +301,15 @@ namespace ClassicalSharp {
if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) ) if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) )
HandleHotkey( key ); HandleHotkey( key );
} }
lastKey = key;
}
bool IsShutdown( Key key ) {
if( key == Key.F4 && (lastKey == Key.AltLeft || lastKey == Key.AltRight) )
return true;
// On OSX, Cmd+Q should also terminate the process.
if( !OpenTK.Configuration.RunningOnMacOS ) return false;
return key == Key.Q && (lastKey == Key.WinLeft || lastKey == Key.WinRight);
} }
void HandleHotkey( Key key ) { void HandleHotkey( Key key ) {

View File

@ -40,9 +40,8 @@ namespace ClassicalSharp {
/// <summary> Returns the next highest power of 2 that is ≥ to the given value. </summary> /// <summary> Returns the next highest power of 2 that is ≥ to the given value. </summary>
public static int NextPowerOf2( int value ) { public static int NextPowerOf2( int value ) {
int next = 1; int next = 1;
while( value > next ) { while( value > next )
next <<= 1; next <<= 1;
}
return next; return next;
} }
@ -53,10 +52,7 @@ namespace ClassicalSharp {
/// <summary> Returns a string with all the colour codes stripped from it. </summary> /// <summary> Returns a string with all the colour codes stripped from it. </summary>
public static string StripColours( string value ) { public static string StripColours( string value ) {
if( value.IndexOf( '&' ) == -1 ) { if( value.IndexOf( '&' ) == -1 ) return value;
return value;
}
char[] output = new char[value.Length]; char[] output = new char[value.Length];
int usedChars = 0; int usedChars = 0;