diff options
Diffstat (limited to 'src/macterm.c')
| -rw-r--r-- | src/macterm.c | 735 |
1 files changed, 545 insertions, 190 deletions
diff --git a/src/macterm.c b/src/macterm.c index e3b8b3b5881..549e1e7977b 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -3531,19 +3531,28 @@ x_draw_stretch_glyph_string (s) | |||
| 3531 | { | 3531 | { |
| 3532 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | 3532 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor |
| 3533 | as wide as the stretch glyph. */ | 3533 | as wide as the stretch glyph. */ |
| 3534 | int width = min (FRAME_COLUMN_WIDTH (s->f), s->background_width); | 3534 | int width, background_width = s->background_width; |
| 3535 | int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA); | ||
| 3536 | |||
| 3537 | if (x < left_x) | ||
| 3538 | { | ||
| 3539 | background_width -= left_x - x; | ||
| 3540 | x = left_x; | ||
| 3541 | } | ||
| 3542 | width = min (FRAME_COLUMN_WIDTH (s->f), background_width); | ||
| 3535 | 3543 | ||
| 3536 | /* Draw cursor. */ | 3544 | /* Draw cursor. */ |
| 3537 | x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); | 3545 | x_draw_glyph_string_bg_rect (s, x, s->y, width, s->height); |
| 3538 | 3546 | ||
| 3539 | /* Clear rest using the GC of the original non-cursor face. */ | 3547 | /* Clear rest using the GC of the original non-cursor face. */ |
| 3540 | if (width < s->background_width) | 3548 | if (width < background_width) |
| 3541 | { | 3549 | { |
| 3542 | int x = s->x + width, y = s->y; | 3550 | int y = s->y; |
| 3543 | int w = s->background_width - width, h = s->height; | 3551 | int w = background_width - width, h = s->height; |
| 3544 | Rect r; | 3552 | Rect r; |
| 3545 | GC gc; | 3553 | GC gc; |
| 3546 | 3554 | ||
| 3555 | x += width; | ||
| 3547 | if (s->row->mouse_face_p | 3556 | if (s->row->mouse_face_p |
| 3548 | && cursor_in_mouse_face_p (s->w)) | 3557 | && cursor_in_mouse_face_p (s->w)) |
| 3549 | { | 3558 | { |
| @@ -3570,8 +3579,18 @@ x_draw_stretch_glyph_string (s) | |||
| 3570 | } | 3579 | } |
| 3571 | } | 3580 | } |
| 3572 | else if (!s->background_filled_p) | 3581 | else if (!s->background_filled_p) |
| 3573 | x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, | 3582 | { |
| 3574 | s->height); | 3583 | int background_width = s->background_width; |
| 3584 | int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA); | ||
| 3585 | |||
| 3586 | if (x < left_x) | ||
| 3587 | { | ||
| 3588 | background_width -= left_x - x; | ||
| 3589 | x = left_x; | ||
| 3590 | } | ||
| 3591 | if (background_width > 0) | ||
| 3592 | x_draw_glyph_string_bg_rect (s, x, s->y, background_width, s->height); | ||
| 3593 | } | ||
| 3575 | 3594 | ||
| 3576 | s->background_filled_p = 1; | 3595 | s->background_filled_p = 1; |
| 3577 | } | 3596 | } |
| @@ -5398,8 +5417,7 @@ x_draw_hollow_cursor (w, row) | |||
| 5398 | return; | 5417 | return; |
| 5399 | 5418 | ||
| 5400 | /* Compute frame-relative coordinates for phys cursor. */ | 5419 | /* Compute frame-relative coordinates for phys cursor. */ |
| 5401 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | 5420 | get_phys_cursor_geometry (w, row, cursor_glyph, &x, &y, &h); |
| 5402 | y = get_phys_cursor_geometry (w, row, cursor_glyph, &h); | ||
| 5403 | wd = w->phys_cursor_width; | 5421 | wd = w->phys_cursor_width; |
| 5404 | 5422 | ||
| 5405 | /* The foreground of cursor_gc is typically the same as the normal | 5423 | /* The foreground of cursor_gc is typically the same as the normal |
| @@ -6135,6 +6153,7 @@ mac_handle_visibility_change (f) | |||
| 6135 | EVENT_INIT (buf); | 6153 | EVENT_INIT (buf); |
| 6136 | buf.kind = DEICONIFY_EVENT; | 6154 | buf.kind = DEICONIFY_EVENT; |
| 6137 | XSETFRAME (buf.frame_or_window, f); | 6155 | XSETFRAME (buf.frame_or_window, f); |
| 6156 | buf.arg = Qnil; | ||
| 6138 | kbd_buffer_store_event (&buf); | 6157 | kbd_buffer_store_event (&buf); |
| 6139 | } | 6158 | } |
| 6140 | else if (! NILP (Vframe_list) && ! NILP (XCDR (Vframe_list))) | 6159 | else if (! NILP (Vframe_list) && ! NILP (XCDR (Vframe_list))) |
| @@ -6148,6 +6167,7 @@ mac_handle_visibility_change (f) | |||
| 6148 | EVENT_INIT (buf); | 6167 | EVENT_INIT (buf); |
| 6149 | buf.kind = ICONIFY_EVENT; | 6168 | buf.kind = ICONIFY_EVENT; |
| 6150 | XSETFRAME (buf.frame_or_window, f); | 6169 | XSETFRAME (buf.frame_or_window, f); |
| 6170 | buf.arg = Qnil; | ||
| 6151 | kbd_buffer_store_event (&buf); | 6171 | kbd_buffer_store_event (&buf); |
| 6152 | } | 6172 | } |
| 6153 | 6173 | ||
| @@ -8341,6 +8361,26 @@ x_find_ccl_program (fontp) | |||
| 8341 | } | 8361 | } |
| 8342 | 8362 | ||
| 8343 | #if USE_MAC_FONT_PANEL | 8363 | #if USE_MAC_FONT_PANEL |
| 8364 | /* Whether Font Panel has been shown before. The first call to font | ||
| 8365 | panel functions (FPIsFontPanelVisible, SetFontInfoForSelection) is | ||
| 8366 | slow. This variable is used for deferring such a call as much as | ||
| 8367 | possible. */ | ||
| 8368 | static int font_panel_shown_p = 0; | ||
| 8369 | |||
| 8370 | int | ||
| 8371 | mac_font_panel_visible_p () | ||
| 8372 | { | ||
| 8373 | return font_panel_shown_p && FPIsFontPanelVisible (); | ||
| 8374 | } | ||
| 8375 | |||
| 8376 | OSStatus | ||
| 8377 | mac_show_hide_font_panel () | ||
| 8378 | { | ||
| 8379 | font_panel_shown_p = 1; | ||
| 8380 | |||
| 8381 | return FPShowHideFontPanel (); | ||
| 8382 | } | ||
| 8383 | |||
| 8344 | OSStatus | 8384 | OSStatus |
| 8345 | mac_set_font_info_for_selection (f, face_id, c) | 8385 | mac_set_font_info_for_selection (f, face_id, c) |
| 8346 | struct frame *f; | 8386 | struct frame *f; |
| @@ -8350,6 +8390,9 @@ mac_set_font_info_for_selection (f, face_id, c) | |||
| 8350 | EventTargetRef target = NULL; | 8390 | EventTargetRef target = NULL; |
| 8351 | XFontStruct *font = NULL; | 8391 | XFontStruct *font = NULL; |
| 8352 | 8392 | ||
| 8393 | if (!mac_font_panel_visible_p ()) | ||
| 8394 | return noErr; | ||
| 8395 | |||
| 8353 | if (f) | 8396 | if (f) |
| 8354 | { | 8397 | { |
| 8355 | target = GetWindowEventTarget (FRAME_MAC_WINDOW (f)); | 8398 | target = GetWindowEventTarget (FRAME_MAC_WINDOW (f)); |
| @@ -8484,6 +8527,13 @@ static Lisp_Object Qtoolbar_switch_mode; | |||
| 8484 | extern Lisp_Object Qfont; | 8527 | extern Lisp_Object Qfont; |
| 8485 | static Lisp_Object Qpanel_closed, Qselection; | 8528 | static Lisp_Object Qpanel_closed, Qselection; |
| 8486 | #endif | 8529 | #endif |
| 8530 | #if USE_MAC_TSM | ||
| 8531 | static TSMDocumentID tsm_document_id; | ||
| 8532 | static Lisp_Object Qtext_input; | ||
| 8533 | static Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; | ||
| 8534 | static Lisp_Object Vmac_ts_active_input_overlay; | ||
| 8535 | extern Lisp_Object Qbefore_string; | ||
| 8536 | #endif | ||
| 8487 | #endif | 8537 | #endif |
| 8488 | extern int mac_ready_for_apple_events; | 8538 | extern int mac_ready_for_apple_events; |
| 8489 | extern Lisp_Object Qundefined; | 8539 | extern Lisp_Object Qundefined; |
| @@ -8835,13 +8885,17 @@ is_emacs_window (WindowPtr win) | |||
| 8835 | static void | 8885 | static void |
| 8836 | do_app_resume () | 8886 | do_app_resume () |
| 8837 | { | 8887 | { |
| 8838 | /* Window-activate events will do the job. */ | 8888 | #if USE_MAC_TSM |
| 8889 | ActivateTSMDocument (tsm_document_id); | ||
| 8890 | #endif | ||
| 8839 | } | 8891 | } |
| 8840 | 8892 | ||
| 8841 | static void | 8893 | static void |
| 8842 | do_app_suspend () | 8894 | do_app_suspend () |
| 8843 | { | 8895 | { |
| 8844 | /* Window-deactivate events will do the job. */ | 8896 | #if USE_MAC_TSM |
| 8897 | DeactivateTSMDocument (tsm_document_id); | ||
| 8898 | #endif | ||
| 8845 | } | 8899 | } |
| 8846 | 8900 | ||
| 8847 | 8901 | ||
| @@ -9101,6 +9155,9 @@ mac_store_event_ref_as_apple_event (class, id, class_key, id_key, | |||
| 9101 | { | 9155 | { |
| 9102 | mac_store_apple_event (class_key, id_key, &apple_event); | 9156 | mac_store_apple_event (class_key, id_key, &apple_event); |
| 9103 | AEDisposeDesc (&apple_event); | 9157 | AEDisposeDesc (&apple_event); |
| 9158 | /* Post a harmless event so as to wake up from | ||
| 9159 | ReceiveNextEvent. */ | ||
| 9160 | mac_post_mouse_moved_event (); | ||
| 9104 | } | 9161 | } |
| 9105 | } | 9162 | } |
| 9106 | } | 9163 | } |
| @@ -9290,6 +9347,18 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9290 | } | 9347 | } |
| 9291 | return err == noErr ? noErr : result; | 9348 | return err == noErr ? noErr : result; |
| 9292 | #endif | 9349 | #endif |
| 9350 | |||
| 9351 | #if USE_MAC_TSM | ||
| 9352 | case kEventWindowFocusAcquired: | ||
| 9353 | result = CallNextEventHandler (next_handler, event); | ||
| 9354 | err = ActivateTSMDocument (tsm_document_id); | ||
| 9355 | return err == noErr ? noErr : result; | ||
| 9356 | |||
| 9357 | case kEventWindowFocusRelinquish: | ||
| 9358 | result = CallNextEventHandler (next_handler, event); | ||
| 9359 | err = DeactivateTSMDocument (tsm_document_id); | ||
| 9360 | return err == noErr ? noErr : result; | ||
| 9361 | #endif | ||
| 9293 | } | 9362 | } |
| 9294 | 9363 | ||
| 9295 | return eventNotHandledErr; | 9364 | return eventNotHandledErr; |
| @@ -9416,6 +9485,183 @@ mac_handle_font_event (next_handler, event, data) | |||
| 9416 | } | 9485 | } |
| 9417 | #endif | 9486 | #endif |
| 9418 | 9487 | ||
| 9488 | #if USE_MAC_TSM | ||
| 9489 | static pascal OSStatus | ||
| 9490 | mac_handle_text_input_event (next_handler, event, data) | ||
| 9491 | EventHandlerCallRef next_handler; | ||
| 9492 | EventRef event; | ||
| 9493 | void *data; | ||
| 9494 | { | ||
| 9495 | OSStatus result, err = noErr; | ||
| 9496 | Lisp_Object id_key = Qnil; | ||
| 9497 | int num_params; | ||
| 9498 | EventParamName *names; | ||
| 9499 | EventParamType *types; | ||
| 9500 | static UInt32 seqno_uaia = 0; | ||
| 9501 | static EventParamName names_uaia[] = | ||
| 9502 | {kEventParamTextInputSendComponentInstance, | ||
| 9503 | kEventParamTextInputSendRefCon, | ||
| 9504 | kEventParamTextInputSendSLRec, | ||
| 9505 | kEventParamTextInputSendFixLen, | ||
| 9506 | kEventParamTextInputSendText, | ||
| 9507 | kEventParamTextInputSendUpdateRng, | ||
| 9508 | kEventParamTextInputSendHiliteRng, | ||
| 9509 | kEventParamTextInputSendClauseRng, | ||
| 9510 | kEventParamTextInputSendPinRng, | ||
| 9511 | kEventParamTextInputSendTextServiceEncoding, | ||
| 9512 | kEventParamTextInputSendTextServiceMacEncoding, | ||
| 9513 | EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER}; | ||
| 9514 | static EventParamType types_uaia[] = | ||
| 9515 | {typeComponentInstance, | ||
| 9516 | typeLongInteger, | ||
| 9517 | typeIntlWritingCode, | ||
| 9518 | typeLongInteger, | ||
| 9519 | typeUnicodeText, | ||
| 9520 | typeTextRangeArray, | ||
| 9521 | typeTextRangeArray, | ||
| 9522 | typeOffsetArray, | ||
| 9523 | typeTextRange, | ||
| 9524 | typeUInt32, | ||
| 9525 | typeUInt32, | ||
| 9526 | typeUInt32}; | ||
| 9527 | static EventParamName names_ufke[] = | ||
| 9528 | {kEventParamTextInputSendComponentInstance, | ||
| 9529 | kEventParamTextInputSendRefCon, | ||
| 9530 | kEventParamTextInputSendSLRec, | ||
| 9531 | kEventParamTextInputSendText}; | ||
| 9532 | static EventParamType types_ufke[] = | ||
| 9533 | {typeComponentInstance, | ||
| 9534 | typeLongInteger, | ||
| 9535 | typeIntlWritingCode, | ||
| 9536 | typeUnicodeText}; | ||
| 9537 | |||
| 9538 | result = CallNextEventHandler (next_handler, event); | ||
| 9539 | |||
| 9540 | switch (GetEventKind (event)) | ||
| 9541 | { | ||
| 9542 | case kEventTextInputUpdateActiveInputArea: | ||
| 9543 | id_key = Qupdate_active_input_area; | ||
| 9544 | num_params = sizeof (names_uaia) / sizeof (names_uaia[0]); | ||
| 9545 | names = names_uaia; | ||
| 9546 | types = types_uaia; | ||
| 9547 | SetEventParameter (event, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER, | ||
| 9548 | typeUInt32, sizeof (UInt32), &seqno_uaia); | ||
| 9549 | seqno_uaia++; | ||
| 9550 | break; | ||
| 9551 | |||
| 9552 | case kEventTextInputUnicodeForKeyEvent: | ||
| 9553 | { | ||
| 9554 | EventRef kbd_event; | ||
| 9555 | UInt32 actual_size, modifiers, mapped_modifiers; | ||
| 9556 | UniChar code; | ||
| 9557 | |||
| 9558 | err = GetEventParameter (event, kEventParamTextInputSendKeyboardEvent, | ||
| 9559 | typeEventRef, NULL, sizeof (EventRef), NULL, | ||
| 9560 | &kbd_event); | ||
| 9561 | if (err == noErr) | ||
| 9562 | err = GetEventParameter (kbd_event, kEventParamKeyModifiers, | ||
| 9563 | typeUInt32, NULL, | ||
| 9564 | sizeof (UInt32), NULL, &modifiers); | ||
| 9565 | if (err == noErr) | ||
| 9566 | { | ||
| 9567 | mapped_modifiers = | ||
| 9568 | (NILP (Vmac_control_modifier) ? 0 : controlKey) | ||
| 9569 | | (NILP (Vmac_option_modifier) ? 0 : optionKey) | ||
| 9570 | | (NILP (Vmac_command_modifier) ? 0 : cmdKey); | ||
| 9571 | #ifdef MAC_OSX | ||
| 9572 | mapped_modifiers |= | ||
| 9573 | (NILP (Vmac_function_modifier) ? 0 : kEventKeyModifierFnMask); | ||
| 9574 | #endif | ||
| 9575 | if (modifiers & mapped_modifiers) | ||
| 9576 | /* There're mapped modifier keys. Process it in | ||
| 9577 | XTread_socket. */ | ||
| 9578 | return eventNotHandledErr; | ||
| 9579 | } | ||
| 9580 | if (err == noErr) | ||
| 9581 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, | ||
| 9582 | typeUnicodeText, NULL, 0, &actual_size, | ||
| 9583 | NULL); | ||
| 9584 | if (err == noErr) | ||
| 9585 | { | ||
| 9586 | if (actual_size == sizeof (UniChar)) | ||
| 9587 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, | ||
| 9588 | typeUnicodeText, NULL, | ||
| 9589 | sizeof (UniChar), NULL, &code); | ||
| 9590 | if (err == noErr && code < 0x80) | ||
| 9591 | { | ||
| 9592 | /* ASCII character. Process it in XTread_socket. */ | ||
| 9593 | if (read_socket_inev && code >= 0x20 && code <= 0x7e) | ||
| 9594 | { | ||
| 9595 | struct frame *f = mac_focus_frame (&one_mac_display_info); | ||
| 9596 | |||
| 9597 | read_socket_inev->kind = ASCII_KEYSTROKE_EVENT; | ||
| 9598 | read_socket_inev->code = code; | ||
| 9599 | read_socket_inev->modifiers = | ||
| 9600 | (extra_keyboard_modifiers | ||
| 9601 | & (meta_modifier | alt_modifier | ||
| 9602 | | hyper_modifier | super_modifier)); | ||
| 9603 | XSETFRAME (read_socket_inev->frame_or_window, f); | ||
| 9604 | } | ||
| 9605 | return eventNotHandledErr; | ||
| 9606 | } | ||
| 9607 | } | ||
| 9608 | } | ||
| 9609 | /* Non-ASCII keystrokes without mapped modifiers are processed | ||
| 9610 | at the Lisp level. */ | ||
| 9611 | id_key = Qunicode_for_key_event; | ||
| 9612 | num_params = sizeof (names_ufke) / sizeof (names_ufke[0]); | ||
| 9613 | names = names_ufke; | ||
| 9614 | types = types_ufke; | ||
| 9615 | break; | ||
| 9616 | |||
| 9617 | case kEventTextInputOffsetToPos: | ||
| 9618 | { | ||
| 9619 | struct frame *f; | ||
| 9620 | struct window *w; | ||
| 9621 | Point p; | ||
| 9622 | |||
| 9623 | if (!OVERLAYP (Vmac_ts_active_input_overlay)) | ||
| 9624 | return eventNotHandledErr; | ||
| 9625 | |||
| 9626 | /* Strictly speaking, this is not always correct because | ||
| 9627 | previous events may change some states about display. */ | ||
| 9628 | if (NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string))) | ||
| 9629 | { | ||
| 9630 | /* Active input area is displayed in the echo area. */ | ||
| 9631 | w = XWINDOW (echo_area_window); | ||
| 9632 | f = WINDOW_XFRAME (w); | ||
| 9633 | } | ||
| 9634 | else | ||
| 9635 | { | ||
| 9636 | /* Active input area is displayed around the current point. */ | ||
| 9637 | f = SELECTED_FRAME (); | ||
| 9638 | w = XWINDOW (f->selected_window); | ||
| 9639 | } | ||
| 9640 | |||
| 9641 | p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) | ||
| 9642 | + WINDOW_LEFT_FRINGE_WIDTH (w)); | ||
| 9643 | p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) | ||
| 9644 | + FONT_BASE (FRAME_FONT (f))); | ||
| 9645 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 9646 | LocalToGlobal (&p); | ||
| 9647 | err = SetEventParameter (event, kEventParamTextInputReplyPoint, | ||
| 9648 | typeQDPoint, sizeof (typeQDPoint), &p); | ||
| 9649 | } | ||
| 9650 | break; | ||
| 9651 | |||
| 9652 | default: | ||
| 9653 | abort (); | ||
| 9654 | } | ||
| 9655 | |||
| 9656 | if (!NILP (id_key)) | ||
| 9657 | err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, | ||
| 9658 | event, num_params, | ||
| 9659 | names, types); | ||
| 9660 | |||
| 9661 | return err == noErr ? noErr : result; | ||
| 9662 | } | ||
| 9663 | #endif | ||
| 9664 | |||
| 9419 | #ifdef MAC_OSX | 9665 | #ifdef MAC_OSX |
| 9420 | OSStatus | 9666 | OSStatus |
| 9421 | mac_store_service_event (event) | 9667 | mac_store_service_event (event) |
| @@ -9477,6 +9723,10 @@ install_window_handler (window) | |||
| 9477 | #ifdef MAC_OSX | 9723 | #ifdef MAC_OSX |
| 9478 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, | 9724 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, |
| 9479 | #endif | 9725 | #endif |
| 9726 | #if USE_MAC_TSM | ||
| 9727 | {kEventClassWindow, kEventWindowFocusAcquired}, | ||
| 9728 | {kEventClassWindow, kEventWindowFocusRelinquish}, | ||
| 9729 | #endif | ||
| 9480 | }; | 9730 | }; |
| 9481 | EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}}; | 9731 | EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}}; |
| 9482 | static EventHandlerUPP handle_window_eventUPP = NULL; | 9732 | static EventHandlerUPP handle_window_eventUPP = NULL; |
| @@ -9486,6 +9736,13 @@ install_window_handler (window) | |||
| 9486 | {kEventClassFont, kEventFontSelection}}; | 9736 | {kEventClassFont, kEventFontSelection}}; |
| 9487 | static EventHandlerUPP handle_font_eventUPP = NULL; | 9737 | static EventHandlerUPP handle_font_eventUPP = NULL; |
| 9488 | #endif | 9738 | #endif |
| 9739 | #if USE_MAC_TSM | ||
| 9740 | EventTypeSpec specs_text_input[] = | ||
| 9741 | {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, | ||
| 9742 | {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, | ||
| 9743 | {kEventClassTextInput, kEventTextInputOffsetToPos}}; | ||
| 9744 | static EventHandlerUPP handle_text_input_eventUPP = NULL; | ||
| 9745 | #endif | ||
| 9489 | 9746 | ||
| 9490 | if (handle_window_eventUPP == NULL) | 9747 | if (handle_window_eventUPP == NULL) |
| 9491 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); | 9748 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); |
| @@ -9495,6 +9752,11 @@ install_window_handler (window) | |||
| 9495 | if (handle_font_eventUPP == NULL) | 9752 | if (handle_font_eventUPP == NULL) |
| 9496 | handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event); | 9753 | handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event); |
| 9497 | #endif | 9754 | #endif |
| 9755 | #if USE_MAC_TSM | ||
| 9756 | if (handle_text_input_eventUPP == NULL) | ||
| 9757 | handle_text_input_eventUPP = | ||
| 9758 | NewEventHandlerUPP (mac_handle_text_input_event); | ||
| 9759 | #endif | ||
| 9498 | err = InstallWindowEventHandler (window, handle_window_eventUPP, | 9760 | err = InstallWindowEventHandler (window, handle_window_eventUPP, |
| 9499 | GetEventTypeCount (specs_window), | 9761 | GetEventTypeCount (specs_window), |
| 9500 | specs_window, NULL, NULL); | 9762 | specs_window, NULL, NULL); |
| @@ -9508,6 +9770,12 @@ install_window_handler (window) | |||
| 9508 | GetEventTypeCount (specs_font), | 9770 | GetEventTypeCount (specs_font), |
| 9509 | specs_font, NULL, NULL); | 9771 | specs_font, NULL, NULL); |
| 9510 | #endif | 9772 | #endif |
| 9773 | #if USE_MAC_TSM | ||
| 9774 | if (err == noErr) | ||
| 9775 | err = InstallWindowEventHandler (window, handle_text_input_eventUPP, | ||
| 9776 | GetEventTypeCount (specs_text_input), | ||
| 9777 | specs_text_input, window, NULL); | ||
| 9778 | #endif | ||
| 9511 | #endif | 9779 | #endif |
| 9512 | if (err == noErr) | 9780 | if (err == noErr) |
| 9513 | err = install_drag_handler (window); | 9781 | err = install_drag_handler (window); |
| @@ -9633,7 +9901,7 @@ static unsigned char keycode_to_xkeysym_table[] = { | |||
| 9633 | 9901 | ||
| 9634 | /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/, | 9902 | /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/, |
| 9635 | /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/, | 9903 | /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/, |
| 9636 | /*0x68*/ 0, 0xca /*f13*/, 0, 0xcb /*f14*/, | 9904 | /*0x68*/ 0, 0xca /*f13*/, 0xcd /*f16*/, 0xcb /*f14*/, |
| 9637 | /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/, | 9905 | /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/, |
| 9638 | 9906 | ||
| 9639 | /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/, | 9907 | /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/, |
| @@ -9650,7 +9918,13 @@ keycode_to_xkeysym (int keyCode, int *xKeySym) | |||
| 9650 | return *xKeySym != 0; | 9918 | return *xKeySym != 0; |
| 9651 | } | 9919 | } |
| 9652 | 9920 | ||
| 9653 | static unsigned char fn_keycode_to_xkeysym_table[] = { | 9921 | #ifdef MAC_OSX |
| 9922 | /* Table for translating Mac keycode with the laptop `fn' key to that | ||
| 9923 | without it. Destination symbols in comments are keys on US | ||
| 9924 | keyboard, and they may not be the same on other types of keyboards. | ||
| 9925 | If the destination is identical to the source (f1 ... f12), it | ||
| 9926 | doesn't map `fn' key to a modifier. */ | ||
| 9927 | static unsigned char fn_keycode_to_keycode_table[] = { | ||
| 9654 | /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 9928 | /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 9655 | /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 9929 | /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 9656 | /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 9930 | /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| @@ -9660,113 +9934,27 @@ static unsigned char fn_keycode_to_xkeysym_table[] = { | |||
| 9660 | /*0x38*/ 0, 0, 0, 0, | 9934 | /*0x38*/ 0, 0, 0, 0, |
| 9661 | /*0x3C*/ 0, 0, 0, 0, | 9935 | /*0x3C*/ 0, 0, 0, 0, |
| 9662 | 9936 | ||
| 9663 | /*0x40*/ 0, 0x2e /*kp-. = .*/, 0, 0x50 /*kp-* = 'p'*/, | 9937 | /*0x40*/ 0, 0x2f /*kp-. -> '.'*/, 0, 0x23 /*kp-* -> 'p'*/, |
| 9664 | /*0x44*/ 0, '/' /*kp-+*/, 0, 0, | 9938 | /*0x44*/ 0, 0x2c /*kp-+ -> '/'*/, 0, 0x16 /*clear -> '6'*/, |
| 9665 | /*0x48*/ 0, 0, 0, 0x30 /*kp-/ = '0'*/, | 9939 | /*0x48*/ 0, 0, 0, 0x1d /*kp-/ -> '0'*/, |
| 9666 | /*0x4C*/ 0, 0, 0x3b /*kp-- = ';'*/, 0, | 9940 | /*0x4C*/ 0x24 /*kp-enter -> return*/, 0, 0x29 /*kp-- -> ';'*/, 0, |
| 9667 | 9941 | ||
| 9668 | /*0x50*/ 0, 0x2d /*kp-= = '-'*/, 0x6d /*kp-0 = 'm'*/, 0x6a /*kp-1 = 'j'*/, | 9942 | /*0x50*/ 0, 0x1b /*kp-= -> '-'*/, 0x2e /*kp-0 -> 'm'*/, 0x26 /*kp-1 -> 'j'*/, |
| 9669 | /*0x54*/ 0x6b /*kp-2 = 'k'*/, 0x6c /*kp-3 = 'l'*/, 'u' /*kp-4*/, 'i' /*kp-5*/, | 9943 | /*0x54*/ 0x28 /*kp-2 -> 'k'*/, 0x25 /*kp-3 -> 'l'*/, 0x20 /*kp-4 -> 'u'*/, 0x22 /*kp-5 ->'i'*/, |
| 9670 | /*0x58*/ 'o' /*kp-6*/, '7' /*kp-7*/, 0, '8' /*kp-8*/, | 9944 | /*0x58*/ 0x1f /*kp-6 -> 'o'*/, 0x1a /*kp-7 -> '7'*/, 0, 0x1c /*kp-8 -> '8'*/, |
| 9671 | /*0x5C*/ '9' /*kp-9*/, 0, 0, 0, | 9945 | /*0x5C*/ 0x19 /*kp-9 -> '9'*/, 0, 0, 0, |
| 9672 | 9946 | ||
| 9673 | /*0x60*/ 0, 0, 0, 0, | 9947 | /*0x60*/ 0x60 /*f5 = f5*/, 0x61 /*f6 = f6*/, 0x62 /*f7 = f7*/, 0x63 /*f3 = f3*/, |
| 9674 | /*0x64*/ 0, 0, 0, 0, | 9948 | /*0x64*/ 0x64 /*f8 = f8*/, 0x65 /*f9 = f9*/, 0, 0x67 /*f11 = f11*/, |
| 9675 | /*0x68*/ 0, 0, 0, 0, | 9949 | /*0x68*/ 0, 0, 0, 0, |
| 9676 | /*0x6C*/ 0, 0, 0, 0, | 9950 | /*0x6C*/ 0, 0x6d /*f10 = f10*/, 0, 0x6f /*f12 = f12*/, |
| 9677 | 9951 | ||
| 9678 | /*0x70*/ 0, 0, 0, 0, | 9952 | /*0x70*/ 0, 0, 0, 0x7b /*home -> left*/, |
| 9679 | /*0x74*/ 0, 0, 0, 0, | 9953 | /*0x74*/ 0x7e /*pgup -> up*/, 0x33 /*delete -> backspace*/, 0x76 /*f4 = f4*/, 0x7c /*end -> right*/, |
| 9680 | /*0x78*/ 0, 0, 0, 0, | 9954 | /*0x78*/ 0x78 /*f2 = f2*/, 0x7d /*pgdown -> down*/, 0x7a /*f1 = f1*/, 0, |
| 9681 | /*0x7C*/ 0, 0, 0, 0 | 9955 | /*0x7C*/ 0, 0, 0, 0 |
| 9682 | }; | 9956 | }; |
| 9683 | static int | 9957 | #endif /* MAC_OSX */ |
| 9684 | convert_fn_keycode (EventRef eventRef, int keyCode, int *newCode) | ||
| 9685 | { | ||
| 9686 | #ifdef MAC_OSX | ||
| 9687 | /* Use the special map to translate keys when function modifier is | ||
| 9688 | to be caught. KeyTranslate can't be used in that case. | ||
| 9689 | We can't detect the function key using the input_event.modifiers, | ||
| 9690 | because this uses the high word of an UInt32. Therefore, | ||
| 9691 | we'll just read it out of the original eventRef. | ||
| 9692 | */ | ||
| 9693 | |||
| 9694 | |||
| 9695 | /* TODO / known issues | ||
| 9696 | |||
| 9697 | - Fn-Shift-j is regonized as Fn-j and not Fn-J. | ||
| 9698 | The above table always translates to lower characters. We need to use | ||
| 9699 | the KCHR keyboard resource (KeyTranslate() ) to map k->K and 8->*. | ||
| 9700 | |||
| 9701 | - The table is meant for English language keyboards, and it will work | ||
| 9702 | for many others with the exception of key combinations like Fn-ö on | ||
| 9703 | a German keyboard, which is currently mapped to Fn-;. | ||
| 9704 | How to solve this without keeping separate tables for all keyboards | ||
| 9705 | around? KeyTranslate isn't of much help here, as it only takes a 16-bit | ||
| 9706 | value for keycode with the modifiers in he high byte, i.e. no room for the | ||
| 9707 | Fn modifier. That's why we need the table. | ||
| 9708 | |||
| 9709 | */ | ||
| 9710 | OSStatus err; | ||
| 9711 | UInt32 mods = 0; | ||
| 9712 | if (!NILP(Vmac_function_modifier)) | ||
| 9713 | { | ||
| 9714 | err = GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, | ||
| 9715 | NULL, sizeof (UInt32), NULL, &mods); | ||
| 9716 | if (err != noErr && mods & kEventKeyModifierFnMask) | ||
| 9717 | { *newCode = fn_keycode_to_xkeysym_table [keyCode & 0x7f]; | ||
| 9718 | |||
| 9719 | return (*newCode != 0); | ||
| 9720 | } | ||
| 9721 | } | ||
| 9722 | #endif | ||
| 9723 | return false; | ||
| 9724 | } | ||
| 9725 | |||
| 9726 | static int | ||
| 9727 | backtranslate_modified_keycode(int mods, int keycode, int def) | ||
| 9728 | { | ||
| 9729 | EventModifiers mapped_modifiers = | ||
| 9730 | (NILP (Vmac_control_modifier) ? 0 : controlKey) | ||
| 9731 | | (NILP (Vmac_option_modifier) ? 0 : optionKey) | ||
| 9732 | | (NILP (Vmac_command_modifier) ? 0 : cmdKey); | ||
| 9733 | |||
| 9734 | if (mods & mapped_modifiers) | ||
| 9735 | { | ||
| 9736 | /* This code comes from Keyboard Resource, | ||
| 9737 | Appendix C of IM - Text. This is necessary | ||
| 9738 | since shift is ignored in KCHR table | ||
| 9739 | translation when option or command is pressed. | ||
| 9740 | It also does not translate correctly | ||
| 9741 | control-shift chars like C-% so mask off shift | ||
| 9742 | here also. | ||
| 9743 | |||
| 9744 | Not done for combinations with the option key (alt) | ||
| 9745 | unless it is to be caught by Emacs: this is | ||
| 9746 | to preserve key combinations translated by the OS | ||
| 9747 | such as Alt-3. | ||
| 9748 | */ | ||
| 9749 | /* Mask off modifier keys that are mapped to some Emacs | ||
| 9750 | modifiers. */ | ||
| 9751 | int new_modifiers = mods & ~mapped_modifiers; | ||
| 9752 | /* set high byte of keycode to modifier high byte*/ | ||
| 9753 | int new_keycode = keycode | new_modifiers; | ||
| 9754 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 9755 | unsigned long some_state = 0; | ||
| 9756 | return (int) KeyTranslate (kchr_ptr, new_keycode, | ||
| 9757 | &some_state) & 0xff; | ||
| 9758 | /* TO DO: Recognize two separate resulting characters, "for | ||
| 9759 | example, when the user presses Option-E followed by N, you | ||
| 9760 | can map this through the KeyTranslate function using the | ||
| 9761 | U.S. 'KCHR' resource to produce ´n, which KeyTranslate | ||
| 9762 | returns as two characters in the bytes labeled Character code | ||
| 9763 | 1 and Character code 2." (from Carbon API doc) */ | ||
| 9764 | |||
| 9765 | } | ||
| 9766 | else | ||
| 9767 | return def; | ||
| 9768 | } | ||
| 9769 | |||
| 9770 | 9958 | ||
| 9771 | #if !USE_CARBON_EVENTS | 9959 | #if !USE_CARBON_EVENTS |
| 9772 | static RgnHandle mouse_region = NULL; | 9960 | static RgnHandle mouse_region = NULL; |
| @@ -9840,6 +10028,44 @@ mac_post_mouse_moved_event () | |||
| 9840 | 10028 | ||
| 9841 | return err; | 10029 | return err; |
| 9842 | } | 10030 | } |
| 10031 | |||
| 10032 | static void | ||
| 10033 | mac_set_unicode_keystroke_event (code, buf) | ||
| 10034 | UniChar code; | ||
| 10035 | struct input_event *buf; | ||
| 10036 | { | ||
| 10037 | int charset_id, c1, c2; | ||
| 10038 | |||
| 10039 | if (code < 0x80) | ||
| 10040 | { | ||
| 10041 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 10042 | buf->code = code; | ||
| 10043 | } | ||
| 10044 | else if (code < 0x100) | ||
| 10045 | { | ||
| 10046 | if (code < 0xA0) | ||
| 10047 | charset_id = CHARSET_8_BIT_CONTROL; | ||
| 10048 | else | ||
| 10049 | charset_id = charset_latin_iso8859_1; | ||
| 10050 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10051 | buf->code = MAKE_CHAR (charset_id, code, 0); | ||
| 10052 | } | ||
| 10053 | else | ||
| 10054 | { | ||
| 10055 | if (code < 0x2500) | ||
| 10056 | charset_id = charset_mule_unicode_0100_24ff, | ||
| 10057 | code -= 0x100; | ||
| 10058 | else if (code < 0x33FF) | ||
| 10059 | charset_id = charset_mule_unicode_2500_33ff, | ||
| 10060 | code -= 0x2500; | ||
| 10061 | else if (code >= 0xE000) | ||
| 10062 | charset_id = charset_mule_unicode_e000_ffff, | ||
| 10063 | code -= 0xE000; | ||
| 10064 | c1 = (code / 96) + 32, c2 = (code % 96) + 32; | ||
| 10065 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10066 | buf->code = MAKE_CHAR (charset_id, c1, c2); | ||
| 10067 | } | ||
| 10068 | } | ||
| 9843 | #endif | 10069 | #endif |
| 9844 | 10070 | ||
| 9845 | /* Emacs calls this whenever it wants to read an input event from the | 10071 | /* Emacs calls this whenever it wants to read an input event from the |
| @@ -9889,10 +10115,6 @@ XTread_socket (sd, expected, hold_quit) | |||
| 9889 | struct frame *f; | 10115 | struct frame *f; |
| 9890 | unsigned long timestamp; | 10116 | unsigned long timestamp; |
| 9891 | 10117 | ||
| 9892 | /* It is necessary to set this (additional) argument slot of an | ||
| 9893 | event to nil because keyboard.c protects incompletely | ||
| 9894 | processed event from being garbage collected by placing them | ||
| 9895 | in the kbd_buffer_gcpro vector. */ | ||
| 9896 | EVENT_INIT (inev); | 10118 | EVENT_INIT (inev); |
| 9897 | inev.kind = NO_EVENT; | 10119 | inev.kind = NO_EVENT; |
| 9898 | inev.arg = Qnil; | 10120 | inev.arg = Qnil; |
| @@ -10354,10 +10576,29 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10354 | break; | 10576 | break; |
| 10355 | 10577 | ||
| 10356 | case keyDown: | 10578 | case keyDown: |
| 10579 | case keyUp: | ||
| 10357 | case autoKey: | 10580 | case autoKey: |
| 10358 | { | 10581 | { |
| 10359 | int keycode = (er.message & keyCodeMask) >> 8; | 10582 | int keycode = (er.message & keyCodeMask) >> 8; |
| 10360 | int xkeysym; | 10583 | int xkeysym; |
| 10584 | static SInt16 last_key_script = -1; | ||
| 10585 | SInt16 current_key_script; | ||
| 10586 | UInt32 modifiers = er.modifiers, mapped_modifiers; | ||
| 10587 | |||
| 10588 | mapped_modifiers = | ||
| 10589 | (NILP (Vmac_control_modifier) ? 0 : controlKey) | ||
| 10590 | | (NILP (Vmac_option_modifier) ? 0 : optionKey) | ||
| 10591 | | (NILP (Vmac_command_modifier) ? 0 : cmdKey); | ||
| 10592 | |||
| 10593 | #if USE_CARBON_EVENTS && defined (MAC_OSX) | ||
| 10594 | mapped_modifiers |= | ||
| 10595 | (NILP (Vmac_function_modifier) ? 0 : kEventKeyModifierFnMask); | ||
| 10596 | |||
| 10597 | GetEventParameter (eventRef, kEventParamKeyModifiers, | ||
| 10598 | typeUInt32, NULL, | ||
| 10599 | sizeof (UInt32), NULL, &modifiers); | ||
| 10600 | #endif | ||
| 10601 | mapped_modifiers &= modifiers; | ||
| 10361 | 10602 | ||
| 10362 | #if USE_CARBON_EVENTS && defined (MAC_OSX) | 10603 | #if USE_CARBON_EVENTS && defined (MAC_OSX) |
| 10363 | /* When using Carbon Events, we need to pass raw keyboard | 10604 | /* When using Carbon Events, we need to pass raw keyboard |
| @@ -10365,45 +10606,21 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10365 | will pass back noErr, otherwise it will pass back | 10606 | will pass back noErr, otherwise it will pass back |
| 10366 | "eventNotHandledErr" and we can process it | 10607 | "eventNotHandledErr" and we can process it |
| 10367 | normally. */ | 10608 | normally. */ |
| 10368 | if ((mac_pass_command_to_system | 10609 | if (!(mapped_modifiers |
| 10369 | || !(er.modifiers & cmdKey)) | 10610 | & ~(mac_pass_command_to_system ? cmdKey : 0) |
| 10370 | && (mac_pass_control_to_system | 10611 | & ~(mac_pass_control_to_system ? controlKey : 0))) |
| 10371 | || !(er.modifiers & controlKey)) | ||
| 10372 | && (NILP (Vmac_option_modifier) | ||
| 10373 | || !(er.modifiers & optionKey))) | ||
| 10374 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 10375 | != eventNotHandledErr) | ||
| 10376 | break; | ||
| 10377 | #endif | ||
| 10378 | |||
| 10379 | #if 0 | ||
| 10380 | if (dpyinfo->x_focus_frame == NULL) | ||
| 10381 | { | 10612 | { |
| 10382 | /* Beep if keyboard input occurs when all the frames | 10613 | OSStatus err; |
| 10383 | are invisible. */ | 10614 | |
| 10384 | SysBeep (1); | 10615 | read_socket_inev = &inev; |
| 10385 | break; | 10616 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); |
| 10617 | read_socket_inev = NULL; | ||
| 10618 | if (err != eventNotHandledErr) | ||
| 10619 | break; | ||
| 10386 | } | 10620 | } |
| 10387 | #endif | 10621 | #endif |
| 10388 | 10622 | if (er.what == keyUp) | |
| 10389 | { | 10623 | break; |
| 10390 | static SInt16 last_key_script = -1; | ||
| 10391 | SInt16 current_key_script = GetScriptManagerVariable (smKeyScript); | ||
| 10392 | |||
| 10393 | if (last_key_script != current_key_script) | ||
| 10394 | { | ||
| 10395 | struct input_event event; | ||
| 10396 | |||
| 10397 | EVENT_INIT (event); | ||
| 10398 | event.kind = LANGUAGE_CHANGE_EVENT; | ||
| 10399 | event.arg = Qnil; | ||
| 10400 | event.code = current_key_script; | ||
| 10401 | event.timestamp = timestamp; | ||
| 10402 | kbd_buffer_store_event (&event); | ||
| 10403 | count++; | ||
| 10404 | } | ||
| 10405 | last_key_script = current_key_script; | ||
| 10406 | } | ||
| 10407 | 10624 | ||
| 10408 | ObscureCursor (); | 10625 | ObscureCursor (); |
| 10409 | 10626 | ||
| @@ -10416,51 +10633,163 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10416 | dpyinfo->mouse_face_hidden = 1; | 10633 | dpyinfo->mouse_face_hidden = 1; |
| 10417 | } | 10634 | } |
| 10418 | 10635 | ||
| 10419 | /* translate the keycode back to determine the original key */ | 10636 | current_key_script = GetScriptManagerVariable (smKeyScript); |
| 10420 | /* Convert key code if function key is pressed. | 10637 | if (last_key_script != current_key_script) |
| 10421 | Otherwise, if non-ASCII-event, take care of that | ||
| 10422 | without re-translating the key code. */ | ||
| 10423 | #if USE_CARBON_EVENTS | ||
| 10424 | if (convert_fn_keycode (eventRef, keycode, &xkeysym)) | ||
| 10425 | { | 10638 | { |
| 10426 | inev.code = xkeysym; | 10639 | struct input_event event; |
| 10427 | /* this doesn't work - tried to add shift modifiers */ | 10640 | |
| 10428 | inev.code = | 10641 | EVENT_INIT (event); |
| 10429 | backtranslate_modified_keycode(er.modifiers & (~0x2200), | 10642 | event.kind = LANGUAGE_CHANGE_EVENT; |
| 10430 | xkeysym | 0x80, xkeysym); | 10643 | event.arg = Qnil; |
| 10431 | inev.kind = ASCII_KEYSTROKE_EVENT; | 10644 | event.code = current_key_script; |
| 10645 | event.timestamp = timestamp; | ||
| 10646 | kbd_buffer_store_event (&event); | ||
| 10647 | count++; | ||
| 10648 | last_key_script = current_key_script; | ||
| 10432 | } | 10649 | } |
| 10433 | else | 10650 | |
| 10651 | #if USE_MAC_TSM | ||
| 10652 | if (inev.kind != NO_EVENT) | ||
| 10653 | break; | ||
| 10434 | #endif | 10654 | #endif |
| 10435 | if (keycode_to_xkeysym (keycode, &xkeysym)) | ||
| 10436 | { | ||
| 10437 | inev.code = 0xff00 | xkeysym; | ||
| 10438 | inev.kind = NON_ASCII_KEYSTROKE_EVENT; | ||
| 10439 | } | ||
| 10440 | else | ||
| 10441 | { | ||
| 10442 | inev.code = | ||
| 10443 | backtranslate_modified_keycode(er.modifiers, keycode, | ||
| 10444 | er.message & charCodeMask); | ||
| 10445 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 10446 | } | ||
| 10447 | } | ||
| 10448 | 10655 | ||
| 10449 | #if USE_CARBON_EVENTS | 10656 | #ifdef MAC_OSX |
| 10450 | inev.modifiers = mac_event_to_emacs_modifiers (eventRef); | 10657 | if (mapped_modifiers & kEventKeyModifierFnMask |
| 10451 | #else | 10658 | && keycode <= 0x7f |
| 10452 | inev.modifiers = mac_to_emacs_modifiers (er.modifiers); | 10659 | && fn_keycode_to_keycode_table[keycode]) |
| 10660 | keycode = fn_keycode_to_keycode_table[keycode]; | ||
| 10453 | #endif | 10661 | #endif |
| 10454 | inev.modifiers |= (extra_keyboard_modifiers | 10662 | if (keycode_to_xkeysym (keycode, &xkeysym)) |
| 10455 | & (meta_modifier | alt_modifier | 10663 | { |
| 10456 | | hyper_modifier | super_modifier)); | 10664 | inev.kind = NON_ASCII_KEYSTROKE_EVENT; |
| 10457 | XSETFRAME (inev.frame_or_window, f); | 10665 | inev.code = 0xff00 | xkeysym; |
| 10666 | #ifdef MAC_OSX | ||
| 10667 | if (modifiers & kEventKeyModifierFnMask | ||
| 10668 | && keycode <= 0x7f | ||
| 10669 | && fn_keycode_to_keycode_table[keycode] == keycode) | ||
| 10670 | modifiers &= ~kEventKeyModifierFnMask; | ||
| 10671 | #endif | ||
| 10672 | } | ||
| 10673 | else if (mapped_modifiers) | ||
| 10674 | { | ||
| 10675 | /* translate the keycode back to determine the | ||
| 10676 | original key */ | ||
| 10677 | #ifdef MAC_OSX | ||
| 10678 | static SInt16 last_key_layout_id = 0; | ||
| 10679 | static Handle uchr_handle = (Handle)-1; | ||
| 10680 | SInt16 current_key_layout_id = | ||
| 10681 | GetScriptVariable (current_key_script, smScriptKeys); | ||
| 10682 | |||
| 10683 | if (uchr_handle == (Handle)-1 | ||
| 10684 | || last_key_layout_id != current_key_layout_id) | ||
| 10685 | { | ||
| 10686 | uchr_handle = GetResource ('uchr', current_key_layout_id); | ||
| 10687 | last_key_layout_id = current_key_layout_id; | ||
| 10688 | } | ||
| 10689 | |||
| 10690 | if (uchr_handle) | ||
| 10691 | { | ||
| 10692 | OSStatus status; | ||
| 10693 | UInt16 key_action = er.what - keyDown; | ||
| 10694 | UInt32 modifier_key_state = | ||
| 10695 | (modifiers & ~mapped_modifiers) >> 8; | ||
| 10696 | UInt32 keyboard_type = LMGetKbdType (); | ||
| 10697 | SInt32 dead_key_state = 0; | ||
| 10698 | UniChar code; | ||
| 10699 | UniCharCount actual_length; | ||
| 10700 | |||
| 10701 | status = UCKeyTranslate ((UCKeyboardLayout *)*uchr_handle, | ||
| 10702 | keycode, key_action, | ||
| 10703 | modifier_key_state, | ||
| 10704 | keyboard_type, | ||
| 10705 | kUCKeyTranslateNoDeadKeysMask, | ||
| 10706 | &dead_key_state, | ||
| 10707 | 1, &actual_length, &code); | ||
| 10708 | if (status == noErr && actual_length == 1) | ||
| 10709 | mac_set_unicode_keystroke_event (code, &inev); | ||
| 10710 | } | ||
| 10711 | #endif /* MAC_OSX */ | ||
| 10712 | |||
| 10713 | if (inev.kind == NO_EVENT) | ||
| 10714 | { | ||
| 10715 | /* This code comes from Keyboard Resource, | ||
| 10716 | Appendix C of IM - Text. This is necessary | ||
| 10717 | since shift is ignored in KCHR table | ||
| 10718 | translation when option or command is pressed. | ||
| 10719 | It also does not translate correctly | ||
| 10720 | control-shift chars like C-% so mask off shift | ||
| 10721 | here also. */ | ||
| 10722 | /* Mask off modifier keys that are mapped to some | ||
| 10723 | Emacs modifiers. */ | ||
| 10724 | int new_modifiers = er.modifiers & ~mapped_modifiers; | ||
| 10725 | /* set high byte of keycode to modifier high byte*/ | ||
| 10726 | int new_keycode = keycode | new_modifiers; | ||
| 10727 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 10728 | unsigned long some_state = 0; | ||
| 10729 | UInt32 new_char_code; | ||
| 10730 | |||
| 10731 | new_char_code = KeyTranslate (kchr_ptr, new_keycode, | ||
| 10732 | &some_state); | ||
| 10733 | if (new_char_code == 0) | ||
| 10734 | /* Seems like a dead key. Append up-stroke. */ | ||
| 10735 | new_char_code = KeyTranslate (kchr_ptr, | ||
| 10736 | new_keycode | 0x80, | ||
| 10737 | &some_state); | ||
| 10738 | if (new_char_code) | ||
| 10739 | { | ||
| 10740 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 10741 | inev.code = new_char_code & 0xff; | ||
| 10742 | } | ||
| 10743 | } | ||
| 10744 | } | ||
| 10745 | |||
| 10746 | if (inev.kind == NO_EVENT) | ||
| 10747 | { | ||
| 10748 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 10749 | inev.code = er.message & charCodeMask; | ||
| 10750 | } | ||
| 10751 | |||
| 10752 | inev.modifiers = mac_to_emacs_modifiers (modifiers); | ||
| 10753 | inev.modifiers |= (extra_keyboard_modifiers | ||
| 10754 | & (meta_modifier | alt_modifier | ||
| 10755 | | hyper_modifier | super_modifier)); | ||
| 10756 | XSETFRAME (inev.frame_or_window, f); | ||
| 10757 | |||
| 10758 | #if TARGET_API_MAC_CARBON | ||
| 10759 | if (inev.kind == ASCII_KEYSTROKE_EVENT | ||
| 10760 | && inev.code >= 0x80 && inev.modifiers) | ||
| 10761 | { | ||
| 10762 | OSStatus err; | ||
| 10763 | TextEncoding encoding = kTextEncodingMacRoman; | ||
| 10764 | TextToUnicodeInfo ttu_info; | ||
| 10765 | |||
| 10766 | UpgradeScriptInfoToTextEncoding (current_key_script, | ||
| 10767 | kTextLanguageDontCare, | ||
| 10768 | kTextRegionDontCare, | ||
| 10769 | NULL, &encoding); | ||
| 10770 | err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info); | ||
| 10771 | if (err == noErr) | ||
| 10772 | { | ||
| 10773 | UniChar code; | ||
| 10774 | Str255 pstr; | ||
| 10775 | ByteCount unicode_len; | ||
| 10776 | |||
| 10777 | pstr[0] = 1; | ||
| 10778 | pstr[1] = inev.code; | ||
| 10779 | err = ConvertFromPStringToUnicode (ttu_info, pstr, | ||
| 10780 | sizeof (UniChar), | ||
| 10781 | &unicode_len, &code); | ||
| 10782 | if (err == noErr && unicode_len == sizeof (UniChar)) | ||
| 10783 | mac_set_unicode_keystroke_event (code, &inev); | ||
| 10784 | DisposeTextToUnicodeInfo (&ttu_info); | ||
| 10785 | } | ||
| 10786 | } | ||
| 10787 | #endif | ||
| 10788 | } | ||
| 10458 | break; | 10789 | break; |
| 10459 | 10790 | ||
| 10460 | case kHighLevelEvent: | 10791 | case kHighLevelEvent: |
| 10461 | read_socket_inev = &inev; | ||
| 10462 | AEProcessAppleEvent (&er); | 10792 | AEProcessAppleEvent (&er); |
| 10463 | read_socket_inev = NULL; | ||
| 10464 | break; | 10793 | break; |
| 10465 | 10794 | ||
| 10466 | default: | 10795 | default: |
| @@ -10932,6 +11261,16 @@ init_menu_bar () | |||
| 10932 | #endif | 11261 | #endif |
| 10933 | } | 11262 | } |
| 10934 | 11263 | ||
| 11264 | #if USE_MAC_TSM | ||
| 11265 | static void | ||
| 11266 | init_tsm () | ||
| 11267 | { | ||
| 11268 | static InterfaceTypeList types = {kUnicodeDocument}; | ||
| 11269 | |||
| 11270 | NewTSMDocument (sizeof (types) / sizeof (types[0]), types, | ||
| 11271 | &tsm_document_id, 0); | ||
| 11272 | } | ||
| 11273 | #endif | ||
| 10935 | 11274 | ||
| 10936 | /* Set up use of X before we make the first connection. */ | 11275 | /* Set up use of X before we make the first connection. */ |
| 10937 | 11276 | ||
| @@ -11026,6 +11365,10 @@ mac_initialize () | |||
| 11026 | init_command_handler (); | 11365 | init_command_handler (); |
| 11027 | 11366 | ||
| 11028 | init_menu_bar (); | 11367 | init_menu_bar (); |
| 11368 | |||
| 11369 | #if USE_MAC_TSM | ||
| 11370 | init_tsm (); | ||
| 11371 | #endif | ||
| 11029 | #endif /* USE_CARBON_EVENTS */ | 11372 | #endif /* USE_CARBON_EVENTS */ |
| 11030 | 11373 | ||
| 11031 | #ifdef MAC_OSX | 11374 | #ifdef MAC_OSX |
| @@ -11082,6 +11425,13 @@ syms_of_macterm () | |||
| 11082 | Qpaste = intern ("paste"); staticpro (&Qpaste); | 11425 | Qpaste = intern ("paste"); staticpro (&Qpaste); |
| 11083 | Qperform = intern ("perform"); staticpro (&Qperform); | 11426 | Qperform = intern ("perform"); staticpro (&Qperform); |
| 11084 | #endif | 11427 | #endif |
| 11428 | #if USE_MAC_TSM | ||
| 11429 | Qtext_input = intern ("text-input"); staticpro (&Qtext_input); | ||
| 11430 | Qupdate_active_input_area = intern ("update-active-input-area"); | ||
| 11431 | staticpro (&Qupdate_active_input_area); | ||
| 11432 | Qunicode_for_key_event = intern ("unicode-for-key-event"); | ||
| 11433 | staticpro (&Qunicode_for_key_event); | ||
| 11434 | #endif | ||
| 11085 | #endif | 11435 | #endif |
| 11086 | 11436 | ||
| 11087 | #ifdef MAC_OSX | 11437 | #ifdef MAC_OSX |
| @@ -11224,6 +11574,11 @@ order. */); | |||
| 11224 | make_float (DEFAULT_REHASH_THRESHOLD), | 11574 | make_float (DEFAULT_REHASH_THRESHOLD), |
| 11225 | Qnil, Qnil, Qnil); | 11575 | Qnil, Qnil, Qnil); |
| 11226 | #endif | 11576 | #endif |
| 11577 | #if USE_MAC_TSM | ||
| 11578 | DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay, | ||
| 11579 | doc: /* Overlay used to display Mac TSM active input area. */); | ||
| 11580 | Vmac_ts_active_input_overlay = Qnil; | ||
| 11581 | #endif | ||
| 11227 | } | 11582 | } |
| 11228 | 11583 | ||
| 11229 | /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b | 11584 | /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b |