* java/Makefile.in (clean): Fix distclean and bootstrap-clean rules. * java/debug.sh (jdb_port): (attach_existing): (num_pids): (line): Add new options to upload a gdbserver binary to the device. * java/org/gnu/emacs/EmacsActivity.java (EmacsActivity): Make focusedActivities public. * java/org/gnu/emacs/EmacsContextMenu.java (EmacsContextMenu): New class. * java/org/gnu/emacs/EmacsDrawRectangle.java (perform): Fix bounds computation. * java/org/gnu/emacs/EmacsGC.java (markDirty): Set stroke width explicitly. * java/org/gnu/emacs/EmacsService.java (EmacsService) (getLocationOnScreen, nameKeysym): New functions. * java/org/gnu/emacs/EmacsView.java (EmacsView): Disable focus highlight. (onCreateContextMenu, popupMenu, cancelPopupMenu): New functions. * java/org/gnu/emacs/EmacsWindow.java (EmacsWindow): Implement a kind of ``override redirect'' window for tooltips. * src/android.c (struct android_emacs_service): New method `name_keysym'. (android_run_select_thread, android_init_events): (android_select): Release select thread on semaphores instead of signals to avoid one nasty race on SIGUSR2 delivery. (android_init_emacs_service): Initialize new method. (android_create_window): Handle CW_OVERRIDE_REDIRECT. (android_move_resize_window, android_map_raised) (android_translate_coordinates, android_get_keysym_name) (android_build_string, android_exception_check): New functions. * src/android.h: Update prototypes. * src/androidfns.c (android_set_parent_frame, Fx_create_frame) (unwind_create_tip_frame, android_create_tip_frame) (android_hide_tip, compute_tip_xy, Fx_show_tip, Fx_hide_tip) (syms_of_androidfns): Implement tooltips and iconification reporting. * src/androidgui.h (enum android_window_value_mask): Add CWOverrideRedirect. (struct android_set_window_attributes): Add `override_redirect'. (ANDROID_IS_MODIFIER_KEY): Recognize Caps Lock. * src/androidmenu.c (struct android_emacs_context_menu): New struct. (android_init_emacs_context_menu, android_unwind_local_frame) (android_push_local_frame, android_menu_show, init_androidmenu): New functions. * src/androidterm.c (handle_one_android_event): Fix NULL pointer dereference. (android_fullscreen_hook): Handle fullscreen correctly. (android_draw_box_rect): Fix top line. (get_keysym_name): Implement function. (android_create_terminal): Remove scroll bar stubs and add menu hook. * src/androidterm.h: Update prototypes. * src/emacs.c (android_emacs_init): Initialize androidmenu.c. * xcompile/Makefile.in: Fix clean rules.
230 lines
5.5 KiB
Java
230 lines
5.5 KiB
Java
/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
|
|
|
|
Copyright (C) 2023 Free Software Foundation, Inc.
|
|
|
|
This file is part of GNU Emacs.
|
|
|
|
GNU Emacs is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or (at
|
|
your option) any later version.
|
|
|
|
GNU Emacs is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
|
|
|
|
package org.gnu.emacs;
|
|
|
|
import java.lang.IllegalStateException;
|
|
import java.util.List;
|
|
import java.util.ArrayList;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.FrameLayout.LayoutParams;
|
|
|
|
public class EmacsActivity extends Activity
|
|
implements EmacsWindowAttachmentManager.WindowConsumer
|
|
{
|
|
public static final String TAG = "EmacsActivity";
|
|
|
|
/* The currently attached EmacsWindow, or null if none. */
|
|
private EmacsWindow window;
|
|
|
|
/* The frame layout associated with the activity. */
|
|
private FrameLayout layout;
|
|
|
|
/* List of activities with focus. */
|
|
public static List<EmacsActivity> focusedActivities;
|
|
|
|
/* The currently focused window. */
|
|
public static EmacsWindow focusedWindow;
|
|
|
|
/* Whether or not this activity is paused. */
|
|
private boolean isPaused;
|
|
|
|
static
|
|
{
|
|
focusedActivities = new ArrayList<EmacsActivity> ();
|
|
};
|
|
|
|
public static void
|
|
invalidateFocus1 (EmacsWindow window)
|
|
{
|
|
if (window.view.isFocused ())
|
|
focusedWindow = window;
|
|
|
|
for (EmacsWindow child : window.children)
|
|
invalidateFocus1 (child);
|
|
}
|
|
|
|
public static void
|
|
invalidateFocus ()
|
|
{
|
|
EmacsWindow oldFocus;
|
|
|
|
/* Walk through each focused activity and assign the window focus
|
|
to the bottom-most focused window within. Record the old focus
|
|
as well. */
|
|
oldFocus = focusedWindow;
|
|
focusedWindow = null;
|
|
|
|
for (EmacsActivity activity : focusedActivities)
|
|
{
|
|
if (activity.window != null)
|
|
invalidateFocus1 (activity.window);
|
|
}
|
|
|
|
/* Send focus in- and out- events to the previous and current
|
|
focus. */
|
|
|
|
if (oldFocus != null)
|
|
EmacsNative.sendFocusOut (oldFocus.handle,
|
|
System.currentTimeMillis ());
|
|
|
|
if (focusedWindow != null)
|
|
EmacsNative.sendFocusIn (focusedWindow.handle,
|
|
System.currentTimeMillis ());
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
detachWindow ()
|
|
{
|
|
if (window == null)
|
|
Log.w (TAG, "detachWindow called, but there is no window");
|
|
else
|
|
{
|
|
/* Clear the window's pointer to this activity and remove the
|
|
window's view. */
|
|
window.setConsumer (null);
|
|
|
|
/* The window can't be iconified any longer. */
|
|
window.noticeDeiconified ();
|
|
layout.removeView (window.view);
|
|
window = null;
|
|
|
|
invalidateFocus ();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
attachWindow (EmacsWindow child)
|
|
{
|
|
Log.d (TAG, "attachWindow: " + child);
|
|
|
|
if (window != null)
|
|
throw new IllegalStateException ("trying to attach window when one"
|
|
+ " already exists");
|
|
|
|
/* Record and attach the view. */
|
|
|
|
window = child;
|
|
layout.addView (window.view);
|
|
child.setConsumer (this);
|
|
|
|
/* If the activity is iconified, send that to the window. */
|
|
if (isPaused)
|
|
window.noticeIconified ();
|
|
|
|
/* Invalidate the focus. */
|
|
invalidateFocus ();
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
destroy ()
|
|
{
|
|
finish ();
|
|
}
|
|
|
|
@Override
|
|
public EmacsWindow
|
|
getAttachedWindow ()
|
|
{
|
|
return window;
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
onCreate (Bundle savedInstanceState)
|
|
{
|
|
FrameLayout.LayoutParams params;
|
|
|
|
/* Set the theme to one without a title bar. */
|
|
setTheme (android.R.style.Theme_NoTitleBar);
|
|
|
|
params = new FrameLayout.LayoutParams (LayoutParams.MATCH_PARENT,
|
|
LayoutParams.MATCH_PARENT);
|
|
|
|
/* Make the frame layout. */
|
|
layout = new FrameLayout (this);
|
|
layout.setLayoutParams (params);
|
|
|
|
/* Set it as the content view. */
|
|
setContentView (layout);
|
|
|
|
if (EmacsService.SERVICE == null)
|
|
/* Start the Emacs service now. */
|
|
startService (new Intent (this, EmacsService.class));
|
|
|
|
/* Add this activity to the list of available activities. */
|
|
EmacsWindowAttachmentManager.MANAGER.registerWindowConsumer (this);
|
|
|
|
super.onCreate (savedInstanceState);
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
onDestroy ()
|
|
{
|
|
/* The activity will die shortly hereafter. If there is a window
|
|
attached, close it now. */
|
|
Log.d (TAG, "onDestroy " + this);
|
|
EmacsWindowAttachmentManager.MANAGER.removeWindowConsumer (this);
|
|
focusedActivities.remove (this);
|
|
invalidateFocus ();
|
|
super.onDestroy ();
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
onWindowFocusChanged (boolean isFocused)
|
|
{
|
|
if (isFocused && !focusedActivities.contains (this))
|
|
focusedActivities.add (this);
|
|
else
|
|
focusedActivities.remove (this);
|
|
|
|
invalidateFocus ();
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
onPause ()
|
|
{
|
|
isPaused = true;
|
|
|
|
EmacsWindowAttachmentManager.MANAGER.noticeIconified (this);
|
|
super.onResume ();
|
|
}
|
|
|
|
@Override
|
|
public void
|
|
onResume ()
|
|
{
|
|
isPaused = false;
|
|
|
|
EmacsWindowAttachmentManager.MANAGER.noticeDeiconified (this);
|
|
super.onResume ();
|
|
}
|
|
};
|