mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-02 17:11:10 +00:00
Added Quit menu item + shortcut (Cmd+Q).
This commit is contained in:
parent
a24ce9ba11
commit
160e6ecb31
|
@ -61,6 +61,16 @@ namespace OpenTK.Platform.MacOS
|
|||
Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem);
|
||||
Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar);
|
||||
|
||||
// Add a "Quit" menu item and bind the button.
|
||||
var appMenu = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc),
|
||||
Selector.Autorelease);
|
||||
var quitMenuItem = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenuItem"), Selector.Alloc),
|
||||
Selector.Get("initWithTitle:action:keyEquivalent:"), Cocoa.ToNSString("Quit"), Selector.Get("terminate:"), Cocoa.ToNSString("q")),
|
||||
Selector.Autorelease);
|
||||
|
||||
Cocoa.SendIntPtr(appMenu, Selector.Get("addItem:"), quitMenuItem);
|
||||
Cocoa.SendIntPtr(menuItem, Selector.Get("setSubmenu:"), appMenu);
|
||||
|
||||
// Tell cocoa we're ready to run the application (usually called by [NSApp run]).
|
||||
Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ namespace OpenTK.Platform.MacOS
|
|||
// Create the window class
|
||||
Interlocked.Increment(ref UniqueId);
|
||||
windowClass = Class.AllocateClass("OpenTK_GameWindow" + UniqueId, "NSWindow");
|
||||
Class.RegisterMethod(windowClass, new WindowKeyDownDelegate(WindowKeyDown), "keyDown:", "v@:@");
|
||||
Class.RegisterMethod(windowClass, new WindowDidResizeDelegate(WindowDidResize), "windowDidResize:", "v@:@");
|
||||
Class.RegisterMethod(windowClass, new WindowDidMoveDelegate(WindowDidMove), "windowDidMove:", "v@:@");
|
||||
Class.RegisterMethod(windowClass, new WindowDidBecomeKeyDelegate(WindowDidBecomeKey), "windowDidBecomeKey:", "v@:@");
|
||||
|
@ -185,6 +186,7 @@ namespace OpenTK.Platform.MacOS
|
|||
ResetTrackingArea();
|
||||
}
|
||||
|
||||
delegate void WindowKeyDownDelegate(IntPtr self, IntPtr cmd, IntPtr notification);
|
||||
delegate void WindowDidResizeDelegate(IntPtr self, IntPtr cmd, IntPtr notification);
|
||||
delegate void WindowDidMoveDelegate(IntPtr self, IntPtr cmd, IntPtr notification);
|
||||
delegate void WindowDidBecomeKeyDelegate(IntPtr self, IntPtr cmd, IntPtr notification);
|
||||
|
@ -198,6 +200,11 @@ namespace OpenTK.Platform.MacOS
|
|||
delegate bool CanBecomeKeyWindowDelegate(IntPtr self, IntPtr cmd);
|
||||
delegate bool CanBecomeMainWindowDelegate(IntPtr self, IntPtr cmd);
|
||||
|
||||
private void WindowKeyDown(IntPtr self, IntPtr cmd, IntPtr notification)
|
||||
{
|
||||
// Steal the event to remove the "beep" sound that is normally played for unhandled key events.
|
||||
}
|
||||
|
||||
private void WindowDidResize(IntPtr self, IntPtr cmd, IntPtr notification)
|
||||
{
|
||||
OnResize(true);
|
||||
|
@ -389,10 +396,8 @@ namespace OpenTK.Platform.MacOS
|
|||
KeyPress(this, keyPressArgs);
|
||||
}
|
||||
}
|
||||
|
||||
// Steal all keydown events to avoid the annoying "bleep" sound.
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case NSEventType.KeyUp:
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue