mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-02 21:30:40 +00:00
Revert "Add a basic mouse grab mode when running on macOS"
This reverts commit 587eb48f61
.
This commit is contained in:
parent
2a0f391113
commit
920c2024be
57
main_sdl.m
57
main_sdl.m
@ -20,12 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <SDL.h>
|
||||
|
||||
@interface DPPCResponder : NSResponder
|
||||
@end
|
||||
|
||||
static DPPCResponder *dppcResponder;
|
||||
|
||||
/** @file SDL-specific main function additions for macOS hosts. */
|
||||
|
||||
@ -43,55 +37,4 @@ void remap_appkit_menu_shortcuts(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add a "Grab Mouse" commamand to the Window menu.
|
||||
NSMenuItem *windowMenuItem = [[NSApp mainMenu] itemWithTitle:@"Window"];
|
||||
if (windowMenuItem) {
|
||||
NSMenu *windowMenu = [windowMenuItem submenu];
|
||||
if (windowMenu) {
|
||||
NSMenuItem *grabMouseMenuItem = [[NSMenuItem alloc] initWithTitle:@"Grab Mouse"
|
||||
action:@selector(grabMouse:)
|
||||
keyEquivalent:@"g"];
|
||||
[grabMouseMenuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl];
|
||||
[windowMenu addItem:grabMouseMenuItem];
|
||||
}
|
||||
}
|
||||
|
||||
// Insert a responder in the chain to handle the command (SDL does not
|
||||
// expose its NSAppDelegate implementation so we can't subclass it).
|
||||
dppcResponder = [DPPCResponder new];
|
||||
[dppcResponder setNextResponder:[NSApp nextResponder]];
|
||||
[NSApp setNextResponder:dppcResponder];
|
||||
}
|
||||
|
||||
@implementation DPPCResponder
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
||||
if ([menuItem action] == @selector(grabMouse:)) {
|
||||
[menuItem setState:SDL_GetRelativeMouseMode() ? NSControlStateValueOn : NSControlStateValueOff];
|
||||
return YES;
|
||||
}
|
||||
return [super validateMenuItem:menuItem];
|
||||
}
|
||||
|
||||
- (void)grabMouse:(id)sender {
|
||||
NSWindow *mainWindow = NSApp.mainWindow;
|
||||
if (mainWindow) {
|
||||
// If we're about to grab the mouse, move the mouse to the middle of the
|
||||
// window so that SDL knows that this window is what we want coordinates
|
||||
// to be relative to.
|
||||
if (!SDL_GetRelativeMouseMode()) {
|
||||
NSRect frame = mainWindow.frame;
|
||||
NSPoint center = NSMakePoint(frame.size.width/2, frame.size.height/2);
|
||||
center = [mainWindow convertPointToScreen:center];
|
||||
CGWarpMouseCursorPosition(center);
|
||||
mainWindow.subtitle = @"Mouse grabbed";
|
||||
} else {
|
||||
mainWindow.subtitle = @"";
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode());
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user