subreader: fix unsafe sscanf calls with "%["
[mplayer.git] / libvo / osx_common.c
blob2aa0a28126d051899de5e2a7c22fc4144170da10
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #include "config.h"
20 // only to get keycode definitions from HIToolbox/Events.h
21 #include <Carbon/Carbon.h>
22 #include <CoreServices/CoreServices.h>
23 #include "config.h"
24 #include "osx_common.h"
25 #include "video_out.h"
26 #include "input/keycodes.h"
27 #include "input/input.h"
28 #include "mp_msg.h"
31 * Define keycodes only found in OSX >= 10.5 for older versions
33 #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1040
34 #define kVK_ANSI_Keypad0 0x52
35 #define kVK_ANSI_Keypad1 0x53
36 #define kVK_ANSI_Keypad2 0x54
37 #define kVK_ANSI_Keypad3 0x55
38 #define kVK_ANSI_Keypad4 0x56
39 #define kVK_ANSI_Keypad5 0x57
40 #define kVK_ANSI_Keypad6 0x58
41 #define kVK_ANSI_Keypad7 0x59
42 #define kVK_ANSI_Keypad8 0x5b
43 #define kVK_ANSI_Keypad9 0x5c
44 #define kVK_ANSI_KeypadDecimal 0x41
45 #define kVK_ANSI_KeypadDivide 0x4b
46 #define kVK_ANSI_KeypadEnter 0x4c
47 #define kVK_ANSI_KeypadMinus 0x4e
48 #define kVK_ANSI_KeypadMultiply 0x43
49 #define kVK_ANSI_KeypadPlus 0x45
50 #define kVK_Control 0x3b
51 #define kVK_Delete 0x33
52 #define kVK_DownArrow 0x7d
53 #define kVK_End 0x77
54 #define kVK_Escape 0x35
55 #define kVK_F1 0x7a
56 #define kVK_F10 0x6d
57 #define kVK_F11 0x67
58 #define kVK_F12 0x6f
59 #define kVK_F2 0x78
60 #define kVK_F3 0x63
61 #define kVK_F4 0x76
62 #define kVK_F5 0x60
63 #define kVK_F6 0x61
64 #define kVK_F7 0x62
65 #define kVK_F8 0x64
66 #define kVK_F9 0x65
67 #define kVK_ForwardDelete 0x75
68 #define kVK_Help 0x72
69 #define kVK_Home 0x73
70 #define kVK_LeftArrow 0x7b
71 #define kVK_Option 0x3a
72 #define kVK_PageDown 0x79
73 #define kVK_PageUp 0x74
74 #define kVK_Return 0x24
75 #define kVK_RightArrow 0x7c
76 #define kVK_Shift 0x38
77 #define kVK_Tab 0x30
78 #define kVK_UpArrow 0x7e
79 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED <= 1040 */
81 static const struct mp_keymap keymap[] = {
82 // special keys
83 {0x34, KEY_ENTER}, // Enter key on some iBooks?
84 {kVK_Return, KEY_ENTER},
85 {kVK_Escape, KEY_ESC},
86 {kVK_Delete, KEY_BACKSPACE}, {kVK_Option, KEY_BACKSPACE}, {kVK_Control, KEY_BACKSPACE}, {kVK_Shift, KEY_BACKSPACE},
87 {kVK_Tab, KEY_TAB},
89 // cursor keys
90 {kVK_UpArrow, KEY_UP}, {kVK_DownArrow, KEY_DOWN}, {kVK_LeftArrow, KEY_LEFT}, {kVK_RightArrow, KEY_RIGHT},
92 // navigation block
93 {kVK_Help, KEY_INSERT}, {kVK_ForwardDelete, KEY_DELETE}, {kVK_Home, KEY_HOME},
94 {kVK_End, KEY_END}, {kVK_PageUp, KEY_PAGE_UP}, {kVK_PageDown, KEY_PAGE_DOWN},
96 // F-keys
97 {kVK_F1, KEY_F + 1}, {kVK_F2, KEY_F + 2}, {kVK_F3, KEY_F + 3}, {kVK_F4, KEY_F + 4},
98 {kVK_F5, KEY_F + 5}, {kVK_F6, KEY_F + 6}, {kVK_F7, KEY_F + 7}, {kVK_F8, KEY_F + 8},
99 {kVK_F9, KEY_F + 9}, {kVK_F10, KEY_F + 10}, {kVK_F11, KEY_F + 11}, {kVK_F12, KEY_F + 12},
101 // numpad
102 {kVK_ANSI_KeypadPlus, '+'}, {kVK_ANSI_KeypadMinus, '-'}, {kVK_ANSI_KeypadMultiply, '*'},
103 {kVK_ANSI_KeypadDivide, '/'}, {kVK_ANSI_KeypadEnter, KEY_KPENTER}, {kVK_ANSI_KeypadDecimal, KEY_KPDEC},
104 {kVK_ANSI_Keypad0, KEY_KP0}, {kVK_ANSI_Keypad1, KEY_KP1}, {kVK_ANSI_Keypad2, KEY_KP2}, {kVK_ANSI_Keypad3, KEY_KP3},
105 {kVK_ANSI_Keypad4, KEY_KP4}, {kVK_ANSI_Keypad5, KEY_KP5}, {kVK_ANSI_Keypad6, KEY_KP6}, {kVK_ANSI_Keypad7, KEY_KP7},
106 {kVK_ANSI_Keypad8, KEY_KP8}, {kVK_ANSI_Keypad9, KEY_KP9},
108 {0, 0}
111 int convert_key(unsigned key, unsigned charcode)
113 int mpkey = lookup_keymap_table(keymap, key);
114 if (mpkey)
115 return mpkey;
116 return charcode;
120 * Checks at runtime that OSX version is the same or newer than the one
121 * provided as input.
123 int is_osx_version_at_least(int majorv, int minorv, int bugfixv)
125 OSErr err;
126 SInt32 major, minor, bugfix;
127 if ((err = Gestalt(gestaltSystemVersionMajor, &major)) != noErr)
128 goto fail;
129 if ((err = Gestalt(gestaltSystemVersionMinor, &minor)) != noErr)
130 goto fail;
131 if ((err = Gestalt(gestaltSystemVersionBugFix, &bugfix)) != noErr)
132 goto fail;
134 if(major > majorv ||
135 (major == majorv && (minor > minorv ||
136 (minor == minorv && bugfix >= bugfixv))))
137 return 1;
138 else
139 return 0;
140 fail:
141 // There's no reason the Gestalt system call should fail on OSX.
142 mp_msg(MSGT_VO, MSGL_FATAL, "[osx] Failed to get system version number. "
143 "Please contact the developers. Error code: %ld\n", (long)err);
144 return 0;