1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Simplify management of Android handle IDs

* java/org/gnu/emacs/EmacsCursor.java (EmacsCursor):

* java/org/gnu/emacs/EmacsGC.java (EmacsGC):

* java/org/gnu/emacs/EmacsHandleObject.java (EmacsHandleObject):
Remove HANDLE argument to constructor.

* java/org/gnu/emacs/EmacsPixmap.java (EmacsPixmap):

* java/org/gnu/emacs/EmacsWindow.java (EmacsWindow):

* java/org/gnu/emacs/EmacsInputConnection.java
(EmacsInputConnection) <windowHandle>: Change type to long.

* java/org/gnu/emacs/EmacsNative.java (EmacsNative)
(sendConfigureNotify, sendKeyPress, sendKeyRelease, sendFocusIn)
(sendFocusOut, sendWindowAction, sendEnterNotify)
(sendLeaveNotify, sendMotionNotify, sendButtonPress)
(sendButtonRelease, sendTouchDown, sendTouchUp, sendTouchMove)
(sendWheel, sendIconified, sendDeiconified, sendContextMenu)
(sendExpose, sendDndDrag, sendDndUri, sendDndText)
(beginBatchEdit, commitCompletion, endBatchEdit, commitText)
(deleteSurroundingText, finishComposingText, replaceText)
(getSelectedText, getTextAfterCursor, getTextBeforeCursor)
(setComposingText, setComposingRegion, setSelection)
(performEditorAction, performContextMenuAction, getExtractedText)
(requestSelectionUpdate, requestCursorUpdates, clearInputFlags)
(getSurroundingText, takeSnapshot, getSelection): Accept handles
as longs, rather than shorts.  All callers changed.

* java/org/gnu/emacs/EmacsService.java (queryTree): Return
handles as longs rather than shorts.
(viewGetSelection): Take long WINDOW, not short.

* src/android.c (struct android_emacs_handle): New structure.
(handle_class): New variable.
(android_init_emacs_service, android_init_emacs_pixmap)
(android_init_emacs_gc_class, android_init_emacs_cursor): Adjust
to match signature changes in constructors.
(android_init_emacs_handle): New function.
(initEmacs): Initialize the handle class, its fields and metods.
(sendConfigureNotify, sendKeyPress, sendKeyRelease, sendFocusIn)
(sendFocusOut, sendWindowAction, sendEnterNotify)
(sendLeaveNotify, sendMotionNotify, sendButtonPress)
(sendButtonRelease, sendTouchDown, sendTouchUp, sendTouchMove)
(sendWheel, sendIconified, sendDeiconified, sendContextMenu)
(sendExpose, sendDndDrag, sendDndUri, sendDndText): Update for
changes to handle type.
(android_alloc_id, android_resolve_handle)
(android_resolve_handle2): Remove functions; replace the second
with a macro that accepts one fewer argument.  All callers
changed.
(android_destroy_handle): Cease indexing the handle list for the
handle object.
(android_globalize_reference): New function.
(android_create_window, android_create_gc, android_create_pixmap)
(android_create_font_cursor): Call android_globalize_reference
to convert global references into handles.
(android_free_cursor, android_destroy_window): Cease verifying
the handle type.
(android_copy_area): Check destination object type rather than
handle entry.
(android_query_tree): Adjust for changes to return types.
(likely): Define __builtin_expect variant unconditionally.

* src/android.h (android_resolve_handle): New macro.

* src/androidgui.h (android_handle): Define to intptr_t.

* src/androidterm.c (deleteSurroundingText, finishComposingText)
(performEditorAction, performContextMenuAction, getExtractedText)
(getSelectedText, requestSelectionUpdate, requestCursorUpdates)
(clearInputFlags, getSurroundingText)
(android_get_surrounding_text_internal): Accept handles as
longs, not jshorts.
This commit is contained in:
Po Lu 2024-05-04 11:36:09 +08:00
parent 7a7dd87842
commit 139931fefb
18 changed files with 307 additions and 525 deletions

