diff options
| author | Po Lu | 2025-11-24 10:16:21 +0800 |
|---|---|---|
| committer | Po Lu | 2025-11-24 10:16:49 +0800 |
| commit | 7550791287503ebc582c92841f6483032aa0b050 (patch) | |
| tree | 12d9c7bcc1cba5a0ddf0a2be2199c661af6de429 /java | |
| parent | 435c3948a477a3e24af9cd866584c4e0f41f86b9 (diff) | |
| download | emacs-7550791287503ebc582c92841f6483032aa0b050.tar.gz emacs-7550791287503ebc582c92841f6483032aa0b050.zip | |
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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsNative.java | 9 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsNoninteractive.java | 2 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 20 |
3 files changed, 25 insertions, 6 deletions
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index 49a21ce1c4d..fac4b6f01df 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java | |||
| @@ -61,6 +61,9 @@ public final class EmacsNative | |||
| 61 | scaledDensity is the DPI value used to translate point sizes to | 61 | scaledDensity is the DPI value used to translate point sizes to |
| 62 | pixel sizes when loading fonts. | 62 | pixel sizes when loading fonts. |
| 63 | 63 | ||
| 64 | uiMode holds the bits of the system's UI mode specification | ||
| 65 | defining the active system theme. | ||
| 66 | |||
| 64 | classPath must be the classpath of this app_process process, or | 67 | classPath must be the classpath of this app_process process, or |
| 65 | NULL. | 68 | NULL. |
| 66 | 69 | ||
| @@ -74,6 +77,7 @@ public final class EmacsNative | |||
| 74 | float pixelDensityX, | 77 | float pixelDensityX, |
| 75 | float pixelDensityY, | 78 | float pixelDensityY, |
| 76 | float scaledDensity, | 79 | float scaledDensity, |
| 80 | int uiMode, | ||
| 77 | String classPath, | 81 | String classPath, |
| 78 | EmacsService emacsService, | 82 | EmacsService emacsService, |
| 79 | int apiLevel); | 83 | int apiLevel); |
| @@ -197,8 +201,9 @@ public final class EmacsNative | |||
| 197 | public static native void sendNotificationAction (String tag, String action); | 201 | public static native void sendNotificationAction (String tag, String action); |
| 198 | 202 | ||
| 199 | /* Send an ANDROID_CONFIGURATION_CHANGED event. */ | 203 | /* Send an ANDROID_CONFIGURATION_CHANGED event. */ |
| 200 | public static native void sendConfigurationChanged (float dpiX, float dpiY, | 204 | public static native void sendConfigurationChanged (int detail, float dpiX, |
| 201 | float dpiScaled); | 205 | float dpiY, float dpiScaled, |
| 206 | int ui_mode); | ||
| 202 | 207 | ||
| 203 | /* Return the file name associated with the specified file | 208 | /* Return the file name associated with the specified file |
| 204 | descriptor, or NULL if there is none. */ | 209 | descriptor, or NULL if there is none. */ |
diff --git a/java/org/gnu/emacs/EmacsNoninteractive.java b/java/org/gnu/emacs/EmacsNoninteractive.java index 83ef04b1cf1..b4d055ce4c9 100644 --- a/java/org/gnu/emacs/EmacsNoninteractive.java +++ b/java/org/gnu/emacs/EmacsNoninteractive.java | |||
| @@ -67,7 +67,7 @@ public final class EmacsNoninteractive | |||
| 67 | cacheDir = context.getCacheDir ().getCanonicalPath (); | 67 | cacheDir = context.getCacheDir ().getCanonicalPath (); |
| 68 | EmacsNative.setEmacsParams (assets, filesDir, | 68 | EmacsNative.setEmacsParams (assets, filesDir, |
| 69 | libDir, cacheDir, 0.0f, | 69 | libDir, cacheDir, 0.0f, |
| 70 | 0.0f, 0.0f, null, null, | 70 | 0.0f, 0.0f, 0x0, null, null, |
| 71 | Build.VERSION.SDK_INT); | 71 | Build.VERSION.SDK_INT); |
| 72 | 72 | ||
| 73 | /* Now find the dump file that Emacs should use, if it has already | 73 | /* Now find the dump file that Emacs should use, if it has already |
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 3630329839f..d141f6f4d0d 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -150,6 +150,10 @@ public final class EmacsService extends Service | |||
| 150 | consulted for font scaling. */ | 150 | consulted for font scaling. */ |
| 151 | private double dpiX, dpiY, dpiScaled; | 151 | private double dpiX, dpiY, dpiScaled; |
| 152 | 152 | ||
| 153 | /* The display's previously observed UI mode as it relates to the | ||
| 154 | system theme. */ | ||
| 155 | private int uiMode; | ||
| 156 | |||
| 153 | static | 157 | static |
| 154 | { | 158 | { |
| 155 | servicingQuery = new AtomicInteger (); | 159 | servicingQuery = new AtomicInteger (); |
| @@ -240,6 +244,7 @@ public final class EmacsService extends Service | |||
| 240 | float tempScaledDensity; | 244 | float tempScaledDensity; |
| 241 | Resources resources; | 245 | Resources resources; |
| 242 | DisplayMetrics metrics; | 246 | DisplayMetrics metrics; |
| 247 | Configuration configuration; | ||
| 243 | 248 | ||
| 244 | super.onCreate (); | 249 | super.onCreate (); |
| 245 | 250 | ||
| @@ -254,6 +259,8 @@ public final class EmacsService extends Service | |||
| 254 | tempScaledDensity = ((getScaledDensity (metrics) | 259 | tempScaledDensity = ((getScaledDensity (metrics) |
| 255 | / metrics.density) | 260 | / metrics.density) |
| 256 | * pixelDensityX); | 261 | * pixelDensityX); |
| 262 | configuration = resources.getConfiguration (); | ||
| 263 | uiMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK; | ||
| 257 | resolver = getContentResolver (); | 264 | resolver = getContentResolver (); |
| 258 | mainThread = Thread.currentThread (); | 265 | mainThread = Thread.currentThread (); |
| 259 | 266 | ||
| @@ -311,7 +318,8 @@ public final class EmacsService extends Service | |||
| 311 | EmacsNative.setEmacsParams (manager, filesDir, libDir, | 318 | EmacsNative.setEmacsParams (manager, filesDir, libDir, |
| 312 | cacheDir, pixelDensityX, | 319 | cacheDir, pixelDensityX, |
| 313 | pixelDensityY, scaledDensity, | 320 | pixelDensityY, scaledDensity, |
| 314 | classPath, EmacsService.this, | 321 | uiMode, classPath, |
| 322 | EmacsService.this, | ||
| 315 | Build.VERSION.SDK_INT); | 323 | Build.VERSION.SDK_INT); |
| 316 | } | 324 | } |
| 317 | }, extraStartupArguments); | 325 | }, extraStartupArguments); |
| @@ -375,8 +383,14 @@ public final class EmacsService extends Service | |||
| 375 | dpiX = pixelDensityX; | 383 | dpiX = pixelDensityX; |
| 376 | dpiY = pixelDensityY; | 384 | dpiY = pixelDensityY; |
| 377 | dpiScaled = scaledDensity; | 385 | dpiScaled = scaledDensity; |
| 378 | EmacsNative.sendConfigurationChanged (pixelDensityX, pixelDensityY, | 386 | EmacsNative.sendConfigurationChanged (0, pixelDensityX, pixelDensityY, |
| 379 | scaledDensity); | 387 | scaledDensity, 0); |
| 388 | } | ||
| 389 | |||
| 390 | if ((newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) != uiMode) | ||
| 391 | { | ||
| 392 | uiMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK; | ||
| 393 | EmacsNative.sendConfigurationChanged (1, 0.0f, 0.0f, 0.0f, uiMode); | ||
| 380 | } | 394 | } |
| 381 | 395 | ||
| 382 | super.onConfigurationChanged (newConfig); | 396 | super.onConfigurationChanged (newConfig); |