Skip to content

Commit

Permalink
OS X: Implement a Dock Tile Plugin to display recent games menu in dock
Browse files Browse the repository at this point in the history
This allows to start a recently played game directly from the dock. The
ScummVM.app application should have been permanently added to the
dock and the menu is only present when ScummVM is not running. The
list of recently played game is written by the taskbar code in ScummVM.
The Dock Tile Plugin only reads that list to populate the menu.
  • Loading branch information
criezy authored and sev- committed Mar 27, 2016
1 parent 07dc5bd commit eae40af
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ lib*.a
/config.log
/scummvm
/scummvm-static
/ScummVMDockTilePlugin*
/config.h
/config.mk
/.gdb_history
Expand All @@ -19,6 +20,7 @@ lib*.a
/MT32_CONTROL.ROM
/MT32_PCM.ROM
/ScummVM.app
/scummvm.docktileplugin
/scummvm-ps3.pkg
/*.ipk
/.project
Expand Down
16 changes: 0 additions & 16 deletions backends/taskbar/macosx/macosx-taskbar.mm
Expand Up @@ -232,9 +232,6 @@
}

void MacOSXTaskbarManager::addRecent(const Common::String &name, const Common::String &description) {
// TODO: Implement recent list, maybe as a custom menu on dock tile when app is not running
// See Dock Tile plug-in at https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/customizing_docktile/CreatingaDockTilePlug-in/CreatingaDockTilePlug-in.html

//warning("[MacOSXTaskbarManager::addRecent] Adding recent list entry: %s (%s)", name.c_str(), description.c_str());

if (_dockTile == nil)
Expand Down Expand Up @@ -290,19 +287,6 @@
[dict release];
CFRelease(gameName);
CFRelease(desc);


// The command to use would be "open " + path + " --args " + game.
// NSString *cmdString = [NSString stringWithFormat:@"open %@ --args %@", bundlePath, gameName];
// We could use [[NSBundle mainBundle] bundlePath] to get the path here and then store it in the user preferences.
// Or we can let the NSDockTilePlugin find the path with:
// NSString *scummVMPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"org.scummvm.scummvm"];
// We can then also use NSWorkspace to launch the app.
// if (scummVMPath == nil)
// return;
// NSURL* url = [NSURL fileURLWithPath:scummVMPath];
// [NSWorkspace launchApplicationAtURL:url options: configuration: error:] to start the application with some arguments

}


Expand Down
23 changes: 23 additions & 0 deletions configure
Expand Up @@ -128,6 +128,7 @@ _timidity=auto
_zlib=auto
_mpeg2=auto
_sparkle=auto
_osxdockplugin=auto
_jpeg=auto
_png=auto
_theoradec=auto
Expand Down Expand Up @@ -985,6 +986,8 @@ Optional Libraries:
--with-sparkle-prefix=DIR Prefix where sparkle is installed (Mac OS X only - optional)
--disable-sparkle disable sparkle automatic update support [Mac OS X only - autodetect]
--disable-osx-dock-plugin disable the NSDockTilePlugin support [Mac OS X only - autodetect]
--with-sdl-prefix=DIR Prefix where the sdl-config script is
installed (optional)
Expand Down Expand Up @@ -1047,6 +1050,8 @@ for ac_option in $@; do
--disable-zlib) _zlib=no ;;
--enable-sparkle) _sparkle=yes ;;
--disable-sparkle) _sparkle=no ;;
--enable-osx-dock-plugin) _osxdockplugin=yes;;
--disable-osx-dock-plugin) _osxdockplugin=no;;
--enable-nasm) _nasm=yes ;;
--disable-nasm) _nasm=no ;;
--enable-mpeg2) _mpeg2=yes ;;
Expand Down Expand Up @@ -3934,6 +3939,24 @@ define_in_config_if_yes "$_sparkle" 'USE_SPARKLE'
fi
echo "$_sparkle"

#
# Check is NSDockTilePlugIn protocol is supported
#
# NSDockTilePlugIn was added in OS X 10.6, so will not be available when compiling on older OS X versions.
echocheck "DockTilePlugin"
if test "$_osxdockplugin" = auto ; then
_osxdockplugin=no
cat > $TMPC << EOF
#include <Cocoa/Cocoa.h>
@interface ScummVMDockTilePlugIn : NSObject <NSDockTilePlugIn> {
}
@end
EOF
cc_check -c -ObjC++ && _osxdockplugin=yes
fi
define_in_config_if_yes "$_osxdockplugin" 'USE_DOCKTILEPLUGIN'
echo "$_osxdockplugin"

#
# Check for FluidSynth
#
Expand Down
1 change: 1 addition & 0 deletions devtools/update-version.pl
Expand Up @@ -37,6 +37,7 @@
dists/scummvm.rc
dists/slackware/scummvm.SlackBuild
dists/macosx/Info.plist
dists/macosx/dockplugin/Info.plist
dists/iphone/Info.plist
dists/ios7/Info.plist
dists/irix/scummvm.spec
Expand Down
2 changes: 2 additions & 0 deletions dists/macosx/Info.plist
Expand Up @@ -54,6 +54,8 @@
<string>NSApplication</string>
<key>SUFeedURL</key>
<string>http://www.scummvm.org/appcasts/macosx/release.xml</string>
<key>NSDockTilePlugIn</key>
<string>scummvm.docktileplugin</string>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
</dict>
Expand Down
2 changes: 2 additions & 0 deletions dists/macosx/Info.plist.in
Expand Up @@ -54,6 +54,8 @@
<string>NSApplication</string>
<key>SUFeedURL</key>
<string>http://www.scummvm.org/appcasts/macosx/release.xml</string>
<key>NSDockTilePlugIn</key>
<string>scummvm.docktileplugin</string>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
</dict>
Expand Down
26 changes: 26 additions & 0 deletions dists/macosx/dockplugin/Info.plist
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>ScummVMDockTilePlugin</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleIdentifier</key>
<string>org.scummvm.scummvm.DockTilePlugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.9.0git</string>
<key>CFBundleVersion</key>
<string>1.9.0git</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2001-2016 The ScummVM Team</string>
<key>NSPrincipalClass</key>
<string>ScummVMDockTilePlugIn</string>
</dict>
</plist>
26 changes: 26 additions & 0 deletions dists/macosx/dockplugin/Info.plist.in
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>ScummVMDockTilePlugin</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleIdentifier</key>
<string>org.scummvm.scummvm.DockTilePlugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>@VERSION@</string>
<key>CFBundleVersion</key>
<string>@VERSION@</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2001-2016 The ScummVM Team</string>
<key>NSPrincipalClass</key>
<string>ScummVMDockTilePlugIn</string>
</dict>
</plist>
125 changes: 125 additions & 0 deletions dists/macosx/dockplugin/dockplugin.m
@@ -0,0 +1,125 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include <Cocoa/Cocoa.h>

@interface ScummVMDockTilePlugIn : NSObject <NSDockTilePlugIn> {
NSMenu* recentGamesMenu;
}
@end

@interface StartGameMenuItem : NSMenuItem {
NSString* game;
}
- (IBAction) startGame;
- (NSMenuItem*)initWithGame:(NSString *)gameId description:(NSString*)desc icon:(NSString*)iconFile;
@end

@implementation ScummVMDockTilePlugIn

- (id)init {
self = [super init];
if (self) {
recentGamesMenu = nil;
}
return self;
}

- (void)dealloc {
[recentGamesMenu release];
[super dealloc];
}


- (void)setDockTile:(NSDockTile *)dockTile {
}

- (NSMenu*)dockMenu {
// Get the list or recent games
CFPreferencesAppSynchronize(CFSTR("org.scummvm.scummvm"));
NSArray* array = CFPreferencesCopyAppValue(CFSTR("recentGames"), CFSTR("org.scummvm.scummvm"));
if (array == nil)
return nil;

// Create the menu
if (recentGamesMenu == nil)
recentGamesMenu = [[NSMenu alloc] init];
else
[recentGamesMenu removeAllItems];

NSEnumerator *enumerator = [array objectEnumerator];
NSDictionary* recentGame;
while (recentGame = [enumerator nextObject]) {
NSString* gameId = [recentGame valueForKey:@"game"];
NSString* desc = [recentGame valueForKey:@"description"];
NSString* iconFile = [recentGame valueForKey:@"icon"];

StartGameMenuItem* menuItem = [[StartGameMenuItem alloc] initWithGame:gameId description:desc icon:iconFile];
[recentGamesMenu addItem:menuItem];
[menuItem release];
}

return recentGamesMenu;
}

@end

@implementation StartGameMenuItem

- (NSMenuItem*)initWithGame:(NSString *)gameId description:(NSString*)desc icon:(NSString*)iconFile {
self = [super initWithTitle:(desc == nil ? gameId : desc) action:@selector(startGame) keyEquivalent:@""];
[self setTarget:self];

if (iconFile != nil) {
NSImage* image = [[NSImage alloc] initWithContentsOfFile:iconFile];
[self setImage:image];
[image release];
}

game = gameId;
[game retain];

return self;
}

- (void)dealloc {
[game release];
[super dealloc];
}

- (IBAction) startGame {
NSLog(@"Starting Game %@...", game);

NSString *scummVMPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"org.scummvm.scummvm"];
if (scummVMPath == nil) {
NSLog(@"Cannot find ScummVM.app!");
return;
}
// Start ScummVM.app with the game ID as argument
NSURL* url = [NSURL fileURLWithPath:scummVMPath];
NSMutableDictionary* args = [[NSMutableDictionary alloc] init];
[args setObject:[NSArray arrayWithObject:game] forKey:NSWorkspaceLaunchConfigurationArguments];
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:url options:NSWorkspaceLaunchDefault configuration:args error:nil];
[args release];
}

@end
39 changes: 39 additions & 0 deletions ports.mk
Expand Up @@ -53,8 +53,43 @@ ifdef DYNAMIC_MODULES
endif

# Special target to create a application wrapper for Mac OS X

ifdef USE_DOCKTILEPLUGIN

# The NsDockTilePlugIn needs to be compiled in both 32 and 64 bits irrespective of how ScummVM itself is compiled.
# Therefore do not use $(CXXFLAGS) and $(LDFLAGS).

ScummVMDockTilePlugin32.o:
$(CXX) -mmacosx-version-min=10.6 -arch i386 -O2 -c $(srcdir)/dists/macosx/dockplugin/dockplugin.m -o ScummVMDockTilePlugin32.o

ScummVMDockTilePlugin32: ScummVMDockTilePlugin32.o
$(CXX) -mmacosx-version-min=10.6 -arch i386 -bundle -framework Foundation -framework AppKit -fobjc-link-runtime ScummVMDockTilePlugin32.o -o ScummVMDockTilePlugin32

ScummVMDockTilePlugin64.o:
$(CXX) -mmacosx-version-min=10.6 -arch x86_64 -O2 -c $(srcdir)/dists/macosx/dockplugin/dockplugin.m -o ScummVMDockTilePlugin64.o

ScummVMDockTilePlugin64: ScummVMDockTilePlugin64.o
$(CXX) -mmacosx-version-min=10.6 -arch x86_64 -bundle -framework Foundation -framework AppKit -fobjc-link-runtime ScummVMDockTilePlugin64.o -o ScummVMDockTilePlugin64

ScummVMDockTilePlugin: ScummVMDockTilePlugin32 ScummVMDockTilePlugin64
lipo -create ScummVMDockTilePlugin32 ScummVMDockTilePlugin64 -output ScummVMDockTilePlugin

dockplugin: ScummVMDockTilePlugin
mkdir -p scummvm.docktileplugin/Contents
cp $(srcdir)/dists/macosx/dockplugin/Info.plist scummvm.docktileplugin/Contents
mkdir -p scummvm.docktileplugin/Contents/MacOS
cp ScummVMDockTilePlugIn scummvm.docktileplugin/Contents/MacOS/
chmod 644 scummvm.docktileplugin/Contents/MacOS/ScummVMDockTilePlugIn

endif

bundle_name = ScummVM.app

ifdef USE_DOCKTILEPLUGIN
bundle: scummvm-static dockplugin
else
bundle: scummvm-static
endif
mkdir -p $(bundle_name)/Contents/MacOS
mkdir -p $(bundle_name)/Contents/Resources
echo "APPL????" > $(bundle_name)/Contents/PkgInfo
Expand All @@ -75,6 +110,10 @@ endif
cp scummvm-static $(bundle_name)/Contents/MacOS/scummvm
chmod 755 $(bundle_name)/Contents/MacOS/scummvm
$(STRIP) $(bundle_name)/Contents/MacOS/scummvm
ifdef USE_DOCKTILEPLUGIN
mkdir -p $(bundle_name)/Contents/PlugIns
cp -r scummvm.docktileplugin $(bundle_name)/Contents/PlugIns/
endif

iphonebundle: iphone
mkdir -p $(bundle_name)
Expand Down

0 comments on commit eae40af

Please sign in to comment.