Skip to content

Commit c748b37

Browse files
committed
Alter Makefile so that .nib files get copied into Resources/ directory
in the application bundle. Don't load the IDE as part of the app. As part of this: * change NSPrincipalClass in Info.plist to NSApplication * use ccl::*nsapp* instead of gui::*nsapp* * load some files from ccl:mac-ide; which contain functionality we need * use ccl::call-in-initial-process instead of gui::execute-in-gui * copy shift-key-now-p * use (require 'objc-support) rather than (require 'cocoa) in build.lisp To get the app rolling, we define an :after method on the generic function ccl::initialize-user-interface (see bottom of dpf.lisp).
1 parent fee4282 commit c748b37

File tree

6 files changed

+29
-49
lines changed

6 files changed

+29
-49
lines changed

Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
<key>NSMainNibFile</key>
3232
<string>MainMenu</string>
3333
<key>NSPrincipalClass</key>
34-
<string>LispApplication</string>
34+
<string>NSApplication</string>
3535
</dict>
3636
</plist>

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CONTENTS="build/Picture Window.app/Contents/"
2+
RESOURCES=$(CONTENTS)/Resources
23
BINARY="$(CONTENTS)/MacOS/Picture Window"
34

45
%.nib : en.lproj/%.xib
@@ -7,12 +8,11 @@ BINARY="$(CONTENTS)/MacOS/Picture Window"
78
NIBS=MainMenu.nib dpf-preferences.nib help.nib
89

910
build: nibs
10-
mkdir -p $(CONTENTS)
11-
cp $(NIBS) $(CONTENTS)
11+
mkdir -p $(RESOURCES)
12+
cp $(NIBS) $(RESOURCES)
1213
ccl --no-init --load build.lisp
1314

1415
nibs: $(NIBS)
15-
1616

1717
clean:
1818
rm -f $(NIBS)

application.lisp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
(in-package "CCL")
22

3-
(defclass cocoa-event-process (process)
4-
())
5-
6-
(defmethod process-interrupt ((process cocoa-event-process) function
7-
&rest args)
8-
(if (eq process *current-process*)
9-
(apply function args)
10-
(if (and *nsapp* (#/isRunning *nsapp*))
11-
(queue-for-event-process #'(lambda () (apply function args)))
12-
(call-next-method))))
13-
14-
(defmethod process-exit-application :before ((process cocoa-event-process)
15-
(thunk t))
16-
(when (eq process *initial-process*)
17-
(#/terminate: *nsapp* +null-ptr+)))
18-
193
(defclass cocoa-ui-object (ui-object)
204
())
215

@@ -90,7 +74,6 @@
9074
app))))
9175

9276
(defun become-foreground-application ()
93-
#+apple-objc
9477
(rlet ((psn #>ProcessSerialNumber))
9578
(#_GetCurrentProcess psn)
9679
(#_TransformProcessType psn #$kProcessTransformToForegroundApplication)))

build.lisp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
(setq ccl:*save-source-locations* nil)
44

5-
(require "COCOA")
6-
75
(defparameter *source-dir* (make-pathname :name nil :type nil
86
:defaults *load-truename*))
97
(defparameter *build-dir* (merge-pathnames "build/" *source-dir*))
@@ -52,12 +50,14 @@
5250
(finish-output t)
5351
(save-application (merge-pathnames "ccl/Picture Window.image"
5452
*resources-dir*)
55-
:application-class (find-symbol "DPF-APPLICATION"
56-
"DPF"))))
53+
:application-class (find-symbol "COCOA-APPLICATION"
54+
"CCL"))))
5755

58-
(require 'cocoa)
56+
(require 'objc-support)
5957
(ccl::define-special-objc-word "DPF")
6058
;; Core Animation lives in QuartzCore
6159
(objc:load-framework "QuartzCore" :quartzcore)
6260

61+
(load "ccl:mac-ui;cf-utils")
62+
(load "ccl:mac-ui;event-process")
6363
(build-dpf)

dpf.lisp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(b (#/initWithFrame: (#/alloc ns:ns-button) r)))
66
(#/setButtonType: b #$NSSwitchButton)
77
(#/setTitle: b #@"Look for pictures in subfolders")
8-
(gui::execute-in-gui
8+
(ccl::call-in-initial-process
99
#'(lambda ()
1010
(let ((op (#/openPanel ns:ns-open-panel)))
1111
(#/retain op)
@@ -457,7 +457,7 @@
457457

458458
(defun restore-slideshow-state ()
459459
(let ((path (merge-pathnames *saved-state-filename* *saved-state-directory*)))
460-
(if (gui::shift-key-now-p)
460+
(if (shift-key-now-p)
461461
(ignore-errors (delete-file path))
462462
(when (probe-file path)
463463
(with-open-file (input path)
@@ -1055,13 +1055,13 @@
10551055
(make-instance 'iphoto-library
10561056
:album-data-pathname
10571057
(merge-pathnames "AlbumData.xml" dir)))))
1058-
(gui::execute-in-gui #'(lambda ()
1059-
(retarget-preferences-menu-item)
1060-
(make-view-menu)
1061-
(add-slideshow-menu)
1062-
(configure-help-menu)
1063-
(maybe-show-help-window)
1064-
(restore-slideshow-state))))
1058+
(ccl::call-in-initial-process #'(lambda ()
1059+
(retarget-preferences-menu-item)
1060+
(make-view-menu)
1061+
(add-slideshow-menu)
1062+
(configure-help-menu)
1063+
(maybe-show-help-window)
1064+
(restore-slideshow-state))))
10651065

10661066
(defun make-slideshow (assets title source &optional plist)
10671067
(ns:with-ns-rect (r 0 0 500 310)
@@ -1085,15 +1085,15 @@
10851085
(if (directory-pathname-p title)
10861086
(with-cfstring (s (native-translated-namestring title))
10871087
(#/setTitleWithRepresentedFilename: w s)
1088-
(#/addWindowsItem:title:filename: gui::*nsapp* w
1088+
(#/addWindowsItem:title:filename: ccl::*nsapp* w
10891089
(#/lastPathComponent s) nil)
10901090
(#/setFrameAutosaveName: w s)
10911091
(unless (#/setFrameUsingName: w s)
10921092
;; lower left corner
10931093
(#/setFrameOrigin: w #&NSZeroPoint)))
10941094
(with-cfstring (s (native-translated-namestring title))
10951095
(#/setTitle: w s)
1096-
(#/addWindowsItem:title:filename: gui::*nsapp* w s nil)
1096+
(#/addWindowsItem:title:filename: ccl::*nsapp* w s nil)
10971097
(#/setFrameAutosaveName: w s)
10981098
(unless (#/setFrameUsingName: w s)
10991099
;; lower left corner
@@ -1192,17 +1192,7 @@
11921192
(make-slideshow assets (iphoto-album-name album)
11931193
(iphoto-album-name album) plist)))))
11941194

1195-
;;; hack-o-rama. better than having to alter the ide sources, though.
11961195

1197-
(defclass dpf-application (ccl::cocoa-application)
1198-
())
11991196

1200-
(defmethod toplevel-function ((a dpf-application) init-file)
1201-
(declare (ignore init-file))
1202-
(process-run-function "initialize DPF"
1203-
#'(lambda ()
1204-
;; (wait-on-semaphore
1205-
;; gui::*cocoa-ide-finished-launching*)
1206-
(objc:with-autorelease-pool
1207-
(init-slideshow))))
1208-
(call-next-method))
1197+
(defmethod ccl::initialize-user-interface :after ((a ccl::cocoa-application))
1198+
(init-slideshow))

misc.lisp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414

1515
(defloadvar *black-color* (#/retain (#/blackColor ns:ns-color)))
1616
(defloadvar *clear-color* (#/retain (#/clearColor ns:ns-color)))
17+
18+
(defun shift-key-now-p ()
19+
(let* ((event (#_CGEventCreate +null-ptr+))
20+
(flags (#_CGEventGetFlags event)))
21+
(prog1
22+
(logtest flags #$kCGEventFlagMaskShift)
23+
(#_CFRelease event))))

0 commit comments

Comments
 (0)