View file

@ -440,8 +440,7 @@ public class EmacsActivity extends Activity
if (!EmacsContextMenu.itemAlreadySelected)
{
serial = EmacsContextMenu.lastMenuEventSerial;
EmacsNative.sendContextMenu ((short) 0, 0,
serial);
EmacsNative.sendContextMenu (0, 0, serial);
}
super.onContextMenuClosed (menu);

View file

@ -121,8 +121,7 @@ public final class EmacsContextMenu
}
/* Send a context menu event. */
EmacsNative.sendContextMenu ((short) 0, itemID,
lastMenuEventSerial);
EmacsNative.sendContextMenu (0, itemID, lastMenuEventSerial);
/* Say that an item has already been selected. */
itemAlreadySelected = true;

View file

@ -31,9 +31,9 @@ public final class EmacsCursor extends EmacsHandleObject
public final PointerIcon icon;
public
EmacsCursor (short handle, int glyph)
EmacsCursor (int glyph)
{
super (handle);
super ();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
{

View file

@ -93,7 +93,7 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener
onClick (View view)
{
wasButtonClicked = true;
EmacsNative.sendContextMenu ((short) 0, id, menuEventSerial);
EmacsNative.sendContextMenu (0, id, menuEventSerial);
dismissDialog.dismiss ();
}
@ -102,7 +102,7 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener
onClick (DialogInterface dialog, int which)
{
wasButtonClicked = true;
EmacsNative.sendContextMenu ((short) 0, id, menuEventSerial);
EmacsNative.sendContextMenu (0, id, menuEventSerial);
}
};
@ -414,6 +414,6 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener
if (wasButtonClicked)
return;
EmacsNative.sendContextMenu ((short) 0, 0, menuEventSerial);
EmacsNative.sendContextMenu (0, 0, menuEventSerial);
}
};

View file

