From 4d96da6a02636caab3d5ac14b4280ab6e5d98664 Mon Sep 17 00:00:00 2001 From: mjwybrow Date: Tue, 11 Mar 2008 06:02:23 +0000 Subject: [PATCH] * packaging/macosx/ScriptExec/main.c: Update ScriptExec with upstream fixes and changes. X11.app now gets focus if the Inkscape icon is clicked while Inkscape is already open (previously nothing happened). * packaging/macosx/Resources/openDoc: If Inkscape.app is already open and a file is dropped on the Inkscape dock icon, or an Inkscape file is double-clicked in the Finder, that document will now be correctly opened in a new Inkscape window (previously nothing happened). * packaging/macosx/Resources/script: Some minor fixes, plus alert the user about the font cache building time only if ~/.fontconfig/ doesn't exist. * packaging/macosx/Resources/bin/inkscape: Only override the fontconfig configuration on OSX 10.4 or earlier, since the fc-cache behaviour has been corrected on 10.5. * Info.plist.in: Update the copyright dates, and change Inkscape to be an Editor for SVG files, rather than a Viewer as it was previously. --- Info.plist.in | 6 +- packaging/macosx/Resources/bin/inkscape | 17 +++-- packaging/macosx/Resources/openDoc | 13 +++- packaging/macosx/Resources/script | 10 +-- packaging/macosx/ScriptExec/main.c | 90 ++++++++++++++++++++++++- 5 files changed, 117 insertions(+), 19 deletions(-) diff --git a/Info.plist.in b/Info.plist.in index fa4e8007a..a93e6e216 100644 --- a/Info.plist.in +++ b/Info.plist.in @@ -7,7 +7,7 @@ CFBundleExecutable Inkscape CFBundleGetInfoString - @VERSION@, Copyright 2003-2007 Inkscape Developers + @VERSION@, Copyright 2003-2008 Inkscape Developers CFBundleIconFile Inkscape.icns CFBundleIdentifier @@ -32,7 +32,7 @@ SVG CFBundleTypeRole - Viewer + Editor CFBundleTypeExtensions @@ -186,7 +186,7 @@ CFBundleVersion @VERSION@ NSHumanReadableCopyright - Copyright 2007 Inkscape Developers, GNU General Public License. + Copyright 2008 Inkscape Developers, GNU General Public License. LSMinimumSystemVersion 10.3 diff --git a/packaging/macosx/Resources/bin/inkscape b/packaging/macosx/Resources/bin/inkscape index 2242f6861..093cb3550 100755 --- a/packaging/macosx/Resources/bin/inkscape +++ b/packaging/macosx/Resources/bin/inkscape @@ -30,8 +30,11 @@ export PYTHONPATH="$TOP/python/site-packages/$ARCH/$PYTHON_VERS" export DYLD_LIBRARY_PATH="$TOP/lib" +# For Panther and Tiger, override the default fontconfig configuration +if [[ $VERSION -le 4 ]]; then + export FONTCONFIG_PATH="$TOP/etc/fonts" +fi export PANGO_RC_FILE="$HOME/.inkscape-etc/pangorc" -export FONTCONFIG_PATH="$TOP/etc/fonts" export GTK_IM_MODULE_FILE="$HOME/.inkscape-etc/gtk.immodules" export GDK_PIXBUF_MODULE_FILE="$HOME/.inkscape-etc/gdk-pixbuf.loaders" export GTK_DATA_PREFIX="$TOP" @@ -65,14 +68,14 @@ export LANG="`grep \"\`defaults read .GlobalPreferences AppleCollationOrder \ # This '#' needs to be escaped in pango.modules for Pango to work properly. ESCAPEDTOP=`echo $TOP | sed 's/#/\\\\\\\\#/'` -mkdir -p ~/.inkscape-etc -sed 's|${HOME}|'"$HOME|g" "$TOP/etc/pango/pangorc" > ~/.inkscape-etc/pangorc +mkdir -p ${HOME}/.inkscape-etc +sed 's|${HOME}|'"$HOME|g" "$TOP/etc/pango/pangorc" > ${HOME}/.inkscape-etc/pangorc sed 's|${CWD}|'"$ESCAPEDTOP|g" "$TOP/etc/pango/pango.modules" \ - > ~/.inkscape-etc/pango.modules -cp -f "$TOP/etc/pango/pangox.aliases" ~/.inkscape-etc/ + > ${HOME}/.inkscape-etc/pango.modules +cp -f "$TOP/etc/pango/pangox.aliases" ${HOME}/.inkscape-etc/ sed 's|${CWD}|'"$TOP|g" "$TOP/etc/gtk-2.0/gtk.immodules" \ - > ~/.inkscape-etc/gtk.immodules + > ${HOME}/.inkscape-etc/gtk.immodules sed 's|${CWD}|'"$TOP|g" "$TOP/etc/gtk-2.0/gdk-pixbuf.loaders" \ - > ~/.inkscape-etc/gdk-pixbuf.loaders + > ${HOME}/.inkscape-etc/gdk-pixbuf.loaders exec "$CWD/inkscape-bin" "$@" diff --git a/packaging/macosx/Resources/openDoc b/packaging/macosx/Resources/openDoc index 8e6ac0399..9b1d7718c 100755 --- a/packaging/macosx/Resources/openDoc +++ b/packaging/macosx/Resources/openDoc @@ -1,8 +1,17 @@ #!/bin/sh # # Author: Aaron Voisine +# Inkscape Modifications: Michael Wybrow -export "DISPLAY=`cat /tmp/display.$UID`" -BASE="`echo "$0" | sed -e 's/\/[A-Za-z]*.app\/Contents\/Resources\/script/\//'`" +CWD="`dirname \"$0\"`" + +# System version: 3 for Panther, 4 for Tiger, 5 for Leopard +export VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'` + +if [[ $VERSION -le 4 ]]; then + export "DISPLAY=`cat /tmp/display.$UID`" +fi + +BASE="`echo "$0" | sed -e 's/\/[A-Za-z]*.app\/Contents\/Resources\/openDoc/\//'`" cd "$BASE" exec "$CWD/bin/inkscape" "$@" diff --git a/packaging/macosx/Resources/script b/packaging/macosx/Resources/script index 48bfc76cb..95ee6afbf 100755 --- a/packaging/macosx/Resources/script +++ b/packaging/macosx/Resources/script @@ -6,7 +6,7 @@ CWD="`dirname \"$0\"`" # System version: 3 for Panther, 4 for Tiger, 5 for Leopard -VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'` +export VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'` # On Leopard, X11.app is installed by default, and will be started # automatically via launchd. On older systems, we need to start @@ -18,9 +18,9 @@ if [[ $VERSION -le 4 ]]; then # from xinitrc but when is it really used? Should we modify # the .xinitrc of the user without warning? ps -wx -ocommand | grep -e '[X]11' > /dev/null - if [ "$?" != "0" -a ! -f ~/.xinitrc ]; then - echo "rm -f ~/.xinitrc" > ~/.xinitrc - sed 's/xterm/# xterm/' /usr/X11R6/lib/X11/xinit/xinitrc >> ~/.xinitrc + if [ "$?" != "0" -a ! -f ${HOME}/.xinitrc ]; then + echo "rm -f ${HOME}/.xinitrc" > ${HOME}/.xinitrc + sed 's/xterm/# xterm/' /usr/X11R6/lib/X11/xinit/xinitrc >> ${HOME}/.xinitrc fi # Start X11 and get DISPLAY @@ -40,7 +40,7 @@ fi # Warn the user about time-consuming generation of fontconfig caches. -test -f ~/.inkscape/.fccache-new || exit 12 +test -d ${HOME}/.fontconfig || exit 12 BASE="`echo "$0" | sed -e 's/\/Contents\/Resources\/script/\//'`" diff --git a/packaging/macosx/ScriptExec/main.c b/packaging/macosx/ScriptExec/main.c index c3e14a0a1..2c4e8f301 100644 --- a/packaging/macosx/ScriptExec/main.c +++ b/packaging/macosx/ScriptExec/main.c @@ -3,6 +3,10 @@ This is the executable that goes into Platypus apps Copyright (C) 2003 Sveinbjorn Thordarson + With modifications by Aaron Voisine for gimp.app + With modifications by Marianne gagnon for Wilber-loves-apple + With modifications by Michael Wybrow for Inkscape.app + 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 @@ -21,6 +25,14 @@ */ +/* + * This app laucher basically takes care of: + * - launching Inkscape and X11 when double-clicked + * - bringing X11 to the top when its icon is clicked in the dock (via a small applescript) + * - catch file dropped on icon events (and double-clicked gimp documents) and notify gimp. + * - catch quit events performed outside gimp, e.g. on the dock icon. + */ + /////////////////////////////////////// // Includes /////////////////////////////////////// @@ -89,6 +101,14 @@ static OSStatus X11FailedHandler(EventHandlerCallRef theHandlerCall, EventRef theEvent, void *userData); static OSStatus FCCacheFailedHandler(EventHandlerCallRef theHandlerCall, EventRef theEvent, void *userData); +static OSErr AppReopenAppAEHandler(const AppleEvent *theAppleEvent, + AppleEvent *reply, long refCon); + +static OSStatus CompileAppleScript(const void* text, long textLength, + AEDesc *resultData); +static OSStatus SimpleCompileAppleScript(const char* theScript); +static void runScript(); + /////////////////////////////////////// // Globals /////////////////////////////////////// @@ -137,6 +157,11 @@ int main(int argc, char* argv[]) err += AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(AppOpenAppAEHandler), 0, false); + + err += AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, + NewAEEventHandlerUPP(AppReopenAppAEHandler), + 0, false); + err += InstallEventHandler(GetApplicationEventTarget(), NewEventHandlerUPP(X11FailedHandler), 1, &X11events, NULL, NULL); @@ -153,6 +178,9 @@ int main(int argc, char* argv[]) GetParameters(); //load data from files containing exec settings + // compile "icon clicked" script so it's ready to execute + SimpleCompileAppleScript("tell application \"X11\" to activate"); + RunApplicationEventLoop(); //Run the event loop return 0; } @@ -625,6 +653,14 @@ static OSErr AppOpenDocAEHandler(const AppleEvent *theAppleEvent, /////////////////////////////// // Handler for clicking on app icon /////////////////////////////// +// if app is already open +static OSErr AppReopenAppAEHandler(const AppleEvent *theAppleEvent, + AppleEvent *reply, long refCon) +{ + runScript(); +} + +// if app is being opened static OSErr AppOpenAppAEHandler(const AppleEvent *theAppleEvent, AppleEvent *reply, long refCon) { @@ -688,10 +724,10 @@ static OSStatus X11FailedHandler(EventHandlerCallRef theHandlerCall, StandardAlert(kAlertStopAlert, "\pFailed to start X11", "\pInkscape.app requires Apple's X11, which is freely downloadable from Apple's website for Panther (10.3.x) users and available as an optional install from the installation DVD for Tiger (10.4.x) users.\n\nPlease install X11 and restart Inkscape.", ¶ms, &itemHit); - + if (itemHit == kAlertStdAlertCancelButton) { - OpenURL("http://www.apple.com/downloads/macosx/apple/x11formacosx.html"); + OpenURL("http://www.apple.com/downloads/macosx/apple/macosx_updates/x11formacosx.html"); } ExitToShell(); @@ -699,3 +735,53 @@ static OSStatus X11FailedHandler(EventHandlerCallRef theHandlerCall, return noErr; } + + +// Compile and run a small AppleScript. The code below does no cleanup and no proper error checks +// but since it's there until the app is shut down, and since we know the script is okay, +// there should not be any problems. +ComponentInstance theComponent; +AEDesc scriptTextDesc; +OSStatus err; +OSAID scriptID, resultID; + +static OSStatus CompileAppleScript(const void* text, long textLength, + AEDesc *resultData) { + + resultData = NULL; + /* set up locals to a known state */ + theComponent = NULL; + AECreateDesc(typeNull, NULL, 0, &scriptTextDesc); + scriptID = kOSANullScript; + resultID = kOSANullScript; + + /* open the scripting component */ + theComponent = OpenDefaultComponent(kOSAComponentType, + typeAppleScript); + if (theComponent == NULL) { err = paramErr; return err; } + + /* put the script text into an aedesc */ + err = AECreateDesc(typeChar, text, textLength, &scriptTextDesc); + if (err != noErr) return err; + + /* compile the script */ + err = OSACompile(theComponent, &scriptTextDesc, + kOSAModeNull, &scriptID); + + return err; +} + +/* runs the compiled applescript */ +static void runScript() +{ + /* run the script */ + err = OSAExecute(theComponent, scriptID, kOSANullScript, + kOSAModeNull, &resultID); + return err; +} + + +/* Simple shortcut to the function that actually compiles the applescript. */ +static OSStatus SimpleCompileAppleScript(const char* theScript) { + return CompileAppleScript(theScript, strlen(theScript), NULL); +} -- 2.30.2