aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-03-12 19:36:09 +0800
committerPo Lu2023-03-12 19:36:09 +0800
commit776f1ca3e3551b98569ab7daa58cd6921048881e (patch)
tree641b5e5790ebffc1f9caf313caee4a0443d5e92e /src
parent82b4b9e8692c349a45d319fe05c9fbfed4ab203d (diff)
downloademacs-776f1ca3e3551b98569ab7daa58cd6921048881e.tar.gz
emacs-776f1ca3e3551b98569ab7daa58cd6921048881e.zip
Update Android port
* src/android.c (android_check_if_event): * src/androidgui.h: New function. * src/androidterm.c (android_event_is_for_frame): New function. (android_reset_conversion): Free and unqueue all text conversion events for the given frame.
Diffstat (limited to 'src')
-rw-r--r--src/android.c34
-rw-r--r--src/androidgui.h4
-rw-r--r--src/androidterm.c35
3 files changed, 73 insertions, 0 deletions
diff --git a/src/android.c b/src/android.c
index e4f9dd0ffbe..a2c239736a7 100644
--- a/src/android.c
+++ b/src/android.c
@@ -601,6 +601,40 @@ android_next_event (union android_event *event_return)
601 pthread_mutex_unlock (&event_queue.mutex); 601 pthread_mutex_unlock (&event_queue.mutex);
602} 602}
603 603
604bool
605android_check_if_event (union android_event *event_return,
606 bool (*predicate) (union android_event *,
607 void *),
608 void *arg)
609{
610 struct android_event_container *container;
611
612 pthread_mutex_lock (&event_queue.mutex);
613
614 /* Loop over each event. */
615 container = event_queue.events.last;
616 for (; container != &event_queue.events; container = container->last)
617 {
618 /* See if the predicate matches. */
619 if ((*predicate) (&container->event, arg))
620 {
621 /* Copy out the event and return true. */
622 *event_return = container->event;
623 --event_queue.num_events;
624
625 /* Unlink container. */
626 container->last->next = container->next;
627 container->next->last = container->last;
628 free (container);
629 pthread_mutex_unlock (&event_queue.mutex);
630 return true;
631 }
632 }
633
634 pthread_mutex_unlock (&event_queue.mutex);
635 return false;
636}
637
604void 638void
605android_write_event (union android_event *event) 639android_write_event (union android_event *event)
606{ 640{
diff --git a/src/androidgui.h b/src/androidgui.h
index 0e311b629c6..ddd8e9fcf72 100644
--- a/src/androidgui.h
+++ b/src/androidgui.h
@@ -524,6 +524,10 @@ enum android_ic_mode
524 524
525extern int android_pending (void); 525extern int android_pending (void);
526extern void android_next_event (union android_event *); 526extern void android_next_event (union android_event *);
527extern bool android_check_if_event (union android_event *,
528 bool (*) (union android_event *,
529 void *),
530 void *);
527 531
528extern android_window android_create_window (android_window, int, 532extern android_window android_create_window (android_window, int,
529 int, int, int, 533 int, int, int,
diff --git a/src/androidterm.c b/src/androidterm.c
index ed375ef53fe..72d81744128 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -5474,6 +5474,19 @@ android_update_selection (struct frame *f, struct window *w)
5474 } 5474 }
5475} 5475}
5476 5476
5477/* Return whether or not EVENT is an input method event destined for
5478 the frame (struct frame *) ARG. */
5479
5480static bool
5481android_event_is_for_frame (union android_event *event, void *arg)
5482{
5483 struct frame *f;
5484
5485 f = arg;
5486 return (event->type == ANDROID_INPUT_METHOD
5487 && event->ime.window == FRAME_ANDROID_WINDOW (f));
5488}
5489
5477/* Notice that the input method connection to F should be reset as a 5490/* Notice that the input method connection to F should be reset as a
5478 result of a change to its contents. */ 5491 result of a change to its contents. */
5479 5492
@@ -5484,6 +5497,7 @@ android_reset_conversion (struct frame *f)
5484 struct window *w; 5497 struct window *w;
5485 struct buffer *buffer; 5498 struct buffer *buffer;
5486 Lisp_Object style; 5499 Lisp_Object style;
5500 union android_event event;
5487 5501
5488 /* Reset the input method. 5502 /* Reset the input method.
5489 5503
@@ -5507,6 +5521,27 @@ android_reset_conversion (struct frame *f)
5507 else 5521 else
5508 mode = ANDROID_IC_MODE_TEXT; 5522 mode = ANDROID_IC_MODE_TEXT;
5509 5523
5524 /* Remove any existing input method events that apply to FRAME from
5525 the event queue.
5526
5527 There's a small window between this and the call to
5528 android_reset_ic between which more events can be generated. */
5529
5530 while (android_check_if_event (&event, android_event_is_for_frame, f))
5531 {
5532 switch (event.ime.operation)
5533 {
5534 case ANDROID_IME_COMMIT_TEXT:
5535 case ANDROID_IME_FINISH_COMPOSING_TEXT:
5536 case ANDROID_IME_SET_COMPOSING_TEXT:
5537 xfree (event.ime.text);
5538 break;
5539
5540 default:
5541 break;
5542 }
5543 }
5544
5510 android_reset_ic (FRAME_ANDROID_WINDOW (f), mode); 5545 android_reset_ic (FRAME_ANDROID_WINDOW (f), mode);
5511 5546
5512 /* Clear extracted text flags. Since the IM has been reinitialised, 5547 /* Clear extracted text flags. Since the IM has been reinitialised,