Browse code
feat: get rid of nsrect-expose.m
(requires HEAD of CFFI)
Edward authored on 14/03/2021 07:08:02Showing 5 changed files
... | ... |
@@ -29,7 +29,8 @@ demo-app.iconset: demo-app.svg |
29 | 29 |
mkapp: dylib demo-app demo-app.iconset |
30 | 30 |
rm -rf demo.app |
31 | 31 |
cp -R demo.app.template demo.app |
32 |
- mkdir -p demo.app/Contents/{Resources,MacOS} |
|
32 |
+ mkdir -p demo.app/Contents/{Resources,MacOS,Frameworks} |
|
33 | 33 |
iconutil -c icns demo-app.iconset -o demo.app/Contents/Resources/demo-app.icns |
34 | 34 |
ibtool --compile demo.app/Contents/Resources/MainMenu.nib MainMenu.xib |
35 |
- cp demo-app libnsrect-expose.dylib demo.app/Contents/MacOS |
|
35 |
+ cp demo-app demo.app/Contents/MacOS |
|
36 |
+ cp libnsrect-expose.dylib demo.app/Contents/MacOS |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
* Intro |
2 |
- |
|
2 |
+ |
|
3 | 3 |
CCL and LispWorks and other implementations have their own bridges to |
4 | 4 |
the objective-c runtime. This project is an attempt to create a |
5 | 5 |
bridge that only uses CFFI so that arbitrary lisp implementations can |
... | ... |
@@ -20,19 +20,23 @@ lisp's ffi types. |
20 | 20 |
https://github.com/fiddlerwoaroof/fwoar.lisputils and put it |
21 | 21 |
somewhere quicklisp can find it (e.g. ~/quicklisp/local-projects) |
22 | 22 |
|
23 |
-2. Install rsvg-convert: |
|
23 |
+2. clone cffi from https://github.com/cffi/cffi and put it in the same |
|
24 |
+ place (on Big Sur, at least, I need changes that haven't made it to |
|
25 |
+ Quicklisp) |
|
26 |
+ |
|
27 |
+3. Install rsvg-convert: |
|
24 | 28 |
#+BEGIN_SRC sh :tangle no |
25 |
-brew install librsvg |
|
29 |
+ brew install librsvg |
|
26 | 30 |
#+END_SRC |
27 |
- |
|
28 |
-3. build + run the demo: |
|
31 |
+ |
|
32 |
+4. build + run the demo: |
|
29 | 33 |
#+BEGIN_SRC sh :tangle no |
30 |
-make mkapp CCL=/path/to/ccl |
|
31 |
-open demo.app |
|
34 |
+ make mkapp CL=/path/to/cl |
|
35 |
+ open demo.app |
|
32 | 36 |
#+END_SRC |
33 | 37 |
|
34 | 38 |
* Show me the code! |
35 |
- |
|
39 |
+ |
|
36 | 40 |
From demo-app.lisp: |
37 | 41 |
|
38 | 42 |
#+BEGIN_SRC lisp :tangle no |
... | ... |
@@ -48,7 +52,7 @@ From demo-app.lisp: |
48 | 52 |
"profitButton"))) |
49 | 53 |
|
50 | 54 |
(demo-app::load-nib "MainMenu") |
51 |
- |
|
55 |
+ |
|
52 | 56 |
(let ((app-delegate [objc-runtime::ns-app @(delegate)])) |
53 | 57 |
(demo-app::make-button-delegate (value-for-key app-delegate "actionButton") |
54 | 58 |
(cffi:callback do-things-action)) |
... | ... |
@@ -56,7 +60,7 @@ From demo-app.lisp: |
56 | 60 |
(cffi:callback alert-action)) |
57 | 61 |
(demo-app::make-button-delegate (value-for-key app-delegate "profitButton") |
58 | 62 |
(cffi:callback profit-action))) |
59 |
- |
|
63 |
+ |
|
60 | 64 |
[objc-runtime::ns-app @(activateIgnoringOtherApps:) :boolean t] |
61 | 65 |
[objc-runtime::ns-app @(run)])) |
62 | 66 |
|
... | ... |
@@ -118,12 +122,12 @@ From demo-app.lisp: |
118 | 122 |
(defun main () |
119 | 123 |
<<disable-sbcl-debugger>> |
120 | 124 |
(make-org-file *standard-output* |
121 |
- (get-readinglist-info |
|
122 |
- (translate-plist |
|
125 |
+ (get-readinglist-info |
|
126 |
+ (translate-plist |
|
123 | 127 |
(get-bookmark-filename))))) |
124 | 128 |
#+end_src |
125 |
- |
|
126 |
- This pair of functions builds an org file from data extracted from the Safari bookmark file. |
|
129 |
+ |
|
130 |
+ This pair of functions builds an org file from data extracted from the Safari bookmark file. |
|
127 | 131 |
|
128 | 132 |
#+name: make-org-file |
129 | 133 |
#+begin_src lisp :tangle no :results no |
... | ... |
@@ -141,7 +145,7 @@ From demo-app.lisp: |
141 | 145 |
url |
142 | 146 |
(serapeum:tokens preview))) |
143 | 147 |
#+end_src |
144 |
- |
|
148 |
+ |
|
145 | 149 |
Here we extract the data from Bookmarks.plist using our polymorphic objc data extractor framework |
146 | 150 |
|
147 | 151 |
#+name: translate-plist |
... | ... |
@@ -180,7 +184,7 @@ From demo-app.lisp: |
180 | 184 |
#+end_src |
181 | 185 |
|
182 | 186 |
** Appendices |
183 |
- |
|
187 |
+ |
|
184 | 188 |
*** objc-data-extractor.lisp |
185 | 189 |
|
186 | 190 |
#+begin_src lisp :tangle objc-data-extractors.lisp :noweb yes :comments both |
... | ... |
@@ -270,7 +274,7 @@ From demo-app.lisp: |
270 | 274 |
#+end_src |
271 | 275 |
|
272 | 276 |
*** build-reading-list-reader.sh |
273 |
- |
|
277 |
+ |
|
274 | 278 |
#+begin_src sh :tangle build-reading-list-reader.sh |
275 | 279 |
#!/usr/bin/env bash |
276 | 280 |
set -eu -x -o pipefail |
... | ... |
@@ -310,7 +314,7 @@ From demo-app.lisp: |
310 | 314 |
|
311 | 315 |
*** reading-list-reader.lisp |
312 | 316 |
|
313 |
- #+begin_src lisp :mkdirp yes :results no :noweb yes :tangle reading-list-reader.lisp |
|
317 |
+ #+begin_src lisp :mkdirp yes :results no :noweb yes :tangle reading-list-reader.lisp |
|
314 | 318 |
(defpackage :reading-list-reader |
315 | 319 |
(:use :cl ) |
316 | 320 |
(:export )) |
... | ... |
@@ -349,7 +353,7 @@ From demo-app.lisp: |
349 | 353 |
(sb-alien:extern-alien "disable_lossage_handler" |
350 | 354 |
(function sb-alien:void)))) |
351 | 355 |
#+end_src |
352 |
- |
|
356 |
+ |
|
353 | 357 |
|
354 | 358 |
# Local Variables: |
355 | 359 |
# fill-column: 120 : |
... | ... |
@@ -10,22 +10,30 @@ |
10 | 10 |
(format t "~&Exxception: ~a~%" [exception reason]) |
11 | 11 |
(values))) |
12 | 12 |
|
13 |
-(cffi:defcfun (init-window "initWindow") |
|
14 |
- :pointer |
|
15 |
- (window :pointer) |
|
16 |
- (rect :pointer) |
|
17 |
- (a :char) |
|
18 |
- (b :char) |
|
19 |
- (c :boolean)) |
|
13 |
+(defun init-window (window rect a b c) |
|
14 |
+ (format t "~&got rect: ~s" rect) |
|
15 |
+ (cffi:foreign-funcall "objc_msgSend" |
|
16 |
+ :pointer window |
|
17 |
+ :pointer @(initWithContentRect:) |
|
18 |
+ :pointer window |
|
19 |
+ (:struct objc-runtime::ns-rect) rect |
|
20 |
+ :char a |
|
21 |
+ :char b |
|
22 |
+ :boolean c |
|
23 |
+ :pointer)) |
|
20 | 24 |
|
21 | 25 |
(defmacro selector-lambda (selector &rest args) |
22 | 26 |
`(lambda (receiver) |
23 | 27 |
[receiver ,selector ,@args])) |
24 | 28 |
|
25 |
-(cffi:defcfun (init-with-frame "initWithFrame") |
|
26 |
- :pointer |
|
27 |
- (thing :pointer) |
|
28 |
- (rect :pointer)) |
|
29 |
+(defun init-with-frame (thing rect) |
|
30 |
+ (format t "~&got rect: ~s" rect) |
|
31 |
+ (cffi:foreign-funcall "objc_msgSend" |
|
32 |
+ :pointer thing |
|
33 |
+ :pointer @(initWithFrame:) |
|
34 |
+ (:struct objc-runtime::ns-rect) rect |
|
35 |
+ :pointer)) |
|
36 |
+ |
|
29 | 37 |
|
30 | 38 |
(cffi:defcfun (print-rect "printRect") |
31 | 39 |
:void |
... | ... |
@@ -110,7 +118,7 @@ |
110 | 118 |
(load "~/quicklisp/setup.lisp") |
111 | 119 |
(funcall (intern "QUICKLOAD" (find-package :QL)) :swank) |
112 | 120 |
(funcall (intern "CREATE-SERVER" (find-package :swank)) :port 5060 :dont-close t) |
113 |
- |
|
121 |
+ |
|
114 | 122 |
(show-alert "Started swank on 5060")) |
115 | 123 |
|
116 | 124 |
(cffi:defcallback alert-action :void ((a :pointer) (b :pointer) (sender :pointer)) |
... | ... |
@@ -199,7 +207,7 @@ |
199 | 207 |
"profitButton"))) |
200 | 208 |
|
201 | 209 |
(load-nib "MainMenu.nib") |
202 |
- |
|
210 |
+ |
|
203 | 211 |
(let ((app-delegate [objc-runtime::ns-app @(delegate)])) |
204 | 212 |
(make-button-delegate (value-for-key app-delegate "actionButton") |
205 | 213 |
(cffi:callback do-things-action)) |
... | ... |
@@ -207,7 +215,7 @@ |
207 | 215 |
(cffi:callback alert-action)) |
208 | 216 |
(make-button-delegate (value-for-key app-delegate "profitButton") |
209 | 217 |
(cffi:callback profit-action))) |
210 |
- |
|
218 |
+ |
|
211 | 219 |
[objc-runtime::ns-app @(activateIgnoringOtherApps:) :boolean t] |
212 | 220 |
[objc-runtime::ns-app @(run)])) |
213 | 221 |
|
... | ... |
@@ -303,7 +311,7 @@ |
303 | 311 |
(with-point (p (20 20)) |
304 | 312 |
(let* ((foreign-rect (make-rect 10 10 120 120)) |
305 | 313 |
(the-window (init-window [#@NSWindow @(alloc)] foreign-rect 15 2 nil))) |
306 |
- |
|
314 |
+ |
|
307 | 315 |
[(value-for-key the-window "contentView") @(addSubview:) :pointer (main-view *application-shim*)] |
308 | 316 |
[the-window @(cascadeTopLeftFromPoint:) :pointer p] |
309 | 317 |
[the-window @(setTitle:) :pointer application-name] |
... | ... |
@@ -344,8 +352,8 @@ |
344 | 352 |
(defun text-view (parent-view) |
345 | 353 |
(let ((text-view [#@NSTextView @(alloc)])) |
346 | 354 |
|
347 |
- |
|
348 |
- |
|
355 |
+ |
|
356 |
+ |
|
349 | 357 |
|
350 | 358 |
|
351 | 359 |
(trivial-main-thread:with-body-in-main-thread (:blocking nil) |
... | ... |
@@ -354,7 +362,7 @@ |
354 | 362 |
(init-with-frame *text-view* v)) |
355 | 363 |
[*window-view* @(addSubview:) :pointer *text-view*]?) |
356 | 364 |
|
357 |
- (defparameter *view-dictionary* |
|
365 |
+ (defparameter *view-dictionary* |
|
358 | 366 |
) |
359 | 367 |
)) |
360 | 368 |
|
361 | 369 |
deleted file mode 100644 |
... | ... |
@@ -1,43 +0,0 @@ |
1 |
-#include <stdio.h> |
|
2 |
- |
|
3 |
-// #include <Foundation/NSException.h> |
|
4 |
-#include <Foundation/NSGeometry.h> |
|
5 |
-#include <AppKit/NSWindow.h> |
|
6 |
- |
|
7 |
-#import <Cocoa/Cocoa.h> |
|
8 |
- |
|
9 |
-#define EXPORT __attribute__((visibility("default"))) |
|
10 |
- |
|
11 |
-// // misguided attempt to recover from cocoa exceptions |
|
12 |
-// EXPORT void set_uncaught_exception_handler(NSUncaughtExceptionHandler * _Nullable handler) { |
|
13 |
-// NSSetUncaughtExceptionHandler(handler);}; |
|
14 |
- |
|
15 |
-EXPORT void printRect(NSRect rect) { |
|
16 |
- printf("Got a rect: (%f %f), (%f %f)\n", |
|
17 |
- rect.size.width, |
|
18 |
- rect.size.height, |
|
19 |
- rect.origin.x, |
|
20 |
- rect.origin.y);} |
|
21 |
- |
|
22 |
-EXPORT id initWindow(NSWindow *window, NSRect *rect, char a, char b, Boolean c) { |
|
23 |
- printf("Got a rect: (%f %f), (%f %f)\n", rect->size.width, rect->size.height, rect->origin.x, rect->origin.y); |
|
24 |
- return [window initWithContentRect: *rect |
|
25 |
- styleMask: a |
|
26 |
- backing: b |
|
27 |
- defer: c];} |
|
28 |
-EXPORT id initWithFrame(id thing, NSRect *rect) { |
|
29 |
- printf("Got a rect: (%f %f), (%f %f)\n", rect->size.width, rect->size.height, rect->origin.x, rect->origin.y); |
|
30 |
- return [thing initWithFrame: *rect];} |
|
31 |
- |
|
32 |
-// one way to make this usable with performSelectorOnMainThread: |
|
33 |
-// @interface NSStackView (FWOARStackView) |
|
34 |
-// - (NSStackView *)addViewLeading:(NSView *)view; |
|
35 |
-// @end |
|
36 |
- |
|
37 |
-// @implementation NSStackView (FWOARStackView) |
|
38 |
-// - (NSStackView *)addViewLeading:(NSView *)view { |
|
39 |
-// [self addView:view |
|
40 |
-// inGravity:NSStackViewGravityLeading]; |
|
41 |
-// return self; |
|
42 |
-// } |
|
43 |
-// @end |
... | ... |
@@ -5,18 +5,15 @@ |
5 | 5 |
(serapeum:eval-always |
6 | 6 |
(cffi:define-foreign-library cocoa |
7 | 7 |
(:darwin (:framework "Cocoa"))) |
8 |
- (define-foreign-library foundation |
|
8 |
+ (cffi:define-foreign-library foundation |
|
9 | 9 |
(:darwin (:framework "Foundation"))) |
10 |
- (define-foreign-library appkit |
|
11 |
- (:darwin (:framework "AppKit"))) |
|
12 |
- (define-foreign-library expose-stuff |
|
13 |
- (:darwin #p"libnsrect-expose.dylib"))) |
|
10 |
+ (cffi:define-foreign-library appkit |
|
11 |
+ (:darwin (:framework "AppKit")))) |
|
14 | 12 |
|
15 | 13 |
|
16 | 14 |
(use-foreign-library foundation) |
17 | 15 |
(use-foreign-library cocoa) |
18 | 16 |
(use-foreign-library appkit) |
19 |
-(use-foreign-library expose-stuff) |
|
20 | 17 |
|
21 | 18 |
(defctype o-class :pointer) |
22 | 19 |
(defctype o-selector :pointer) |
... | ... |
@@ -340,7 +337,7 @@ |
340 | 337 |
(let* ((class-cache (objc-class-cache (closer-mop:class-prototype (find-class 'objc-class)))) |
341 | 338 |
(cached (gethash name class-cache))) |
342 | 339 |
(if cached |
343 |
- cached |
|
340 |
+ cached |
|
344 | 341 |
(let ((objc-class (objc-look-up-class name))) |
345 | 342 |
(if (null-pointer-p objc-class) |
346 | 343 |
(error 'no-such-objc-class :wanted-name name) |
... | ... |
@@ -353,7 +350,7 @@ |
353 | 350 |
;; Or should we let that fall through to message sending? |
354 | 351 |
(defun %ensure-wrapped-objc-selector (name target-class result-type args) |
355 | 352 |
(assert (= (count #\: name) |
356 |
- (length args)) |
|
353 |
+ (length args)) |
|
357 | 354 |
(name args) |
358 | 355 |
"Invalid number of arg types for selector ~s" name) |
359 | 356 |
|
... | ... |
@@ -361,7 +358,7 @@ |
361 | 358 |
(cached (gethash (list name target-class) |
362 | 359 |
class-cache))) |
363 | 360 |
(if cached |
364 |
- cached |
|
361 |
+ cached |
|
365 | 362 |
(let ((objc-selector (ensure-selector name))) |
366 | 363 |
(setf (gethash (list name target-class) class-cache) |
367 | 364 |
(make-instance 'objc-selector |
... | ... |
@@ -411,10 +408,9 @@ |
411 | 408 |
|
412 | 409 |
(defmacro with-typed-selectors ((&rest defs) &body body) |
413 | 410 |
(let ((expanded-defs (loop for ((name objc-name) args ret-type) in defs |
414 |
- collect |
|
415 |
- `((,name (&rest r) (apply ,name r)) |
|
416 |
- (,name (%ensure-wrapped-objc-selector ,objc-name ',ret-type ',args)))))) |
|
411 |
+ collect |
|
412 |
+ `((,name (&rest r) (apply ,name r)) |
|
413 |
+ (,name (%ensure-wrapped-objc-selector ,objc-name ',ret-type ',args)))))) |
|
417 | 414 |
`(let (,@(mapcar #'second expanded-defs)) |
418 | 415 |
(flet (,@(mapcar #'first expanded-defs)) |
419 | 416 |
,@body)))) |
420 |
- |