[Scummvm-git-logs] scummvm master -> a421962b38512d8bc061bc35d3b3db820a6b1240

criezy criezy at scummvm.org
Thu Jul 27 00:47:14 CEST 2017


This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b8142ff362 COMMON: Add method in EventManager to clear the event queue
b8c2f26098 OSX: Clear pending events when closing the native file browser
6162cd1c19 OSX: Set focus back to the ScummVM window when closing the native file browser
4981b4bbef OSX: Make sure to release the NSOpenPanel immediately after closing it
a421962b38 OSX: Make sure the native file browser runs in the main thread


Commit: b8142ff362668bdf3880a0de2e1531a292cbc785
    https://github.com/scummvm/scummvm/commit/b8142ff362668bdf3880a0de2e1531a292cbc785
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2017-07-26T21:39:31+01:00

Commit Message:
COMMON: Add method in EventManager to clear the event queue

Changed paths:
    common/EventDispatcher.cpp
    common/events.h


diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp
index 2650d79..b81db6f 100644
--- a/common/EventDispatcher.cpp
+++ b/common/EventDispatcher.cpp
@@ -70,6 +70,17 @@ void EventDispatcher::dispatch() {
 	}
 }
 
+void EventDispatcher::clearEvents() {
+	Event event;
+
+	for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
+		while (i->source->pollEvent(event)) {}
+	}
+
+	List<Event> delayedEvents = _mapper->getDelayedEvents();
+}
+
+
 void EventDispatcher::registerMapper(EventMapper *mapper, bool autoFree) {
 	if (_autoFreeMapper) {
 		delete _mapper;
diff --git a/common/events.h b/common/events.h
index 484564e..21a65a6 100644
--- a/common/events.h
+++ b/common/events.h
@@ -282,6 +282,12 @@ public:
 	void dispatch();
 
 	/**
+	 * Clear all events currently in the event queue.
+	 * The cleared events are not dispatched and are simply discarded.
+	 */
+	void clearEvents();
+
+	/**
 	 * Registers an event mapper with the dispatcher.
 	 *
 	 * The ownership of the "mapper" variable will pass


Commit: b8c2f26098640374a0ccc784ff49ef51307cb6e5
    https://github.com/scummvm/scummvm/commit/b8c2f26098640374a0ccc784ff49ef51307cb6e5
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2017-07-26T21:50:32+01:00

Commit Message:
OSX: Clear pending events when closing the native file browser

This is to avoid dispatching to ScummVM events that were intended for
the NSOpenPanel dialog.

Changed paths:
    gui/browser_osx.mm


diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm
index cfb70a3..6c5f036 100644
--- a/gui/browser_osx.mm
+++ b/gui/browser_osx.mm
@@ -29,6 +29,7 @@
 #include "common/system.h"
 #include "common/algorithm.h"
 #include "common/translation.h"
+#include "common/events.h"
 
 #include <AppKit/NSNibDeclarations.h>
 #include <AppKit/NSOpenPanel.h>
@@ -170,6 +171,14 @@ int BrowserDialog::runModal() {
 	[showHiddenFilesButton release];
 	[showHiddenFilesController release];
 
+	// While the native macOS file browser is open, any input events (e.g. keypresses) are
+	// still received by the NSApplication. With SDL backend for example this results in the
+	// events beeing queued and processed after we return, thus dispatching events that were
+	// intended for the native file browser. For example: pressing Esc to cancel the native
+	// macOS file browser would cause the application to quit in addition to closing the
+	// file browser. To avoid this happening clear all pending vents.
+	g_system->getEventManager()->getEventDispatcher()->clearEvents();
+
 	// If we were in fullscreen mode, switch back
 	if (wasFullscreen) {
 		g_system->beginGFXTransaction();


Commit: 6162cd1c1947d9f254a9f0433fc145ecb7e17b72
    https://github.com/scummvm/scummvm/commit/6162cd1c1947d9f254a9f0433fc145ecb7e17b72
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2017-07-26T23:08:39+01:00

Commit Message:
OSX: Set focus back to the ScummVM window when closing the native file browser

Changed paths:
    gui/browser_osx.mm


diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm
index 6c5f036..9bc163c 100644
--- a/gui/browser_osx.mm
+++ b/gui/browser_osx.mm
@@ -33,6 +33,7 @@
 
 #include <AppKit/NSNibDeclarations.h>
 #include <AppKit/NSOpenPanel.h>
+#include <AppKit/NSApplication.h>
 #include <AppKit/NSButton.h>
 #include <Foundation/NSString.h>
 #include <Foundation/NSURL.h>
@@ -125,6 +126,8 @@ int BrowserDialog::runModal() {
 	// Temporarily show the real mouse
 	CGDisplayShowCursor(kCGDirectMainDisplay);
 
+	NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
+
 	NSOpenPanel *panel = [NSOpenPanel openPanel];
 	[panel setCanChooseFiles:!_isDirBrowser];
 	[panel setCanChooseDirectories:_isDirBrowser];
@@ -171,6 +174,8 @@ int BrowserDialog::runModal() {
 	[showHiddenFilesButton release];
 	[showHiddenFilesController release];
 
+	[keyWindow makeKeyAndOrderFront:nil];
+
 	// While the native macOS file browser is open, any input events (e.g. keypresses) are
 	// still received by the NSApplication. With SDL backend for example this results in the
 	// events beeing queued and processed after we return, thus dispatching events that were


Commit: 4981b4bbef89e4fad7673c03ca61a4c656d4b210
    https://github.com/scummvm/scummvm/commit/4981b4bbef89e4fad7673c03ca61a4c656d4b210
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2017-07-26T23:08:48+01:00

Commit Message:
OSX: Make sure to release the NSOpenPanel immediately after closing it

This is an attempt to fix a difficult to reproduce issue where the NSOpenPanel
remains open in the background and locks the application. Some tests suggest
that it might fix the issue, but only time will tell.

Changed paths:
    gui/browser_osx.mm


diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm
index 9bc163c..6977d14 100644
--- a/gui/browser_osx.mm
+++ b/gui/browser_osx.mm
@@ -37,6 +37,7 @@
 #include <AppKit/NSButton.h>
 #include <Foundation/NSString.h>
 #include <Foundation/NSURL.h>
+#include <Foundation/NSAutoreleasePool.h>
 
 @interface ShowHiddenFilesController : NSObject {
 	NSOpenPanel* _panel;
@@ -126,6 +127,7 @@ int BrowserDialog::runModal() {
 	// Temporarily show the real mouse
 	CGDisplayShowCursor(kCGDirectMainDisplay);
 
+	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 	NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
 
 	NSOpenPanel *panel = [NSOpenPanel openPanel];
@@ -174,6 +176,7 @@ int BrowserDialog::runModal() {
 	[showHiddenFilesButton release];
 	[showHiddenFilesController release];
 
+	[pool release];
 	[keyWindow makeKeyAndOrderFront:nil];
 
 	// While the native macOS file browser is open, any input events (e.g. keypresses) are


Commit: a421962b38512d8bc061bc35d3b3db820a6b1240
    https://github.com/scummvm/scummvm/commit/a421962b38512d8bc061bc35d3b3db820a6b1240
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2017-07-26T23:31:24+01:00

Commit Message:
OSX: Make sure the native file browser runs in the main thread

Changed paths:
    gui/browser.h
    gui/browser_osx.mm


diff --git a/gui/browser.h b/gui/browser.h
index b77907b..10663f5 100644
--- a/gui/browser.h
+++ b/gui/browser.h
@@ -52,7 +52,6 @@ protected:
 #ifdef MACOSX
 	const void *_titleRef;
 	const void *_chooseRef;
-	const void *_hiddenFilesRef;
 #else
 	ListWidget		*_fileList;
 	StaticTextWidget	*_currentPath;
diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm
index 6977d14..ffb64ee 100644
--- a/gui/browser_osx.mm
+++ b/gui/browser_osx.mm
@@ -27,9 +27,9 @@
 
 #include "common/config-manager.h"
 #include "common/system.h"
+#include "common/events.h"
 #include "common/algorithm.h"
 #include "common/translation.h"
-#include "common/events.h"
 
 #include <AppKit/NSNibDeclarations.h>
 #include <AppKit/NSOpenPanel.h>
@@ -39,36 +39,81 @@
 #include <Foundation/NSURL.h>
 #include <Foundation/NSAutoreleasePool.h>
 
- at interface ShowHiddenFilesController : NSObject {
-	NSOpenPanel* _panel;
-}
 
+ at interface BrowserDialogPresenter : NSObject {
+ at public
+	NSURL *_url;
+ at private
+	NSOpenPanel *_panel;
+}
 - (id) init;
 - (void) dealloc;
-- (void) setOpenPanel : (NSOpenPanel*) panel;
+- (void) showOpenPanel: (NSOpenPanel*) panel;
 - (IBAction) showHiddenFiles : (id) sender;
-
 @end
 
- at implementation ShowHiddenFilesController
+ at implementation BrowserDialogPresenter
 
 - (id) init {
 	self = [super init];
+	_url = 0;
 	_panel = 0;
-
 	return self;
 }
 
 - (void) dealloc {
-	[_panel release];
+	[_url release];
 	[super dealloc];
 }
 
-- (void) setOpenPanel : (NSOpenPanel*) panel {
+- (void) showOpenPanel: (NSOpenPanel*) panel {
 	_panel = panel;
-	[_panel retain];
-}
 
+	NSButton *showHiddenFilesButton = 0;
+	if ([panel respondsToSelector:@selector(setShowsHiddenFiles:)]) {
+		showHiddenFilesButton = [[NSButton alloc] init];
+		[showHiddenFilesButton setButtonType:NSSwitchButton];
+
+#ifdef USE_TRANSLATION
+		CFStringRef encStr = CFStringCreateWithCString(NULL, TransMan.getCurrentCharset().c_str(), kCFStringEncodingASCII);
+		CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding(encStr);
+		CFRelease(encStr);
+#else
+		CFStringEncoding stringEncoding = kCFStringEncodingASCII;
+#endif
+		CFStringRef hiddenFilesString = CFStringCreateWithCString(0, _("Show hidden files"), stringEncoding);
+		[showHiddenFilesButton setTitle:(NSString*)hiddenFilesString];
+		CFRelease(hiddenFilesString);
+
+		[showHiddenFilesButton sizeToFit];
+		if (ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain)) {
+			[showHiddenFilesButton setState:NSOnState];
+			[panel setShowsHiddenFiles: YES];
+		} else {
+			[showHiddenFilesButton setState:NSOffState];
+			[panel setShowsHiddenFiles: NO];
+		}
+		[panel setAccessoryView:showHiddenFilesButton];
+
+		[showHiddenFilesButton setTarget:self];
+		[showHiddenFilesButton setAction:@selector(showHiddenFiles:)];
+	}
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1090
+	if ([panel runModal] == NSOKButton) {
+#else
+	if ([panel runModal] == NSModalResponseOK) {
+#endif
+		NSURL *url = [panel URL];
+		if ([url isFileURL]) {
+			_url = url;
+			[_url retain];
+		}
+	}
+
+	[showHiddenFilesButton release];
+	_panel = 0;
+}
 
 - (IBAction) showHiddenFiles : (id) sender {
 	if ([sender state] == NSOnState) {
@@ -104,13 +149,11 @@ BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
 
 	// Convert button text to NSString
 	_chooseRef = CFStringCreateWithCString(0, _("Choose"), stringEncoding);
-	_hiddenFilesRef = CFStringCreateWithCString(0, _("Show hidden files"), stringEncoding);
 }
 
 BrowserDialog::~BrowserDialog() {
 	CFRelease(_titleRef);
 	CFRelease(_chooseRef);
-	CFRelease(_hiddenFilesRef);
 }
 
 int BrowserDialog::runModal() {
@@ -130,6 +173,7 @@ int BrowserDialog::runModal() {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 	NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
 
+
 	NSOpenPanel *panel = [NSOpenPanel openPanel];
 	[panel setCanChooseFiles:!_isDirBrowser];
 	[panel setCanChooseDirectories:_isDirBrowser];
@@ -138,43 +182,14 @@ int BrowserDialog::runModal() {
 	[panel setTitle:(NSString *)_titleRef];
 	[panel setPrompt:(NSString *)_chooseRef];
 
-	NSButton *showHiddenFilesButton = 0;
-	ShowHiddenFilesController *showHiddenFilesController = 0;
-	if ([panel respondsToSelector:@selector(setShowsHiddenFiles:)]) {
-		showHiddenFilesButton = [[NSButton alloc] init];
-		[showHiddenFilesButton setButtonType:NSSwitchButton];
-		[showHiddenFilesButton setTitle:(NSString *)_hiddenFilesRef];
-		[showHiddenFilesButton sizeToFit];
-		if (ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain)) {
-			[showHiddenFilesButton setState:NSOnState];
-			[panel setShowsHiddenFiles: YES];
-		} else {
-			[showHiddenFilesButton setState:NSOffState];
-			[panel setShowsHiddenFiles: NO];
-		}
-		[panel setAccessoryView:showHiddenFilesButton];
-
-		showHiddenFilesController = [[ShowHiddenFilesController alloc] init];
-		[showHiddenFilesController setOpenPanel:panel];
-		[showHiddenFilesButton setTarget:showHiddenFilesController];
-		[showHiddenFilesButton setAction:@selector(showHiddenFiles:)];
+	BrowserDialogPresenter* presenter = [[BrowserDialogPresenter alloc] init];
+	[presenter performSelectorOnMainThread:@selector(showOpenPanel:) withObject:panel waitUntilDone:YES];
+	if (presenter->_url) {
+		Common::String filename = [[presenter->_url path] UTF8String];
+		_choice = Common::FSNode(filename);
+		choiceMade = true;
 	}
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1090
-	if ([panel runModal] == NSOKButton) {
-#else
-	if ([panel runModal] == NSModalResponseOK) {
-#endif
-		NSURL *url = [panel URL];
-		if ([url isFileURL]) {
-			const char *filename = [[url path] UTF8String];
-			_choice = Common::FSNode(filename);
-			choiceMade = true;
-		}
-	}
-
-	[showHiddenFilesButton release];
-	[showHiddenFilesController release];
+	[presenter release];
 
 	[pool release];
 	[keyWindow makeKeyAndOrderFront:nil];
@@ -184,7 +199,7 @@ int BrowserDialog::runModal() {
 	// events beeing queued and processed after we return, thus dispatching events that were
 	// intended for the native file browser. For example: pressing Esc to cancel the native
 	// macOS file browser would cause the application to quit in addition to closing the
-	// file browser. To avoid this happening clear all pending vents.
+	// file browser. To avoid this happening clear all pending events.
 	g_system->getEventManager()->getEventDispatcher()->clearEvents();
 
 	// If we were in fullscreen mode, switch back





More information about the Scummvm-git-logs mailing list