Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
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
35 changes: 35 additions & 0 deletions docs/dictionary/message/systemAppearanceChanged.lcdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Name: systemAppearanceChanged

Type: message

Syntax: systemAppearanceChanged

Summary:
Sent to the <current card> of the <defaultStack> when the <system appearance|systemAppearance>
changes.

Associations: card

Introduced: 1.0

OS: mac, ios, android

Platforms: desktop,mobile

Example:
on systemAppearanceChanged
if the systemAppearance is "dark" then
set the backColor of me to "black"
set the foreColor of me to "white"
else
set the backColor of me to "white"
set the foreColor of me to "black"
end if
on systemAppearanceChanged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this has a copy-paste error (end systemAppearanceChanged) :)


Description:
Handle the <systemAppearanceChanged> <message> if you need to change the color
of objects when the application enters either light or dark mode.

References: systemAppearance (property), message (glossary), defaultStack (property)

30 changes: 30 additions & 0 deletions docs/dictionary/property/systemAppearance.lcdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Name: systemAppearance

Type: property

Syntax: get the systemAppearance

Summary:
Determins if the system appearance is dark or light mode.

Introduced: 9.6

OS: mac, android, ios

Platforms: desktop, mobile

Example:
if the systemAppearance is "dark" then
set the backColor of me to "black"
set the foreColor of me to "white"
else
set the backColor of me to "white"
set the foreColor of me to "black"
end if

Description:
The <systemAppearance> property returns either "dark" or "light" depending on
Comment thread
montegoulding marked this conversation as resolved.
whether the application is running in a dark mode context or not. On windows
and linux the property will return "light".

References: systemAppearanceChanged (message)
7 changes: 7 additions & 0 deletions docs/notes/bugfix-22607.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Dark mode detection

A new `systemAppearance` property has been added which returns `dark` if
the application is running in dark mode and `light` otherwise.

A new `systemAppearanceChanged` message is now sent to the current card of the
defaultStack when the system appearance changes.
7 changes: 7 additions & 0 deletions engine/src/desktop-dc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,13 @@ void MCScreenDC::closeIME()

////////////////////////////////////////////////////////////////////////////////

void MCScreenDC::getsystemappearance(MCSystemAppearance &r_appearance)
{
MCPlatformGetSystemProperty(kMCPlatformSystemPropertySystemAppearance, kMCPlatformPropertyTypeInt32, &r_appearance);
}

////////////////////////////////////////////////////////////////////////////////

extern bool MCListSystemPrinters(MCStringRef &);
extern MCPrinter *MCCreateSystemPrinter(void);

Expand Down
4 changes: 3 additions & 1 deletion engine/src/desktop-dc.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ class MCScreenDC: public MCUIDC

// MW-2014-04-26: [[ Bug 5545 ]] Override this method to defer to the MCPlatform method.
virtual void hidecursoruntilmousemoves(void);


virtual void getsystemappearance(MCSystemAppearance &r_appearance);

//////////
Comment thread
montegoulding marked this conversation as resolved.

bool isbackdrop(MCPlatformWindowRef window);
Expand Down
10 changes: 10 additions & 0 deletions engine/src/desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ void MCPlatformHandleScreenParametersChanged(void)

////////////////////////////////////////////////////////////////////////////////

void MCPlatformHandleSystemAppearanceChanged(void)
{
if (MCscreen == nil)
return;

MCscreen -> delaymessage(MCdefaultstackptr -> getcurcard(), MCM_system_appearance_changed);
}

////////////////////////////////////////////////////////////////////////////////

#if defined (FEATURE_PLATFORM_WINDOW)
void MCPlatformHandleWindowCloseRequest(MCPlatformWindowRef p_window)
{
Expand Down
23 changes: 23 additions & 0 deletions engine/src/exec-interface2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ static MCExecEnumTypeInfo _kMCInterfaceSelectionModeTypeInfo =
_kMCInterfaceSelectionModeElementInfo,
};

//////////

