Fix OS X cmd/alt key modifiers status when app is reactivated

This commit is contained in:
David Capello 2016-07-04 14:14:57 -03:00
parent 7b4a1ec4af
commit 51a0bbe6a4
4 changed files with 22 additions and 0 deletions

View File

@ -14,6 +14,8 @@
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)app;
- (void)applicationWillTerminate:(NSNotification*)notification;
- (void)applicationWillResignActive:(NSNotification*)notification;
- (void)applicationDidBecomeActive:(NSNotification*)notification;
- (BOOL)application:(NSApplication*)app openFiles:(NSArray*)filenames;
@end

View File

@ -17,6 +17,7 @@
#include "she/event_queue.h"
#include "she/osx/app.h"
#include "she/osx/generate_drop_files.h"
#include "she/osx/view.h"
#include "she/system.h"
@implementation OSXAppDelegate
@ -38,6 +39,20 @@
she::queue_event(ev);
}
- (void)applicationWillResignActive:(NSNotification*)notification
{
NSEvent* event = [NSApp currentEvent];
if (event != nil)
[OSXView updateKeyFlags:event];
}
- (void)applicationDidBecomeActive:(NSNotification*)notification
{
NSEvent* event = [NSApp currentEvent];
if (event != nil)
[OSXView updateKeyFlags:event];
}
- (BOOL)application:(NSApplication*)app openFiles:(NSArray*)filenames
{
generate_drop_files_from_nsarray(filenames);

View File

@ -28,6 +28,7 @@
- (void)keyDown:(NSEvent*)event;
- (void)keyUp:(NSEvent*)event;
- (void)flagsChanged:(NSEvent*)event;
+ (void)updateKeyFlags:(NSEvent*)event;
- (void)mouseEntered:(NSEvent*)event;
- (void)mouseMoved:(NSEvent*)event;
- (void)mouseExited:(NSEvent*)event;

View File

@ -188,7 +188,11 @@ bool is_key_pressed(KeyScancode scancode)
- (void)flagsChanged:(NSEvent*)event
{
[super flagsChanged:event];
[OSXView updateKeyFlags:event];
}
+ (void)updateKeyFlags:(NSEvent*)event
{
static int lastFlags = 0;
static int flags[] = {
NSShiftKeyMask,