diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/macterm.c | 225 |
1 files changed, 171 insertions, 54 deletions
diff --git a/src/macterm.c b/src/macterm.c index a0997c4e061..0fb644222cb 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -12630,7 +12630,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) | |||
| 12630 | expected | 12630 | expected |
| 12631 | ? TicksToEventTime (app_sleep_time) | 12631 | ? TicksToEventTime (app_sleep_time) |
| 12632 | : 0, | 12632 | : 0, |
| 12633 | true, &eventRef); | 12633 | kEventRemoveFromQueue, &eventRef); |
| 12634 | if (!rneResult) | 12634 | if (!rneResult) |
| 12635 | { | 12635 | { |
| 12636 | /* Handle new events */ | 12636 | /* Handle new events */ |
| @@ -12661,7 +12661,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) | |||
| 12661 | bufp->timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60); | 12661 | bufp->timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60); |
| 12662 | count++; | 12662 | count++; |
| 12663 | } | 12663 | } |
| 12664 | else | 12664 | else |
| 12665 | SendEventToEventTarget (eventRef, GetEventDispatcherTarget ()); | 12665 | SendEventToEventTarget (eventRef, GetEventDispatcherTarget ()); |
| 12666 | 12666 | ||
| 12667 | break; | 12667 | break; |
| @@ -12911,16 +12911,16 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) | |||
| 12911 | break; | 12911 | break; |
| 12912 | } | 12912 | } |
| 12913 | #endif | 12913 | #endif |
| 12914 | 12914 | ||
| 12915 | if (!IsValidWindowPtr (FrontNonFloatingWindow ())) | 12915 | if (!IsValidWindowPtr (FrontNonFloatingWindow ())) |
| 12916 | { | 12916 | { |
| 12917 | SysBeep (1); | 12917 | SysBeep (1); |
| 12918 | UNBLOCK_INPUT; | 12918 | UNBLOCK_INPUT; |
| 12919 | return 0; | 12919 | return 0; |
| 12920 | } | 12920 | } |
| 12921 | 12921 | ||
| 12922 | ObscureCursor (); | 12922 | ObscureCursor (); |
| 12923 | 12923 | ||
| 12924 | if (keycode == 0x33) /* delete key (charCode translated to 0x8) */ | 12924 | if (keycode == 0x33) /* delete key (charCode translated to 0x8) */ |
| 12925 | { | 12925 | { |
| 12926 | bufp->code = 0x7f; | 12926 | bufp->code = 0x7f; |
| @@ -12945,76 +12945,76 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) | |||
| 12945 | else | 12945 | else |
| 12946 | { | 12946 | { |
| 12947 | if (er.modifiers & macMetaKey) | 12947 | if (er.modifiers & macMetaKey) |
| 12948 | { | 12948 | { |
| 12949 | /* This code comes from Keyboard Resource, Appendix | 12949 | /* This code comes from Keyboard Resource, Appendix |
| 12950 | C of IM - Text. This is necessary since shift is | 12950 | C of IM - Text. This is necessary since shift is |
| 12951 | ignored in KCHR table translation when option or | 12951 | ignored in KCHR table translation when option or |
| 12952 | command is pressed. */ | 12952 | command is pressed. */ |
| 12953 | int new_modifiers = er.modifiers & 0xf600; | 12953 | int new_modifiers = er.modifiers & 0xf600; |
| 12954 | /* mask off option and command */ | 12954 | /* mask off option and command */ |
| 12955 | int new_keycode = keycode | new_modifiers; | 12955 | int new_keycode = keycode | new_modifiers; |
| 12956 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | 12956 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); |
| 12957 | unsigned long some_state = 0; | 12957 | unsigned long some_state = 0; |
| 12958 | bufp->code = KeyTranslate (kchr_ptr, new_keycode, | 12958 | bufp->code = KeyTranslate (kchr_ptr, new_keycode, |
| 12959 | &some_state) & 0xff; | 12959 | &some_state) & 0xff; |
| 12960 | } | 12960 | } |
| 12961 | else | 12961 | else |
| 12962 | bufp->code = er.message & charCodeMask; | 12962 | bufp->code = er.message & charCodeMask; |
| 12963 | bufp->kind = ASCII_KEYSTROKE_EVENT; | 12963 | bufp->kind = ASCII_KEYSTROKE_EVENT; |
| 12964 | } | 12964 | } |
| 12965 | } | 12965 | } |
| 12966 | 12966 | ||
| 12967 | /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil, | 12967 | /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil, |
| 12968 | convert non-ASCII characters typed at the Mac keyboard | 12968 | convert non-ASCII characters typed at the Mac keyboard |
| 12969 | (presumed to be in the Mac Roman encoding) to iso-latin-1 | 12969 | (presumed to be in the Mac Roman encoding) to iso-latin-1 |
| 12970 | encoding before they are passed to Emacs. This enables the | 12970 | encoding before they are passed to Emacs. This enables the |
| 12971 | Mac keyboard to be used to enter non-ASCII iso-latin-1 | 12971 | Mac keyboard to be used to enter non-ASCII iso-latin-1 |
| 12972 | characters directly. */ | 12972 | characters directly. */ |
| 12973 | if (mac_keyboard_text_encoding != kTextEncodingMacRoman | 12973 | if (mac_keyboard_text_encoding != kTextEncodingMacRoman |
| 12974 | && bufp->kind == ASCII_KEYSTROKE_EVENT && bufp->code >= 128) | 12974 | && bufp->kind == ASCII_KEYSTROKE_EVENT && bufp->code >= 128) |
| 12975 | { | 12975 | { |
| 12976 | static TECObjectRef converter = NULL; | 12976 | static TECObjectRef converter = NULL; |
| 12977 | OSStatus the_err = noErr; | 12977 | OSStatus the_err = noErr; |
| 12978 | OSStatus convert_status = noErr; | 12978 | OSStatus convert_status = noErr; |
| 12979 | 12979 | ||
| 12980 | if (converter == NULL) | 12980 | if (converter == NULL) |
| 12981 | { | 12981 | { |
| 12982 | the_err = TECCreateConverter (&converter, | 12982 | the_err = TECCreateConverter (&converter, |
| 12983 | kTextEncodingMacRoman, | 12983 | kTextEncodingMacRoman, |
| 12984 | mac_keyboard_text_encoding); | 12984 | mac_keyboard_text_encoding); |
| 12985 | current_mac_keyboard_text_encoding | 12985 | current_mac_keyboard_text_encoding |
| 12986 | = mac_keyboard_text_encoding; | 12986 | = mac_keyboard_text_encoding; |
| 12987 | } | 12987 | } |
| 12988 | else if (mac_keyboard_text_encoding | 12988 | else if (mac_keyboard_text_encoding |
| 12989 | != current_mac_keyboard_text_encoding) | 12989 | != current_mac_keyboard_text_encoding) |
| 12990 | { | 12990 | { |
| 12991 | /* Free the converter for the current encoding before | 12991 | /* Free the converter for the current encoding before |
| 12992 | creating a new one. */ | 12992 | creating a new one. */ |
| 12993 | TECDisposeConverter (converter); | 12993 | TECDisposeConverter (converter); |
| 12994 | the_err = TECCreateConverter (&converter, | 12994 | the_err = TECCreateConverter (&converter, |
| 12995 | kTextEncodingMacRoman, | 12995 | kTextEncodingMacRoman, |
| 12996 | mac_keyboard_text_encoding); | 12996 | mac_keyboard_text_encoding); |
| 12997 | current_mac_keyboard_text_encoding | 12997 | current_mac_keyboard_text_encoding |
| 12998 | = mac_keyboard_text_encoding; | 12998 | = mac_keyboard_text_encoding; |
| 12999 | } | 12999 | } |
| 13000 | 13000 | ||
| 13001 | if (the_err == noErr) | 13001 | if (the_err == noErr) |
| 13002 | { | 13002 | { |
| 13003 | unsigned char ch = bufp->code; | 13003 | unsigned char ch = bufp->code; |
| 13004 | ByteCount actual_input_length, actual_output_length; | 13004 | ByteCount actual_input_length, actual_output_length; |
| 13005 | unsigned char outch; | 13005 | unsigned char outch; |
| 13006 | 13006 | ||
| 13007 | convert_status = TECConvertText (converter, &ch, 1, | 13007 | convert_status = TECConvertText (converter, &ch, 1, |
| 13008 | &actual_input_length, | 13008 | &actual_input_length, |
| 13009 | &outch, 1, | 13009 | &outch, 1, |
| 13010 | &actual_output_length); | 13010 | &actual_output_length); |
| 13011 | if (convert_status == noErr | 13011 | if (convert_status == noErr |
| 13012 | && actual_input_length == 1 | 13012 | && actual_input_length == 1 |
| 13013 | && actual_output_length == 1) | 13013 | && actual_output_length == 1) |
| 13014 | bufp->code = outch; | 13014 | bufp->code = outch; |
| 13015 | } | 13015 | } |
| 13016 | } | 13016 | } |
| 13017 | 13017 | ||
| 13018 | #if USE_CARBON_EVENTS | 13018 | #if USE_CARBON_EVENTS |
| 13019 | bufp->modifiers = mac_event_to_emacs_modifiers (eventRef); | 13019 | bufp->modifiers = mac_event_to_emacs_modifiers (eventRef); |
| 13020 | #else | 13020 | #else |
| @@ -13026,7 +13026,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) | |||
| 13026 | = (mac_output *) GetWRefCon (FrontNonFloatingWindow ()); | 13026 | = (mac_output *) GetWRefCon (FrontNonFloatingWindow ()); |
| 13027 | XSETFRAME (bufp->frame_or_window, mwp->mFP); | 13027 | XSETFRAME (bufp->frame_or_window, mwp->mFP); |
| 13028 | } | 13028 | } |
| 13029 | 13029 | ||
| 13030 | bufp->timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ | 13030 | bufp->timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ |
| 13031 | 13031 | ||
| 13032 | count++; | 13032 | count++; |
| @@ -13446,6 +13446,36 @@ mac_term_init (display_name, xrm_option, resource_name) | |||
| 13446 | 13446 | ||
| 13447 | #ifdef MAC_OSX | 13447 | #ifdef MAC_OSX |
| 13448 | void | 13448 | void |
| 13449 | mac_check_bundle() | ||
| 13450 | { | ||
| 13451 | extern int inhibit_window_system; | ||
| 13452 | extern int noninteractive; | ||
| 13453 | CFBundleRef appsBundle; | ||
| 13454 | pid_t child; | ||
| 13455 | |||
| 13456 | /* No need to test if already -nw*/ | ||
| 13457 | if (inhibit_window_system || noninteractive) | ||
| 13458 | return; | ||
| 13459 | |||
| 13460 | appsBundle = CFBundleGetMainBundle(); | ||
| 13461 | if (appsBundle != NULL) | ||
| 13462 | { | ||
| 13463 | CFStringRef cfBI = CFSTR("CFBundleIdentifier"); | ||
| 13464 | CFTypeRef res = CFBundleGetValueForInfoDictionaryKey(appsBundle, cfBI); | ||
| 13465 | /* We found the bundle identifier, now we know we are valid. */ | ||
| 13466 | if (res != NULL) | ||
| 13467 | { | ||
| 13468 | CFRelease(res); | ||
| 13469 | return; | ||
| 13470 | } | ||
| 13471 | } | ||
| 13472 | /* MAC_TODO: Have this start the bundled executable */ | ||
| 13473 | |||
| 13474 | /* For now, prevent the fatal error by bringing it up in the terminal */ | ||
| 13475 | inhibit_window_system = 1; | ||
| 13476 | } | ||
| 13477 | |||
| 13478 | void | ||
| 13449 | MakeMeTheFrontProcess () | 13479 | MakeMeTheFrontProcess () |
| 13450 | { | 13480 | { |
| 13451 | ProcessSerialNumber psn; | 13481 | ProcessSerialNumber psn; |
| @@ -13455,6 +13485,91 @@ MakeMeTheFrontProcess () | |||
| 13455 | if (err == noErr) | 13485 | if (err == noErr) |
| 13456 | (void) SetFrontProcess (&psn); | 13486 | (void) SetFrontProcess (&psn); |
| 13457 | } | 13487 | } |
| 13488 | |||
| 13489 | /***** Code to handle C-g testing *****/ | ||
| 13490 | |||
| 13491 | /* Contains the Mac modifier formed from quit_char */ | ||
| 13492 | static mac_quit_char_modifiers = 0; | ||
| 13493 | static mac_quit_char_keycode; | ||
| 13494 | extern int quit_char; | ||
| 13495 | |||
| 13496 | static void | ||
| 13497 | mac_determine_quit_char_modifiers() | ||
| 13498 | { | ||
| 13499 | /* Todo: Determine modifiers from quit_char. */ | ||
| 13500 | UInt32 qc_modifiers = ctrl_modifier; | ||
| 13501 | |||
| 13502 | /* Map modifiers */ | ||
| 13503 | mac_quit_char_modifiers = 0; | ||
| 13504 | if (qc_modifiers & ctrl_modifier) mac_quit_char_modifiers |= macCtrlKey; | ||
| 13505 | if (qc_modifiers & shift_modifier) mac_quit_char_modifiers |= macShiftKey; | ||
| 13506 | if (qc_modifiers & meta_modifier) mac_quit_char_modifiers |= macMetaKey; | ||
| 13507 | if (qc_modifiers & alt_modifier) mac_quit_char_modifiers |= macAltKey; | ||
| 13508 | } | ||
| 13509 | |||
| 13510 | static void | ||
| 13511 | init_quit_char_handler () | ||
| 13512 | { | ||
| 13513 | /* TODO: Let this support keys other the 'g' */ | ||
| 13514 | mac_quit_char_keycode = 5; | ||
| 13515 | /* Look at <architecture/adb_kb_map.h> for details */ | ||
| 13516 | /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/ | ||
| 13517 | |||
| 13518 | mac_determine_quit_char_modifiers(); | ||
| 13519 | } | ||
| 13520 | |||
| 13521 | static Boolean | ||
| 13522 | quit_char_comp (EventRef inEvent, void *inCompData) | ||
| 13523 | { | ||
| 13524 | if (GetEventClass(inEvent) != kEventClassKeyboard) | ||
| 13525 | return false; | ||
| 13526 | if (GetEventKind(inEvent) != kEventRawKeyDown) | ||
| 13527 | return false; | ||
| 13528 | { | ||
| 13529 | UInt32 keyCode; | ||
| 13530 | UInt32 keyModifiers; | ||
| 13531 | GetEventParameter(inEvent, kEventParamKeyCode, | ||
| 13532 | typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); | ||
| 13533 | if (keyCode != mac_quit_char_keycode) | ||
| 13534 | return false; | ||
| 13535 | GetEventParameter(inEvent, kEventParamKeyModifiers, | ||
| 13536 | typeUInt32, NULL, sizeof(UInt32), NULL, &keyModifiers); | ||
| 13537 | if (keyModifiers != mac_quit_char_modifiers) | ||
| 13538 | return false; | ||
| 13539 | } | ||
| 13540 | return true; | ||
| 13541 | } | ||
| 13542 | |||
| 13543 | void | ||
| 13544 | mac_check_for_quit_char() | ||
| 13545 | { | ||
| 13546 | EventRef event; | ||
| 13547 | /* If windows are not initialized, return immediately (keep it bouncin')*/ | ||
| 13548 | if (!mac_quit_char_modifiers) | ||
| 13549 | return; | ||
| 13550 | |||
| 13551 | /* Redetermine modifiers because they are based on lisp variables */ | ||
| 13552 | mac_determine_quit_char_modifiers(); | ||
| 13553 | |||
| 13554 | /* Fill the queue with events */ | ||
| 13555 | ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &event); | ||
| 13556 | event = FindSpecificEventInQueue (GetMainEventQueue(), quit_char_comp, NULL); | ||
| 13557 | if (event) | ||
| 13558 | { | ||
| 13559 | struct input_event e; | ||
| 13560 | struct mac_output *mwp = (mac_output*) GetWRefCon (FrontNonFloatingWindow ()); | ||
| 13561 | /* Use an input_event to emulate what the interrupt handler does. */ | ||
| 13562 | e.kind = ASCII_KEYSTROKE_EVENT; | ||
| 13563 | e.code = quit_char; | ||
| 13564 | e.timestamp = EventTimeToTicks(GetEventTime(event))*(1000/60); | ||
| 13565 | XSETFRAME(e.frame_or_window, mwp->mFP); | ||
| 13566 | /* Remove event from queue to prevent looping. */ | ||
| 13567 | RemoveEventFromQueue(GetMainEventQueue(), event); | ||
| 13568 | ReleaseEvent(event); | ||
| 13569 | kbd_buffer_store_event(&e); | ||
| 13570 | } | ||
| 13571 | } | ||
| 13572 | |||
| 13458 | #endif /* MAC_OSX */ | 13573 | #endif /* MAC_OSX */ |
| 13459 | 13574 | ||
| 13460 | /* Set up use of X before we make the first connection. */ | 13575 | /* Set up use of X before we make the first connection. */ |
| @@ -13563,6 +13678,8 @@ mac_initialize () | |||
| 13563 | 13678 | ||
| 13564 | #if USE_CARBON_EVENTS | 13679 | #if USE_CARBON_EVENTS |
| 13565 | init_service_handler (); | 13680 | init_service_handler (); |
| 13681 | |||
| 13682 | init_quit_char_handler (); | ||
| 13566 | #endif | 13683 | #endif |
| 13567 | 13684 | ||
| 13568 | DisableMenuCommand (NULL, kHICommandQuit); | 13685 | DisableMenuCommand (NULL, kHICommandQuit); |