aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/newt/native/MacWindow.m3
-rw-r--r--src/newt/native/NewtMacWindow.h25
-rw-r--r--src/newt/native/NewtMacWindow.m224
3 files changed, 129 insertions, 123 deletions
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m
index 1dcfacb6d..5470be5ae 100644
--- a/src/newt/native/MacWindow.m
+++ b/src/newt/native/MacWindow.m
@@ -473,9 +473,10 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_macosx_MacScreen_setScreenMod
CGDirectDisplayID display = NewtScreen_getCGDirectDisplayIDByNSScreen(screen);
CFArrayRef availableModes = CGDisplayAvailableModes(display);
+#ifdef VERBOSE_ON
CFIndex numberOfAvailableModes = CFArrayGetCount(availableModes);
CFIndex numberOfAvailableModesRots = ROTMODES_PER_REALMODE * numberOfAvailableModes;
-
+#endif
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModes, mode_idx / ROTMODES_PER_REALMODE);
// mode = CGDisplayModeRetain(mode); // 10.6 on CGDisplayModeRef
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index dea7e32ae..24a7cd632 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -129,13 +129,26 @@
- (NSPoint) newtClientWinPos2OSXScreenPos: (NSPoint) p;
- (NSPoint) getLocationOnScreen: (NSPoint) p;
- (NSPoint) screenPos2NewtClientWinPos: (NSPoint) p;
-- (BOOL) isMouseInside;
+- (BOOL) isMouseInside;
- (void) cursorHide:(BOOL)v;
-- (void) setMouseVisible:(BOOL)v;
+- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus;
- (void) setMouseConfined:(BOOL)v;
- (void) setMousePosition:(NSPoint)p;
+- (void) sendKeyEvent: (NSEvent*) event eventType: (jint) evType;
+- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType;
+- (void) focusChanged: (BOOL) gained;
+
+- (BOOL) becomeFirstResponder;
+- (BOOL) resignFirstResponder;
+- (BOOL) canBecomeKeyWindow;
+- (void) becomeKeyWindow;
+- (void) resignKeyWindow;
+- (void) windowDidBecomeKey: (NSNotification *) notification;
+- (void) windowDidResignKey: (NSNotification *) notification;
+- (void) keyDown: (NSEvent*) theEvent;
+- (void) keyUp: (NSEvent*) theEvent;
- (void) mouseEntered: (NSEvent*) theEvent;
- (void) mouseExited: (NSEvent*) theEvent;
- (void) mouseMoved: (NSEvent*) theEvent;
@@ -149,12 +162,4 @@
- (void) otherMouseDown: (NSEvent*) theEvent;
- (void) otherMouseUp: (NSEvent*) theEvent;
-- (BOOL) becomeFirstResponder;
-- (BOOL) resignFirstResponder;
-- (void) becomeKeyWindow;
-- (void) resignKeyWindow;
-- (void) windowDidBecomeKey: (NSNotification *) notification;
-- (void) windowDidResignKey: (NSNotification *) notification;
-- (void) focusChanged: (BOOL) gained;
-
@end
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 204feeef7..539672f2b 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -476,11 +476,47 @@ static jmethodID windowRepaintID = NULL;
viewFrame.origin.y <= l0.y && l0.y < (viewFrame.origin.y+viewFrame.size.height) ;
}
-- (BOOL) canBecomeKeyWindow
+- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus
{
- // Even if the window is borderless, we still want it to be able
- // to become the key window to receive keyboard events
- return YES;
+ mouseVisible = v;
+ mouseInside = [self isMouseInside];
+ DBG_PRINT( "setMouseVisible: confined %d, visible %d (current: %d), mouseInside %d, hasFocus %d\n",
+ mouseConfined, mouseVisible, !cursorIsHidden, mouseInside, focus);
+ if(YES == focus && YES == mouseInside) {
+ [self cursorHide: !mouseVisible];
+ }
+}
+
+- (void) cursorHide:(BOOL)v
+{
+ DBG_PRINT( "cursorHide: %d -> %d\n", cursorIsHidden, v);
+ if(v) {
+ if(!cursorIsHidden) {
+ [NSCursor hide];
+ cursorIsHidden = YES;
+ }
+ } else {
+ if(cursorIsHidden) {
+ [NSCursor unhide];
+ cursorIsHidden = NO;
+ }
+ }
+}
+
+- (void) setMouseConfined:(BOOL)v
+{
+ mouseConfined = v;
+ DBG_PRINT( "setMouseConfined: confined %d, visible %d\n", mouseConfined, mouseVisible);
+}
+
+- (void) setMousePosition:(NSPoint)p
+{
+ NSScreen* screen = [self screen];
+ NSRect screenRect = [screen frame];
+
+ CGPoint pt = { p.x, screenRect.size.height - p.y }; // y-flip (CG is top-left origin)
+ CGEventRef ev = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, pt, kCGMouseButtonLeft);
+ CGEventPost (kCGHIDEventTap, ev);
}
static jint mods2JavaMods(NSUInteger mods)
@@ -547,17 +583,6 @@ static jint mods2JavaMods(NSUInteger mods)
}
}
-- (void) keyDown: (NSEvent*) theEvent
-{
- [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED];
-}
-
-- (void) keyUp: (NSEvent*) theEvent
-{
- [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED];
- [self sendKeyEvent: theEvent eventType: EVENT_KEY_TYPED];
-}
-
- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType
{
NSView* nsview = [self contentView];
@@ -633,47 +658,91 @@ static jint mods2JavaMods(NSUInteger mods)
}
}
-- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus
+- (void) focusChanged: (BOOL) gained
{
- mouseVisible = v;
- mouseInside = [self isMouseInside];
- DBG_PRINT( "setMouseVisible: confined %d, visible %d (current: %d), mouseInside %d, hasFocus %d\n",
- mouseConfined, mouseVisible, !cursorIsHidden, mouseInside, focus);
- if(YES == focus && YES == mouseInside) {
- [self cursorHide: !mouseVisible];
+ DBG_PRINT( "focusChanged: gained %d\n", gained);
+ NSView* nsview = [self contentView];
+ if( ! [nsview isMemberOfClass:[NewtView class]] ) {
+ return;
+ }
+ NewtView* view = (NewtView *) nsview;
+ jobject javaWindowObject = [view getJavaWindowObject];
+ if (javaWindowObject == NULL) {
+ DBG_PRINT("focusChanged: null javaWindowObject\n");
+ return;
+ }
+ int shallBeDetached = 0;
+ JavaVM *jvmHandle = [view getJVMHandle];
+ JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
+ if(NULL==env) {
+ DBG_PRINT("focusChanged: null JNIEnv\n");
+ return;
+ }
+
+ (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, (gained == YES) ? JNI_TRUE : JNI_FALSE);
+
+ if (shallBeDetached) {
+ (*jvmHandle)->DetachCurrentThread(jvmHandle);
}
}
-- (void) cursorHide:(BOOL)v
+- (BOOL) becomeFirstResponder
{
- DBG_PRINT( "cursorHide: %d -> %d\n", cursorIsHidden, v);
- if(v) {
- if(!cursorIsHidden) {
- [NSCursor hide];
- cursorIsHidden = YES;
- }
- } else {
- if(cursorIsHidden) {
- [NSCursor unhide];
- cursorIsHidden = NO;
- }
+ DBG_PRINT( "*************** becomeFirstResponder\n");
+ return [super becomeFirstResponder];
+}
+
+- (BOOL) resignFirstResponder
+{
+ DBG_PRINT( "*************** resignFirstResponder\n");
+ return [super resignFirstResponder];
+}
+
+- (BOOL) canBecomeKeyWindow
+{
+ // Even if the window is borderless, we still want it to be able
+ // to become the key window to receive keyboard events
+ return YES;
+}
+
+- (void) becomeKeyWindow
+{
+ DBG_PRINT( "*************** becomeKeyWindow\n");
+ [super becomeKeyWindow];
+}
+
+- (void) resignKeyWindow
+{
+ DBG_PRINT( "*************** resignKeyWindow\n");
+ [super resignKeyWindow];
+}
+
+- (void) windowDidBecomeKey: (NSNotification *) notification
+{
+ DBG_PRINT( "*************** windowDidBecomeKey\n");
+ mouseInside = [self isMouseInside];
+ if(YES == mouseInside) {
+ [self cursorHide: !mouseVisible];
}
+ [self focusChanged: YES];
}
-- (void) setMouseConfined:(BOOL)v
+- (void) windowDidResignKey: (NSNotification *) notification
{
- mouseConfined = v;
- DBG_PRINT( "setMouseConfined: confined %d, visible %d\n", mouseConfined, mouseVisible);
+ DBG_PRINT( "*************** windowDidResignKey\n");
+ // Implicit mouse exit by OS X
+ [self focusChanged: NO];
}
-- (void) setMousePosition:(NSPoint)p
+- (void) keyDown: (NSEvent*) theEvent
{
- NSScreen* screen = [self screen];
- NSRect screenRect = [screen frame];
+ [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED];
+}
- CGPoint pt = { p.x, screenRect.size.height - p.y }; // y-flip (CG is top-left origin)
- CGEventRef ev = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, pt, kCGMouseButtonLeft);
- CGEventPost (kCGHIDEventTap, ev);
+- (void) keyUp: (NSEvent*) theEvent
+{
+ [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED];
+ [self sendKeyEvent: theEvent eventType: EVENT_KEY_TYPED];
}
- (void) mouseEntered: (NSEvent*) theEvent
@@ -869,73 +938,4 @@ static jint mods2JavaMods(NSUInteger mods)
[pool release];
}
-- (BOOL) becomeFirstResponder
-{
- DBG_PRINT( "*************** becomeFirstResponder\n");
- return [super becomeFirstResponder];
-}
-
-- (BOOL) resignFirstResponder
-{
- DBG_PRINT( "*************** resignFirstResponder\n");
- return [super resignFirstResponder];
-}
-
-- (void) becomeKeyWindow
-{
- DBG_PRINT( "*************** becomeKeyWindow\n");
- [super becomeKeyWindow];
-}
-
-- (void) resignKeyWindow
-{
- DBG_PRINT( "*************** resignKeyWindow\n");
- [super resignKeyWindow];
-}
-
-- (void) windowDidBecomeKey: (NSNotification *) notification
-{
- DBG_PRINT( "*************** windowDidBecomeKey\n");
- mouseInside = [self isMouseInside];
- if(YES == mouseInside) {
- [self cursorHide: !mouseVisible];
- }
- [self focusChanged: YES];
-}
-
-- (void) windowDidResignKey: (NSNotification *) notification
-{
- DBG_PRINT( "*************** windowDidResignKey\n");
- // Implicit mouse exit by OS X
- [self focusChanged: NO];
-}
-
-- (void) focusChanged: (BOOL) gained
-{
- DBG_PRINT( "focusChanged: gained %d\n", gained);
- NSView* nsview = [self contentView];
- if( ! [nsview isMemberOfClass:[NewtView class]] ) {
- return;
- }
- NewtView* view = (NewtView *) nsview;
- jobject javaWindowObject = [view getJavaWindowObject];
- if (javaWindowObject == NULL) {
- DBG_PRINT("focusChanged: null javaWindowObject\n");
- return;
- }
- int shallBeDetached = 0;
- JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
- if(NULL==env) {
- DBG_PRINT("focusChanged: null JNIEnv\n");
- return;
- }
-
- (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, (gained == YES) ? JNI_TRUE : JNI_FALSE);
-
- if (shallBeDetached) {
- (*jvmHandle)->DetachCurrentThread(jvmHandle);
- }
-}
-
@end