git.fiddlerwoaroof.com
Browse code

works --- on ccl at least

Ed Langley authored on 06/01/2018 02:20:15
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+*.*f*sl
2
+foo*
3
+*tmp*
4
+ns-test
5
+*.dylib
6
+*~
... ...
@@ -9,6 +9,13 @@
9 9
     (format t "~&Exxception: ~a~%" [exception reason])
10 10
     (values)))
11 11
 
12
+(cffi:defcfun (init-window "initWindow")
13
+    :pointer
14
+  (window :pointer)
15
+  (rect (:pointer (:struct objc-runtime:ns-rect)))
16
+  (a :char)
17
+  (b :char)
18
+  (c :boolean))
12 19
 
13 20
 #+null
14 21
 (cffi:defcfun (set-uncaught-exception-handler "set_uncaught_exception_handler"
... ...
@@ -70,32 +77,34 @@
70 77
                            '(:struct objc-runtime:ns-rect)))
71 78
 
72 79
 (defun main ()
73
-  (with-selectors ((shared-application "sharedApplication")
74
-                   (process-info "processInfo")
75
-                   (process-name "processName")
76
-                   (set-activation-policy "setActivationPolicy:")
77
-                   (init-with-content-rect "initWithContentRect:styleMask:backing:defer:")
78
-                   (set-title "setTitle:")
79
-                   (run "run")
80
-                   (activate-ignoring-other-apps "activateIgnoringOtherApps:")
81
-                   alloc
82
-                   (make-key-and-order-front "makeKeyAndOrderFront:")
83
-                   (cascade-top-left-from-point "cascadeTopLeftFromPoint:")
84
-                   ;; (application-should-terminate "applicationShouldTerminate:")
85
-                   ;; (set-delegate "setDelegate:")
86
-                   ;; (finish-launching "finishLaunching")
87
-                   )
88
-    [#@NSApplication shared-application]
89
-    [objc-runtime::ns-app set-activation-policy :int 0]
80
+  (trivial-main-thread:with-body-in-main-thread ()
81
+    (with-selectors ((shared-application "sharedApplication")
82
+                     (process-info "processInfo")
83
+                     (process-name "processName")
84
+                     (set-activation-policy "setActivationPolicy:")
85
+                     (init-with-content-rect "initWithContentRect:styleMask:backing:defer:")
86
+                     (set-title "setTitle:")
87
+                     (run "run")
88
+                     (activate-ignoring-other-apps "activateIgnoringOtherApps:")
89
+                     alloc
90
+                     (make-key-and-order-front "makeKeyAndOrderFront:")
91
+                     (cascade-top-left-from-point "cascadeTopLeftFromPoint:")
92
+                     ;; (application-should-terminate "applicationShouldTerminate:")
93
+                     ;; (set-delegate "setDelegate:")
94
+                     ;; (finish-launching "finishLaunching")
95
+                     )
96
+      [#@NSApplication shared-application]
97
+      [objc-runtime::ns-app set-activation-policy :int 0]
90 98
 
91
-    (break)
92
-    (let* ((application-name [[#@NSProcessInfo process-info] process-name]))
93
-      (with-point (p (20 20))
94
-        (let* ((the-window [#@NSWindow alloc]))
95
-          [the-window init-with-content-rect :pointer (make-rect 10 10 120 120)
96
-                                             :char 1 :char 2 :boolean nil]
97
-          [the-window cascade-top-left-from-point :pointer p]
98
-          [the-window set-title :pointer application-name]
99
-          [the-window make-key-and-order-front :pointer (cffi:null-pointer)]
100
-          [ objc-runtime::ns-app activate-ignoring-other-apps :boolean t]
101
-          [ objc-runtime::ns-app run])))))
99
+      ;; (break)
100
+      (let* ((application-name [[#@NSProcessInfo process-info] process-name]))
101
+        (with-point (p (20 20))
102
+          (let* ((the-window [#@NSWindow alloc])
103
+                 (foreign-rect (make-rect 10 10 120 120)))
104
+            (format t "~&My rect: ~s~%" (cffi:convert-from-foreign foreign-rect '(:struct objc-runtime::ns-rect)))
105
+            (init-window the-window foreign-rect 1 2 nil)
106
+            [the-window cascade-top-left-from-point :pointer p]
107
+            [the-window set-title :pointer application-name]
108
+            [the-window make-key-and-order-front :pointer (cffi:null-pointer)]
109
+            [ objc-runtime::ns-app activate-ignoring-other-apps :boolean t]
110
+            [ objc-runtime::ns-app run]))))))
... ...
@@ -1,6 +1,18 @@
1
+#include <stdio.h>
2
+
1 3
 #include <Foundation/NSException.h>
4
+#include <Foundation/NSGeometry.h>
5
+#include <AppKit/NSWindow.h>
2 6
 #define EXPORT __attribute__((visibility("default")))
3 7
 
4 8
 EXPORT void set_uncaught_exception_handler(NSUncaughtExceptionHandler * _Nullable handler) {
5 9
   NSSetUncaughtExceptionHandler(handler);
6 10
 };
11
+
12
+EXPORT id initWindow(NSWindow *window, NSRect *rect, char a, char b, Boolean c) {
13
+  printf("Got a rect: (%f %f), (%f %f)\n", rect->size.width, rect->size.height, rect->origin.x, rect->origin.y);
14
+  return [window initWithContentRect: *rect
15
+                           styleMask: a
16
+                             backing: b
17
+                               defer: c];
18
+}
... ...
@@ -9,8 +9,11 @@
9 9
                #:uiop
10 10
                #:serapeum
11 11
                #:fwoar.lisputils
12
-               #:cffi)
12
+               #:cffi
13
+               #:trivial-main-thread
14
+               #:cffi-libffi)
13 15
   :defsystem-depends-on (#:cffi-grovel)
14 16
   :components ((:file "package")
15 17
                (:cffi-grovel-file "objc-runtime-types" :depends-on ("package"))
16
-               (:file "objc-runtime" :depends-on ("package" "objc-runtime-types"))))
18
+               (:file "readtable" :depends-on ("package"))
19
+               (:file "objc-runtime" :depends-on ("package" "readtable" "objc-runtime-types"))))
... ...
@@ -1,4 +1,6 @@
1 1
 (in-package :objc-runtime)
2
+(serapeum:eval-always
3
+ (named-readtables:in-readtable :objc-readtable))
2 4
 
3 5
 (serapeum:eval-always
4 6
   (cffi:define-foreign-library cocoa
... ...
@@ -131,28 +133,6 @@
131 133
      ,@body))
132 134
 
133 135
 
134
-(eval-when (:compile-toplevel :load-toplevel :execute)
135
-  (named-readtables:defreadtable :objc-readtable
136
-    (:merge :standard)
137
-    (:syntax-from :standard #\) #\])
138
-    (:macro-char #\[ (lambda (s char)
139
-                       char
140
-                       (destructuring-bind (obj message . args)
141
-                           (read-delimited-list #\] s t)
142
-                         `(objc-msg-send ,obj ,message ,@args)))
143
-                 nil)
144
-    (:dispatch-macro-char #\# #\@
145
-                          (lambda (s c b)
146
-                            c b
147
-                            (let ((class-name (coerce (loop for c = (read-char s nil nil t)
148
-                                                         until (or (null c)
149
-                                                                   (serapeum:whitespacep c))
150
-                                                         collect c)
151
-                                                      'string)))
152
-                              `(objc-look-up-class ,class-name))))))
153
-
154
-(named-readtables:in-readtable :objc-readtable)
155
-
156 136
 (defgeneric make-objc-instance (class &rest args)
157 137
   (:method ((class string) &rest args)
158 138
     (apply #'make-objc-instance (objc-look-up-class class) args))
159 139
new file mode 100644
... ...
@@ -0,0 +1,21 @@
1
+(in-package :objc-runtime)
2
+
3
+(named-readtables:defreadtable :objc-readtable
4
+  (:merge :standard)
5
+  (:syntax-from :standard #\) #\])
6
+  (:macro-char #\[ (lambda (s char)
7
+                     char
8
+                     (let ((info (read-delimited-list #\] s t)))
9
+                       (when info
10
+                         (destructuring-bind (obj message . args) info
11
+                           `(objc-msg-send ,obj ,message ,@args)))))
12
+               nil)
13
+  (:dispatch-macro-char #\# #\@
14
+                        (lambda (s c b)
15
+                          c b
16
+                          (let ((class-name (coerce (loop for c = (read-char s nil nil t)
17
+                                                       until (or (null c)
18
+                                                                 (serapeum:whitespacep c))
19
+                                                       collect c)
20
+                                                    'string)))
21
+                            `(objc-look-up-class ,class-name)))))