From 0291c41afa2c80d9a1a8276f937aebb2c19f55cf Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sat, 14 Jul 2018 11:18:21 -0700 Subject: [PATCH] fix(Metal): Fix blank screen after full screen toggle; window focus --- gfx/common/metal_common.m | 12 +++++ .../RetroArch_Metal.xcodeproj/project.pbxproj | 20 ++++++- ui/drivers/ui_cocoa.m | 53 ++++++++++++++----- 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index efdb0853d2..ad433da056 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -104,6 +104,16 @@ .height = _video.height, .fullscreen = _video.fullscreen, }; + + if (mode.width == 0 || mode.height == 0) + { + // 0 indicates full screen, so we'll use the view's dimensions, which should already be full screen + // If this turns out to be the wrong assumption, we can use NSScreen to query the dimensions + CGSize size = view.frame.size; + mode.width = (unsigned int)size.width; + mode.height = (unsigned int)size.height; + } + [apple_platform setVideoMode:mode]; *input = NULL; @@ -213,6 +223,8 @@ - (void)_updateViewport:(CGSize)size { + RARCH_LOG("[Metal]: _updateViewport size %.0fx%.0f\n", size.width, size.height); + _viewport->full_width = (unsigned int)size.width; _viewport->full_height = (unsigned int)size.height; video_driver_set_size(&_viewport->full_width, &_viewport->full_height); diff --git a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj index 842da09730..2b2e562f91 100644 --- a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj +++ b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj @@ -55,6 +55,14 @@ 0538875720DE11D300769232 /* retro_assert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = retro_assert.h; sourceTree = ""; }; 0538875820DE11D300769232 /* retro_endianness.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = retro_endianness.h; sourceTree = ""; }; 0538875920DE11D300769232 /* libretro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = libretro.h; sourceTree = ""; }; + 0548E2B220F976E10094A083 /* driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = driver.c; path = ../../driver.c; sourceTree = ""; }; + 0548E2B320F976E10094A083 /* dynamic.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = dynamic.c; path = ../../dynamic.c; sourceTree = ""; }; + 0548E2B420F976E10094A083 /* dynamic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = dynamic.h; path = ../../dynamic.h; sourceTree = ""; }; + 0548E2B520F976E20094A083 /* driver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = driver.h; path = ../../driver.h; sourceTree = ""; }; + 0548E2B620F977060094A083 /* playlist.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = playlist.h; path = ../../playlist.h; sourceTree = ""; }; + 0548E2B720F977060094A083 /* performance_counters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = performance_counters.h; path = ../../performance_counters.h; sourceTree = ""; }; + 0548E2B820F977060094A083 /* performance_counters.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = performance_counters.c; path = ../../performance_counters.c; sourceTree = ""; }; + 0548E2B920F977060094A083 /* playlist.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = playlist.c; path = ../../playlist.c; sourceTree = ""; }; 055312AB20DE130A00C4D7F4 /* gl_capabilities.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = gl_capabilities.c; sourceTree = ""; }; 055312AD20DE130A00C4D7F4 /* scaler_int.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = scaler_int.c; sourceTree = ""; }; 055312AE20DE130A00C4D7F4 /* pixconv.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = pixconv.c; sourceTree = ""; }; @@ -1070,8 +1078,6 @@ 05BF821320ED69A500D95B19 /* core */ = { isa = PBXGroup; children = ( - 05B5F91120ED6AAE009C521F /* retroarch.c */, - 05B5F91220ED6AAF009C521F /* retroarch.h */, 05B5F90F20ED6A03009C521F /* command.c */, 05BF821720ED69D100D95B19 /* command.h */, 05BF821420ED69D100D95B19 /* config.def.h */, @@ -1085,6 +1091,16 @@ 05BF821B20ED69D100D95B19 /* core_info.h */, 05B5F90E20ED6A03009C521F /* core_type.h */, 05BF821920ED69D100D95B19 /* core.h */, + 0548E2B220F976E10094A083 /* driver.c */, + 0548E2B520F976E20094A083 /* driver.h */, + 0548E2B320F976E10094A083 /* dynamic.c */, + 0548E2B420F976E10094A083 /* dynamic.h */, + 0548E2B820F977060094A083 /* performance_counters.c */, + 0548E2B720F977060094A083 /* performance_counters.h */, + 0548E2B920F977060094A083 /* playlist.c */, + 0548E2B620F977060094A083 /* playlist.h */, + 05B5F91120ED6AAE009C521F /* retroarch.c */, + 05B5F91220ED6AAF009C521F /* retroarch.h */, ); name = core; sourceTree = ""; diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 6b84e3e857..aced897a60 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -42,6 +42,24 @@ #import #endif +@interface WindowListener : NSResponder +@end + +@implementation WindowListener + +/* Similarly to SDL, we'll respond to key events by doing nothing so we don't beep. + */ +- (void)flagsChanged:(NSEvent *)event +{} + +- (void)keyDown:(NSEvent *)event +{} + +- (void)keyUp:(NSEvent *)event +{} + +@end + id apple_platform; #if (defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__))) @@ -54,7 +72,7 @@ id apple_platform; apple_view_type_t _vt; NSView* _renderView; id _sleepActivity; - + WindowListener *_listener; } @property (nonatomic, retain) NSWindow IBOutlet* window; @@ -109,7 +127,7 @@ static void app_terminate(void) case NSEventTypeKeyDown: case NSEventTypeKeyUp: { - NSString* ch = (NSString*)event.characters; + NSString* ch = event.characters; uint32_t character = 0; uint32_t mod = 0; @@ -164,13 +182,13 @@ static void app_terminate(void) return; /* Relative */ - apple->mouse_rel_x = event.deltaX; - apple->mouse_rel_y = event.deltaY; + apple->mouse_rel_x = (int16_t)event.deltaX; + apple->mouse_rel_y = (int16_t)event.deltaY; /* Absolute */ pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil]; - apple->touches[0].screen_x = pos.x; - apple->touches[0].screen_y = pos.y; + apple->touches[0].screen_x = (int16_t)pos.x; + apple->touches[0].screen_y = (int16_t)pos.y; mouse_pos = [apple_platform.renderView convertPoint:[event locationInWindow] fromView:nil]; apple->window_pos_x = (int16_t)mouse_pos.x; @@ -245,8 +263,13 @@ static char** waiting_argv; [self.window setCollectionBehavior:NS_WINDOW_COLLECTION_BEHAVIOR_FULLSCREEN_PRIMARY]; } #endif + + _listener = [WindowListener new]; + [self.window setAcceptsMouseMovedEvents: YES]; - + [self.window setNextResponder:_listener]; + self.window.delegate = _listener; + [[self.window contentView] setAutoresizesSubviews:YES]; for (i = 0; i < waiting_argc; i++) @@ -262,7 +285,10 @@ static char** waiting_argv; app_terminate(); waiting_argc = 0; - + + [self.window makeMainWindow]; + [self.window makeKeyWindow]; + [self performSelectorOnMainThread:@selector(rarch_main) withObject:nil waitUntilDone:NO]; } @@ -271,7 +297,7 @@ static char** waiting_argv; return; } - RARCH_LOG("[Cocoa] change view type: %d → %d\n", _vt, vt); + RARCH_LOG("[Cocoa]: change view type: %d → %d\n", _vt, vt); _vt = vt; if (_renderView != nil) @@ -279,6 +305,7 @@ static char** waiting_argv; _renderView.wantsLayer = NO; _renderView.layer = nil; [_renderView removeFromSuperview]; + self.window.contentView = nil; _renderView = nil; } @@ -294,7 +321,7 @@ static char** waiting_argv; } #endif break; - + case APPLE_VIEW_TYPE_OPENGL: { _renderView = [CocoaView get]; @@ -308,9 +335,9 @@ static char** waiting_argv; _renderView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; _renderView.frame = self.window.contentView.bounds; - - [self.window.contentView addSubview:_renderView]; - [self.window makeFirstResponder:_renderView]; + + self.window.contentView = _renderView; + [self.window.contentView setNextResponder:_listener]; } - (apple_view_type_t)viewType {