Skip to content

Commit fb93010

Browse files
committed
add --keyboard-layout-independent option, implemented for cocoa
1 parent 6052178 commit fb93010

12 files changed

+68
-8
lines changed

mpvcore/options.c

+1
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ const m_option_t mp_opts[] = {
604604
// set fullscreen switch method (workaround for buggy WMs)
605605
OPT_INTRANGE("fsmode-dontuse", vo.fsmode, 0, 31, 4096),
606606
OPT_FLAG("native-keyrepeat", vo.native_keyrepeat, 0),
607+
OPT_FLAG("keyboard-layout-independent", vo.keyboard_layout_independent, 0),
607608
OPT_FLOATRANGE("panscan", vo.panscan, 0, 0.0, 1.0),
608609
OPT_FLOATRANGE("video-zoom", vo.zoom, 0, -20.0, 20.0),
609610
OPT_FLOATRANGE("video-pan-x", vo.pan_x, 0, -3.0, 3.0),

mpvcore/options.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef struct mp_vo_opts {
1717
char *winname;
1818
char** fstype_list;
1919
int native_keyrepeat;
20+
int keyboard_layout_independent;
2021

2122
float panscan;
2223
float zoom;

mpvcore/player/main.c

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx,
126126

127127
#if HAVE_COCOA
128128
cocoa_set_input_context(NULL);
129+
cocoa_set_options(NULL);
129130
#endif
130131

131132
command_uninit(mpctx);
@@ -323,6 +324,10 @@ static int mpv_main(int argc, char *argv[])
323324
mpctx->global = talloc_zero(mpctx, struct mpv_global);
324325
mpctx->global->opts = opts;
325326

327+
#if HAVE_COCOA
328+
cocoa_set_options(opts);
329+
#endif
330+
326331
// Nothing must call mp_msg() before this
327332
mp_msg_init(mpctx->global);
328333
mpctx->log = mp_log_new(mpctx, mpctx->global->log, "!cplayer");

osdep/macosx_application.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define MPV_MACOSX_APPLICATION
2121

2222
struct input_ctx;
23+
struct MPOpts;
2324

2425
typedef int (*mpv_main_fn)(int, char**);
2526

@@ -47,6 +48,7 @@ void cocoa_stop_runloop(void);
4748
void cocoa_post_fake_event(void);
4849

4950
void cocoa_set_input_context(struct input_ctx *input_context);
51+
void cocoa_set_options(struct MPOpts *opts);
5052

5153
void macosx_finder_args_preinit(int *argc, char ***argv);
5254

osdep/macosx_application.m

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ @implementation Application
7575
@synthesize willStopOnOpenEvent = _will_stop_on_open_event;
7676

7777
@synthesize inputContext = _input_context;
78+
@synthesize options = _options;
7879
@synthesize eventsResponder = _events_responder;
7980
@synthesize menuItems = _menu_items;
8081
@synthesize input_ready = _input_ready;
@@ -396,6 +397,11 @@ void cocoa_set_input_context(struct input_ctx *input_context)
396397
mpv_shared_app().inputContext = input_context;
397398
}
398399

400+
void cocoa_set_options(struct MPOpts *opts)
401+
{
402+
mpv_shared_app().options = opts;
403+
}
404+
399405
void cocoa_post_fake_event(void)
400406
{
401407
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined

osdep/macosx_application_objc.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- (void)stopPlayback;
3939

4040
@property(nonatomic, assign) struct input_ctx *inputContext;
41+
@property(nonatomic, assign) struct MPOpts *options;
4142
@property(nonatomic, retain) EventsResponder *eventsResponder;
4243
@property(nonatomic, retain) NSMutableDictionary *menuItems;
4344
@property(nonatomic, retain) NSArray *files;

osdep/macosx_events.m

+47-3
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,53 @@ static bool RightAltPressed(int mask)
8080
{kVK_ANSI_Keypad6, MP_KEY_KP6}, {kVK_ANSI_Keypad7, MP_KEY_KP7},
8181
{kVK_ANSI_Keypad8, MP_KEY_KP8}, {kVK_ANSI_Keypad9, MP_KEY_KP9},
8282

83-
{0, 0}
83+
{-1, 0}
8484
};
8585

86-
static int convert_key(unsigned key, unsigned charcode)
86+
static const struct mp_keymap keymap_english_us[] = {
87+
{kVK_ANSI_Grave, '`'}, {kVK_ANSI_1, '1'}, {kVK_ANSI_2, '2'}, {kVK_ANSI_3, '3'},
88+
{kVK_ANSI_4, '4'}, {kVK_ANSI_5, '5'}, {kVK_ANSI_6, '6'}, {kVK_ANSI_7, '7'},
89+
{kVK_ANSI_8, '8'}, {kVK_ANSI_9, '9'}, {kVK_ANSI_0, '0'}, {kVK_ANSI_Minus, '-'},
90+
{kVK_ANSI_Equal, '='}, {kVK_ANSI_Q, 'q'}, {kVK_ANSI_W, 'w'}, {kVK_ANSI_E, 'e'},
91+
{kVK_ANSI_R, 'r'}, {kVK_ANSI_T, 't'}, {kVK_ANSI_Y, 'y'}, {kVK_ANSI_U, 'u'},
92+
{kVK_ANSI_I, 'i'}, {kVK_ANSI_O, 'o'}, {kVK_ANSI_P, 'p'}, {kVK_ANSI_LeftBracket, '['},
93+
{kVK_ANSI_RightBracket, ']'}, {kVK_ANSI_Backslash, '\\'}, {kVK_ANSI_A, 'a'},
94+
{kVK_ANSI_S, 's'}, {kVK_ANSI_D, 'd'}, {kVK_ANSI_F, 'f'}, {kVK_ANSI_G, 'g'},
95+
{kVK_ANSI_H, 'h'}, {kVK_ANSI_J, 'j'}, {kVK_ANSI_K, 'k'}, {kVK_ANSI_L, 'l'},
96+
{kVK_ANSI_Semicolon, ';'}, {kVK_ANSI_Quote, '\''}, {kVK_ANSI_Z, 'z'}, {kVK_ANSI_X, 'x'},
97+
{kVK_ANSI_C, 'c'}, {kVK_ANSI_V, 'v'}, {kVK_ANSI_B, 'b'}, {kVK_ANSI_N, 'n'},
98+
{kVK_ANSI_M, 'm'}, {kVK_ANSI_Comma, ','}, {kVK_ANSI_Period, '.'}, {kVK_ANSI_Slash, '/'},
99+
100+
{-1, 0}
101+
};
102+
103+
static const struct mp_keymap keymap_english_us_shift[] = {
104+
{kVK_ANSI_Grave, '~'}, {kVK_ANSI_1, '!'}, {kVK_ANSI_2, '@'}, {kVK_ANSI_3, '#'},
105+
{kVK_ANSI_4, '$'}, {kVK_ANSI_5, '%'}, {kVK_ANSI_6, '^'}, {kVK_ANSI_7, '&'},
106+
{kVK_ANSI_8, '*'}, {kVK_ANSI_9, '('}, {kVK_ANSI_0, ')'}, {kVK_ANSI_Minus, '_'},
107+
{kVK_ANSI_Equal, '+'}, {kVK_ANSI_Q, 'Q'}, {kVK_ANSI_W, 'W'}, {kVK_ANSI_E, 'E'},
108+
{kVK_ANSI_R, 'R'}, {kVK_ANSI_T, 'T'}, {kVK_ANSI_Y, 'Y'}, {kVK_ANSI_U, 'U'},
109+
{kVK_ANSI_I, 'I'}, {kVK_ANSI_O, 'O'}, {kVK_ANSI_P, 'P'}, {kVK_ANSI_LeftBracket, '{'},
110+
{kVK_ANSI_RightBracket, '}'}, {kVK_ANSI_Backslash, '|'}, {kVK_ANSI_A, 'A'},
111+
{kVK_ANSI_S, 'S'}, {kVK_ANSI_D, 'D'}, {kVK_ANSI_F, 'F'}, {kVK_ANSI_G, 'G'},
112+
{kVK_ANSI_H, 'H'}, {kVK_ANSI_J, 'J'}, {kVK_ANSI_K, 'K'}, {kVK_ANSI_L, 'L'},
113+
{kVK_ANSI_Semicolon, ':'}, {kVK_ANSI_Quote, '\"'}, {kVK_ANSI_Z, 'Z'}, {kVK_ANSI_X, 'X'},
114+
{kVK_ANSI_C, 'C'}, {kVK_ANSI_V, 'V'}, {kVK_ANSI_B, 'B'}, {kVK_ANSI_N, 'N'},
115+
{kVK_ANSI_M, 'M'}, {kVK_ANSI_Comma, '<'}, {kVK_ANSI_Period, '>'}, {kVK_ANSI_Slash, '?'},
116+
117+
{-1, 0}
118+
};
119+
120+
static int convert_key(unsigned key, unsigned charcode, bool layout_independent, bool shift)
87121
{
88122
int mpkey = lookup_keymap_table(keymap, key);
89123
if (mpkey)
90124
return mpkey;
125+
if (layout_independent) {
126+
mpkey = lookup_keymap_table(shift ? keymap_english_us_shift : keymap_english_us, key);
127+
if (mpkey)
128+
return mpkey;
129+
}
91130
return charcode;
92131
}
93132

@@ -338,7 +377,12 @@ - (NSEvent*)handleKey:(NSEvent *)event
338377
else
339378
chars = [event charactersIgnoringModifiers];
340379

341-
int key = convert_key([event keyCode], *[chars UTF8String]);
380+
bool layout_independent = false;
381+
if (mpv_shared_app().options)
382+
layout_independent = mpv_shared_app().options->vo.keyboard_layout_independent;
383+
384+
int key = convert_key([event keyCode], *[chars UTF8String], layout_independent,
385+
[event modifierFlags] & NSShiftKeyMask);
342386

343387
if (key > -1) {
344388
if ([self isAppKeyEquivalent:chars withEvent:event])

video/out/vo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ int vo_reconfig(struct vo *vo, struct mp_image_params *params, int flags)
453453
* if not found.
454454
*/
455455
int lookup_keymap_table(const struct mp_keymap *map, int key) {
456-
while (map->from && map->from != key) map++;
456+
while (map->from != -1 && map->from != key) map++;
457457
return map->to;
458458
}
459459

video/out/vo_caca.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static const struct mp_keymap keysym_map[] = {
155155
{CACA_KEY_F11, MP_KEY_F+11}, {CACA_KEY_F12, MP_KEY_F+12},
156156
{CACA_KEY_F13, MP_KEY_F+13}, {CACA_KEY_F14, MP_KEY_F+14},
157157
{CACA_KEY_F15, MP_KEY_F+15},
158-
{0, 0}
158+
{-1, 0}
159159
};
160160

161161
static void check_events(struct vo *vo)

video/out/w32_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static const struct mp_keymap vk_map[] = {
6060
{VK_NUMPAD6, MP_KEY_KP6}, {VK_NUMPAD7, MP_KEY_KP7}, {VK_NUMPAD8, MP_KEY_KP8},
6161
{VK_NUMPAD9, MP_KEY_KP9}, {VK_DECIMAL, MP_KEY_KPDEC},
6262

63-
{0, 0}
63+
{-1, 0}
6464
};
6565

6666
static void add_window_borders(HWND hwnd, RECT *rc)

video/out/wayland_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static const struct mp_keymap keymap[] = {
106106
{XKB_KEY_KP_Up, MP_KEY_KP8}, {XKB_KEY_KP_Page_Up, MP_KEY_KP9},
107107
{XKB_KEY_KP_Delete, MP_KEY_KPDEL},
108108

109-
{0, 0}
109+
{-1, 0}
110110
};
111111

112112

video/out/x11_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ static const struct mp_keymap keymap[] = {
589589
{XF86XK_Search, MP_KEY_SEARCH}, {XF86XK_Sleep, MP_KEY_SLEEP},
590590
#endif
591591

592-
{0, 0}
592+
{-1, 0}
593593
};
594594

595595
static int vo_x11_lookupkey(int key)

0 commit comments

Comments
 (0)