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