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.
20 // only to get keycode definitions from HIToolbox/Events.h
21 #include <Carbon/Carbon.h>
23 #include "osx_common.h"
24 #include "old_vo_defines.h"
25 #include "video_out.h"
26 #include "osdep/keycodes.h"
27 #include "input/input.h"
30 * Define keycodes only found in OSX >= 10.5 for older versions
32 #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1040
33 #define kVK_ANSI_Keypad0 0x52
34 #define kVK_ANSI_Keypad1 0x53
35 #define kVK_ANSI_Keypad2 0x54
36 #define kVK_ANSI_Keypad3 0x55
37 #define kVK_ANSI_Keypad4 0x56
38 #define kVK_ANSI_Keypad5 0x57
39 #define kVK_ANSI_Keypad6 0x58
40 #define kVK_ANSI_Keypad7 0x59
41 #define kVK_ANSI_Keypad8 0x5b
42 #define kVK_ANSI_Keypad9 0x5c
43 #define kVK_ANSI_KeypadDecimal 0x41
44 #define kVK_ANSI_KeypadDivide 0x4b
45 #define kVK_ANSI_KeypadEnter 0x4c
46 #define kVK_ANSI_KeypadMinus 0x4e
47 #define kVK_ANSI_KeypadMultiply 0x43
48 #define kVK_ANSI_KeypadPlus 0x45
49 #define kVK_Control 0x3b
50 #define kVK_Delete 0x33
51 #define kVK_DownArrow 0x7d
53 #define kVK_Escape 0x35
66 #define kVK_ForwardDelete 0x75
69 #define kVK_LeftArrow 0x7b
70 #define kVK_Option 0x3a
71 #define kVK_PageDown 0x79
72 #define kVK_PageUp 0x74
73 #define kVK_Return 0x24
74 #define kVK_RightArrow 0x7c
75 #define kVK_Shift 0x38
77 #define kVK_UpArrow 0x7e
78 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED <= 1040 */
80 static const struct mp_keymap keymap
[] = {
82 {0x34, KEY_ENTER
}, // Enter key on some iBooks?
83 {kVK_Return
, KEY_ENTER
},
84 {kVK_Escape
, KEY_ESC
},
85 {kVK_Delete
, KEY_BACKSPACE
}, {kVK_Option
, KEY_BACKSPACE
}, {kVK_Control
, KEY_BACKSPACE
}, {kVK_Shift
, KEY_BACKSPACE
},
89 {kVK_UpArrow
, KEY_UP
}, {kVK_DownArrow
, KEY_DOWN
}, {kVK_LeftArrow
, KEY_LEFT
}, {kVK_RightArrow
, KEY_RIGHT
},
92 {kVK_Help
, KEY_INSERT
}, {kVK_ForwardDelete
, KEY_DELETE
}, {kVK_Home
, KEY_HOME
},
93 {kVK_End
, KEY_END
}, {kVK_PageUp
, KEY_PAGE_UP
}, {kVK_PageDown
, KEY_PAGE_DOWN
},
96 {kVK_F1
, KEY_F
+ 1}, {kVK_F2
, KEY_F
+ 2}, {kVK_F3
, KEY_F
+ 3}, {kVK_F4
, KEY_F
+ 4},
97 {kVK_F5
, KEY_F
+ 5}, {kVK_F6
, KEY_F
+ 6}, {kVK_F7
, KEY_F
+ 7}, {kVK_F8
, KEY_F
+ 8},
98 {kVK_F9
, KEY_F
+ 9}, {kVK_F10
, KEY_F
+ 10}, {kVK_F11
, KEY_F
+ 11}, {kVK_F12
, KEY_F
+ 12},
101 {kVK_ANSI_KeypadPlus
, '+'}, {kVK_ANSI_KeypadMinus
, '-'}, {kVK_ANSI_KeypadMultiply
, '*'},
102 {kVK_ANSI_KeypadDivide
, '/'}, {kVK_ANSI_KeypadEnter
, KEY_KPENTER
}, {kVK_ANSI_KeypadDecimal
, KEY_KPDEC
},
103 {kVK_ANSI_Keypad0
, KEY_KP0
}, {kVK_ANSI_Keypad1
, KEY_KP1
}, {kVK_ANSI_Keypad2
, KEY_KP2
}, {kVK_ANSI_Keypad3
, KEY_KP3
},
104 {kVK_ANSI_Keypad4
, KEY_KP4
}, {kVK_ANSI_Keypad5
, KEY_KP5
}, {kVK_ANSI_Keypad6
, KEY_KP6
}, {kVK_ANSI_Keypad7
, KEY_KP7
},
105 {kVK_ANSI_Keypad8
, KEY_KP8
}, {kVK_ANSI_Keypad9
, KEY_KP9
},
110 int convert_key(unsigned key
, unsigned charcode
)
112 int mpkey
= lookup_keymap_table(keymap
, key
);
118 static int our_aspect_change
;
119 static float old_movie_aspect
;
122 * Sends MPlayer a command to change aspect to the requested value.
123 * @param new_aspect desired new aspect, < 0 means restore original.
125 void change_movie_aspect(float new_aspect
)
129 new_aspect
= old_movie_aspect
;
130 our_aspect_change
= 1;
131 snprintf(cmd_str
, sizeof(cmd_str
), "switch_ratio %f", new_aspect
);
132 mp_input_queue_cmd(global_vo
->input_ctx
, mp_input_parse_cmd(cmd_str
));
136 * Call in config to save the original movie aspect.
137 * This will ignore config calls caused by change_movie_aspect.
139 void config_movie_aspect(float config_aspect
)
141 if (!our_aspect_change
)
142 old_movie_aspect
= config_aspect
;
143 our_aspect_change
= 0;
146 /** This chunk of code is heavily based off SDL_macosx.m from SDL.
147 * The CPSEnableForegroundOperation that was here before is private
148 * and should not be used.
149 * Replaced by a call to the 10.3+ TransformProcessType.
151 void osx_foreground_hack(void)
153 #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL)
154 ProcessSerialNumber myProc
, frProc
;
157 if (GetFrontProcess(&frProc
) == noErr
&&
158 GetCurrentProcess(&myProc
) == noErr
) {
159 if (SameProcess(&frProc
, &myProc
, &sameProc
) == noErr
&& !sameProc
) {
160 TransformProcessType(&myProc
,
161 kProcessTransformToForegroundApplication
);
163 SetFrontProcess(&myProc
);