aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-01-20 19:06:32 +0800
committerPo Lu2023-01-20 19:06:32 +0800
commitd44b60c2f001d57b010f0e9b82f798fbad9a23d6 (patch)
tree1ff208bfccd74a3b2ad4488cd66c89762d0acd7e /src
parente07b58dc35a66b5e611f437ec007292d82dc8f13 (diff)
downloademacs-d44b60c2f001d57b010f0e9b82f798fbad9a23d6.tar.gz
emacs-d44b60c2f001d57b010f0e9b82f798fbad9a23d6.zip
Update Android port
* .gitignore: Don't ignore verbose.mk.android. * doc/emacs/Makefile.in (EMACSSOURCES): Add android.texi and input.texi. * doc/emacs/android.texi (Android): Document support for the on-screen keyboard. (Android Startup): Document how to start Emacs with -Q on Android. (Android Environment): Document how Emacs works around the system ``task killer''. Document changes to frame deletion behavior. * doc/emacs/emacs.texi (Top): * doc/emacs/input.texi (Other Input Devices, On-Screen Keyboards): Document how to use Emacs with virtual keyboards. * doc/lispref/commands.texi (Touchscreen Events): Document changes to `touch-screen-track-drag'. * doc/lispref/frames.texi (Frames, On-Screen Keyboards): New node. * java/AndroidManifest.xml.in: Add settings activity and appropriate OSK adjustment mode. * java/org/gnu/emacs/EmacsActivity.java (onCreate): Allow creating Emacs with -Q. (onDestroy): Don't remove if killed by the system. * java/org/gnu/emacs/EmacsContextMenu.java (inflateMenuItems): Fix context menus again. * java/org/gnu/emacs/EmacsNative.java (EmacsNative): Make all event sending functions return long. * java/org/gnu/emacs/EmacsPreferencesActivity.java (EmacsPreferencesActivity): New class. * java/org/gnu/emacs/EmacsService.java (EmacsService) (onStartCommand, onCreate, startEmacsService): Start as a foreground service if necessary to bypass system restrictions. * java/org/gnu/emacs/EmacsSurfaceView.java (EmacsSurfaceView): * java/org/gnu/emacs/EmacsThread.java (EmacsThread, run): * java/org/gnu/emacs/EmacsView.java (EmacsView, onLayout) (onDetachedFromWindow): * java/org/gnu/emacs/EmacsWindow.java (EmacsWindow, viewLayout): Implement frame resize synchronization.. * java/org/gnu/emacs/EmacsWindowAttachmentManager.java (EmacsWindowAttachmentManager, removeWindowConsumer): Adjust accordingly for changes to frame deletion behavior. * lisp/frame.el (android-toggle-on-screen-keyboard) (frame-toggle-on-screen-keyboard): New function. * lisp/minibuffer.el (minibuffer-setup-on-screen-keyboard) (minibuffer-exit-on-screen-keyboard): New functions. (minibuffer-setup-hook, minibuffer-exit-hook): Add new functions to hooks. * lisp/touch-screen.el (touch-screen-relative-xy): Accept new value of window `frame'. Return frame coordinates in that case. (touch-screen-set-point-commands): New variable. (touch-screen-handle-point-up): Respect that variable. (touch-screen-track-drag): Return `no-drag' where appropriate. (touch-screen-drag-mode-line-1, touch-screen-drag-mode-line): Refactor to use `no-drag'. * src/android.c (struct android_emacs_window): New methods. Make all event sending functions return the event serial. (android_toggle_on_screen_keyboard, android_window_updated): New functions. * src/android.h: Update prototypes. * src/androidfns.c (Fandroid_toggle_on_screen_keyboard) (syms_of_androidfns): New function. * src/androidgui.h (struct android_any_event) (struct android_key_event, struct android_configure_event) (struct android_focus_event, struct android_window_action_event) (struct android_crossing_event, struct android_motion_event) (struct android_button_event, struct android_touch_event) (struct android_wheel_event, struct android_iconify_event) (struct android_menu_event): Add `serial' fields. * src/androidterm.c (handle_one_android_event) (android_frame_up_to_date): * src/androidterm.h (struct android_output): Implement frame resize synchronization.
Diffstat (limited to 'src')
-rw-r--r--src/android.c147
-rw-r--r--src/android.h2
-rw-r--r--src/androidfns.c25
-rw-r--r--src/androidgui.h20
-rw-r--r--src/androidterm.c24
-rw-r--r--src/androidterm.h5
6 files changed, 193 insertions, 30 deletions
diff --git a/src/android.c b/src/android.c
index eb9c404f1a3..43ac3b3f754 100644
--- a/src/android.c
+++ b/src/android.c
@@ -121,6 +121,8 @@ struct android_emacs_window
121{ 121{
122 jclass class; 122 jclass class;
123 jmethodID swap_buffers; 123 jmethodID swap_buffers;
124 jmethodID toggle_on_screen_keyboard;
125 jmethodID window_updated;
124}; 126};
125 127
126/* The asset manager being used. */ 128/* The asset manager being used. */
@@ -193,6 +195,10 @@ static struct android_emacs_drawable drawable_class;
193/* Various methods associated with the EmacsWindow class. */ 195/* Various methods associated with the EmacsWindow class. */
194static struct android_emacs_window window_class; 196static struct android_emacs_window window_class;
195 197
198/* The last event serial used. This is a 32 bit value, but it is
199 stored in unsigned long to be consistent with X. */
200static unsigned int event_serial;
201
196 202
197 203
198/* Event handling functions. Events are stored on a (circular) queue 204/* Event handling functions. Events are stored on a (circular) queue
@@ -1435,6 +1441,9 @@ android_init_emacs_window (void)
1435 assert (window_class.c_name); 1441 assert (window_class.c_name);
1436 1442
1437 FIND_METHOD (swap_buffers, "swapBuffers", "()V"); 1443 FIND_METHOD (swap_buffers, "swapBuffers", "()V");
1444 FIND_METHOD (toggle_on_screen_keyboard,
1445 "toggleOnScreenKeyboard", "(Z)V");
1446 FIND_METHOD (window_updated, "windowUpdated", "(J)V");
1438#undef FIND_METHOD 1447#undef FIND_METHOD
1439} 1448}
1440 1449
@@ -1497,7 +1506,7 @@ NATIVE_NAME (emacsAbort) (JNIEnv *env, jobject object)
1497 emacs_abort (); 1506 emacs_abort ();
1498} 1507}
1499 1508
1500extern JNIEXPORT void JNICALL 1509extern JNIEXPORT jlong JNICALL
1501NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object, 1510NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
1502 jshort window, jlong time, 1511 jshort window, jlong time,
1503 jint x, jint y, jint width, 1512 jint x, jint y, jint width,
@@ -1506,6 +1515,7 @@ NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
1506 union android_event event; 1515 union android_event event;
1507 1516
1508 event.xconfigure.type = ANDROID_CONFIGURE_NOTIFY; 1517 event.xconfigure.type = ANDROID_CONFIGURE_NOTIFY;
1518 event.xconfigure.serial = ++event_serial;
1509 event.xconfigure.window = window; 1519 event.xconfigure.window = window;
1510 event.xconfigure.time = time; 1520 event.xconfigure.time = time;
1511 event.xconfigure.x = x; 1521 event.xconfigure.x = x;
@@ -1514,9 +1524,10 @@ NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
1514 event.xconfigure.height = height; 1524 event.xconfigure.height = height;
1515 1525
1516 android_write_event (&event); 1526 android_write_event (&event);
1527 return event_serial;
1517} 1528}
1518 1529
1519extern JNIEXPORT void JNICALL 1530extern JNIEXPORT jlong JNICALL
1520NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object, 1531NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object,
1521 jshort window, jlong time, 1532 jshort window, jlong time,
1522 jint state, jint keycode, 1533 jint state, jint keycode,
@@ -1525,6 +1536,7 @@ NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object,
1525 union android_event event; 1536 union android_event event;
1526 1537
1527 event.xkey.type = ANDROID_KEY_PRESS; 1538 event.xkey.type = ANDROID_KEY_PRESS;
1539 event.xkey.serial = ++event_serial;
1528 event.xkey.window = window; 1540 event.xkey.window = window;
1529 event.xkey.time = time; 1541 event.xkey.time = time;
1530 event.xkey.state = state; 1542 event.xkey.state = state;
@@ -1532,9 +1544,10 @@ NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object,
1532 event.xkey.unicode_char = unicode_char; 1544 event.xkey.unicode_char = unicode_char;
1533 1545
1534 android_write_event (&event); 1546 android_write_event (&event);
1547 return event_serial;
1535} 1548}
1536 1549
1537extern JNIEXPORT void JNICALL 1550extern JNIEXPORT jlong JNICALL
1538NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object, 1551NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object,
1539 jshort window, jlong time, 1552 jshort window, jlong time,
1540 jint state, jint keycode, 1553 jint state, jint keycode,
@@ -1543,6 +1556,7 @@ NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object,
1543 union android_event event; 1556 union android_event event;
1544 1557
1545 event.xkey.type = ANDROID_KEY_RELEASE; 1558 event.xkey.type = ANDROID_KEY_RELEASE;
1559 event.xkey.serial = ++event_serial;
1546 event.xkey.window = window; 1560 event.xkey.window = window;
1547 event.xkey.time = time; 1561 event.xkey.time = time;
1548 event.xkey.state = state; 1562 event.xkey.state = state;
@@ -1550,48 +1564,55 @@ NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object,
1550 event.xkey.unicode_char = unicode_char; 1564 event.xkey.unicode_char = unicode_char;
1551 1565
1552 android_write_event (&event); 1566 android_write_event (&event);
1567 return event_serial;
1553} 1568}
1554 1569
1555extern JNIEXPORT void JNICALL 1570extern JNIEXPORT jlong JNICALL
1556NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object, 1571NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object,
1557 jshort window, jlong time) 1572 jshort window, jlong time)
1558{ 1573{
1559 union android_event event; 1574 union android_event event;
1560 1575
1561 event.xkey.type = ANDROID_FOCUS_IN; 1576 event.xfocus.type = ANDROID_FOCUS_IN;
1562 event.xkey.window = window; 1577 event.xfocus.serial = ++event_serial;
1563 event.xkey.time = time; 1578 event.xfocus.window = window;
1579 event.xfocus.time = time;
1564 1580
1565 android_write_event (&event); 1581 android_write_event (&event);
1582 return event_serial;
1566} 1583}
1567 1584
1568extern JNIEXPORT void JNICALL 1585extern JNIEXPORT jlong JNICALL
1569NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object, 1586NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object,
1570 jshort window, jlong time) 1587 jshort window, jlong time)
1571{ 1588{
1572 union android_event event; 1589 union android_event event;
1573 1590
1574 event.xkey.type = ANDROID_FOCUS_OUT; 1591 event.xfocus.type = ANDROID_FOCUS_OUT;
1575 event.xkey.window = window; 1592 event.xfocus.serial = ++event_serial;
1576 event.xkey.time = time; 1593 event.xfocus.window = window;
1594 event.xfocus.time = time;
1577 1595
1578 android_write_event (&event); 1596 android_write_event (&event);
1597 return ++event_serial;
1579} 1598}
1580 1599
1581extern JNIEXPORT void JNICALL 1600extern JNIEXPORT jlong JNICALL
1582NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object, 1601NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object,
1583 jshort window, jint action) 1602 jshort window, jint action)
1584{ 1603{
1585 union android_event event; 1604 union android_event event;
1586 1605
1587 event.xaction.type = ANDROID_WINDOW_ACTION; 1606 event.xaction.type = ANDROID_WINDOW_ACTION;
1607 event.xaction.serial = ++event_serial;
1588 event.xaction.window = window; 1608 event.xaction.window = window;
1589 event.xaction.action = action; 1609 event.xaction.action = action;
1590 1610
1591 android_write_event (&event); 1611 android_write_event (&event);
1612 return event_serial;
1592} 1613}
1593 1614
1594extern JNIEXPORT void JNICALL 1615extern JNIEXPORT jlong JNICALL
1595NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object, 1616NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object,
1596 jshort window, jint x, jint y, 1617 jshort window, jint x, jint y,
1597 jlong time) 1618 jlong time)
@@ -1599,15 +1620,17 @@ NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object,
1599 union android_event event; 1620 union android_event event;
1600 1621
1601 event.xcrossing.type = ANDROID_ENTER_NOTIFY; 1622 event.xcrossing.type = ANDROID_ENTER_NOTIFY;
1623 event.xcrossing.serial = ++event_serial;
1602 event.xcrossing.window = window; 1624 event.xcrossing.window = window;
1603 event.xcrossing.x = x; 1625 event.xcrossing.x = x;
1604 event.xcrossing.y = y; 1626 event.xcrossing.y = y;
1605 event.xcrossing.time = time; 1627 event.xcrossing.time = time;
1606 1628
1607 android_write_event (&event); 1629 android_write_event (&event);
1630 return event_serial;
1608} 1631}
1609 1632
1610extern JNIEXPORT void JNICALL 1633extern JNIEXPORT jlong JNICALL
1611NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object, 1634NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object,
1612 jshort window, jint x, jint y, 1635 jshort window, jint x, jint y,
1613 jlong time) 1636 jlong time)
@@ -1615,15 +1638,17 @@ NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object,
1615 union android_event event; 1638 union android_event event;
1616 1639
1617 event.xcrossing.type = ANDROID_LEAVE_NOTIFY; 1640 event.xcrossing.type = ANDROID_LEAVE_NOTIFY;
1641 event.xcrossing.serial = ++event_serial;
1618 event.xcrossing.window = window; 1642 event.xcrossing.window = window;
1619 event.xcrossing.x = x; 1643 event.xcrossing.x = x;
1620 event.xcrossing.y = y; 1644 event.xcrossing.y = y;
1621 event.xcrossing.time = time; 1645 event.xcrossing.time = time;
1622 1646
1623 android_write_event (&event); 1647 android_write_event (&event);
1648 return event_serial;
1624} 1649}
1625 1650
1626extern JNIEXPORT void JNICALL 1651extern JNIEXPORT jlong JNICALL
1627NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object, 1652NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object,
1628 jshort window, jint x, jint y, 1653 jshort window, jint x, jint y,
1629 jlong time) 1654 jlong time)
@@ -1631,15 +1656,17 @@ NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object,
1631 union android_event event; 1656 union android_event event;
1632 1657
1633 event.xmotion.type = ANDROID_MOTION_NOTIFY; 1658 event.xmotion.type = ANDROID_MOTION_NOTIFY;
1659 event.xmotion.serial = ++event_serial;
1634 event.xmotion.window = window; 1660 event.xmotion.window = window;
1635 event.xmotion.x = x; 1661 event.xmotion.x = x;
1636 event.xmotion.y = y; 1662 event.xmotion.y = y;
1637 event.xmotion.time = time; 1663 event.xmotion.time = time;
1638 1664
1639 android_write_event (&event); 1665 android_write_event (&event);
1666 return event_serial;
1640} 1667}
1641 1668
1642extern JNIEXPORT void JNICALL 1669extern JNIEXPORT jlong JNICALL
1643NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object, 1670NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object,
1644 jshort window, jint x, jint y, 1671 jshort window, jint x, jint y,
1645 jlong time, jint state, 1672 jlong time, jint state,
@@ -1648,6 +1675,7 @@ NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object,
1648 union android_event event; 1675 union android_event event;
1649 1676
1650 event.xbutton.type = ANDROID_BUTTON_PRESS; 1677 event.xbutton.type = ANDROID_BUTTON_PRESS;
1678 event.xbutton.serial = ++event_serial;
1651 event.xbutton.window = window; 1679 event.xbutton.window = window;
1652 event.xbutton.x = x; 1680 event.xbutton.x = x;
1653 event.xbutton.y = y; 1681 event.xbutton.y = y;
@@ -1656,9 +1684,10 @@ NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object,
1656 event.xbutton.button = button; 1684 event.xbutton.button = button;
1657 1685
1658 android_write_event (&event); 1686 android_write_event (&event);
1687 return event_serial;
1659} 1688}
1660 1689
1661extern JNIEXPORT void JNICALL 1690extern JNIEXPORT jlong JNICALL
1662NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object, 1691NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object,
1663 jshort window, jint x, jint y, 1692 jshort window, jint x, jint y,
1664 jlong time, jint state, 1693 jlong time, jint state,
@@ -1667,6 +1696,7 @@ NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object,
1667 union android_event event; 1696 union android_event event;
1668 1697
1669 event.xbutton.type = ANDROID_BUTTON_RELEASE; 1698 event.xbutton.type = ANDROID_BUTTON_RELEASE;
1699 event.xbutton.serial = ++event_serial;
1670 event.xbutton.window = window; 1700 event.xbutton.window = window;
1671 event.xbutton.x = x; 1701 event.xbutton.x = x;
1672 event.xbutton.y = y; 1702 event.xbutton.y = y;
@@ -1675,9 +1705,10 @@ NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object,
1675 event.xbutton.button = button; 1705 event.xbutton.button = button;
1676 1706
1677 android_write_event (&event); 1707 android_write_event (&event);
1708 return event_serial;
1678} 1709}
1679 1710
1680extern JNIEXPORT void JNICALL 1711extern JNIEXPORT jlong JNICALL
1681NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object, 1712NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object,
1682 jshort window, jint x, jint y, 1713 jshort window, jint x, jint y,
1683 jlong time, jint pointer_id) 1714 jlong time, jint pointer_id)
@@ -1685,6 +1716,7 @@ NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object,
1685 union android_event event; 1716 union android_event event;
1686 1717
1687 event.touch.type = ANDROID_TOUCH_DOWN; 1718 event.touch.type = ANDROID_TOUCH_DOWN;
1719 event.touch.serial = ++event_serial;
1688 event.touch.window = window; 1720 event.touch.window = window;
1689 event.touch.x = x; 1721 event.touch.x = x;
1690 event.touch.y = y; 1722 event.touch.y = y;
@@ -1692,9 +1724,10 @@ NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object,
1692 event.touch.pointer_id = pointer_id; 1724 event.touch.pointer_id = pointer_id;
1693 1725
1694 android_write_event (&event); 1726 android_write_event (&event);
1727 return event_serial;
1695} 1728}
1696 1729
1697extern JNIEXPORT void JNICALL 1730extern JNIEXPORT jlong JNICALL
1698NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object, 1731NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object,
1699 jshort window, jint x, jint y, 1732 jshort window, jint x, jint y,
1700 jlong time, jint pointer_id) 1733 jlong time, jint pointer_id)
@@ -1702,6 +1735,7 @@ NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object,
1702 union android_event event; 1735 union android_event event;
1703 1736
1704 event.touch.type = ANDROID_TOUCH_UP; 1737 event.touch.type = ANDROID_TOUCH_UP;
1738 event.touch.serial = ++event_serial;
1705 event.touch.window = window; 1739 event.touch.window = window;
1706 event.touch.x = x; 1740 event.touch.x = x;
1707 event.touch.y = y; 1741 event.touch.y = y;
@@ -1709,9 +1743,10 @@ NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object,
1709 event.touch.pointer_id = pointer_id; 1743 event.touch.pointer_id = pointer_id;
1710 1744
1711 android_write_event (&event); 1745 android_write_event (&event);
1746 return event_serial;
1712} 1747}
1713 1748
1714extern JNIEXPORT void JNICALL 1749extern JNIEXPORT jlong JNICALL
1715NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object, 1750NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object,
1716 jshort window, jint x, jint y, 1751 jshort window, jint x, jint y,
1717 jlong time, jint pointer_id) 1752 jlong time, jint pointer_id)
@@ -1719,6 +1754,7 @@ NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object,
1719 union android_event event; 1754 union android_event event;
1720 1755
1721 event.touch.type = ANDROID_TOUCH_MOVE; 1756 event.touch.type = ANDROID_TOUCH_MOVE;
1757 event.touch.serial = ++event_serial;
1722 event.touch.window = window; 1758 event.touch.window = window;
1723 event.touch.x = x; 1759 event.touch.x = x;
1724 event.touch.y = y; 1760 event.touch.y = y;
@@ -1726,9 +1762,10 @@ NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object,
1726 event.touch.pointer_id = pointer_id; 1762 event.touch.pointer_id = pointer_id;
1727 1763
1728 android_write_event (&event); 1764 android_write_event (&event);
1765 return event_serial;
1729} 1766}
1730 1767
1731extern JNIEXPORT void JNICALL 1768extern JNIEXPORT jlong JNICALL
1732NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object, 1769NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object,
1733 jshort window, jint x, jint y, 1770 jshort window, jint x, jint y,
1734 jlong time, jint state, 1771 jlong time, jint state,
@@ -1737,6 +1774,7 @@ NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object,
1737 union android_event event; 1774 union android_event event;
1738 1775
1739 event.wheel.type = ANDROID_WHEEL; 1776 event.wheel.type = ANDROID_WHEEL;
1777 event.wheel.serial = ++event_serial;
1740 event.wheel.window = window; 1778 event.wheel.window = window;
1741 event.wheel.x = x; 1779 event.wheel.x = x;
1742 event.wheel.y = y; 1780 event.wheel.y = y;
@@ -1746,43 +1784,50 @@ NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object,
1746 event.wheel.y_delta = y_delta; 1784 event.wheel.y_delta = y_delta;
1747 1785
1748 android_write_event (&event); 1786 android_write_event (&event);
1787 return event_serial;
1749} 1788}
1750 1789
1751extern JNIEXPORT void JNICALL 1790extern JNIEXPORT jlong JNICALL
1752NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object, 1791NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object,
1753 jshort window) 1792 jshort window)
1754{ 1793{
1755 union android_event event; 1794 union android_event event;
1756 1795
1757 event.iconified.type = ANDROID_ICONIFIED; 1796 event.iconified.type = ANDROID_ICONIFIED;
1797 event.iconified.serial = ++event_serial;
1758 event.iconified.window = window; 1798 event.iconified.window = window;
1759 1799
1760 android_write_event (&event); 1800 android_write_event (&event);
1801 return event_serial;
1761} 1802}
1762 1803
1763extern JNIEXPORT void JNICALL 1804extern JNIEXPORT jlong JNICALL
1764NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object, 1805NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object,
1765 jshort window) 1806 jshort window)
1766{ 1807{
1767 union android_event event; 1808 union android_event event;
1768 1809
1769 event.iconified.type = ANDROID_DEICONIFIED; 1810 event.iconified.type = ANDROID_DEICONIFIED;
1811 event.iconified.serial = ++event_serial;
1770 event.iconified.window = window; 1812 event.iconified.window = window;
1771 1813
1772 android_write_event (&event); 1814 android_write_event (&event);
1815 return event_serial;
1773} 1816}
1774 1817
1775extern JNIEXPORT void JNICALL 1818extern JNIEXPORT jlong JNICALL
1776NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object, 1819NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object,
1777 jshort window, jint menu_event_id) 1820 jshort window, jint menu_event_id)
1778{ 1821{
1779 union android_event event; 1822 union android_event event;
1780 1823
1781 event.menu.type = ANDROID_CONTEXT_MENU; 1824 event.menu.type = ANDROID_CONTEXT_MENU;
1825 event.menu.serial = ++event_serial;
1782 event.menu.window = window; 1826 event.menu.window = window;
1783 event.menu.menu_event_id = menu_event_id; 1827 event.menu.menu_event_id = menu_event_id;
1784 1828
1785 android_write_event (&event); 1829 android_write_event (&event);
1830 return event_serial;
1786} 1831}
1787 1832
1788#ifdef __clang__ 1833#ifdef __clang__
@@ -3599,6 +3644,15 @@ android_translate_coordinates (android_window src, int x,
3599 ANDROID_DELETE_LOCAL_REF (coordinates); 3644 ANDROID_DELETE_LOCAL_REF (coordinates);
3600} 3645}
3601 3646
3647void
3648android_sync (void)
3649{
3650 (*android_java_env)->CallVoidMethod (android_java_env,
3651 emacs_service,
3652 service_class.sync);
3653 android_exception_check ();
3654}
3655
3602 3656
3603 3657
3604/* Low level drawing primitives. */ 3658/* Low level drawing primitives. */
@@ -3795,12 +3849,45 @@ android_get_keysym_name (int keysym, char *name_return, size_t size)
3795 ANDROID_DELETE_LOCAL_REF (string); 3849 ANDROID_DELETE_LOCAL_REF (string);
3796} 3850}
3797 3851
3852/* Display the on screen keyboard on window WINDOW, or hide it if SHOW
3853 is false. Ask the system to bring up or hide the on-screen
3854 keyboard on behalf of WINDOW. The request may be rejected by the
3855 system, especially when the window does not have the input
3856 focus. */
3857
3798void 3858void
3799android_sync (void) 3859android_toggle_on_screen_keyboard (android_window window, bool show)
3800{ 3860{
3801 (*android_java_env)->CallVoidMethod (android_java_env, 3861 jobject object;
3802 emacs_service, 3862 jmethodID method;
3803 service_class.sync); 3863
3864 object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
3865 method = window_class.toggle_on_screen_keyboard;
3866
3867 /* Now display the on screen keyboard. */
3868 (*android_java_env)->CallVoidMethod (android_java_env, object,
3869 method, (jboolean) show);
3870
3871 /* Check for out of memory errors. */
3872 android_exception_check ();
3873}
3874
3875/* Tell the window system that all configure events sent to WINDOW
3876 have been fully processed, and that it is now okay to display its
3877 new contents. SERIAL is the serial of the last configure event
3878 processed. */
3879
3880void
3881android_window_updated (android_window window, unsigned long serial)
3882{
3883 jobject object;
3884 jmethodID method;
3885
3886 object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
3887 method = window_class.window_updated;
3888
3889 (*android_java_env)->CallVoidMethod (android_java_env, object,
3890 method, (jlong) serial);
3804 android_exception_check (); 3891 android_exception_check ();
3805} 3892}
3806 3893
@@ -3811,7 +3898,7 @@ android_sync (void)
3811#undef faccessat 3898#undef faccessat
3812 3899
3813/* Replace the system faccessat with one which understands AT_EACCESS. 3900/* Replace the system faccessat with one which understands AT_EACCESS.
3814 Android's faccessat simply fails upon using AT_EACCESS, so repalce 3901 Android's faccessat simply fails upon using AT_EACCESS, so replace
3815 it with zero here. This isn't caught during configuration. 3902 it with zero here. This isn't caught during configuration.
3816 3903
3817 This replacement is only done when building for Android 17 or 3904 This replacement is only done when building for Android 17 or
@@ -3829,7 +3916,7 @@ faccessat (int dirfd, const char *pathname, int mode, int flags)
3829 return real_faccessat (dirfd, pathname, mode, flags & ~AT_EACCESS); 3916 return real_faccessat (dirfd, pathname, mode, flags & ~AT_EACCESS);
3830} 3917}
3831 3918
3832#endif /* __ANDROID_API__ < 16 */ 3919#endif /* __ANDROID_API__ >= 17 */
3833 3920
3834 3921
3835 3922
diff --git a/src/android.h b/src/android.h
index 240bc90d831..97818ab4911 100644
--- a/src/android.h
+++ b/src/android.h
@@ -91,6 +91,8 @@ extern void android_exception_check (void);
91 91
92extern void android_get_keysym_name (int, char *, size_t); 92extern void android_get_keysym_name (int, char *, size_t);
93extern void android_wait_event (void); 93extern void android_wait_event (void);
94extern void android_toggle_on_screen_keyboard (android_window, bool);
95extern void android_window_updated (android_window, unsigned long);
94 96
95 97
96 98
diff --git a/src/androidfns.c b/src/androidfns.c
index bb37c415069..77ee2e8de44 100644
--- a/src/androidfns.c
+++ b/src/androidfns.c
@@ -2332,6 +2332,30 @@ there is no mouse. */)
2332#endif 2332#endif
2333} 2333}
2334 2334
2335DEFUN ("android-toggle-on-screen-keyboard",
2336 Fandroid_toggle_on_screen_keyboard,
2337 Sandroid_toggle_on_screen_keyboard, 2, 2, 0,
2338 doc: /* Display or hide the on-screen keyboard.
2339If HIDE is non-nil, hide the on screen keyboard if it is currently
2340being displayed. Else, request that the system display it on behalf
2341of FRAME. This request may be rejected if FRAME does not have the
2342input focus. */)
2343 (Lisp_Object frame, Lisp_Object hide)
2344{
2345#ifndef ANDROID_STUBIFY
2346 struct frame *f;
2347
2348 f = decode_window_system_frame (frame);
2349
2350 block_input ();
2351 android_toggle_on_screen_keyboard (FRAME_ANDROID_WINDOW (f),
2352 NILP (hide));
2353 unblock_input ();
2354#endif
2355
2356 return Qnil;
2357}
2358
2335 2359
2336 2360
2337#ifndef ANDROID_STUBIFY 2361#ifndef ANDROID_STUBIFY
@@ -2781,6 +2805,7 @@ syms_of_androidfns (void)
2781 defsubr (&Sx_show_tip); 2805 defsubr (&Sx_show_tip);
2782 defsubr (&Sx_hide_tip); 2806 defsubr (&Sx_hide_tip);
2783 defsubr (&Sandroid_detect_mouse); 2807 defsubr (&Sandroid_detect_mouse);
2808 defsubr (&Sandroid_toggle_on_screen_keyboard);
2784 2809
2785#ifndef ANDROID_STUBIFY 2810#ifndef ANDROID_STUBIFY
2786 tip_timer = Qnil; 2811 tip_timer = Qnil;
diff --git a/src/androidgui.h b/src/androidgui.h
index 1f28c18ff34..3b9a74dc0b0 100644
--- a/src/androidgui.h
+++ b/src/androidgui.h
@@ -239,6 +239,7 @@ enum android_event_type
239struct android_any_event 239struct android_any_event
240{ 240{
241 enum android_event_type type; 241 enum android_event_type type;
242 unsigned long serial;
242 android_window window; 243 android_window window;
243}; 244};
244 245
@@ -252,6 +253,7 @@ enum android_modifier_mask
252struct android_key_event 253struct android_key_event
253{ 254{
254 enum android_event_type type; 255 enum android_event_type type;
256 unsigned long serial;
255 android_window window; 257 android_window window;
256 android_time time; 258 android_time time;
257 unsigned int state; 259 unsigned int state;
@@ -271,6 +273,7 @@ struct android_key_event
271struct android_configure_event 273struct android_configure_event
272{ 274{
273 enum android_event_type type; 275 enum android_event_type type;
276 unsigned long serial;
274 android_window window; 277 android_window window;
275 android_time time; 278 android_time time;
276 int x, y; 279 int x, y;
@@ -280,6 +283,7 @@ struct android_configure_event
280struct android_focus_event 283struct android_focus_event
281{ 284{
282 enum android_event_type type; 285 enum android_event_type type;
286 unsigned long serial;
283 android_window window; 287 android_window window;
284 android_time time; 288 android_time time;
285}; 289};
@@ -287,6 +291,7 @@ struct android_focus_event
287struct android_window_action_event 291struct android_window_action_event
288{ 292{
289 enum android_event_type type; 293 enum android_event_type type;
294 unsigned long serial;
290 295
291 /* The window handle. This can be ANDROID_NONE. */ 296 /* The window handle. This can be ANDROID_NONE. */
292 android_window window; 297 android_window window;
@@ -301,6 +306,7 @@ struct android_window_action_event
301struct android_crossing_event 306struct android_crossing_event
302{ 307{
303 enum android_event_type type; 308 enum android_event_type type;
309 unsigned long serial;
304 android_window window; 310 android_window window;
305 int x, y; 311 int x, y;
306 unsigned long time; 312 unsigned long time;
@@ -309,6 +315,7 @@ struct android_crossing_event
309struct android_motion_event 315struct android_motion_event
310{ 316{
311 enum android_event_type type; 317 enum android_event_type type;
318 unsigned long serial;
312 android_window window; 319 android_window window;
313 int x, y; 320 int x, y;
314 unsigned long time; 321 unsigned long time;
@@ -317,6 +324,7 @@ struct android_motion_event
317struct android_button_event 324struct android_button_event
318{ 325{
319 enum android_event_type type; 326 enum android_event_type type;
327 unsigned long serial;
320 android_window window; 328 android_window window;
321 int x, y; 329 int x, y;
322 unsigned long time; 330 unsigned long time;
@@ -329,6 +337,9 @@ struct android_touch_event
329 /* Type of the event. */ 337 /* Type of the event. */
330 enum android_event_type type; 338 enum android_event_type type;
331 339
340 /* Serial identifying the event. */
341 unsigned long serial;
342
332 /* Window associated with the event. */ 343 /* Window associated with the event. */
333 android_window window; 344 android_window window;
334 345
@@ -347,6 +358,9 @@ struct android_wheel_event
347 /* Type of the event. */ 358 /* Type of the event. */
348 enum android_event_type type; 359 enum android_event_type type;
349 360
361 /* Serial identifying the event. */
362 unsigned long serial;
363
350 /* Window associated with the event. */ 364 /* Window associated with the event. */
351 android_window window; 365 android_window window;
352 366
@@ -368,6 +382,9 @@ struct android_iconify_event
368 /* Type of the event. */ 382 /* Type of the event. */
369 enum android_event_type type; 383 enum android_event_type type;
370 384
385 /* Serial identifying the event. */
386 unsigned long serial;
387
371 /* Window associated with the event. */ 388 /* Window associated with the event. */
372 android_window window; 389 android_window window;
373}; 390};
@@ -377,6 +394,9 @@ struct android_menu_event
377 /* Type of the event. */ 394 /* Type of the event. */
378 enum android_event_type type; 395 enum android_event_type type;
379 396
397 /* Serial identifying the event. */
398 unsigned long serial;
399
380 /* Window associated with the event. Always None. */ 400 /* Window associated with the event. Always None. */
381 android_window window; 401 android_window window;
382 402
diff --git a/src/androidterm.c b/src/androidterm.c
index 3c16b542d91..3024890d789 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -591,7 +591,17 @@ handle_one_android_event (struct android_display_info *dpyinfo,
591 android_clear_under_internal_border (f); 591 android_clear_under_internal_border (f);
592 SET_FRAME_GARBAGED (f); 592 SET_FRAME_GARBAGED (f);
593 cancel_mouse_face (f); 593 cancel_mouse_face (f);
594
595 /* Now stash the serial of this configure event somewhere,
596 and call android_window_updated with it once the redraw
597 completes. */
598 FRAME_OUTPUT_DATA (f)->last_configure_serial
599 = configureEvent.xconfigure.serial;
594 } 600 }
601 else
602 /* Reply to this ConfigureNotify event immediately. */
603 android_window_updated (FRAME_ANDROID_WINDOW (f),
604 configureEvent.xconfigure.serial);
595 605
596 goto OTHER; 606 goto OTHER;
597 607
@@ -1194,6 +1204,9 @@ handle_one_android_event (struct android_display_info *dpyinfo,
1194 /* Iconification. This is vastly simpler than on X. */ 1204 /* Iconification. This is vastly simpler than on X. */
1195 case ANDROID_ICONIFIED: 1205 case ANDROID_ICONIFIED:
1196 1206
1207 if (!any)
1208 goto OTHER;
1209
1197 if (FRAME_ICONIFIED_P (any)) 1210 if (FRAME_ICONIFIED_P (any))
1198 goto OTHER; 1211 goto OTHER;
1199 1212
@@ -1206,6 +1219,9 @@ handle_one_android_event (struct android_display_info *dpyinfo,
1206 1219
1207 case ANDROID_DEICONIFIED: 1220 case ANDROID_DEICONIFIED:
1208 1221
1222 if (!any)
1223 goto OTHER;
1224
1209 if (!FRAME_ICONIFIED_P (any)) 1225 if (!FRAME_ICONIFIED_P (any))
1210 goto OTHER; 1226 goto OTHER;
1211 1227
@@ -1311,6 +1327,14 @@ android_frame_up_to_date (struct frame *f)
1311 /* The frame is now complete, as its contents have been drawn. */ 1327 /* The frame is now complete, as its contents have been drawn. */
1312 FRAME_ANDROID_COMPLETE_P (f) = true; 1328 FRAME_ANDROID_COMPLETE_P (f) = true;
1313 1329
1330 /* If there was an outstanding configure event, then tell system
1331 that the update has finished and the new contents can now be
1332 displayed. */
1333 if (FRAME_OUTPUT_DATA (f)->last_configure_serial)
1334 android_window_updated (FRAME_ANDROID_WINDOW (f),
1335 FRAME_OUTPUT_DATA (f)->last_configure_serial);
1336 FRAME_OUTPUT_DATA (f)->last_configure_serial = 0;
1337
1314 /* Shrink the scanline buffer used by the font backend. */ 1338 /* Shrink the scanline buffer used by the font backend. */
1315 sfntfont_android_shrink_scanline_buffer (); 1339 sfntfont_android_shrink_scanline_buffer ();
1316 unblock_input (); 1340 unblock_input ();
diff --git a/src/androidterm.h b/src/androidterm.h
index c0f862e35fb..11b24d40b73 100644
--- a/src/androidterm.h
+++ b/src/androidterm.h
@@ -241,6 +241,11 @@ struct android_output
241 /* List of all tools (either styluses or fingers) pressed onto the 241 /* List of all tools (either styluses or fingers) pressed onto the
242 frame. */ 242 frame. */
243 struct android_touch_point *touch_points; 243 struct android_touch_point *touch_points;
244
245 /* Event serial of the last ConfigureNotify event received that has
246 not yet been drawn. This is used to synchronize resize with the
247 window system. 0 if no such outstanding event exists. */
248 unsigned long last_configure_serial;
244}; 249};
245 250
246enum 251enum