Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8343336: Add persistentScrollBars preference #1618

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,12 @@ public Map<String, Object> getPlatformPreferences() {
* <li>accentColor
* <li>reducedMotion
* <li>reducedTransparency
* <li>persistentScrollBars
* </ul>
*
* @return a map of platform-specific keys to well-known keys
*/
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?, ?>> getPlatformKeyMappings() {
return Map.of();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,13 @@ protected boolean _supportsInputMethods() {
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?, ?>> getPlatformKeyMappings() {
return Map.of(
"GTK.theme_fg_color", new PreferenceMapping<>("foregroundColor", Color.class),
"GTK.theme_bg_color", new PreferenceMapping<>("backgroundColor", Color.class),
"GTK.theme_selected_bg_color", new PreferenceMapping<>("accentColor", Color.class),
"GTK.enable_animations", new PreferenceMapping<>("reducedMotion", Boolean.class, b -> !b)
"GTK.enable_animations", new PreferenceMapping<>("reducedMotion", Boolean.class, b -> !b),
"GTK.overlay_scrolling", new PreferenceMapping<>("persistentScrollBars", Boolean.class, b -> !b)
);
}

Expand All @@ -480,7 +481,8 @@ public Map<String, Class<?>> getPlatformKeys() {
Map.entry("GTK.warning_color", Color.class),
Map.entry("GTK.error_color", Color.class),
Map.entry("GTK.success_color", Color.class),
Map.entry("GTK.enable_animations", Boolean.class)
Map.entry("GTK.enable_animations", Boolean.class),
Map.entry("GTK.overlay_scrolling", Boolean.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,14 @@ public String getDataDirectory() {
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?, ?>> getPlatformKeyMappings() {
return Map.of(
"macOS.NSColor.textColor", new PreferenceMapping<>("foregroundColor", Color.class),
"macOS.NSColor.textBackgroundColor", new PreferenceMapping<>("backgroundColor", Color.class),
"macOS.NSColor.controlAccentColor", new PreferenceMapping<>("accentColor", Color.class),
"macOS.NSWorkspace.accessibilityDisplayShouldReduceMotion", new PreferenceMapping<>("reducedMotion", Boolean.class),
"macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency", new PreferenceMapping<>("reducedTransparency", Boolean.class)
"macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency", new PreferenceMapping<>("reducedTransparency", Boolean.class),
"macOS.NSScroller.preferredScrollerStyle", new PreferenceMapping<>("persistentScrollBars", String.class, "NSScrollerStyleLegacy"::equals)
);
}

Expand Down Expand Up @@ -485,7 +486,8 @@ public Map<String, Class<?>> getPlatformKeys() {
Map.entry("macOS.NSColor.systemTealColor", Color.class),
Map.entry("macOS.NSColor.systemYellowColor", Color.class),
Map.entry("macOS.NSWorkspace.accessibilityDisplayShouldReduceMotion", Boolean.class),
Map.entry("macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency", Boolean.class)
Map.entry("macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency", Boolean.class),
Map.entry("macOS.NSScroller.preferredScrollerStyle", String.class)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,13 @@ public String getDataDirectory() {

// This list needs to be kept in sync with PlatformSupport.cpp in the Glass toolkit for Windows.
@Override
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?, ?>> getPlatformKeyMappings() {
return Map.of(
"Windows.UIColor.Foreground", new PreferenceMapping<>("foregroundColor", Color.class),
"Windows.UIColor.Background", new PreferenceMapping<>("backgroundColor", Color.class),
"Windows.UIColor.Accent", new PreferenceMapping<>("accentColor", Color.class),
"Windows.UISettings.AdvancedEffectsEnabled", new PreferenceMapping<>("reducedTransparency", Boolean.class, b -> !b),
"Windows.UISettings.AutoHideScrollBars", new PreferenceMapping<>("persistentScrollBars", Boolean.class, b -> !b),
"Windows.SPI.ClientAreaAnimation", new PreferenceMapping<>("reducedMotion", Boolean.class, b -> !b)
);
}
Expand Down Expand Up @@ -391,7 +392,8 @@ public Map<String, Class<?>> getPlatformKeys() {
Map.entry("Windows.UIColor.AccentLight1", Color.class),
Map.entry("Windows.UIColor.AccentLight2", Color.class),
Map.entry("Windows.UIColor.AccentLight3", Color.class),
Map.entry("Windows.UISettings.AdvancedEffectsEnabled", Boolean.class)
Map.entry("Windows.UISettings.AdvancedEffectsEnabled", Boolean.class),
Map.entry("Windows.UISettings.AutoHideScrollBars", Boolean.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ public static PlatformPreferences getPlatformPreferences() {
* @param preferences the initial set of platform preferences
*/
public static void initPreferences(Map<String, Class<?>> platformKeys,
Map<String, PreferenceMapping<?>> platformKeyMappings,
Map<String, PreferenceMapping<?, ?>> platformKeyMappings,
Map<String, Object> preferences) {
platformPreferences = new PlatformPreferences(platformKeys, platformKeyMappings);
platformPreferences.update(preferences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class PlatformPreferences extends AbstractMap<String, Object> imple
* Contains mappings from platform-specific keys to well-known keys, which are used
* in the implementation of the property-based API in {@link PreferenceProperties}.
*/
private final Map<String, PreferenceMapping<?>> platformKeyMappings;
private final Map<String, PreferenceMapping<?, ?>> platformKeyMappings;

/**
* Contains the current set of effective preferences, i.e. the set of preferences that
Expand All @@ -88,7 +88,7 @@ public final class PlatformPreferences extends AbstractMap<String, Object> imple
* contains {@code null} keys or values
*/
public PlatformPreferences(Map<String, Class<?>> platformKeys,
Map<String, PreferenceMapping<?>> platformKeyMappings) {
Map<String, PreferenceMapping<?, ?>> platformKeyMappings) {
this.platformKeys = Map.copyOf(platformKeys);
this.platformKeyMappings = Map.copyOf(platformKeyMappings);
}
Expand Down Expand Up @@ -223,6 +223,16 @@ public boolean isReducedTransparency() {
return properties.isReducedTransparency();
}

@Override
public ReadOnlyBooleanProperty persistentScrollBarsProperty() {
return properties.persistentScrollBarsProperty();
}

@Override
public boolean isPersistentScrollBars() {
return properties.isPersistentScrollBars();
}

@Override
public ReadOnlyObjectProperty<ColorScheme> colorSchemeProperty() {
return properties.colorSchemeProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@
* A mapping from platform-specific keys to platform-independent keys defined by JavaFX, including a
* function that maps the platform-specific value to the platform-independent value.
*/
public record PreferenceMapping<T>(String keyName, Class<T> valueType, Function<T, T> valueMapper) {
public record PreferenceMapping<T, U>(String keyName, Class<T> valueType, Function<T, U> valueMapper) {

public PreferenceMapping {
Objects.requireNonNull(keyName, "keyName cannot be null");
Objects.requireNonNull(valueType, "valueType cannot be null");
Objects.requireNonNull(valueMapper, "valueMapper cannot be null");
}

@SuppressWarnings("unchecked")
public PreferenceMapping(String keyName, Class<T> valueType) {
this(keyName, valueType, Function.identity());
this(keyName, valueType, value -> (U)value);
}

@SuppressWarnings("unchecked")
public T map(Object value) {
public U map(Object value) {
if (valueType.isInstance(value)) {
return valueMapper.apply((T)value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ final class PreferenceProperties {
private final ColorSchemeProperty colorScheme = new ColorSchemeProperty();
private final DeferredProperty<Boolean> reducedMotion = new DeferredProperty<>("reducedMotion", false);
private final DeferredProperty<Boolean> reducedTransparency = new DeferredProperty<>("reducedTransparency", false);
private final DeferredProperty<Boolean> persistentScrollBars = new DeferredProperty<>("persistentScrollBars", false);
private final ReadOnlyBooleanWrapper reducedMotionFlag;
private final ReadOnlyBooleanWrapper reducedTransparencyFlag;
private final ReadOnlyBooleanWrapper persistentScrollBarsFlag;
private final Object bean;

PreferenceProperties(Object bean) {
Expand All @@ -63,6 +65,9 @@ final class PreferenceProperties {

reducedTransparencyFlag = new ReadOnlyBooleanWrapper(bean, reducedTransparency.getName());
reducedTransparencyFlag.bind(reducedTransparency);

persistentScrollBarsFlag = new ReadOnlyBooleanWrapper(bean, persistentScrollBars.getName());
persistentScrollBarsFlag.bind(persistentScrollBars);
}

public ReadOnlyBooleanProperty reducedMotionProperty() {
Expand All @@ -89,6 +94,18 @@ public void setReducedTransparency(boolean value) {
reducedTransparency.setValueOverride(value);
}

public ReadOnlyBooleanProperty persistentScrollBarsProperty() {
return persistentScrollBarsFlag.getReadOnlyProperty();
}

public boolean isPersistentScrollBars() {
return persistentScrollBars.get();
}

public void setPersistentScrollBars(boolean value) {
persistentScrollBars.setValueOverride(value);
}

public ReadOnlyObjectProperty<ColorScheme> colorSchemeProperty() {
return colorScheme.getReadOnlyProperty();
}
Expand Down Expand Up @@ -138,9 +155,9 @@ public void setAccentColor(Color color) {
}

public void update(Map<String, ChangedValue> changedPreferences,
Map<String, PreferenceMapping<?>> platformKeyMappings) {
Map<String, PreferenceMapping<?, ?>> platformKeyMappings) {
for (Map.Entry<String, ChangedValue> entry : changedPreferences.entrySet()) {
if (platformKeyMappings.get(entry.getKey()) instanceof PreferenceMapping<?> mapping
if (platformKeyMappings.get(entry.getKey()) instanceof PreferenceMapping<?, ?> mapping
&& deferredProperties.get(mapping.keyName()) instanceof DeferredProperty<?> property) {
property.setPlatformValue(mapping.map(entry.getValue().newValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ public static Preferences getPreferences() {
* <tr><td>{@code Windows.UIColor.AccentLight2}</td><td>{@link Color}</td></tr>
* <tr><td>{@code Windows.UIColor.AccentLight3}</td><td>{@link Color}</td></tr>
* <tr><td>{@code Windows.UISettings.AdvancedEffectsEnabled}</td><td>{@link Boolean}</td></tr>
* <tr><td>{@code Windows.UISettings.AutoHideScrollBars}</td><td>{@link Boolean}</td></tr>
* <tr></tr>
* </tbody>
* </table>
Expand Down Expand Up @@ -551,6 +552,7 @@ public static Preferences getPreferences() {
* <tr><td>{@code macOS.NSColor.systemYellowColor}</td><td>{@link Color}</td></tr>
* <tr><td>{@code macOS.NSWorkspace.accessibilityDisplayShouldReduceMotion}</td><td>{@link Boolean}</td></tr>
* <tr><td>{@code macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency}</td><td>{@link Boolean}</td></tr>
* <tr><td>{@code macOS.NSScroller.preferredScrollerStyle}</td><td>{@link String}</td></tr>
* <tr></tr>
* </tbody>
* </table>
Expand All @@ -577,6 +579,7 @@ public static Preferences getPreferences() {
* <tr><td>{@code GTK.error_color}</td><td>{@link Color}</td></tr>
* <tr><td>{@code GTK.success_color}</td><td>{@link Color}</td></tr>
* <tr><td>{@code GTK.enable_animations}</td><td>{@link Boolean}</td></tr>
* <tr><td>{@code GTK.overlay_scrolling}</td><td>{@link Boolean}</td></tr>
* <tr></tr>
* </tbody>
* </table>
Expand All @@ -586,6 +589,20 @@ public static Preferences getPreferences() {
public sealed interface Preferences extends ObservableMap<String, Object>
permits com.sun.javafx.application.preferences.PlatformPreferences {

/**
* Specifies whether applications should always show scroll bars. If not set, an application may
* choose to hide scroll bars that are not actively used, or make them smaller or less noticeable.
* <p>
* If the platform does not report this preference, this property defaults to {@code false}.
*
* @return the {@code persistentScrollBars} property
* @defaultValue {@code false}
* @since 24
*/
ReadOnlyBooleanProperty persistentScrollBarsProperty();
kevinrushforth marked this conversation as resolved.
Show resolved Hide resolved

boolean isPersistentScrollBars();

/**
* Specifies whether applications should minimize the amount of non-essential animations,
* reducing discomfort for users who experience motion sickness or vertigo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ jobject PlatformSupport::collectPreferences() const {
gboolean enableAnimations = true;
g_object_get(settings, "gtk-enable-animations", &enableAnimations, NULL);
putBoolean(env, prefs, "GTK.enable_animations", enableAnimations);

if (g_object_class_find_property(G_OBJECT_GET_CLASS(settings), "gtk-overlay-scrolling")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, presuming that we want the property to be absent on systems that don't support this setting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a property that isn't available shouldn't be included in the preferences map. We've documented that in Platform.Preferences:

     * The preferences that are reported by the platform may be dependent on the operating system version
     * and its current configuration, so applications should not assume that a particular preference is
     * always available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so this is fine.

gboolean overlayScrolling = true;
g_object_get(settings, "gtk-overlay-scrolling", &overlayScrolling, NULL);
putBoolean(env, prefs, "GTK.overlay_scrolling", overlayScrolling);
}
}

return prefs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,7 +32,8 @@ class PlatformSupport final
public:
static constexpr const char* observedSettings[] = {
"notify::gtk-theme-name",
"notify::gtk-enable-animations"
"notify::gtk-enable-animations",
"notify::gtk-overlay-scrolling"
};

PlatformSupport(JNIEnv*, jobject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
name:NSApplicationDidChangeScreenParametersNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(platformPreferencesDidChange)
name:NSPreferredScrollerStyleDidChangeNotification
object:nil];

[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(platformPreferencesDidChange)
name:@"AppleInterfaceThemeChangedNotification"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ + (jobject)collectPreferences {
key:"macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency"
value:[[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceTransparency]];

[PlatformSupport putString:preferences
key:"macOS.NSScroller.preferredScrollerStyle"
value:[NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay
? "NSScrollerStyleOverlay" : "NSScrollerStyleLegacy"];

return preferences;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jclass GlassApplication::ClassForName(JNIEnv *env, char *className)
return foundClass;
}

GlassApplication::GlassApplication(jobject jrefThis) : BaseWnd(), m_platformSupport(GetEnv())
GlassApplication::GlassApplication(jobject jrefThis) : BaseWnd(), m_platformSupport(GetEnv(), jrefThis)
{
m_grefThis = GetEnv()->NewGlobalRef(jrefThis);
m_clipboard = NULL;
Expand Down Expand Up @@ -168,7 +168,7 @@ LRESULT GlassApplication::WindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
}
break;
case WM_SETTINGCHANGE:
if (m_platformSupport.onSettingChanged(m_grefThis, wParam, lParam)) {
if (m_platformSupport.onSettingChanged(wParam, lParam)) {
return 0;
}

Expand All @@ -182,7 +182,7 @@ LRESULT GlassApplication::WindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
case WM_THEMECHANGED:
case WM_SYSCOLORCHANGE:
case WM_DWMCOLORIZATIONCOLORCHANGED:
if (m_platformSupport.updatePreferences(m_grefThis)) {
if (m_platformSupport.updatePreferences()) {
return 0;
}
break;
Expand Down Expand Up @@ -304,9 +304,6 @@ BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH) {
GlassApplication::SetHInstance((HINSTANCE)hinstDLL);
tryInitializeRoActivationSupport();
} else if (dwReason == DLL_PROCESS_DETACH) {
uninitializeRoActivationSupport();
}
return TRUE;
}
Expand Down
Loading