Support `toolkit-theme-set-functions' on Android and execute hooks safely

* java/org/gnu/emacs/EmacsNative.java (setEmacsParams): New arg
UIMODE.
(sendConfigurationChanged): New args DETAIL and UI_MODE.

* java/org/gnu/emacs/EmacsNoninteractive.java (main1): Provide
an undefined UI mode.

* java/org/gnu/emacs/EmacsService.java (EmacsService): New field
uiMode.
(onCreate): Initialize this field at start-up and provide the
same to setEmacsParams.
(onConfigurationChanged): If the UI mode has been altered,
generate a configuration changed event to match.

* src/android.c (android_ui_mode): New variable.
(setEmacsParams): New argument UI_MODE.  Initialize the same
from this variable.

* src/androidgui.h (enum android_configuration_changed): New
enum.
(struct android_configuration_changed_event): New field
`DETAIL'.  Convert fields providing specifics into a union of
display density information and a UI mode integer.

* src/androidterm.c (handle_one_android_event): Handle both
manners of configuration change events.
(android_term_init): Initialize Vtoolkit_theme from UI mode
provided at start-up.

* src/frame.c (syms_of_frame): Always define Vtoolkit_theme.
Define Qtoolkit_theme_set_functions.

* src/gtkutil.c (xg_update_dark_mode_for_all_displays):

* src/w32term.c (w32_read_socket): Generate special toolkit
theme events, rather than executing hooks directly within the
read_socket callback.

* src/keyboard.c (kbd_buffer_get_event)
<TOOLKIT_THEME_CHANGED_EVENT>: Run Qtoolkit_theme_set_functions
and set Vtoolkit_theme from event->ie.arg.

* src/termhooks.h (enum event_kind): New event
TOOLKIT_THEME_CHANGED_EVENT.
This commit is contained in:
Po Lu
2025-11-24 10:16:21 +08:00
parent 435c3948a4
commit 7550791287
13 changed files with 132 additions and 52 deletions

View File

@@ -61,6 +61,9 @@ public final class EmacsNative
scaledDensity is the DPI value used to translate point sizes to
pixel sizes when loading fonts.
uiMode holds the bits of the system's UI mode specification
defining the active system theme.
classPath must be the classpath of this app_process process, or
NULL.
@@ -74,6 +77,7 @@ public final class EmacsNative
float pixelDensityX,
float pixelDensityY,
float scaledDensity,
int uiMode,
String classPath,
EmacsService emacsService,
int apiLevel);
@@ -197,8 +201,9 @@ public final class EmacsNative
public static native void sendNotificationAction (String tag, String action);
/* Send an ANDROID_CONFIGURATION_CHANGED event. */
public static native void sendConfigurationChanged (float dpiX, float dpiY,
float dpiScaled);
public static native void sendConfigurationChanged (int detail, float dpiX,
float dpiY, float dpiScaled,
int ui_mode);
/* Return the file name associated with the specified file
descriptor, or NULL if there is none. */