diff options
| author | Po Lu | 2024-02-05 18:34:22 +0800 |
|---|---|---|
| committer | Po Lu | 2024-02-05 18:34:22 +0800 |
| commit | c1f8fe09e6641cc6c1195edcb8666ace1e6e8829 (patch) | |
| tree | 7b9eef95a1585e1f71dff55d0cf7e8d85930cdc9 /java | |
| parent | 98d62c5f7675b24ad66e010765ce3012046f2ff8 (diff) | |
| download | emacs-c1f8fe09e6641cc6c1195edcb8666ace1e6e8829.tar.gz emacs-c1f8fe09e6641cc6c1195edcb8666ace1e6e8829.zip | |
Fix frame focus tracking under Android
* java/org/gnu/emacs/EmacsActivity.java (invalidateFocus): New
argument WHENCE, a unique number identifying the circumstances
leading up to the call. All callers changed.
(attachWindow): Call `invalidateFocus' from the UI thread.
(onWindowFocusChanged): Don't remove activity from
`focusedActivities' if it already exists should `hasWindowFocus'
return true.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsActivity.java | 32 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindow.java | 4 |
2 files changed, 26 insertions, 10 deletions
diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index 3237f650240..b821694b18a 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java | |||
| @@ -97,7 +97,7 @@ public class EmacsActivity extends Activity | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | public static void | 99 | public static void |
| 100 | invalidateFocus () | 100 | invalidateFocus (int whence) |
| 101 | { | 101 | { |
| 102 | EmacsWindow oldFocus; | 102 | EmacsWindow oldFocus; |
| 103 | 103 | ||
| @@ -144,7 +144,7 @@ public class EmacsActivity extends Activity | |||
| 144 | layout.removeView (window.view); | 144 | layout.removeView (window.view); |
| 145 | window = null; | 145 | window = null; |
| 146 | 146 | ||
| 147 | invalidateFocus (); | 147 | invalidateFocus (0); |
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | 150 | ||
| @@ -172,8 +172,17 @@ public class EmacsActivity extends Activity | |||
| 172 | if (isPaused) | 172 | if (isPaused) |
| 173 | window.noticeIconified (); | 173 | window.noticeIconified (); |
| 174 | 174 | ||
| 175 | /* Invalidate the focus. */ | 175 | /* Invalidate the focus. Since attachWindow may be called from |
| 176 | invalidateFocus (); | 176 | either the main or the UI thread, post this to the UI thread. */ |
| 177 | |||
| 178 | runOnUiThread (new Runnable () { | ||
| 179 | @Override | ||
| 180 | public void | ||
| 181 | run () | ||
| 182 | { | ||
| 183 | invalidateFocus (1); | ||
| 184 | } | ||
| 185 | }); | ||
| 177 | } | 186 | } |
| 178 | 187 | ||
| 179 | @Override | 188 | @Override |
| @@ -261,7 +270,7 @@ public class EmacsActivity extends Activity | |||
| 261 | isMultitask = this instanceof EmacsMultitaskActivity; | 270 | isMultitask = this instanceof EmacsMultitaskActivity; |
| 262 | manager.removeWindowConsumer (this, isMultitask || isFinishing ()); | 271 | manager.removeWindowConsumer (this, isMultitask || isFinishing ()); |
| 263 | focusedActivities.remove (this); | 272 | focusedActivities.remove (this); |
| 264 | invalidateFocus (); | 273 | invalidateFocus (2); |
| 265 | 274 | ||
| 266 | /* Remove this activity from the static field, lest it leak. */ | 275 | /* Remove this activity from the static field, lest it leak. */ |
| 267 | if (lastFocusedActivity == this) | 276 | if (lastFocusedActivity == this) |
| @@ -274,9 +283,16 @@ public class EmacsActivity extends Activity | |||
| 274 | public final void | 283 | public final void |
| 275 | onWindowFocusChanged (boolean isFocused) | 284 | onWindowFocusChanged (boolean isFocused) |
| 276 | { | 285 | { |
| 277 | if (isFocused && !focusedActivities.contains (this)) | 286 | /* At times and on certain versions of Android ISFOCUSED does not |
| 287 | reflect whether the window actually holds focus, so replace it | ||
| 288 | with the value of `hasWindowFocus'. */ | ||
| 289 | isFocused = hasWindowFocus (); | ||
| 290 | |||
| 291 | if (isFocused) | ||
| 278 | { | 292 | { |
| 279 | focusedActivities.add (this); | 293 | if (!focusedActivities.contains (this)) |
| 294 | focusedActivities.add (this); | ||
| 295 | |||
| 280 | lastFocusedActivity = this; | 296 | lastFocusedActivity = this; |
| 281 | 297 | ||
| 282 | /* Update the window insets as the focus change may have | 298 | /* Update the window insets as the focus change may have |
| @@ -291,7 +307,7 @@ public class EmacsActivity extends Activity | |||
| 291 | else | 307 | else |
| 292 | focusedActivities.remove (this); | 308 | focusedActivities.remove (this); |
| 293 | 309 | ||
| 294 | invalidateFocus (); | 310 | invalidateFocus (3); |
| 295 | } | 311 | } |
| 296 | 312 | ||
| 297 | @Override | 313 | @Override |
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 304304a328b..b75d96b2b5a 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java | |||
| @@ -240,7 +240,7 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 240 | } | 240 | } |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | EmacsActivity.invalidateFocus (); | 243 | EmacsActivity.invalidateFocus (4); |
| 244 | 244 | ||
| 245 | if (!children.isEmpty ()) | 245 | if (!children.isEmpty ()) |
| 246 | throw new IllegalStateException ("Trying to destroy window with " | 246 | throw new IllegalStateException ("Trying to destroy window with " |
| @@ -760,7 +760,7 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 760 | public void | 760 | public void |
| 761 | onFocusChanged (boolean gainFocus) | 761 | onFocusChanged (boolean gainFocus) |
| 762 | { | 762 | { |
| 763 | EmacsActivity.invalidateFocus (); | 763 | EmacsActivity.invalidateFocus (gainFocus ? 6 : 5); |
| 764 | } | 764 | } |
| 765 | 765 | ||
| 766 | /* Notice that the activity has been detached or destroyed. | 766 | /* Notice that the activity has been detached or destroyed. |