diff options
| author | Po Lu | 2025-04-10 15:21:15 +0800 |
|---|---|---|
| committer | Po Lu | 2025-04-10 15:25:38 +0800 |
| commit | 884ede7c959b1331e1ede0b1b80f01a06c048bf5 (patch) | |
| tree | 5ca2198d6e17931492b14d99393d83e798a7f011 /java | |
| parent | cb339ad8f4e386505f1eae9e45c4162feea61f53 (diff) | |
| download | emacs-884ede7c959b1331e1ede0b1b80f01a06c048bf5.tar.gz emacs-884ede7c959b1331e1ede0b1b80f01a06c048bf5.zip | |
Respond to display configuration updates on Android
* java/org/gnu/emacs/EmacsNative.java
(sendConfigurationChanged): Declare function.
* java/org/gnu/emacs/EmacsSdk7FontDriver.java (Sdk7FontEntity)
(Sdk7FontObject): Do not access `metrics' field deleted from
`EmacsService'.
* java/org/gnu/emacs/EmacsService.java (EmacsService)
<metrics, resources>: Delete fields.
<dpiX, dpiY, dpiScaled>: New fields.
(onCreate): Adjust accordingly. Record current display metrics
for subsequent comparison.
(onConfigurationChanged): New function.
* lisp/dynamic-setting.el (font-setting-change-default-font):
Enable on systems where font-get-system-font is not defined if
invoked with SET-FONT nil.
* src/android.c (sendConfigurationChanged): New function.
* src/androidgui.h (ANDROID_CONFIGURATION_CHANGED): New enumerator.
(struct android_configuration_changed): New structure.
(union android_event): Add `config' member.
* src/androidterm.c (handle_one_android_event): Handle
ANDROID_CONFIGURATION_CHANGED events.
(syms_of_androidterm): Define Qfont_render, and
Qdynamic_setting. Provide the latter.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsNative.java | 4 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsSdk7FontDriver.java | 10 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 66 |
3 files changed, 64 insertions, 16 deletions
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index 94df9ff39b4..49a21ce1c4d 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java | |||
| @@ -196,6 +196,10 @@ public final class EmacsNative | |||
| 196 | /* Send an ANDROID_NOTIFICATION_ACTION event. */ | 196 | /* Send an ANDROID_NOTIFICATION_ACTION event. */ |
| 197 | public static native void sendNotificationAction (String tag, String action); | 197 | public static native void sendNotificationAction (String tag, String action); |
| 198 | 198 | ||
| 199 | /* Send an ANDROID_CONFIGURATION_CHANGED event. */ | ||
| 200 | public static native void sendConfigurationChanged (float dpiX, float dpiY, | ||
| 201 | float dpiScaled); | ||
| 202 | |||
| 199 | /* Return the file name associated with the specified file | 203 | /* Return the file name associated with the specified file |
| 200 | descriptor, or NULL if there is none. */ | 204 | descriptor, or NULL if there is none. */ |
| 201 | public static native byte[] getProcName (int fd); | 205 | public static native byte[] getProcName (int fd); |
diff --git a/java/org/gnu/emacs/EmacsSdk7FontDriver.java b/java/org/gnu/emacs/EmacsSdk7FontDriver.java index 2fc40551984..b426c3ba74e 100644 --- a/java/org/gnu/emacs/EmacsSdk7FontDriver.java +++ b/java/org/gnu/emacs/EmacsSdk7FontDriver.java | |||
| @@ -29,6 +29,7 @@ import android.graphics.Rect; | |||
| 29 | import android.graphics.Typeface; | 29 | import android.graphics.Typeface; |
| 30 | import android.graphics.Canvas; | 30 | import android.graphics.Canvas; |
| 31 | 31 | ||
| 32 | import android.util.DisplayMetrics; | ||
| 32 | import android.util.Log; | 33 | import android.util.Log; |
| 33 | 34 | ||
| 34 | 35 | ||
| @@ -103,6 +104,8 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver | |||
| 103 | public | 104 | public |
| 104 | Sdk7FontEntity (Sdk7Typeface typeface) | 105 | Sdk7FontEntity (Sdk7Typeface typeface) |
| 105 | { | 106 | { |
| 107 | DisplayMetrics metrics; | ||
| 108 | |||
| 106 | foundry = "Google"; | 109 | foundry = "Google"; |
| 107 | family = typeface.familyName; | 110 | family = typeface.familyName; |
| 108 | adstyle = null; | 111 | adstyle = null; |
| @@ -110,7 +113,8 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver | |||
| 110 | slant = typeface.slant; | 113 | slant = typeface.slant; |
| 111 | spacing = typeface.spacing; | 114 | spacing = typeface.spacing; |
| 112 | width = typeface.width; | 115 | width = typeface.width; |
| 113 | dpi = Math.round (EmacsService.SERVICE.metrics.scaledDensity * 160f); | 116 | metrics = EmacsService.SERVICE.getResources ().getDisplayMetrics (); |
| 117 | dpi = Math.round (metrics.scaledDensity * 160f); | ||
| 114 | 118 | ||
| 115 | this.typeface = typeface; | 119 | this.typeface = typeface; |
| 116 | } | 120 | } |
| @@ -127,6 +131,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver | |||
| 127 | { | 131 | { |
| 128 | float totalWidth; | 132 | float totalWidth; |
| 129 | String testWidth, testString; | 133 | String testWidth, testString; |
| 134 | DisplayMetrics metrics; | ||
| 130 | 135 | ||
| 131 | this.typeface = typeface; | 136 | this.typeface = typeface; |
| 132 | this.pixelSize = pixelSize; | 137 | this.pixelSize = pixelSize; |
| @@ -137,7 +142,8 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver | |||
| 137 | slant = typeface.slant; | 142 | slant = typeface.slant; |
| 138 | spacing = typeface.spacing; | 143 | spacing = typeface.spacing; |
| 139 | width = typeface.width; | 144 | width = typeface.width; |
| 140 | dpi = Math.round (EmacsService.SERVICE.metrics.scaledDensity * 160f); | 145 | metrics = EmacsService.SERVICE.getResources ().getDisplayMetrics (); |
| 146 | dpi = Math.round (metrics.scaledDensity * 160f); | ||
| 141 | 147 | ||
| 142 | /* Compute the ascent and descent. */ | 148 | /* Compute the ascent and descent. */ |
| 143 | typeface.typefacePaint.setTextSize (pixelSize); | 149 | typeface.typefacePaint.setTextSize (pixelSize); |
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index babf2626ba5..3630329839f 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -123,9 +123,6 @@ public final class EmacsService extends Service | |||
| 123 | public static final int IC_MODE_TEXT = 2; | 123 | public static final int IC_MODE_TEXT = 2; |
| 124 | public static final int IC_MODE_PASSWORD = 3; | 124 | public static final int IC_MODE_PASSWORD = 3; |
| 125 | 125 | ||
| 126 | /* Display metrics used by font backends. */ | ||
| 127 | public DisplayMetrics metrics; | ||
| 128 | |||
| 129 | /* Flag that says whether or not to print verbose debugging | 126 | /* Flag that says whether or not to print verbose debugging |
| 130 | information when responding to an input method. */ | 127 | information when responding to an input method. */ |
| 131 | public static final boolean DEBUG_IC = false; | 128 | public static final boolean DEBUG_IC = false; |
| @@ -149,8 +146,9 @@ public final class EmacsService extends Service | |||
| 149 | thread. */ | 146 | thread. */ |
| 150 | private Thread mainThread; | 147 | private Thread mainThread; |
| 151 | 148 | ||
| 152 | /* "Resources" object required by GContext bookkeeping. */ | 149 | /* The display's horizontal and vertical density and that which is |
| 153 | public static Resources resources; | 150 | consulted for font scaling. */ |
| 151 | private double dpiX, dpiY, dpiScaled; | ||
| 154 | 152 | ||
| 155 | static | 153 | static |
| 156 | { | 154 | { |
| @@ -236,10 +234,12 @@ public final class EmacsService extends Service | |||
| 236 | final AssetManager manager; | 234 | final AssetManager manager; |
| 237 | Context app_context; | 235 | Context app_context; |
| 238 | final String filesDir, libDir, cacheDir, classPath; | 236 | final String filesDir, libDir, cacheDir, classPath; |
| 239 | final double pixelDensityX; | 237 | final float pixelDensityX; |
| 240 | final double pixelDensityY; | 238 | final float pixelDensityY; |
| 241 | final double scaledDensity; | 239 | final float scaledDensity; |
| 242 | double tempScaledDensity; | 240 | float tempScaledDensity; |
| 241 | Resources resources; | ||
| 242 | DisplayMetrics metrics; | ||
| 243 | 243 | ||
| 244 | super.onCreate (); | 244 | super.onCreate (); |
| 245 | 245 | ||
| @@ -265,13 +265,18 @@ public final class EmacsService extends Service | |||
| 265 | corresponds to 1 pixel, not 72 or 96 as used elsewhere. This | 265 | corresponds to 1 pixel, not 72 or 96 as used elsewhere. This |
| 266 | difference is codified in PT_PER_INCH defined in font.h. */ | 266 | difference is codified in PT_PER_INCH defined in font.h. */ |
| 267 | 267 | ||
| 268 | if (tempScaledDensity < 160) | 268 | if (tempScaledDensity < 160.0f) |
| 269 | tempScaledDensity = 160; | 269 | tempScaledDensity = 160.0f; |
| 270 | 270 | ||
| 271 | /* scaledDensity is const as required to refer to it from within | 271 | /* scaledDensity is const as required to refer to it from within |
| 272 | the nested function below. */ | 272 | the nested function below. */ |
| 273 | scaledDensity = tempScaledDensity; | 273 | scaledDensity = tempScaledDensity; |
| 274 | 274 | ||
| 275 | /* Save these fields for future reference. */ | ||
| 276 | dpiX = pixelDensityX; | ||
| 277 | dpiY = pixelDensityY; | ||
| 278 | dpiScaled = scaledDensity; | ||
| 279 | |||
| 275 | /* Remove all tasks from previous Emacs sessions but the task | 280 | /* Remove all tasks from previous Emacs sessions but the task |
| 276 | created by the system at startup. */ | 281 | created by the system at startup. */ |
| 277 | EmacsWindowManager.MANAGER.removeOldTasks (this); | 282 | EmacsWindowManager.MANAGER.removeOldTasks (this); |
| @@ -304,9 +309,8 @@ public final class EmacsService extends Service | |||
| 304 | run () | 309 | run () |
| 305 | { | 310 | { |
| 306 | EmacsNative.setEmacsParams (manager, filesDir, libDir, | 311 | EmacsNative.setEmacsParams (manager, filesDir, libDir, |
| 307 | cacheDir, (float) pixelDensityX, | 312 | cacheDir, pixelDensityX, |
| 308 | (float) pixelDensityY, | 313 | pixelDensityY, scaledDensity, |
| 309 | (float) scaledDensity, | ||
| 310 | classPath, EmacsService.this, | 314 | classPath, EmacsService.this, |
| 311 | Build.VERSION.SDK_INT); | 315 | Build.VERSION.SDK_INT); |
| 312 | } | 316 | } |
| @@ -344,6 +348,40 @@ public final class EmacsService extends Service | |||
| 344 | super.onLowMemory (); | 348 | super.onLowMemory (); |
| 345 | } | 349 | } |
| 346 | 350 | ||
| 351 | @Override | ||
| 352 | public void | ||
| 353 | onConfigurationChanged (Configuration newConfig) | ||
| 354 | { | ||
| 355 | DisplayMetrics metrics; | ||
| 356 | float pixelDensityX, pixelDensityY, scaledDensity; | ||
| 357 | |||
| 358 | metrics = getResources ().getDisplayMetrics (); | ||
| 359 | |||
| 360 | /* The display configuration may have been altered. Retrieve the | ||
| 361 | revised display density and deliver an event if so. */ | ||
| 362 | pixelDensityX = metrics.xdpi; | ||
| 363 | pixelDensityY = metrics.ydpi; | ||
| 364 | scaledDensity = ((getScaledDensity (metrics) | ||
| 365 | / metrics.density) * pixelDensityX); | ||
| 366 | |||
| 367 | /* A density below 160 probably indicates a system bug. See | ||
| 368 | onCreate for more commentary. */ | ||
| 369 | if (scaledDensity < 160.0f) | ||
| 370 | scaledDensity = 160.0f; | ||
| 371 | |||
| 372 | if (pixelDensityX != dpiX || pixelDensityY != dpiY | ||
| 373 | || scaledDensity != dpiScaled) | ||
| 374 | { | ||
| 375 | dpiX = pixelDensityX; | ||
| 376 | dpiY = pixelDensityY; | ||
| 377 | dpiScaled = scaledDensity; | ||
| 378 | EmacsNative.sendConfigurationChanged (pixelDensityX, pixelDensityY, | ||
| 379 | scaledDensity); | ||
| 380 | } | ||
| 381 | |||
| 382 | super.onConfigurationChanged (newConfig); | ||
| 383 | } | ||
| 384 | |||
| 347 | 385 | ||
| 348 | 386 | ||
| 349 | /* Functions from here on must only be called from the Emacs | 387 | /* Functions from here on must only be called from the Emacs |