1 /* $Id: MacOSX.c 680 2012-02-09 23:31:11Z felfert $
2  *
3  * Copyright (C) 2006 The OpenNX Team
4  * Author: Fritz Elfert
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Library General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc.,
19  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  */
21 
22 /*
23  * Defines canonicalized platform names (e.g. __LINUX__)
24  */
25 #include <wx/platform.h>
26 
27 #ifdef __WXMAC__
28 /*
29  * Allow app to be started from the commandline
30  */
31 #include <ApplicationServices/ApplicationServices.h>
32 static void __attribute__ ((constructor))
makeForegroundApp()33     makeForegroundApp()
34 {
35     ProcessSerialNumber PSN;
36     if (noErr == GetCurrentProcess(&PSN)) {
37 # ifdef APP_WATCHREADER
38         TransformProcessType(&PSN, 0);
39 # else
40         TransformProcessType(&PSN, kProcessTransformToForegroundApplication);
41 # endif
42     }
43 }
44 
45 /*
46  * 10.4 compatibility. Hence the use of deprecated keyboard services.
47  */
48 #include <Carbon/Carbon.h>
getMacKeyboard()49 const char *getMacKeyboard() {
50     static char ret[256];
51 	KeyboardLayoutRef klr;
52     memset(ret, 0, sizeof(ret));
53 	if (noErr == KLGetCurrentKeyboardLayout(&klr)) {
54 		unsigned int pt = kKLLanguageCode;
55 		const void *oValue;
56 		if (noErr == KLGetKeyboardLayoutProperty(klr, pt, &oValue)) {
57 			char buf[128];
58 			if (CFStringGetCString((CFStringRef)oValue, buf, sizeof(buf), kCFStringEncodingISOLatin1)) {
59                 const char *ktype = "pc105";
60                 snprintf(ret, sizeof(ret), "%s/%s", ktype, buf);
61 			}
62 		}
63 	}
64     return ret;
65 }
66 
67 #include <IOKit/IOKitLib.h>
68 #ifndef kIOPlatformUUIDKey
69 # define kIOPlatformUUIDKey	"IOPlatformUUID"
70 #endif
getMacMachineID()71 const char *getMacMachineID()
72 {
73     static char ret[256];
74     io_registry_entry_t ioRegistryRoot =
75         IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
76     CFStringRef uuidCf =
77         (CFStringRef)IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
78     IOObjectRelease(ioRegistryRoot);
79     CFStringGetCString(uuidCf, ret, sizeof(ret), kCFStringEncodingMacRoman);
80     CFRelease(uuidCf);
81     return ret;
82 }
83 
84 #endif
85