@ -71,13 +71,13 @@ public final class EmacsGC extends EmacsHandleObject
/* The following fields are only set on immutable GCs. */
public
EmacsGC (short handle)
EmacsGC ()
{
/* For historical reasons the C code has an extra layer of
indirection above this GC handle. struct android_gc is the GC
used by Emacs code, while android_gcontext is the type of the
handle. */
super (handle);
super ();
fill_style = GC_FILL_SOLID;
function = GC_COPY;

View file

@ -33,14 +33,9 @@ public abstract class EmacsHandleObject
/* Whether or not this handle has been destroyed. */
volatile boolean destroyed;
/* The handle associated with this object. */
public short handle;
public
EmacsHandleObject (short handle)
{
this.handle = handle;
}
/* The handle associated with this object, set in
android_globalize_reference. */
public long handle;
public void
destroyHandle () throws IllegalStateException

View file

@ -48,7 +48,7 @@ public final class EmacsInputConnection implements InputConnection
private EmacsView view;
/* The handle ID associated with that view's window. */
private short windowHandle;
private long windowHandle;
/* Number of batch edits currently underway. Used to avoid
synchronizing with the Emacs thread after each

View file

@ -108,92 +108,92 @@ public final class EmacsNative
/* Send an ANDROID_CONFIGURE_NOTIFY event. The values of all the
functions below are the serials of the events sent. */
public static native long sendConfigureNotify (short window, long time,
public static native long sendConfigureNotify (long window, long time,
int x, int y, int width,
int height);
/* Send an ANDROID_KEY_PRESS event. */
public static native long sendKeyPress (short window, long time, int state,
public static native long sendKeyPress (long window, long time, int state,
int keyCode, int unicodeChar);
/* Send an ANDROID_KEY_RELEASE event. */
public static native long sendKeyRelease (short window, long time, int state,
public static native long sendKeyRelease (long window, long time, int state,
int keyCode, int unicodeChar);
/* Send an ANDROID_FOCUS_IN event. */
public static native long sendFocusIn (short window, long time);
public static native long sendFocusIn (long window, long time);
/* Send an ANDROID_FOCUS_OUT event. */
public static native long sendFocusOut (short window, long time);
public static native long sendFocusOut (long window, long time);
/* Send an ANDROID_WINDOW_ACTION event. */
public static native long sendWindowAction (short window, int action);
public static native long sendWindowAction (long window, int action);
/* Send an ANDROID_ENTER_NOTIFY event. */
public static native long sendEnterNotify (short window, int x, int y,
public static native long sendEnterNotify (long window, int x, int y,
long time);
/* Send an ANDROID_LEAVE_NOTIFY event. */
public static native long sendLeaveNotify (short window, int x, int y,
public static native long sendLeaveNotify (long window, int x, int y,
long time);
/* Send an ANDROID_MOTION_NOTIFY event. */
public static native long sendMotionNotify (short window, int x, int y,
public static native long sendMotionNotify (long window, int x, int y,
long time);
/* Send an ANDROID_BUTTON_PRESS event. */
public static native long sendButtonPress (short window, int x, int y,
public static native long sendButtonPress (long window, int x, int y,
long time, int state,
int button);
/* Send an ANDROID_BUTTON_RELEASE event. */
public static native long sendButtonRelease (short window, int x, int y,
public static native long sendButtonRelease (long window, int x, int y,
long time, int state,
int button);
/* Send an ANDROID_TOUCH_DOWN event. */
public static native long sendTouchDown (short window, int x, int y,
public static native long sendTouchDown (long window, int x, int y,
long time, int pointerID,
int flags);
/* Send an ANDROID_TOUCH_UP event. */
public static native long sendTouchUp (short window, int x, int y,
public static native long sendTouchUp (long window, int x, int y,
long time, int pointerID,
int flags);
/* Send an ANDROID_TOUCH_MOVE event. */
public static native long sendTouchMove (short window, int x, int y,
public static native long sendTouchMove (long window, int x, int y,
long time, int pointerID,
int flags);
/* Send an ANDROID_WHEEL event. */
public static native long sendWheel (short window, int x, int y,
public static native long sendWheel (long window, int x, int y,
long time, int state,
float xDelta, float yDelta);
/* Send an ANDROID_ICONIFIED event. */
public static native long sendIconified (short window);
public static native long sendIconified (long window);
/* Send an ANDROID_DEICONIFIED event. */
public static native long sendDeiconified (short window);
public static native long sendDeiconified (long window);
/* Send an ANDROID_CONTEXT_MENU event. */
public static native long sendContextMenu (short window, int menuEventID,
public static native long sendContextMenu (long window, int menuEventID,
int menuEventSerial);
/* Send an ANDROID_EXPOSE event. */
public static native long sendExpose (short window, int x, int y,
public static native long sendExpose (long window, int x, int y,
int width, int height);
/* Send an ANDROID_DND_DRAG event. */
public static native long sendDndDrag (short window, int x, int y);
public static native long sendDndDrag (long window, int x, int y);
/* Send an ANDROID_DND_URI event. */
public static native long sendDndUri (short window, int x, int y,
public static native long sendDndUri (long window, int x, int y,
String text);
/* Send an ANDROID_DND_TEXT event. */
public static native long sendDndText (short window, int x, int y,
public static native long sendDndText (long window, int x, int y,
String text);
/* Send an ANDROID_NOTIFICATION_CANCELED event. */
@ -241,48 +241,48 @@ public final class EmacsNative
/* Input connection functions. These mostly correspond to their
counterparts in Android's InputConnection. */
public static native void beginBatchEdit (short window);
public static native void endBatchEdit (short window);
public static native void commitCompletion (short window, String text,
public static native void beginBatchEdit (long window);
public static native void endBatchEdit (long window);
public static native void commitCompletion (long window, String text,
int position);
public static native void commitText (short window, String text,
public static native void commitText (long window, String text,
int position);
public static native void deleteSurroundingText (short window,
public static native void deleteSurroundingText (long window,
int leftLength,
int rightLength);
public static native void finishComposingText (short window);
public static native void replaceText (short window, int start, int end,
public static native void finishComposingText (long window);
public static native void replaceText (long window, int start, int end,
String text, int newCursorPosition,
TextAttribute attributes);
public static native String getSelectedText (short window, int flags);
public static native String getTextAfterCursor (short window, int length,
public static native String getSelectedText (long window, int flags);
public static native String getTextAfterCursor (long window, int length,
int flags);
public static native String getTextBeforeCursor (short window, int length,
public static native String getTextBeforeCursor (long window, int length,
int flags);
public static native void setComposingText (short window, String text,
public static native void setComposingText (long window, String text,
int newCursorPosition);
public static native void setComposingRegion (short window, int start,
public static native void setComposingRegion (long window, int start,
int end);
public static native void setSelection (short window, int start, int end);
public static native void performEditorAction (short window,
public static native void setSelection (long window, int start, int end);
public static native void performEditorAction (long window,
int editorAction);
public static native void performContextMenuAction (short window,
public static native void performContextMenuAction (long window,
int contextMenuAction);
public static native ExtractedText getExtractedText (short window,
public static native ExtractedText getExtractedText (long window,
ExtractedTextRequest req,
int flags);
public static native void requestSelectionUpdate (short window);
public static native void requestCursorUpdates (short window, int mode);
public static native void clearInputFlags (short window);
public static native SurroundingText getSurroundingText (short window,
public static native void requestSelectionUpdate (long window);
public static native void requestCursorUpdates (long window, int mode);
public static native void clearInputFlags (long window);
public static native SurroundingText getSurroundingText (long window,
int left, int right,
int flags);
public static native TextSnapshot takeSnapshot (short window);
public static native TextSnapshot takeSnapshot (long window);
/* Return the current value of the selection, or -1 upon
failure. */
public static native int[] getSelection (short window);
public static native int[] getSelection (long window);
/* Graphics functions used as replacements for potentially buggy

View file

@ -51,9 +51,9 @@ public final class EmacsPixmap extends EmacsHandleObject
private long gcClipRectID;
public
EmacsPixmap (short handle, int width, int height, int depth)
EmacsPixmap (int width, int height, int depth)
{
super (handle);
super ();
if (depth != 1 && depth != 24)
throw new IllegalArgumentException ("Invalid depth specified"

View file

@ -514,10 +514,10 @@ public final class EmacsService extends Service
vibrator.vibrate (duration);
}
public short[]
public long[]
queryTree (EmacsWindow window)
{
short[] array;
long[] array;
List<EmacsWindow> windowList;
int i;
@ -529,7 +529,7 @@ public final class EmacsService extends Service
synchronized (windowList)
{
array = new short[windowList.size () + 1];
array = new long[windowList.size () + 1];
i = 1;
array[0] = (window == null
@ -846,7 +846,7 @@ public final class EmacsService extends Service
}
public static int[]
viewGetSelection (short window)
viewGetSelection (long window)
{
int[] selection;

View file

@ -170,11 +170,9 @@ public final class EmacsWindow extends EmacsHandleObject
public boolean preserve, previouslyAttached;
public
EmacsWindow (short handle, final EmacsWindow parent, int x, int y,
EmacsWindow (final EmacsWindow parent, int x, int y,
int width, int height, boolean overrideRedirect)
{
super (handle);
rect = new Rect (x, y, x + width, y + height);
pointerMap = new SparseArray<Coordinate> ();
@ -205,7 +203,7 @@ public final class EmacsWindow extends EmacsHandleObject
});
}
scratchGC = new EmacsGC ((short) 0);
scratchGC = new EmacsGC ();
/* Create the map of input method-committed strings. Keep at most
ten strings in the map. */

View file

@ -145,7 +145,7 @@ public final class EmacsWindowManager
}
}
EmacsNative.sendWindowAction ((short) 0, 0);
EmacsNative.sendWindowAction (0, 0);
}
public synchronized void