Implement tooltip_reuse_hidden_frame for Android

* java/org/gnu/emacs/EmacsWindow.java
(findSuitableActivityContext): Return Activity rather than
Context.
(mapWindow): Provide window token manually.

* src/androidfns.c (Fx_show_tip, Fx_hide_tip): Respect
tooltip_reuse_hidden_frame.
This commit is contained in:
Po Lu 2024-02-18 12:48:41 +08:00
parent bd0e281a6a
commit c2d714886e
2 changed files with 74 additions and 6 deletions

View file

@ -27,6 +27,8 @@
import java.util.LinkedHashMap;
import java.util.Map;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;
@ -362,6 +364,9 @@ private static class Coordinate
requestViewLayout ();
}
/* Return WM layout parameters for an override redirect window with
the geometry provided here. */
private WindowManager.LayoutParams
getWindowLayoutParams ()
{
@ -384,15 +389,15 @@ private static class Coordinate
return params;
}
private Context
private Activity
findSuitableActivityContext ()
{
/* Find a recently focused activity. */
if (!EmacsActivity.focusedActivities.isEmpty ())
return EmacsActivity.focusedActivities.get (0);
/* Return the service context, which probably won't work. */
return EmacsService.SERVICE;
/* Resort to the last activity to be focused. */
return EmacsActivity.lastFocusedActivity;
}
public synchronized void
@ -416,7 +421,7 @@ private static class Coordinate
{
EmacsWindowAttachmentManager manager;
WindowManager windowManager;
Context ctx;
Activity ctx;
Object tem;
WindowManager.LayoutParams params;
@ -447,11 +452,23 @@ private static class Coordinate
activity using the system window manager. */
ctx = findSuitableActivityContext ();
if (ctx == null)
{
Log.w (TAG, "failed to attach override-redirect window"
+ " for want of activity");
return;
}
tem = ctx.getSystemService (Context.WINDOW_SERVICE);
windowManager = (WindowManager) tem;
/* Calculate layout parameters. */
/* Calculate layout parameters and propagate the
activity's token into it. */
params = getWindowLayoutParams ();
params.token = (ctx.findViewById (android.R.id.content)
.getWindowToken ());
view.setLayoutParams (params);
/* Attach the view. */

View file

@ -2287,6 +2287,57 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
goto start_timer;
}
else if (tooltip_reuse_hidden_frame && BASE_EQ (frame, tip_last_frame))
{
bool delete = false;
Lisp_Object tail, elt, parm, last;
/* Check if every parameter in PARMS has the same value in
tip_last_parms. This may destruct tip_last_parms which,
however, will be recreated below. */
for (tail = parms; CONSP (tail); tail = XCDR (tail))
{
elt = XCAR (tail);
parm = CAR (elt);
/* The left, top, right and bottom parameters are handled
by compute_tip_xy so they can be ignored here. */
if (!EQ (parm, Qleft) && !EQ (parm, Qtop)
&& !EQ (parm, Qright) && !EQ (parm, Qbottom))
{
last = Fassq (parm, tip_last_parms);
if (NILP (Fequal (CDR (elt), CDR (last))))
{
/* We lost, delete the old tooltip. */
delete = true;
break;
}
else
tip_last_parms
= call2 (Qassq_delete_all, parm, tip_last_parms);
}
else
tip_last_parms
= call2 (Qassq_delete_all, parm, tip_last_parms);
}
/* Now check if every parameter in what is left of
tip_last_parms with a non-nil value has an association in
PARMS. */
for (tail = tip_last_parms; CONSP (tail); tail = XCDR (tail))
{
elt = XCAR (tail);
parm = CAR (elt);
if (!EQ (parm, Qleft) && !EQ (parm, Qtop) && !EQ (parm, Qright)
&& !EQ (parm, Qbottom) && !NILP (CDR (elt)))
{
/* We lost, delete the old tooltip. */
delete = true;
break;
}
}
android_hide_tip (delete);
}
else
android_hide_tip (true);
}
@ -2453,7 +2504,7 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
#endif /* 0 */
return Qnil;
#else /* !ANDROID_STUBIFY */
return android_hide_tip (true);
return android_hide_tip (!tooltip_reuse_hidden_frame);
#endif /* ANDROID_STUBIFY */
}