From 7df66b4762ff51e394b8db03dfffe888bdba0a67 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 3 Apr 2024 20:29:10 +0800 Subject: Better align Emacs window management with Android task lifecycles * java/org/gnu/emacs/EmacsActivity.java (onCreate): Permit overriding by child classes. (onDestroy): Minor stylistic adjustments. (getAttachmentToken): New function. * java/org/gnu/emacs/EmacsMultitaskActivity.java (onCreate) (getAttachmentToken): New functions. * java/org/gnu/emacs/EmacsWindow.java (EmacsWindow): : New variables. (onActivityDetached): Remove redundant isFinishing argument. (reparentTo): Reset the foregoing fields before registering with the window manager. * java/org/gnu/emacs/EmacsWindowManager.java (EmacsWindowManager): Rename from EmacsWindowAttachmentManager. (WindowConsumer): New function getAttachmentToken. (isWindowEligible): New function. (registerWindowConsumer, registerWindow, removeWindowConsumer) (detachWindow): Implement a new window management strategy on API 29 and subsequent releases where both varieties of toplevel window are permanently, except when reparented, bound to the activities to which they attach, and Emacs establishes at strategic junctures whether those activities remain present. (getTaskToken, pruneWindows): New functions. --- java/org/gnu/emacs/EmacsWindow.java | 53 +++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'java/org/gnu/emacs/EmacsWindow.java') diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 2baede1d2d0..9b444c3f144 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java @@ -112,7 +112,7 @@ public final class EmacsWindow extends EmacsHandleObject private SparseArray pointerMap; /* The window consumer currently attached, if it exists. */ - private EmacsWindowAttachmentManager.WindowConsumer attached; + private EmacsWindowManager.WindowConsumer attached; /* The window background scratch GC. foreground is always the window background. */ @@ -159,6 +159,16 @@ public final class EmacsWindow extends EmacsHandleObject values are -1 if no drag and drop operation is under way. */ private int dndXPosition, dndYPosition; + /* Identifier binding this window to the activity created for it, or + -1 if the window should be attached to system-created activities + (i.e. the activity launched by the system at startup). Value is + meaningless under API level 29 and earlier. */ + public long attachmentToken; + + /* Whether this window should be preserved during window pruning, + and whether this window has previously been attached to a task. */ + public boolean preserve, previouslyAttached; + public EmacsWindow (short handle, final EmacsWindow parent, int x, int y, int width, int height, boolean overrideRedirect) @@ -255,12 +265,12 @@ public final class EmacsWindow extends EmacsHandleObject run () { ViewManager parent; - EmacsWindowAttachmentManager manager; + EmacsWindowManager manager; if (EmacsActivity.focusedWindow == EmacsWindow.this) EmacsActivity.focusedWindow = null; - manager = EmacsWindowAttachmentManager.MANAGER; + manager = EmacsWindowManager.MANAGER; view.setVisibility (View.GONE); /* If the window manager is set, use that instead. */ @@ -281,12 +291,12 @@ public final class EmacsWindow extends EmacsHandleObject } public void - setConsumer (EmacsWindowAttachmentManager.WindowConsumer consumer) + setConsumer (EmacsWindowManager.WindowConsumer consumer) { attached = consumer; } - public EmacsWindowAttachmentManager.WindowConsumer + public EmacsWindowManager.WindowConsumer getAttachedConsumer () { return attached; @@ -420,7 +430,7 @@ public final class EmacsWindow extends EmacsHandleObject public void run () { - EmacsWindowAttachmentManager manager; + EmacsWindowManager manager; WindowManager windowManager; Activity ctx; Object tem; @@ -431,7 +441,7 @@ public final class EmacsWindow extends EmacsHandleObject if (!overrideRedirect) { - manager = EmacsWindowAttachmentManager.MANAGER; + manager = EmacsWindowManager.MANAGER; /* If parent is the root window, notice that there are new children available for interested activities to pick @@ -527,9 +537,9 @@ public final class EmacsWindow extends EmacsHandleObject public void run () { - EmacsWindowAttachmentManager manager; + EmacsWindowManager manager; - manager = EmacsWindowAttachmentManager.MANAGER; + manager = EmacsWindowManager.MANAGER; view.setVisibility (View.GONE); @@ -809,20 +819,13 @@ public final class EmacsWindow extends EmacsHandleObject EmacsActivity.invalidateFocus (gainFocus ? 6 : 5); } - /* Notice that the activity has been detached or destroyed. - - ISFINISHING is set if the activity is not the main activity, or - if the activity was not destroyed in response to explicit user - action. */ + /* Notice that the activity (or its task) has been detached or + destroyed by explicit user action. */ public void - onActivityDetached (boolean isFinishing) + onActivityDetached () { - /* Destroy the associated frame when the activity is detached in - response to explicit user action. */ - - if (isFinishing) - EmacsNative.sendWindowAction (this.handle, 0); + EmacsNative.sendWindowAction (this.handle, 0); } @@ -1312,13 +1315,17 @@ public final class EmacsWindow extends EmacsHandleObject public void run () { - EmacsWindowAttachmentManager manager; + EmacsWindowManager manager; ViewManager parent; /* First, detach this window if necessary. */ - manager = EmacsWindowAttachmentManager.MANAGER; + manager = EmacsWindowManager.MANAGER; manager.detachWindow (EmacsWindow.this); + /* Reset window management state. */ + previouslyAttached = false; + attachmentToken = false; + /* Also unparent this view. */ /* If the window manager is set, use that instead. */ @@ -1858,7 +1865,7 @@ public final class EmacsWindow extends EmacsHandleObject public void recreateActivity () { - final EmacsWindowAttachmentManager.WindowConsumer attached; + final EmacsWindowManager.WindowConsumer attached; attached = this.attached; -- cgit v1.3