Skip to content

Commit a124e90

Browse files
SiegeLordExSiegeLord
authored andcommitted
Try to fix Ctrl-key chords on MacOS with the new input.
The old code had a confusing logic that dealt with Ctrl-keys, which was misinterpreted by me, which I now changed. Separately, the new input had logic to filter out characters under 32, which was not necessary. (cherry picked from commit 94d5f7b)
1 parent ddda40f commit a124e90

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/macosx/keybd.m

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
270270
if (pressed) {
271271
int32_t unichar = 0;
272272
bool new_input = _al_get_keyboard_compat_version() >= AL_ID(5, 2, 10, 0);
273-
NSString *raw_characters = [event charactersIgnoringModifiers];
274273
NSString *characters = [event characters];
275-
UniChar raw_character = ([raw_characters length] > 0) ? [raw_characters characterAtIndex: 0] : 0;
276274
UniChar character = ([characters length] > 0) ? [characters characterAtIndex: 0] : 0;
277275

278276
if (new_input) {
@@ -307,9 +305,10 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
307305
/* For some reason, pad enter sends a ^C. */
308306
if (scancode == ALLEGRO_KEY_PAD_ENTER && unichar == 3)
309307
unichar = '\r';
310-
/* Single out the few printable characters under 32 */
311-
if (unichar < ' ' && (unichar != '\r' && unichar != '\t' && unichar != '\b'))
312-
unichar = 0;
308+
/* For some reason, Ctrl-<key> sends capital version of the character,
309+
and not the correct invisible character. */
310+
if (key_shifts & ALLEGRO_KEYMOD_CTRL)
311+
unichar = character;
313312
al_ustr_free(ustr);
314313
}
315314
CFRelease(keyboard_input);
@@ -320,14 +319,13 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
320319
/* Apple maps function, arrow, and other keys to Unicode points.
321320
We want to generate CHAR events for them, so we'll override the translation logic.
322321
_handle_key_press will set the unichar back to 0 for these keys. */
323-
if (character >= 0xF700 && character <= 0xF747)
324-
unichar = -1;
325-
/* The delete key. */
326-
if (character == 0xF728 && new_input)
327-
unichar = 127;
328-
/* Special processing to send character 1 for CTRL-A, 2 for CTRL-B etc. */
329-
if ((key_shifts & ALLEGRO_KEYMOD_CTRL) && (isalpha(raw_character)))
330-
unichar = tolower(raw_character) - 'a' + 1;
322+
if (character >= 0xF700 && character <= 0xF747) {
323+
/* The old input did not handle this key (delete) correctly. We preserve the old behavior. */
324+
if (new_input && character == 0xF728)
325+
unichar = 127;
326+
else
327+
unichar = -1;
328+
}
331329
bool is_repeat = pressed ? ([event isARepeat] == YES) : false;
332330
_handle_key_press(dpy, unichar, scancode, key_shifts, is_repeat);
333331
}

0 commit comments

Comments
 (0)