diff options
| author | Po Lu | 2023-05-07 11:09:56 +0800 |
|---|---|---|
| committer | Po Lu | 2023-05-07 11:09:56 +0800 |
| commit | 889b61b99918d1c6313d4f884de2e2cb3ab466c9 (patch) | |
| tree | 963ea5823611ecc74a62098c1d37a378e2bfd83d /src/androidterm.c | |
| parent | c0a52c6cef77b8bc83e9d373ac0d0899c93f7a37 (diff) | |
| download | emacs-889b61b99918d1c6313d4f884de2e2cb3ab466c9.tar.gz emacs-889b61b99918d1c6313d4f884de2e2cb3ab466c9.zip | |
Update Android port
* java/org/gnu/emacs/EmacsInputConnection.java
(requestCursorUpdates):
* java/org/gnu/emacs/EmacsNative.java (requestCursorUpdates):
* java/org/gnu/emacs/EmacsService.java (updateCursorAnchorInfo):
New functions.
* src/android.c (struct android_emacs_service)
(android_init_emacs_service): Add new method.
(android_update_cursor_anchor_info): New function.
* src/androidfns.c (android_set_preeditarea): New function.
* src/androidgui.h (enum android_ime_operation): New operation
`REQUEST_CURSOR_UPDATES'.
(struct android_ime_event): Document new meaning of `length'.
* src/androidterm.c (android_request_cursor_updates): New
function.
(android_handle_ime_event): Handle new operations.
(handle_one_android_event, android_draw_window_cursor): Update
the preedit area if needed, like on X.
(requestCursorUpdates): New function.
* src/androidterm.h (struct android_output): New field
`need_cursor_updates'.
Diffstat (limited to 'src/androidterm.c')
| -rw-r--r-- | src/androidterm.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/androidterm.c b/src/androidterm.c index 8ba7fb6a798..6f7c06875ca 100644 --- a/src/androidterm.c +++ b/src/androidterm.c | |||
| @@ -632,6 +632,40 @@ android_decode_utf16 (unsigned short *utf16, size_t n) | |||
| 632 | return coding.dst_object; | 632 | return coding.dst_object; |
| 633 | } | 633 | } |
| 634 | 634 | ||
| 635 | /* Handle a cursor update request for F from the input method. | ||
| 636 | MODE specifies whether or not an update should be sent immediately, | ||
| 637 | and whether or not they are needed in the future. | ||
| 638 | |||
| 639 | If MODE & ANDROID_CURSOR_UPDATE_IMMEDIATE, report the position of | ||
| 640 | F's old selected window's phys cursor now. | ||
| 641 | |||
| 642 | If MODE & ANDROID_CURSOR_UPDATE_MONITOR, set | ||
| 643 | `need_cursor_updates'. */ | ||
| 644 | |||
| 645 | static void | ||
| 646 | android_request_cursor_updates (struct frame *f, int mode) | ||
| 647 | { | ||
| 648 | struct window *w; | ||
| 649 | |||
| 650 | if (mode & ANDROID_CURSOR_UPDATE_IMMEDIATE | ||
| 651 | && WINDOWP (WINDOW_LIVE_P (f->old_selected_window) | ||
| 652 | ? f->old_selected_window | ||
| 653 | : f->selected_window)) | ||
| 654 | { | ||
| 655 | /* Prefer the old selected window, as its selection is what was | ||
| 656 | reported to the IME previously. */ | ||
| 657 | |||
| 658 | w = XWINDOW (WINDOW_LIVE_P (f->old_selected_window) | ||
| 659 | ? f->old_selected_window | ||
| 660 | : f->selected_window); | ||
| 661 | android_set_preeditarea (w, w->cursor.x, w->cursor.y); | ||
| 662 | } | ||
| 663 | |||
| 664 | /* Now say whether or not updates are needed in the future. */ | ||
| 665 | FRAME_OUTPUT_DATA (f)->need_cursor_updates | ||
| 666 | = (mode & ANDROID_CURSOR_UPDATE_MONITOR); | ||
| 667 | } | ||
| 668 | |||
| 635 | /* Handle a single input method event EVENT, delivered to the frame | 669 | /* Handle a single input method event EVENT, delivered to the frame |
| 636 | F. | 670 | F. |
| 637 | 671 | ||
| @@ -705,6 +739,10 @@ android_handle_ime_event (union android_event *event, struct frame *f) | |||
| 705 | case ANDROID_IME_REQUEST_SELECTION_UPDATE: | 739 | case ANDROID_IME_REQUEST_SELECTION_UPDATE: |
| 706 | request_point_update (f, event->ime.counter); | 740 | request_point_update (f, event->ime.counter); |
| 707 | break; | 741 | break; |
| 742 | |||
| 743 | case ANDROID_IME_REQUEST_CURSOR_UPDATES: | ||
| 744 | android_request_cursor_updates (f, event->ime.length); | ||
| 745 | break; | ||
| 708 | } | 746 | } |
| 709 | } | 747 | } |
| 710 | 748 | ||
| @@ -724,6 +762,7 @@ handle_one_android_event (struct android_display_info *dpyinfo, | |||
| 724 | double scroll_unit; | 762 | double scroll_unit; |
| 725 | int keysym; | 763 | int keysym; |
| 726 | ptrdiff_t nchars, i; | 764 | ptrdiff_t nchars, i; |
| 765 | struct window *w; | ||
| 727 | 766 | ||
| 728 | /* It is okay for this to not resemble handle_one_xevent so much. | 767 | /* It is okay for this to not resemble handle_one_xevent so much. |
| 729 | Differences in event handling code are much less nasty than | 768 | Differences in event handling code are much less nasty than |
| @@ -812,6 +851,12 @@ handle_one_android_event (struct android_display_info *dpyinfo, | |||
| 812 | inev.ie.kind = MOVE_FRAME_EVENT; | 851 | inev.ie.kind = MOVE_FRAME_EVENT; |
| 813 | XSETFRAME (inev.ie.frame_or_window, f); | 852 | XSETFRAME (inev.ie.frame_or_window, f); |
| 814 | } | 853 | } |
| 854 | |||
| 855 | if (f && FRAME_OUTPUT_DATA (f)->need_cursor_updates) | ||
| 856 | { | ||
| 857 | w = XWINDOW (f->selected_window); | ||
| 858 | android_set_preeditarea (w, w->cursor.x, w->cursor.y); | ||
| 859 | } | ||
| 815 | } | 860 | } |
| 816 | 861 | ||
| 817 | goto OTHER; | 862 | goto OTHER; |
| @@ -954,6 +999,16 @@ handle_one_android_event (struct android_display_info *dpyinfo, | |||
| 954 | goto done_keysym; | 999 | goto done_keysym; |
| 955 | 1000 | ||
| 956 | done_keysym: | 1001 | done_keysym: |
| 1002 | |||
| 1003 | /* Now proceed to tell the input method the current position of | ||
| 1004 | the cursor, if required. */ | ||
| 1005 | |||
| 1006 | if (f && FRAME_OUTPUT_DATA (f)->need_cursor_updates) | ||
| 1007 | { | ||
| 1008 | w = XWINDOW (f->selected_window); | ||
| 1009 | android_set_preeditarea (w, w->cursor.x, w->cursor.y); | ||
| 1010 | } | ||
| 1011 | |||
| 957 | goto OTHER; | 1012 | goto OTHER; |
| 958 | 1013 | ||
| 959 | case ANDROID_FOCUS_IN: | 1014 | case ANDROID_FOCUS_IN: |
| @@ -4321,6 +4376,10 @@ android_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, | |||
| 4321 | int x, int y, enum text_cursor_kinds cursor_type, | 4376 | int x, int y, enum text_cursor_kinds cursor_type, |
| 4322 | int cursor_width, bool on_p, bool active_p) | 4377 | int cursor_width, bool on_p, bool active_p) |
| 4323 | { | 4378 | { |
| 4379 | struct frame *f; | ||
| 4380 | |||
| 4381 | f = WINDOW_XFRAME (w); | ||
| 4382 | |||
| 4324 | if (on_p) | 4383 | if (on_p) |
| 4325 | { | 4384 | { |
| 4326 | w->phys_cursor_type = cursor_type; | 4385 | w->phys_cursor_type = cursor_type; |
| @@ -4362,6 +4421,13 @@ android_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, | |||
| 4362 | emacs_abort (); | 4421 | emacs_abort (); |
| 4363 | } | 4422 | } |
| 4364 | } | 4423 | } |
| 4424 | |||
| 4425 | /* Now proceed to tell the input method the current position of | ||
| 4426 | the cursor, if required. */ | ||
| 4427 | |||
| 4428 | if (FRAME_OUTPUT_DATA (f)->need_cursor_updates | ||
| 4429 | && w == XWINDOW (f->selected_window)) | ||
| 4430 | android_set_preeditarea (w, x, y); | ||
| 4365 | } | 4431 | } |
| 4366 | } | 4432 | } |
| 4367 | 4433 | ||
| @@ -5404,6 +5470,28 @@ NATIVE_NAME (requestSelectionUpdate) (JNIEnv *env, jobject object, | |||
| 5404 | android_write_event (&event); | 5470 | android_write_event (&event); |
| 5405 | } | 5471 | } |
| 5406 | 5472 | ||
| 5473 | JNIEXPORT void JNICALL | ||
| 5474 | NATIVE_NAME (requestCursorUpdates) (JNIEnv *env, jobject object, | ||
| 5475 | jshort window, jint mode) | ||
| 5476 | { | ||
| 5477 | JNI_STACK_ALIGNMENT_PROLOGUE; | ||
| 5478 | |||
| 5479 | union android_event event; | ||
| 5480 | |||
| 5481 | event.ime.type = ANDROID_INPUT_METHOD; | ||
| 5482 | event.ime.serial = ++event_serial; | ||
| 5483 | event.ime.window = window; | ||
| 5484 | event.ime.operation = ANDROID_IME_REQUEST_CURSOR_UPDATES; | ||
| 5485 | event.ime.start = 0; | ||
| 5486 | event.ime.end = 0; | ||
| 5487 | event.ime.length = mode; | ||
| 5488 | event.ime.position = 0; | ||
| 5489 | event.ime.text = NULL; | ||
| 5490 | event.ime.counter = ++edit_counter; | ||
| 5491 | |||
| 5492 | android_write_event (&event); | ||
| 5493 | } | ||
| 5494 | |||
| 5407 | #ifdef __clang__ | 5495 | #ifdef __clang__ |
| 5408 | #pragma clang diagnostic pop | 5496 | #pragma clang diagnostic pop |
| 5409 | #else | 5497 | #else |