static MCExecEnumTypeElementInfo _kMCInterfaceSystemAppearanceElementInfo[] =
{
{ "light", 0, false },
{ "dark", 1, false },
};

static MCExecEnumTypeInfo _kMCInterfaceSystemAppearanceTypeInfo =
{
"Interface.ProcessType",
sizeof(_kMCInterfaceSystemAppearanceElementInfo) / sizeof(MCExecEnumTypeElementInfo),
_kMCInterfaceSystemAppearanceElementInfo,
};

////////////////////////////////////////////////////////////////////////////////

MCExecEnumTypeInfo *kMCInterfaceLookAndFeelTypeInfo = &_kMCInterfaceLookAndFeelTypeInfo;
Expand All @@ -441,6 +456,7 @@ MCExecEnumTypeInfo *kMCInterfacePaintCompressionTypeInfo = &_kMCInterfacePaintCo
MCExecEnumTypeInfo *kMCInterfaceProcessTypeTypeInfo = &_kMCInterfaceProcessTypeTypeInfo;
MCExecEnumTypeInfo *kMCInterfaceSelectionModeTypeInfo = &_kMCInterfaceSelectionModeTypeInfo;
MCExecCustomTypeInfo *kMCInterfaceStackFileVersionTypeInfo = &_kMCInterfaceStackFileVersionTypeInfo;
MCExecEnumTypeInfo *kMCInterfaceSystemAppearanceTypeInfo = &_kMCInterfaceSystemAppearanceTypeInfo;

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -1701,6 +1717,13 @@ void MCInterfaceSetSelectionMode(MCExecContext& ctxt, intenum_t p_value)
MCselectintersect = (Boolean)p_value;
}

void MCInterfaceGetSystemAppearance(MCExecContext& ctxt, intenum_t& r_value)
{
MCSystemAppearance t_appearance;
MCscreen->getsystemappearance(t_appearance);
r_value = (intenum_t)t_appearance;
}

