author | Claus Gittinger <cg@exept.de> |
Mon, 27 May 2019 16:53:37 +0200 | |
changeset 24192 | 18512bf68422 |
parent 24095 | ef0a44d99ecf |
child 24339 | d1a2b7e3fb5e |
permissions | -rw-r--r-- |
21452 | 1 |
" |
2 |
COPYRIGHT (c) 2013 by Claus Gittinger |
|
21455 | 3 |
All Rights Reserved |
21452 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
17471 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
"{ NameSpace: Smalltalk }" |
|
14819 | 15 |
|
17471 | 16 |
UnixOperatingSystem subclass:#OSXOperatingSystem |
17 |
instanceVariableNames:'' |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
18 |
classVariableNames:'NSApp' |
17471 | 19 |
poolDictionaries:'' |
20 |
category:'OS-Unix' |
|
21 |
! |
|
22 |
||
21452 | 23 |
!OSXOperatingSystem primitiveDefinitions! |
24 |
%{ |
|
25 |
||
22491 | 26 |
#ifdef __osx__ |
27 |
// mhm - how could they forget this???? |
|
28 |
# ifndef __XPC_IOS_SIMULATOR_AVAILABLE_STARTING |
|
29 |
# define __XPC_IOS_SIMULATOR_AVAILABLE_STARTING(version) |
|
30 |
# endif |
|
31 |
#endif |
|
32 |
||
33 |
#ifndef __osx__ |
|
21452 | 34 |
# define NO_QUARTZ |
35 |
# define NO_COCOA |
|
22959 | 36 |
# define NO_CARBON |
24047 | 37 |
# define NO_COREGRAPHICS |
21452 | 38 |
#endif |
39 |
||
22833 | 40 |
// #include <mach/clock.h> |
41 |
// #include <mach/mach.h> |
|
42 |
// #include <sys/time.h> |
|
43 |
// #include <mach/clock.h> |
|
44 |
||
21452 | 45 |
#ifndef NO_COCOA |
46 |
||
47 |
# undef Array |
|
48 |
# undef Number |
|
49 |
# undef Method |
|
50 |
# undef Point |
|
51 |
# undef Rectangle |
|
52 |
# undef Block |
|
53 |
# undef String |
|
54 |
# undef Character |
|
55 |
# undef Message |
|
56 |
# undef Object |
|
57 |
# undef Context |
|
58 |
# undef Time |
|
59 |
# undef Date |
|
60 |
# undef Set |
|
61 |
# undef Signal |
|
62 |
# undef Delay |
|
63 |
# undef NameSpace |
|
64 |
# undef Process |
|
65 |
# undef Processor |
|
66 |
# undef Class |
|
67 |
# undef FixedPoint |
|
68 |
# undef true |
|
69 |
# undef false |
|
70 |
||
71 |
# undef INT |
|
72 |
# undef UINT |
|
73 |
||
22491 | 74 |
# include <ApplicationServices/ApplicationServices.h> |
75 |
# include <CoreFoundation/CoreFoundation.h> |
|
21452 | 76 |
// #include <Foundation/Foundation.h> |
24047 | 77 |
# include <CoreGraphics/CGGeometry.h> |
21595 | 78 |
|
79 |
// #include <CoreGraphics/CGEventTypes.h> |
|
21452 | 80 |
|
22491 | 81 |
# include <stdlib.h> |
82 |
# include <stdio.h> |
|
83 |
# include <IOKit/graphics/IOGraphicsLib.h> |
|
21452 | 84 |
|
22491 | 85 |
# include <objc/runtime.h> |
86 |
# include <objc/message.h> |
|
21452 | 87 |
|
88 |
# ifdef __DEF_Array |
|
89 |
# define Array __DEF_Array |
|
90 |
# endif |
|
91 |
# ifdef __DEF_Number |
|
92 |
# define Number __DEF_Number |
|
93 |
# endif |
|
94 |
# ifdef __DEF_Method |
|
95 |
# define Method __DEF_Method |
|
96 |
# endif |
|
97 |
# ifdef __DEF_Point |
|
98 |
# define Point __DEF_Point |
|
99 |
# endif |
|
100 |
# ifdef __DEF_Rectangle |
|
101 |
# define Rectangle __DEF_Rectangle |
|
102 |
# endif |
|
103 |
# ifdef __DEF_Block |
|
104 |
# define Block __DEF_Block |
|
105 |
# endif |
|
106 |
# ifdef __DEF_String |
|
107 |
# define String __DEF_String |
|
108 |
# endif |
|
109 |
# ifdef __DEF_Character |
|
110 |
# define Character __DEF_Character |
|
111 |
# endif |
|
112 |
# ifdef __DEF_Message |
|
113 |
# define Message __DEF_Message |
|
114 |
# endif |
|
115 |
# ifdef __DEF_Object |
|
116 |
# define Object __DEF_Object |
|
117 |
# endif |
|
118 |
# ifdef __DEF_Context |
|
119 |
# define Context __DEF_Context |
|
120 |
# endif |
|
121 |
# ifdef __DEF_Date |
|
122 |
# define Date __DEF_Date |
|
123 |
# endif |
|
124 |
# ifdef __DEF_Time |
|
125 |
# define Time __DEF_Time |
|
126 |
# endif |
|
127 |
# ifdef __DEF_Set |
|
128 |
# define Set __DEF_Set |
|
129 |
# endif |
|
130 |
# ifdef __DEF_Signal |
|
131 |
# define Signal __DEF_Signal |
|
132 |
# endif |
|
133 |
# ifdef __DEF_Delay |
|
134 |
# define Delay __DEF_Delay |
|
135 |
# endif |
|
136 |
# ifdef __DEF_NameSpace |
|
137 |
# define NameSpace __DEF_NameSpace |
|
138 |
# endif |
|
139 |
# ifdef __DEF_Process |
|
140 |
# define Process __DEF_Process |
|
141 |
# endif |
|
142 |
# ifdef __DEF_Processor |
|
143 |
# define Processor __DEF_Processor |
|
144 |
# endif |
|
145 |
# ifdef __DEF_Class |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
146 |
# define STX_Class __DEF_Class |
21452 | 147 |
# endif |
148 |
# ifdef __DEF_FixedPoint |
|
149 |
# define FixedPoint __DEF_FixedPoint |
|
150 |
# endif |
|
151 |
# ifdef __DEF_true |
|
152 |
# undef true |
|
153 |
# define true __DEF_true |
|
154 |
# endif |
|
155 |
# ifdef __DEF_false |
|
156 |
# undef false |
|
157 |
# define false __DEF_false |
|
158 |
# endif |
|
159 |
||
160 |
# define INT STX_INT |
|
161 |
# define UINT STX_UINT |
|
162 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
163 |
typedef struct CMPoint { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
164 |
double x; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
165 |
double y; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
166 |
} CMPoint; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
167 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
168 |
typedef struct CMSize { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
169 |
double width; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
170 |
double height; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
171 |
} CMSize; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
172 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
173 |
typedef struct CMRect { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
174 |
CMPoint origin; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
175 |
CMSize size; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
176 |
} CMRect; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
177 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
178 |
typedef struct AppDel { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
179 |
Class isa; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
180 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
181 |
// Will be an NSWindow later. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
182 |
id window; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
183 |
} AppDelegate; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
184 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
185 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
186 |
enum { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
187 |
NSBorderlessWindowMask = 0, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
188 |
NSTitledWindowMask = 1 << 0, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
189 |
NSClosableWindowMask = 1 << 1, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
190 |
NSMiniaturizableWindowMask = 1 << 2, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
191 |
NSResizableWindowMask = 1 << 3, |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
192 |
}; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
193 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
194 |
typedef id(*CMacsSimpleMessage)(id, SEL); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
195 |
typedef void(*CMacsVoidMessage)(id, SEL); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
196 |
typedef void(*CMacsVoidMessage1)(id, SEL, void *); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
197 |
typedef id(*CMacsRectMessage1)(id, SEL, CMRect); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
198 |
typedef id(*CMacsWindowInitMessage)(id, SEL, CMRect, int, int, bool); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
199 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
200 |
extern CMacsSimpleMessage cmacs_simple_msgSend; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
201 |
extern CMacsVoidMessage cmacs_void_msgSend; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
202 |
extern CMacsVoidMessage1 cmacs_void_msgSend1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
203 |
extern CMacsRectMessage1 cmacs_rect_msgSend1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
204 |
extern CMacsWindowInitMessage cmacs_window_init_msgSend; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
205 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
206 |
#endif // NO_COCOA |
21452 | 207 |
|
208 |
%} |
|
209 |
! ! |
|
210 |
||
211 |
!OSXOperatingSystem primitiveFunctions! |
|
212 |
%{ |
|
213 |
||
214 |
#ifndef NO_COCOA |
|
215 |
||
24047 | 216 |
struct ev { |
217 |
struct ev* nextEvent; |
|
218 |
CGEventType type; |
|
219 |
CGKeyCode keycode; |
|
220 |
int x,y; |
|
221 |
int button; |
|
222 |
}; |
|
223 |
static struct ev *nextRecordedEvent = NULL; |
|
224 |
static struct ev *lastRecordedEvent = NULL; |
|
225 |
||
21452 | 226 |
CGEventRef |
227 |
myCGEventCallback(CGEventTapProxy proxy, CGEventType type, |
|
228 |
CGEventRef event, void *refcon) |
|
229 |
{ |
|
24047 | 230 |
if ((type == kCGEventKeyDown) || (type == kCGEventKeyUp)) { |
231 |
// The incoming keycode. |
|
232 |
CGKeyCode keycode = (CGKeyCode)CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); |
|
233 |
} |
|
234 |
if (type == kCGEventMouseMoved) { |
|
235 |
// loc = [NSEvent mouseLocation] |
|
236 |
// int x = loc.x; |
|
237 |
// int y = loc.y; |
|
238 |
} |
|
21452 | 239 |
// We must return the event for it to be useful. |
240 |
return event; |
|
241 |
} |
|
242 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
243 |
BOOL |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
244 |
AppDel_didFinishLaunching(AppDelegate *self, SEL _cmd, id notification) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
245 |
// self->window = cmacs_simple_msgSend((id)objc_getClass("NSWindow"), sel_getUid("alloc")); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
246 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
247 |
// /// Create an instance of the window. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
248 |
// self->window = cmacs_window_init_msgSend(self->window, sel_getUid("initWithContentRect:styleMask:backing:defer:"), (CMRect){0,0,1024,460}, (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask), 0, false); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
249 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
250 |
// /// Create an instance of our view class. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
251 |
// /// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
252 |
// /// Relies on the view having declared a constructor that allocates a class pair for it. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
253 |
// id view = cmacs_rect_msgSend1(cmacs_simple_msgSend((id)objc_getClass("View"), sel_getUid("alloc")), sel_getUid("initWithFrame:"), (CMRect){ 0, 0, 320, 480 }); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
254 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
255 |
// // here we simply add the view to the window. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
256 |
// cmacs_void_msgSend1(self->window, sel_getUid("setContentView:"), view); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
257 |
// cmacs_simple_msgSend(self->window, sel_getUid("becomeFirstResponder")); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
258 |
// |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
259 |
// // Shows our window in the bottom-left hand corner of the screen. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
260 |
// cmacs_void_msgSend1(self->window, sel_getUid("makeKeyAndOrderFront:"), self); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
261 |
return YES; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
262 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
263 |
|
21452 | 264 |
#endif // NO_COCOA |
265 |
||
266 |
%} |
|
267 |
! ! |
|
268 |
||
269 |
!OSXOperatingSystem class methodsFor:'documentation'! |
|
270 |
||
271 |
copyright |
|
272 |
" |
|
273 |
COPYRIGHT (c) 2013 by Claus Gittinger |
|
21455 | 274 |
All Rights Reserved |
21452 | 275 |
|
276 |
This software is furnished under a license and may be used |
|
277 |
only in accordance with the terms of that license and with the |
|
278 |
inclusion of the above copyright notice. This software may not |
|
279 |
be provided or otherwise made available to, or used by, any |
|
280 |
other person. No title to or ownership of the software is |
|
281 |
hereby transferred. |
|
282 |
" |
|
283 |
! |
|
284 |
||
285 |
documentation |
|
286 |
" |
|
287 |
a small number of OS-X specific redefinitions here. |
|
288 |
||
289 |
[Author:] |
|
21455 | 290 |
Claus Gittinger |
21452 | 291 |
" |
292 |
! ! |
|
17471 | 293 |
|
294 |
!OSXOperatingSystem class methodsFor:'initialization'! |
|
295 |
||
296 |
initializeCodeset |
|
297 |
super initializeCodeset. |
|
17493 | 298 |
Codeset := #'utf8-mac'. |
17494 | 299 |
CodesetEncoder := nil. |
17471 | 300 |
! ! |
14819 | 301 |
|
21452 | 302 |
!OSXOperatingSystem class methodsFor:'cocoa - events'! |
303 |
||
21591 | 304 |
finishLaunching |
305 |
"tell the system, that I have finished my startup phase. |
|
306 |
OSX will stop bounding the launch icon then." |
|
21596 | 307 |
|
21591 | 308 |
NSApp isNil ifTrue:[ |
21596 | 309 |
self getNSApp |
21591 | 310 |
]. |
311 |
%{ |
|
312 |
#ifndef NO_COCOA |
|
313 |
id NSApp = __externalAddressVal(@global(NSApp)); |
|
24095 | 314 |
extern int stx_nsAppIsRunning; |
21591 | 315 |
|
24095 | 316 |
if (!stx_nsAppIsRunning) { |
317 |
objc_msgSend(NSApp, sel_getUid("finishLaunching")); |
|
318 |
} |
|
21591 | 319 |
RETURN(self); |
320 |
#endif // NO_COCOA |
|
321 |
%}. |
|
322 |
"/ if compiled without COCOA support (which you should not), |
|
323 |
"/ the icon will probably continue to bounce... |
|
324 |
"/ ... but we do not want an error here. |
|
21596 | 325 |
|
21591 | 326 |
"/ self primitiveFailed |
327 |
||
328 |
" |
|
329 |
self finishLaunching |
|
330 |
" |
|
331 |
||
332 |
"Modified: / 28-02-2017 / 10:59:15 / cg" |
|
333 |
! |
|
334 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
335 |
generateButtonEvent:button down:down x:screenX y:screenY |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
336 |
"synthesize and send a button event to the screen" |
21584 | 337 |
%{ |
338 |
#ifndef NO_COCOA |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
339 |
if (__bothSmallInteger(screenX, screenY) |
21584 | 340 |
&& __isSmallInteger(button)) { |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
341 |
CGPoint pt; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
342 |
pt.x = __intVal(screenX); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
343 |
pt.y = __intVal(screenY); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
344 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
345 |
CGEventType evType; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
346 |
CGMouseButton evButton = __intVal(button); |
21584 | 347 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
348 |
switch (evButton) { |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
349 |
case 1: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
350 |
evType = (down == true) ? kCGEventLeftMouseDown : kCGEventLeftMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
351 |
evButton = 0; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
352 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
353 |
case 2: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
354 |
evType = (down == true) ? kCGEventRightMouseDown : kCGEventRightMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
355 |
evButton = 1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
356 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
357 |
case 3: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
358 |
evType = (down == true) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
359 |
evButton = 2; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
360 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
361 |
default: |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
362 |
evType = (down == true) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
363 |
evButton = __intVal(button) - 1; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
364 |
break; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
365 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
366 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
367 |
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, evType, pt, evButton); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
368 |
CGEventSetType(theEvent, evType); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
369 |
CGEventPost(kCGHIDEventTap, theEvent); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
370 |
CFRelease(theEvent); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
371 |
RETURN(self); |
21584 | 372 |
} |
373 |
#endif // NO_COCOA |
|
374 |
%}. |
|
375 |
self primitiveFailed |
|
376 |
||
377 |
" |
|
378 |
OperatingSystem generateButtonEvent:1 down:true x:150 y:150. |
|
379 |
OperatingSystem generateButtonEvent:1 down:false x:150 y:150. |
|
380 |
||
381 |
OperatingSystem generateButtonEvent:2 down:true x:150 y:150. |
|
382 |
OperatingSystem generateButtonEvent:2 down:false x:150 y:150. |
|
383 |
" |
|
384 |
||
385 |
"Created: / 28-02-2017 / 00:15:18 / cg" |
|
386 |
! |
|
387 |
||
21621 | 388 |
generateKeyboardEvent:keyCode down:down |
389 |
"synthesize and send a keyboard event to the screen" |
|
390 |
%{ |
|
391 |
#ifndef NO_COCOA |
|
392 |
if (__isSmallInteger(keyCode)) { |
|
21627 | 393 |
int evType; |
394 |
||
395 |
CGEventRef theEvent = CGEventCreateKeyboardEvent(NULL, __intVal(keyCode), (down==true)?1:0); |
|
396 |
CGEventSetType(theEvent, (down==true) ? kCGEventKeyDown:kCGEventKeyUp); |
|
397 |
CGEventPost(kCGHIDEventTap, theEvent); |
|
398 |
CFRelease(theEvent); |
|
399 |
RETURN(self); |
|
21621 | 400 |
} |
401 |
#endif // NO_COCOA |
|
402 |
%}. |
|
403 |
self primitiveFailed |
|
404 |
||
405 |
" |
|
406 |
OperatingSystem generateKeyboardEvent:6 down:true. |
|
407 |
OperatingSystem generateKeyboardEvent:6 down:false. |
|
408 |
" |
|
409 |
||
410 |
"Created: / 02-03-2017 / 16:35:04 / cg" |
|
411 |
! |
|
412 |
||
413 |
generateMouseMoveEventX:screenX y:screenY |
|
24047 | 414 |
"synthesize and send a mouse move event to the screen" |
21621 | 415 |
%{ |
416 |
#ifndef NO_COCOA |
|
417 |
if (__bothSmallInteger(screenX, screenY)) { |
|
21627 | 418 |
CGPoint pt; |
419 |
pt.x = __intVal(screenX); |
|
420 |
pt.y = __intVal(screenY); |
|
21621 | 421 |
|
21627 | 422 |
CGEventType evType; |
423 |
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, pt, 0); |
|
424 |
CGEventSetType(theEvent, kCGEventMouseMoved); |
|
425 |
CGEventPost(kCGHIDEventTap, theEvent); |
|
426 |
CFRelease(theEvent); |
|
427 |
RETURN(self); |
|
21621 | 428 |
} |
429 |
#endif // NO_COCOA |
|
430 |
%}. |
|
431 |
self primitiveFailed |
|
432 |
||
433 |
" |
|
434 |
OperatingSystem generateMouseMoveEventX:150 y:5. |
|
435 |
Delay waitFor:(1 seconds). |
|
436 |
OperatingSystem generateMouseMoveEventX:1050 y:150. |
|
437 |
" |
|
438 |
||
439 |
"Created: / 02-03-2017 / 20:01:51 / cg" |
|
440 |
! |
|
441 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
442 |
getNSApp |
23114 | 443 |
"get the NSApplication instance and remember in the global named NSApp" |
444 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
445 |
%{ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
446 |
#ifndef NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
447 |
Class AppDelClass = NULL; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
448 |
id NSApp = NULL; |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
449 |
|
21731 | 450 |
# if 0 /* not needed */ |
21597 | 451 |
Class poolClass = objc_getClass("NSAutoreleasePool"); |
21594 | 452 |
if (poolClass == NULL) { |
21597 | 453 |
fprintf(stderr, "OSX: Unable to get NSAutoreleasePool\n"); |
454 |
RETURN(false); |
|
21594 | 455 |
} |
456 |
id pool = objc_msgSend(poolClass, sel_registerName("alloc")); |
|
457 |
if (pool == NULL) { |
|
21597 | 458 |
fprintf(stderr, "OSX: Unable to create NSAutoreleasePool\n"); |
459 |
RETURN(false); |
|
21594 | 460 |
} |
461 |
objc_msgSend(pool, sel_registerName("init")); |
|
21731 | 462 |
# endif |
21594 | 463 |
|
21731 | 464 |
# if 0 /* not needed */ |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
465 |
AppDelClass = objc_allocateClassPair((Class)objc_getClass("NSObject"), "AppDelegate", 0); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
466 |
class_addMethod(AppDelClass, sel_getUid("applicationDidFinishLaunching:"), (IMP)AppDel_didFinishLaunching, "i@:@"); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
467 |
objc_registerClassPair(AppDelClass); |
21731 | 468 |
# endif |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
469 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
470 |
NSApp = objc_msgSend((id)objc_getClass("NSApplication"), sel_getUid("sharedApplication")); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
471 |
if (NSApp == NULL) { |
21597 | 472 |
fprintf(stderr,"OSX: Failed to initialize NSApplication\n"); |
473 |
RETURN(false); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
474 |
} |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
475 |
@global(NSApp) = __MKEXTERNALADDRESS(NSApp); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
476 |
|
24069 | 477 |
# if 0 /* not needed */ |
21594 | 478 |
id req = objc_msgSend(NSApp,sel_getUid("requestUserAttention:"),0); |
479 |
objc_msgSend(NSApp,sel_getUid("cancelUserAttentionRequest:"),req); |
|
24069 | 480 |
# endif |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
481 |
|
21731 | 482 |
# if 0 /* not needed */ |
21594 | 483 |
id appDelInst = objc_msgSend((id)objc_getClass("AppDelegate"), sel_getUid("alloc")); |
484 |
objc_msgSend(appDelInst, sel_getUid("init")); |
|
485 |
objc_msgSend(NSApp, sel_getUid("setDelegate:"), appDelInst); |
|
21731 | 486 |
# endif |
21594 | 487 |
|
21731 | 488 |
# if 0 /* not needed */ |
21594 | 489 |
objc_msgSend(pool, sel_registerName("release")); |
21731 | 490 |
# endif |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
491 |
RETURN(true); |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
492 |
#endif // NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
493 |
%}. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
494 |
self primitiveFailed |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
495 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
496 |
" |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
497 |
self getNSApp |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
498 |
" |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
499 |
|
21594 | 500 |
"Modified: / 28-02-2017 / 13:45:39 / cg" |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
501 |
! |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
502 |
|
21591 | 503 |
receiveNextEvent |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
504 |
%{ |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
505 |
#ifndef NO_COCOA |
21591 | 506 |
CFMachPortRef eventTap; |
507 |
CGEventMask eventMask; |
|
508 |
CFRunLoopSourceRef runLoopSource; |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
509 |
|
21591 | 510 |
// Create an event tap. We are interested in key presses. |
24047 | 511 |
// sigh: a global event tap requires root privileges |
512 |
eventMask = ((1 << kCGEventKeyDown) |
|
513 |
| (1 << kCGEventKeyUp) |
|
514 |
| (1 << kCGEventMouseMoved)); |
|
21591 | 515 |
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, |
516 |
eventMask, NULL, myCGEventCallback); |
|
517 |
if (!eventTap) { |
|
518 |
fprintf(stderr, "failed to create event tap\n"); |
|
519 |
} else { |
|
520 |
fprintf(stderr, "ok\n"); |
|
521 |
||
522 |
// Create a run loop source. |
|
523 |
runLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, eventTap, 0); |
|
524 |
// Enable the event tap. |
|
525 |
CGEventTapEnable(eventTap, true); |
|
526 |
} |
|
527 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
528 |
#endif // NO_COCOA |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
529 |
%}. |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
530 |
self primitiveFailed |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
531 |
|
21591 | 532 |
"Modified: / 28-02-2017 / 01:05:04 / cg" |
21452 | 533 |
! ! |
534 |
||
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
535 |
!OSXOperatingSystem class methodsFor:'dummy shell operations'! |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
536 |
|
22655 | 537 |
openApplicationForDocument:aFilenameOrString operation:operationSymbol |
538 |
"open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString. |
|
539 |
This is typically used to present help-files, html documents, pdf documents etc. |
|
540 |
operationSymbol is one of: |
|
22833 | 541 |
open |
542 |
edit |
|
543 |
explore |
|
22655 | 544 |
" |
545 |
||
546 |
|openCmd| |
|
547 |
||
548 |
(openCmd := self openApplicationHelperCommand) notNil ifTrue:[ |
|
22833 | 549 |
(operationSymbol = 'open') ifTrue:[ |
550 |
self executeCommand:'open "',aFilenameOrString asFilename pathName,'"' |
|
551 |
] ifFalse:[ |
|
552 |
(operationSymbol = 'explore') ifTrue:[ |
|
553 |
self executeCommand:'open -R "',aFilenameOrString asFilename pathName,'"' |
|
554 |
]. |
|
555 |
]. |
|
22655 | 556 |
]. |
557 |
! |
|
558 |
||
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
559 |
openApplicationHelperCommand |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
560 |
"Return a command line helper to open a default application for file or URL" |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
561 |
|
18279 | 562 |
(self canExecuteCommand: 'open') ifTrue:[ |
563 |
^ 'open' |
|
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
564 |
]. |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
565 |
^ nil |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
566 |
|
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
567 |
"Created: / 13-01-2015 / 09:23:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17427 | 568 |
! |
569 |
||
17428 | 570 |
openTerminalWithCommand:shellCommand inBackground:inBackground |
17427 | 571 |
"open a new terminal, which executes a command" |
572 |
||
17428 | 573 |
|cmd| |
574 |
||
575 |
cmd := 'osascript -e ''tell application "Terminal" to do script "%1"''' bindWith:shellCommand. |
|
576 |
||
577 |
inBackground ifTrue:[ |
|
18279 | 578 |
^ self |
579 |
startProcess:cmd |
|
580 |
inputFrom:nil |
|
581 |
outputTo:nil |
|
582 |
errorTo:nil |
|
583 |
auxFrom:nil |
|
584 |
environment:nil |
|
585 |
inDirectory:nil |
|
17428 | 586 |
] ifFalse:[ |
18279 | 587 |
^ self executeCommand:cmd |
17428 | 588 |
]. |
17427 | 589 |
|
590 |
" |
|
17428 | 591 |
OSXOperatingSystem openTerminalWithCommand:'ls -l' inBackground:true |
17427 | 592 |
" |
17297
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
593 |
! ! |
a56ba300949c
Overriden openApplicationForDocument... to use desktop-specific "open" command.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17179
diff
changeset
|
594 |
|
14819 | 595 |
!OSXOperatingSystem class methodsFor:'file queries'! |
596 |
||
597 |
caseSensitiveFilenames |
|
598 |
"return true, if the OS has caseSensitive file naming. |
|
599 |
On MSDOS, this will return false; |
|
19817 | 600 |
on a real OS, we return true. |
601 |
Be aware, that OSX can be configured to be either. |
|
602 |
Also, that it actually depends on the mounted volume" |
|
14819 | 603 |
|
18279 | 604 |
"/ actually, this is wrong and depends on the mounted volume; |
605 |
"/ so we need a query for a particular directory (and/or volume). |
|
14819 | 606 |
^ false |
607 |
||
608 |
"Modified: / 5.6.1998 / 18:35:18 / cg" |
|
16381 | 609 |
! |
610 |
||
16644 | 611 |
defaultPackagePath |
20639 | 612 |
"redefined to add /Application and /Library stuff" |
20642 | 613 |
"called by Smalltalk initSystemPath" |
614 |
"self defaultPackagePath" |
|
16644 | 615 |
|
21452 | 616 |
|path executablePath executableDir packagesDir |
20637 | 617 |
libDir appDir versionsDir vsnDirName vsnDir| |
16644 | 618 |
|
619 |
path := super defaultPackagePath. |
|
620 |
||
621 |
executablePath := OperatingSystem pathOfSTXExecutable. |
|
622 |
executablePath notNil ifTrue:[ |
|
21452 | 623 |
executableDir := executablePath asFilename directory. |
624 |
packagesDir := executableDir directory directory / 'Packages'. |
|
625 |
packagesDir exists ifTrue:[ |
|
626 |
packagesDir := packagesDir pathName. |
|
627 |
(path includes:packagesDir) ifFalse:[ |
|
628 |
path add:packagesDir. |
|
629 |
]. |
|
630 |
]. |
|
631 |
libDir := '/Library/Frameworks/SmalltalkX.framework' asFilename. |
|
632 |
libDir exists ifTrue:[ |
|
633 |
versionsDir := libDir / 'Versions'. |
|
634 |
versionsDir exists ifTrue:[ |
|
635 |
vsnDirName := '%1.%2.%3' |
|
636 |
bindWith:Smalltalk majorVersionNr |
|
637 |
with:Smalltalk minorVersionNr |
|
638 |
with:Smalltalk revisionNr. |
|
639 |
vsnDir := versionsDir / vsnDirName. |
|
640 |
vsnDir exists ifTrue:[ |
|
641 |
vsnDir := vsnDir pathName. |
|
642 |
(path includes:vsnDir) ifFalse:[ |
|
643 |
path add:vsnDir. |
|
644 |
]. |
|
645 |
]. |
|
646 |
]. |
|
647 |
]. |
|
648 |
appDir := '/Applications/SmalltalkX/' asFilename. |
|
649 |
appDir exists ifTrue:[ |
|
650 |
versionsDir := appDir / 'Versions'. |
|
651 |
versionsDir exists ifTrue:[ |
|
652 |
vsnDirName := '%1.%2.%3' |
|
653 |
bindWith:Smalltalk majorVersionNr |
|
654 |
with:Smalltalk minorVersionNr |
|
655 |
with:Smalltalk revisionNr. |
|
656 |
vsnDir := versionsDir / vsnDirName. |
|
657 |
vsnDir exists ifTrue:[ |
|
658 |
vsnDir := vsnDir pathName. |
|
659 |
(path includes:vsnDir) ifFalse:[ |
|
660 |
path add:vsnDir. |
|
661 |
]. |
|
662 |
]. |
|
663 |
]. |
|
664 |
]. |
|
16644 | 665 |
]. |
16647 | 666 |
^ path |
16644 | 667 |
! |
668 |
||
22655 | 669 |
getDocumentsDirectory |
670 |
"return your documents directory. |
|
671 |
Under osx, that's the user's 'Documents' folder. |
|
672 |
The fallback for other OS's may return the user's home directory." |
|
673 |
||
674 |
"{ Pragma: +optSpace }" |
|
675 |
||
676 |
|home documentsFolder| |
|
677 |
||
678 |
(home := self getHomeDirectory) notNil ifTrue:[ |
|
22833 | 679 |
(documentsFolder := home asFilename / 'Documents') exists ifTrue:[ |
680 |
^ documentsFolder pathName |
|
681 |
]. |
|
22655 | 682 |
]. |
683 |
^ home |
|
684 |
||
685 |
" |
|
686 |
OperatingSystem getDocumentsDirectory |
|
687 |
" |
|
688 |
! |
|
689 |
||
16677 | 690 |
getDriveList |
691 |
"return a list of volumes in the system." |
|
692 |
||
693 |
^ ('/Volumes' asFilename directoryContents) |
|
694 |
, super getDriveList |
|
695 |
! |
|
696 |
||
16381 | 697 |
getTrashDirectory |
698 |
"get the name of a trash folder (if the OS supports it), |
|
699 |
or nil, if not. |
|
700 |
Must be redefined to return non nil in concrete operating systems" |
|
701 |
||
702 |
^ '~/.Trash' |
|
16677 | 703 |
! |
704 |
||
705 |
pathNameForDrive:driveName |
|
706 |
"given a drive name, return the pathname to open it as a directory. |
|
707 |
For Windows, this is the driveName itself. |
|
708 |
For OSX, '/Volumes' is prepended. |
|
709 |
Other OSs might prepent the pount point (i.e. /mnt/)" |
|
710 |
||
16905 | 711 |
driveName isNil ifTrue:[^ nil]. |
16677 | 712 |
driveName asFilename isAbsolute ifTrue:[^ driveName]. |
713 |
^ '/Volumes/',driveName |
|
17177 | 714 |
! |
715 |
||
716 |
supportsVolumes |
|
18279 | 717 |
"return true if the os support a list of drives/volumes |
17179 | 718 |
(here we can return a list of mounted drives in /Volumes)" |
17177 | 719 |
|
720 |
^ true |
|
14819 | 721 |
! ! |
722 |
||
21452 | 723 |
!OSXOperatingSystem class methodsFor:'quartz - screen'! |
724 |
||
725 |
getFrameBufferImage:displayNr |
|
726 |
"returns the framebuffer as an image object" |
|
727 |
||
21580 | 728 |
^ self getFrameBufferImage:displayNr in:nil |
729 |
||
730 |
" |
|
731 |
self getFrameBufferImage:0 |
|
732 |
" |
|
733 |
||
734 |
"Modified: / 25-02-2017 / 10:57:17 / cg" |
|
735 |
! |
|
21452 | 736 |
|
21580 | 737 |
getFrameBufferImage:displayNr in:aRectangleOrNil |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
738 |
"returns the frameBuffer (if rect-arg is nil) |
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
739 |
or part of the framebuffer (if non-nil) as an image object" |
21580 | 740 |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
741 |
|rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok| |
21580 | 742 |
|
743 |
aRectangleOrNil notNil ifTrue:[ |
|
24047 | 744 |
rx := aRectangleOrNil left. |
745 |
ry := aRectangleOrNil top. |
|
746 |
rwidth := aRectangleOrNil width. |
|
747 |
rheight := aRectangleOrNil height. |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
748 |
]. |
21452 | 749 |
%{ |
21596 | 750 |
#ifndef NO_COCOA |
21580 | 751 |
CGImageRef image_ref; |
752 |
CGDirectDisplayID displayID = CGMainDisplayID(); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
753 |
|
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
754 |
ok = false; |
21580 | 755 |
if (rx == nil) { |
24047 | 756 |
image_ref = CGDisplayCreateImage(displayID); |
21580 | 757 |
} else { |
24047 | 758 |
CGRect rect; |
759 |
rect.origin.x = (CGFloat)__intVal(rx); |
|
760 |
rect.origin.y = (CGFloat)__intVal(ry); |
|
761 |
rect.size.width = (CGFloat)__intVal(rwidth); |
|
762 |
rect.size.height = (CGFloat)__intVal(rheight); |
|
763 |
image_ref = CGDisplayCreateImageForRect(displayID, rect); |
|
21580 | 764 |
} |
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
765 |
|
21580 | 766 |
if (image_ref != NULL) { |
24047 | 767 |
CGDataProviderRef provider = CGImageGetDataProvider(image_ref); |
768 |
CFDataRef dataref = CGDataProviderCopyData(provider); |
|
769 |
size_t c_width = CGImageGetWidth(image_ref); |
|
770 |
size_t c_height = CGImageGetHeight(image_ref); |
|
771 |
size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref); |
|
772 |
size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8; |
|
773 |
unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref); |
|
21452 | 774 |
|
24047 | 775 |
if (c_bytesPerPixel == 4) { |
776 |
int row; |
|
777 |
pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * 3); |
|
778 |
unsigned char *srcRowPtr = c_pixels; |
|
779 |
unsigned char *dstRowPtr = __byteArrayVal(pixels); |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
780 |
|
24047 | 781 |
for (row=c_height; row>0; row--) { |
782 |
int col = c_width; |
|
783 |
unsigned int *pixSrcPtr = (int*)srcRowPtr; |
|
784 |
unsigned char *pixDstPtr = dstRowPtr; |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
785 |
|
24047 | 786 |
// convert abgr to rgb |
23954 | 787 |
#if (__POINTER_SIZE__ == 8) && defined(__LSBFIRST__) |
24047 | 788 |
for (; col > 2; col -= 2) { |
789 |
// pick 2 pixels |
|
790 |
unsigned INT pix12 = ((unsigned INT*)pixSrcPtr)[0]; |
|
791 |
pixSrcPtr += 2; |
|
792 |
// a2 r2 g2 b2 a1 r1 g1 b1 => r1..g1..b1..r2..g2..b2 |
|
793 |
pixDstPtr[0] = (pix12 >> 16) & 0xFF; |
|
794 |
pixDstPtr[1] = (pix12 >> 8) & 0xFF; |
|
795 |
pixDstPtr[2] = pix12 & 0xFF; |
|
796 |
pixDstPtr[3] = (pix12 >> 48) & 0xFF; |
|
797 |
pixDstPtr[4] = (pix12 >> 40) & 0xFF; |
|
798 |
pixDstPtr[5] = (pix12 >> 32) & 0xFF; |
|
799 |
pixDstPtr += 6; |
|
800 |
} |
|
23954 | 801 |
#endif |
21452 | 802 |
|
24047 | 803 |
for (; col>0;col--) { |
804 |
unsigned int pix = *pixSrcPtr++; |
|
23954 | 805 |
#if 0 |
24047 | 806 |
pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00); |
807 |
pixDstPtr[0] = (pix >> 0); |
|
808 |
pixDstPtr[1] = (pix >> 8); |
|
809 |
pixDstPtr[2] = (pix >> 16); |
|
23954 | 810 |
#else |
24047 | 811 |
pixDstPtr[0] = (pix >> 16) & 0xFF; |
812 |
pixDstPtr[1] = (pix >> 8) & 0xFF; |
|
813 |
pixDstPtr[2] = pix & 0xFF; |
|
23954 | 814 |
#endif |
24047 | 815 |
pixDstPtr += 3; |
816 |
} |
|
817 |
dstRowPtr += c_width * 3; |
|
818 |
srcRowPtr += c_bytesPerRow; |
|
819 |
} |
|
820 |
bytesPerPixel = __MKSMALLINT(3); |
|
821 |
bytesPerRow = __MKSMALLINT( c_width*3 ); |
|
822 |
ok = true; |
|
823 |
} else { |
|
824 |
// to be determined what we get... |
|
825 |
ok = false; |
|
826 |
} |
|
827 |
CFRelease(dataref); |
|
828 |
CGImageRelease(image_ref); |
|
21580 | 829 |
|
24047 | 830 |
rwidth = __MKUINT( c_width ); |
831 |
rheight = __MKUINT( c_height ); |
|
21580 | 832 |
} |
833 |
||
834 |
// the following is no longer supported by apple |
|
835 |
// CGDisplayBaseAddress is deprecated |
|
836 |
// |
|
837 |
// uint32_t rowBytes, rowUInt32s, *screen; |
|
838 |
// |
|
839 |
// CGDirectDisplayID targetDisplay = 0; |
|
840 |
// |
|
841 |
// screen = (uint32_t *)CGDisplayBaseAddress(targetDisplay); |
|
842 |
// rowBytes = CGDisplayBytesPerRow(targetDisplay); |
|
843 |
// rowUInt32s = rowBytes / 4; |
|
844 |
// rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) ); |
|
845 |
// rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) ); |
|
846 |
// |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
847 |
|
21596 | 848 |
#endif // NO_COCOA |
21452 | 849 |
|
850 |
%}. |
|
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
851 |
(ok not or:[rwidth isNil]) ifTrue:[ |
24047 | 852 |
^ self primitiveFailed |
21452 | 853 |
]. |
854 |
depth := bytesPerPixel * 8. |
|
855 |
||
21587
3ac571f08fbf
hooks to send finishLaunching to NSApp
Claus Gittinger <cg@exept.de>
parents:
21585
diff
changeset
|
856 |
"/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n' |
21580 | 857 |
"/ withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}. |
21452 | 858 |
|
21598 | 859 |
( #(24) includes:depth) ifFalse:[ |
24047 | 860 |
"/ check what we get here... |
861 |
^ self primitiveFailed:'unsupported depth' |
|
21452 | 862 |
]. |
863 |
||
21580 | 864 |
img := Image extent:(rwidth @ rheight) depth:depth bits:pixels. |
21598 | 865 |
depth == 24 ifTrue:[ |
24047 | 866 |
img bitsPerSample:#[8 8 8]. |
867 |
img samplesPerPixel:3. |
|
868 |
img photometric:#rgb. |
|
21598 | 869 |
] ifFalse:[ |
24047 | 870 |
depth == 16 ifTrue:[ |
871 |
"/ to be determined... |
|
872 |
img bitsPerSample:#[5 5 5]. |
|
873 |
img samplesPerPixel:3. |
|
874 |
img photometric:#rgb. |
|
875 |
]. |
|
21627 | 876 |
]. |
21452 | 877 |
^ img |
21580 | 878 |
|
879 |
" |
|
880 |
self getFrameBufferImage:0 in:nil |
|
881 |
self getFrameBufferImage:0 in:(100@100 corner:301@303) |
|
21598 | 882 |
|
883 |
Delay waitFor:3 seconds. self getFrameBufferImage:0 in:nil |
|
21580 | 884 |
" |
885 |
||
886 |
"Created: / 25-02-2017 / 09:49:07 / cg" |
|
21598 | 887 |
"Modified (comment): / 28-02-2017 / 15:22:17 / cg" |
24028 | 888 |
"Modified: / 01-04-2019 / 00:39:22 / Claus Gittinger" |
21625 | 889 |
! |
890 |
||
24047 | 891 |
getMousePosition |
892 |
|xLoc yLoc| |
|
893 |
||
894 |
%{ |
|
895 |
#ifndef NO_COREGRAPHICS |
|
896 |
CGEventRef event = CGEventCreate(NULL); |
|
897 |
CGPoint loc = CGEventGetLocation(event); |
|
898 |
CFRelease(event); |
|
899 |
||
900 |
xLoc = __MKFLOAT(loc.x); |
|
901 |
yLoc = __MKFLOAT(loc.y); |
|
902 |
#endif // NO_COREGRAPHICS |
|
903 |
%}. |
|
904 |
^ xLoc @ yLoc |
|
905 |
! |
|
906 |
||
21627 | 907 |
getScreenBounds:displayNr |
21625 | 908 |
"returns the bounds of the screen. |
909 |
This is needed, because the dimension of the XQuartz screen does not include the dock." |
|
910 |
||
911 |
|rx ry rwidth rheight| |
|
912 |
||
913 |
%{ |
|
914 |
#ifndef NO_COCOA |
|
915 |
CGDirectDisplayID targetDisplay = 0; |
|
916 |
||
917 |
rx = ry = __MKSMALLINT(0); |
|
918 |
rwidth = __MKUINT( CGDisplayPixelsWide(targetDisplay) ); |
|
919 |
rheight = __MKUINT( CGDisplayPixelsHigh(targetDisplay) ); |
|
920 |
#endif // NO_COCOA |
|
921 |
%}. |
|
922 |
(rwidth isNil) ifTrue:[ |
|
21627 | 923 |
^ self primitiveFailed |
21625 | 924 |
]. |
925 |
^ rx@ry extent:(rwidth@rheight) |
|
926 |
||
927 |
" |
|
21627 | 928 |
self getScreenBounds:0 |
21625 | 929 |
" |
930 |
||
931 |
"Created: / 05-03-2017 / 11:10:08 / cg" |
|
21452 | 932 |
! ! |
933 |
||
22962 | 934 |
!OSXOperatingSystem class methodsFor:'sound & voice'! |
935 |
||
23314 | 936 |
canPlaySound |
937 |
^ true |
|
938 |
||
939 |
"Created: / 29-08-2018 / 09:35:52 / Claus Gittinger" |
|
940 |
! |
|
941 |
||
942 |
canSpeak |
|
943 |
^ true |
|
944 |
||
945 |
"Created: / 29-08-2018 / 09:45:16 / Claus Gittinger" |
|
946 |
! |
|
947 |
||
22962 | 948 |
playSound:soundFile |
949 |
"use 'say ...'" |
|
950 |
||
951 |
^ self executeCommand:('afplay "%1"' bindWith:soundFile asFilename pathName) |
|
952 |
||
953 |
" |
|
954 |
self speak:'hello world' |
|
955 |
" |
|
956 |
! |
|
957 |
||
22970 | 958 |
voiceCommandSpec |
959 |
^ #( |
|
23114 | 960 |
"/ triples are: |
961 |
"/ -command |
|
962 |
"/ -commandline for default voice |
|
963 |
"/ -commandline for specific voice |
|
964 |
( |
|
965 |
'say' |
|
966 |
'say "%2"' |
|
967 |
'say -v "%1" "%2"' |
|
968 |
) |
|
969 |
) |
|
22966 | 970 |
! |
971 |
||
972 |
voiceInfo |
|
973 |
"return a list of available voices plus info: |
|
974 |
for each available voice, a triple is returned, containing: |
|
23114 | 975 |
voiceName language_territory comment/description |
22966 | 976 |
" |
977 |
||
978 |
^ (PipeStream outputFromCommand:'say -v ?') |
|
23114 | 979 |
asCollectionOfLines |
980 |
collect:[:l | |
|
981 |
|s name lang comment| |
|
982 |
||
983 |
s := l readStream. |
|
984 |
"/ skip forward for two separators |
|
985 |
[ |
|
986 |
[s next isLetterOrDigit] whileTrue:[]. |
|
987 |
s peek isLetterOrDigit |
|
988 |
] whileTrue. |
|
989 |
name := l copyFrom:1 to:s position - 1. |
|
990 |
s skipSeparators. |
|
991 |
lang := s upToSeparator. |
|
992 |
s skipSeparators. |
|
993 |
s next == $# ifTrue:[ |
|
994 |
s skipSeparators. |
|
995 |
comment := s upToEnd utf8Decoded. |
|
996 |
]. |
|
997 |
{ name . lang . comment } |
|
998 |
] |
|
22962 | 999 |
|
1000 |
" |
|
22966 | 1001 |
OperatingSystem voiceInfo |
22962 | 1002 |
" |
23314 | 1003 |
! |
1004 |
||
1005 |
voiceMapping |
|
1006 |
"return a mapping from common (OS-independent) voice names |
|
1007 |
to OS-specific names or IDs. |
|
1008 |
The speak:voiceName interface will recognize both. |
|
1009 |
For portable programs, always use the OS-independent name and |
|
1010 |
let every OS xlate to its internal name." |
|
1011 |
||
1012 |
|info map v| |
|
1013 |
||
1014 |
VoiceMapping notNil ifTrue:[^ VoiceMapping]. |
|
1015 |
||
1016 |
info := self voiceInfo. |
|
1017 |
map := OrderedCollection new. |
|
1018 |
v := info detect:[:entry | #('Tom' 'Alex' 'Fred' 'Bruce' 'Ralph' 'Daniel') includes:entry first] ifNone:nil. |
|
1019 |
map add:( 'male' -> (v ? #(nil)) first ). |
|
1020 |
v := info detect:[:entry | #('Samantha' 'Fiona' 'Karen' 'Moira') includes:entry first] ifNone:nil. |
|
1021 |
map add:( 'female' -> (v ? #(nil)) first ). |
|
1022 |
v := info detect:[:entry | #('Zarvox') includes:entry first] ifNone:nil. |
|
1023 |
map add:( 'computer' -> (v ? #(nil)) first ). |
|
1024 |
map add:( 'default' -> nil ). |
|
1025 |
VoiceMapping := map. |
|
1026 |
^ VoiceMapping |
|
24047 | 1027 |
|
23314 | 1028 |
"on OSX, this could be: |
24047 | 1029 |
^ { |
1030 |
'male' -> 'Alex' . |
|
1031 |
'female' -> 'Fiona' . |
|
1032 |
'computer' -> 'Zarvox' . |
|
1033 |
'default' -> 'Fiona' |
|
1034 |
} |
|
23314 | 1035 |
" |
1036 |
||
1037 |
" |
|
1038 |
OperatingSystem voiceMapping |
|
1039 |
" |
|
1040 |
||
1041 |
"Created: / 29-08-2018 / 09:55:00 / Claus Gittinger" |
|
22962 | 1042 |
! ! |
1043 |
||
22833 | 1044 |
!OSXOperatingSystem class methodsFor:'time and date'! |
1045 |
||
1046 |
getOSTimeWithNanos |
|
1047 |
"This returns the OS time as a 2-element vector with milliseconds (as before) |
|
1048 |
plus nanoseconds. |
|
1049 |
The base of the returned value is not consistent across |
|
1050 |
different OS's - some return the number of nanoseconds since jan, 1st 1970; |
|
1051 |
others since 1900. The Time classes are prepared for this, and |
|
1052 |
convert as appropriate (by using my fromOSTime: conversion methods). |
|
1053 |
||
1054 |
Don't use this method in application code since it is an internal (private) |
|
1055 |
interface. For compatibility use instances of Time, Date or Timestamp to work with." |
|
1056 |
||
1057 |
|seconds millis nanos| |
|
1058 |
%{ |
|
24047 | 1059 |
// all of the experiments below only provide 1us resolution on my machine |
1060 |
// Not sure if that has to do with the OSX version (high sierra) |
|
22833 | 1061 |
// therefore, it is disabled, and we fall back to the inherited method, |
1062 |
// which returns microsecond resolution nanos anyway. |
|
1063 |
#if 0 |
|
1064 |
unsigned long _secs, _millis, _nanos; |
|
1065 |
||
1066 |
# if defined(CLOCK_REALTIME) && !defined(NO_CLOCK_GETTIME) |
|
1067 |
struct timespec ts; |
|
1068 |
static int has_clock_gettime = 1; |
|
1069 |
unsigned long _secs, _millis, _nanos; |
|
1070 |
||
1071 |
if (has_clock_gettime) { |
|
1072 |
if (clock_gettime(CLOCK_REALTIME, &ts) != -1) { |
|
1073 |
_secs = ts.tv_sec; |
|
1074 |
_millis = ts.tv_nsec / 1000000; |
|
1075 |
_nanos = ts.tv_nsec % 1000000; |
|
1076 |
||
1077 |
seconds = __MKUINT(_secs); |
|
1078 |
millis = __MKUINT(_millis); |
|
1079 |
nanos = __MKUINT(_nanos); |
|
1080 |
} else { |
|
1081 |
/* |
|
1082 |
* clock_gettime is not implemented in the kernel |
|
1083 |
* fall through to alternative implementation |
|
1084 |
*/ |
|
1085 |
has_clock_gettime = 0; |
|
1086 |
} |
|
1087 |
} |
|
1088 |
# else |
|
1089 |
# if 0 |
|
1090 |
// althoug documented, my osx doesn't have it... |
|
1091 |
uint32_t secpart; |
|
1092 |
uint32_t nsecpart; |
|
1093 |
||
1094 |
clock_get_calendar_nanotime(&secpart, &nsecpart); |
|
1095 |
||
1096 |
_secs = secpart; |
|
1097 |
_millis = nsecpart / 1000000; |
|
1098 |
_nanos = nsecpart % 1000000; |
|
1099 |
# else |
|
1100 |
// OS X does not have clock_gettime, use host_get_clock_service |
|
1101 |
clock_serv_t cclock; |
|
1102 |
mach_timespec_t mts; |
|
1103 |
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); |
|
1104 |
clock_get_time(cclock, &mts); |
|
1105 |
mach_port_deallocate(mach_task_self(), cclock); |
|
1106 |
||
1107 |
_secs = mts.tv_sec; |
|
1108 |
_millis = mts.tv_nsec / 1000000; |
|
1109 |
_nanos = mts.tv_nsec % 1000000; |
|
1110 |
# endif |
|
1111 |
||
1112 |
seconds = __MKUINT(_secs); |
|
1113 |
millis = __MKUINT(_millis); |
|
1114 |
nanos = __MKUINT(_nanos); |
|
1115 |
# endif |
|
1116 |
#endif |
|
1117 |
%}. |
|
1118 |
seconds notNil ifTrue:[ |
|
1119 |
^ { ((seconds * 1000) + millis) . nanos } |
|
1120 |
]. |
|
1121 |
||
1122 |
^ super getOSTimeWithNanos. |
|
1123 |
! ! |
|
1124 |
||
14819 | 1125 |
!OSXOperatingSystem class methodsFor:'documentation'! |
1126 |
||
1127 |
version |
|
19817 | 1128 |
^ '$Header$' |
14819 | 1129 |
! |
1130 |
||
1131 |
version_CVS |
|
19817 | 1132 |
^ '$Header$' |
14819 | 1133 |
! ! |