Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 26 additions & 6 deletions src/fw/shell/normal/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static uint32_t s_dynamic_backlight_min_threshold = 0; // default set from board
#if CAPABILITY_HAS_ORIENTATION_MANAGER
#define PREF_KEY_DISPLAY_ORIENTATION_LEFT_HANDED "displayOrientationLeftHanded"
static bool s_display_orientation_left = false;
#endif
#endif

#define PREF_KEY_BACKLIGHT_AMBIENT_THRESHOLD "lightAmbientThreshold"
static uint32_t s_backlight_ambient_threshold = 0; // default set from board config in shell_prefs_init()
Expand Down Expand Up @@ -249,11 +249,13 @@ static GColor s_theme_highlight_color = GColorVividCerulean;
#define PREF_KEY_MENU_SCROLL_VIBE_BEHAVIOR "menuScrollVibeBehavior"
#define PREF_KEY_MUSIC_SHOW_VOLUME_CONTROLS "musicShowVolumeControls"
#define PREF_KEY_MUSIC_SHOW_PROGRESS_BAR "musicShowProgressBar"
#define PREF_KEY_DARK_MODE "darkMode"

static bool s_menu_scroll_wrap_around = false;
static MenuScrollVibeBehavior s_menu_scroll_vibe_behavior = MenuScrollNoVibe;
static bool s_music_show_volume_controls = true;
static bool s_music_show_progress_bar = true;
static uint8_t s_dark_mode = DarkModeOff;

// ============================================================================================
// Handlers for each pref that validate the new setting and store the new value in our globals.
Expand Down Expand Up @@ -391,13 +393,13 @@ static bool prv_set_s_motion_sensitivity(uint8_t *sensitivity) {
return false;
}
s_motion_sensitivity = *sensitivity;

// Update accelerometer sensitivity in accel_manager
// This applies the setting to the hardware
#if CAPABILITY_HAS_ACCEL_SENSITIVITY
accel_manager_update_sensitivity(*sensitivity);
#endif

return true;
}

Expand Down Expand Up @@ -745,7 +747,16 @@ static bool prv_set_s_music_show_progress_bar(bool *enabled) {
s_music_show_progress_bar = *enabled;
return true;
}


static bool prv_set_s_dark_mode(uint8_t *mode) {
if (*mode >= DarkModeCount) {
s_dark_mode = DarkModeOn;
return false;
}
s_dark_mode = *mode;
return true;
}

// ------------------------------------------------------------------------------------
// Table of all prefs
typedef bool (*PrefSetHandler)(const void *value, size_t val_len);
Expand Down Expand Up @@ -830,10 +841,10 @@ void shell_prefs_init(void) {
}

settings_file_close(&file);

// Update the ambient light driver with the loaded threshold value
ambient_light_set_dark_threshold(s_backlight_ambient_threshold);

// Initialize prefs sync (must be after prefs are loaded)
prefs_sync_init();

Expand Down Expand Up @@ -1854,3 +1865,12 @@ bool shell_prefs_get_music_show_progress_bar(void) {
void shell_prefs_set_music_show_progress_bar(bool enable) {
prv_pref_set(PREF_KEY_MUSIC_SHOW_PROGRESS_BAR, &enable, sizeof(enable));
}

DarkMode shell_prefs_get_dark_mode(void) {
return (DarkMode)s_dark_mode;
}

void shell_prefs_set_dark_mode(DarkMode mode) {
uint8_t val = (uint8_t)mode;
prv_pref_set(PREF_KEY_DARK_MODE, &val, sizeof(val));
}
1 change: 1 addition & 0 deletions src/fw/shell/normal/prefs_values.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@
PREFS_MACRO(PREF_KEY_MENU_SCROLL_VIBE_BEHAVIOR, s_menu_scroll_vibe_behavior)
PREFS_MACRO(PREF_KEY_MUSIC_SHOW_VOLUME_CONTROLS, s_music_show_volume_controls)
PREFS_MACRO(PREF_KEY_MUSIC_SHOW_PROGRESS_BAR, s_music_show_progress_bar)
PREFS_MACRO(PREF_KEY_DARK_MODE, s_dark_mode)
12 changes: 12 additions & 0 deletions src/fw/shell/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,15 @@ void shell_prefs_set_music_show_volume_controls(bool enable);

bool shell_prefs_get_music_show_progress_bar(void);
void shell_prefs_set_music_show_progress_bar(bool enable);

typedef enum DarkMode {
DarkModeOff = 0,
DarkModeOn = 1,
#if CAPABILITY_HAS_AMBIENT_LIGHT_SENSOR
DarkModeAuto = 2, // Follows the ambient light sensor; dark mode when ambient light is low
#endif
Comment on lines +216 to +218
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally remove the auto mode tied to ambient light. I think this makes sense on *LED type displays, where black pixels do not emit or emit less light, but on e-paper, backlight has no relation with the displayed color. So IMHO, it's more an aesthetics preference on e-paper.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I do see your point for actual light emitted. My reasoning for this was not so much about light emitted, but more about legibility. It is usually much easier to read black text, white bg in direct sunshine. At night time, white text on dark bg is easier on eyes plus easier to read for me. Although it might not be for everyone, I do think there is a valid use case here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe it could be time based?

DarkModeCount
} DarkMode;

DarkMode shell_prefs_get_dark_mode(void);
void shell_prefs_set_dark_mode(DarkMode mode);
11 changes: 11 additions & 0 deletions src/fw/shell/prf/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ void shell_prefs_set_language_english(bool english) {
void shell_prefs_toggle_language_english(void) {
}

GColor shell_prefs_get_theme_highlight_color(void) {
return PBL_IF_COLOR_ELSE(GColorVividCerulean, GColorBlack);
}

DarkMode shell_prefs_get_dark_mode(void) {
return DarkModeOff;
}

void shell_prefs_set_dark_mode(DarkMode mode) {
}

FontInfo *fonts_get_system_emoji_font_for_size(unsigned int font_height) {
return NULL;
}
Expand Down
8 changes: 8 additions & 0 deletions src/fw/shell/sdk/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ void shell_prefs_set_theme_highlight_color(GColor color) {
// Not used in SDK shell
}

DarkMode shell_prefs_get_dark_mode(void) {
return DarkModeOff;
}

void shell_prefs_set_dark_mode(DarkMode mode) {
// Not used in SDK shell
}

#if CAPABILITY_HAS_APP_SCALING
LegacyAppRenderMode shell_prefs_get_legacy_app_render_mode(void) {
return (LegacyAppRenderMode)s_legacy_app_render_mode;
Expand Down
8 changes: 8 additions & 0 deletions tests/stubs/stubs_shell_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ void WEAK shell_prefs_set_menu_scroll_wrap_around_enable(bool enable) {
s_menu_scroll_enable = enable;
}

GColor WEAK shell_prefs_get_theme_highlight_color(void) {
return PBL_IF_COLOR_ELSE(GColorVividCerulean, GColorBlack);
}

DarkMode WEAK shell_prefs_get_dark_mode(void) {
return DarkModeOff;
}

static MenuScrollVibeBehavior s_menu_scroll_vibe_behavior = MenuScrollNoVibe;

MenuScrollVibeBehavior WEAK shell_prefs_get_menu_scroll_vibe_behavior(void) {
Expand Down