void MCInterfaceGetSelectionHandleColor(MCExecContext& ctxt, MCInterfaceNamedColor& r_color)
{
get_interface_color(MCselectioncolor, MCselectioncolorname, r_color);
Expand Down
2 changes: 2 additions & 0 deletions engine/src/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,7 @@ extern MCExecCustomTypeInfo *kMCInterfaceVisualEffectArgumentTypeInfo;
extern MCExecCustomTypeInfo *kMCInterfaceButtonIconTypeInfo;
extern MCExecCustomTypeInfo *kMCInterfaceTriStateTypeInfo;
extern MCExecCustomTypeInfo *kMCInterfaceStackFileVersionTypeInfo;
extern MCExecEnumTypeInfo *kMCInterfaceSystemAppearanceTypeInfo;

void MCInterfaceInitialize(MCExecContext& ctxt);
void MCInterfaceFinalize(MCExecContext& ctxt);
Expand Down Expand Up @@ -2645,6 +2646,7 @@ void MCInterfaceGetScreenGamma(MCExecContext& ctxt, double& r_value);
void MCInterfaceSetScreenGamma(MCExecContext& ctxt, double p_value);
void MCInterfaceGetSelectionMode(MCExecContext& ctxt, intenum_t& r_value);
void MCInterfaceSetSelectionMode(MCExecContext& ctxt, intenum_t p_value);
void MCInterfaceGetSystemAppearance(MCExecContext& ctxt, intenum_t& r_value);
void MCInterfaceGetSelectionHandleColor(MCExecContext& ctxt, MCInterfaceNamedColor& r_color);
void MCInterfaceSetSelectionHandleColor(MCExecContext& ctxt, const MCInterfaceNamedColor& p_color);
void MCInterfaceGetWindowBoundingRect(MCExecContext& ctxt, MCRectangle& r_value);
Expand Down
33 changes: 32 additions & 1 deletion engine/src/java/com/runrev/android/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public class Engine extends View implements EngineApi
private boolean m_new_intent;

private int m_photo_width, m_photo_height;

private int m_night_mode;

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -239,6 +241,10 @@ public void onScreenOrientationChanged(int orientation)

m_photo_width = 0;
m_photo_height = 0;

m_night_mode =
p_context.getResources().getConfiguration().uiMode &
Configuration.UI_MODE_NIGHT_MASK;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -356,6 +362,15 @@ public String loadExternalLibrary(String name)

public void onConfigurationChanged(Configuration p_new_config)
{
int t_night_mode =
getContext().getResources().getConfiguration().uiMode &
Configuration.UI_MODE_NIGHT_MASK;

if (t_night_mode != m_night_mode)
{
m_night_mode = t_night_mode;
doSystemAppearanceChanged();
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3882,7 +3897,22 @@ public Class getServiceClass()
{
return ((LiveCodeActivity)getContext()).getServiceClass();
}


////////////////////////////////////////////////////////////////////////////////

public int getSystemAppearance()
{
switch (m_night_mode)
{
case Configuration.UI_MODE_NIGHT_YES:
return 1;
case Configuration.UI_MODE_NIGHT_NO:
case Configuration.UI_MODE_NIGHT_UNDEFINED:
default:
return 0;
}
}

////////////////////////////////////////////////////////////////////////////////

// url launch callback
Expand Down Expand Up @@ -3952,6 +3982,7 @@ public static native void doHeadingChanged(double p_heading, double p_magnetic_h
public static native void doShake(int action, long timestamp);

public static native void doOrientationChanged(int orientation);
public static native void doSystemAppearanceChanged();

public static native void doKeyboardShown(int height);
public static native void doKeyboardHidden();
Expand Down
3 changes: 2 additions & 1 deletion engine/src/lextable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,8 @@ const LT factor_table[] =
{"syncrate", TT_PROPERTY, P_SYNC_RATE},
{"syserror", TT_FUNCTION, F_SYS_ERROR},
{"system", TT_PROPERTY, P_SYSTEM},
{"systemcolorselector", TT_PROPERTY, P_SYSTEM_CS},
{"systemappearance", TT_PROPERTY, P_SYSTEM_APPEARANCE},
{"systemcolorselector", TT_PROPERTY, P_SYSTEM_CS},
{"systemfileselector", TT_PROPERTY, P_SYSTEM_FS},
// IM-2013-12-04: [[ PixelScale ]] The "systemPixelScale" token
{"systempixelscale", TT_PROPERTY, P_SYSTEM_PIXEL_SCALE},
Expand Down
25 changes: 24 additions & 1 deletion engine/src/mac-core.mm
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,21 @@ - (void)applicationDidFinishLaunching: (NSNotification *)notification

[t_event release];
}

[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceThemeChangedNotification:)
name:@"AppleInterfaceThemeChangedNotification" object:nil];

// We started up successfully, so queue the root runloop invocation
// message.
[self performSelector: @selector(runMainLoop) withObject: nil afterDelay: 0];
}

- (void)interfaceThemeChangedNotification:(NSNotification *)notification
{
MCPlatformCallbackSendSystemAppearanceChanged();
}

- (void)runMainLoop
{
for(;;)
Expand Down Expand Up @@ -608,7 +617,21 @@ void MCPlatformGetSystemProperty(MCPlatformSystemProperty p_property, MCPlatform
case kMCPlatformSystemPropertyVolume:
MCMacPlatformGetGlobalVolume(*(double *)r_value);
break;


case kMCPlatformSystemPropertySystemAppearance:
{
NSUserDefaults *t_defaults = [NSUserDefaults standardUserDefaults];
NSString *t_appearance = [t_defaults stringForKey:@"AppleInterfaceStyle"];
if (t_appearance == nil || ![t_appearance isEqualToString:@"Dark"])
{
*(int16_t *)r_value = kMCPlatformSystemAppearanceLight;
}
else
{
*(int16_t *)r_value = kMCPlatformSystemAppearanceDark;
}
}
break;
default:
assert(false);
break;
Expand Down
18 changes: 18 additions & 0 deletions engine/src/mblandroiddc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,16 @@ Window MCScreenDC::get_current_window(void)

////////////////////////////////////////////////////////////////////////////////

void MCScreenDC::getsystemappearance(MCSystemAppearance &r_appearance)
{
int t_system_appearance;
MCAndroidEngineRemoteCall("getSystemAppearance", "i", &t_system_appearance);

r_appearance = static_cast<MCSystemAppearance>(t_system_appearance);
}

////////////////////////////////////////////////////////////////////////////////

static MCRectangle android_view_get_bounds(void)
{
return MCRectangleMake(s_android_bitmap_loc_x, s_android_bitmap_loc_y, s_android_bitmap_width, s_android_bitmap_height);
Expand Down Expand Up @@ -2032,6 +2042,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doBackPressed(J
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doMenuKey(JNIEnv *env, jobject object) __attribute__((visibility("default")));
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doSearchKey(JNIEnv *env, jobject object) __attribute__((visibility("default")));
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doOrientationChanged(JNIEnv *env, jobject object, jint orientation) __attribute__((visibility("default")));
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doSystemAppearanceChanged(JNIEnv *env, jobject object) __attribute__((visibility("default")));
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doTextDone(JNIEnv *env, jobject object) __attribute__((visibility("default")));
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doTextCanceled(JNIEnv *env, jobject object) __attribute__((visibility("default")));
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doMediaDone(JNIEnv *env, jobject object, jstring p_media_content) __attribute__((visibility("default")));
Expand Down Expand Up @@ -2375,6 +2386,13 @@ JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doOrientationChanged(JNIEn

//////////

JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doSystemAppearanceChanged(JNIEnv *env, jobject object)
{
MCNotificationPostSystemAppearanceChanged();
}

//////////

struct MCKeyboardActivatedEvent: public MCCustomEvent
{
MCKeyboardActivatedEvent(float p_height)
Expand Down
2 changes: 2 additions & 0 deletions engine/src/mbldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class MCScreenDC: public MCUIDC
Window get_current_window(void);

void refresh_current_window(void);

void getsystemappearance(MCSystemAppearance &r_appearance);
private:
// The top-left of the mobile 'window' in screen co-ordinates.
int32_t m_window_left;
Expand Down
5 changes: 5 additions & 0 deletions engine/src/mbliphoneapp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,11 @@ - (void)voiceOverStatusChanged
}
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
MCNotificationPostSystemAppearanceChanged();
}

@end

////////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 16 additions & 0 deletions engine/src/mbliphonedc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,22 @@ static void MCScreenDCDoSnapshot(void *p_env)

////////////////////////////////////////////////////////////////////////////////

void MCScreenDC::getsystemappearance(MCSystemAppearance &r_appearance)
{
UITraitCollection *t_traits = [MCIPhoneGetRootView() traitCollection];
if ([t_traits respondsToSelector: @selector(userInterfaceStyle)] &&
[t_traits userInterfaceStyle] == 2 /* UIUserInterfaceStyleDark */)
{
r_appearance = kMCSystemAppearanceDark;
}
else
{
r_appearance = kMCSystemAppearanceLight;
}
}

////////////////////////////////////////////////////////////////////////////////

extern void *coretext_font_create_with_name_size_and_style(MCStringRef p_name, uint32_t p_size, bool p_bold, bool p_italic);
extern bool coretext_font_destroy(void *p_font);
extern bool coretext_font_get_metrics(void *p_font, float& r_ascent, float& r_descent, float& r_leading, float& r_xheight);
Expand Down
5 changes: 5 additions & 0 deletions engine/src/mblnotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ void MCNotificationPostLaunchDataChanged()
/* UNCHECKED */ MCNotificationPostCustom(MCM_launch_data_changed, 0);
}

void MCNotificationPostSystemAppearanceChanged()
{
/* UNCHECKED */ MCNotificationPostCustom(MCM_system_appearance_changed, 0);
}

////////////////////////////////////////////////////////////////////////////////
Loading