Skip to content

Commit 4b7e8fc

Browse files
Merge pull request livecode#7298 from montegoulding/bugfix-22607
[[ Bug 22607 ]] Implement system appearance support
2 parents 6918b95 + 0ba1662 commit 4b7e8fc

27 files changed

Lines changed: 266 additions & 6 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Name: systemAppearanceChanged
2+
3+
Type: message
4+
5+
Syntax: systemAppearanceChanged
6+
7+
Summary:
8+
Sent to the <current card> of the <defaultStack> when the <system appearance|systemAppearance>
9+
changes.
10+
11+
Associations: card
12+
13+
Introduced: 1.0
14+
15+
OS: mac, ios, android
16+
17+
Platforms: desktop,mobile
18+
19+
Example:
20+
on systemAppearanceChanged
21+
if the systemAppearance is "dark" then
22+
set the backColor of me to "black"
23+
set the foreColor of me to "white"
24+
else
25+
set the backColor of me to "white"
26+
set the foreColor of me to "black"
27+
end if
28+
on systemAppearanceChanged
29+
30+
Description:
31+
Handle the <systemAppearanceChanged> <message> if you need to change the color
32+
of objects when the application enters either light or dark mode.
33+
34+
References: systemAppearance (property), message (glossary), defaultStack (property)
35+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Name: systemAppearance
2+
3+
Type: property
4+
5+
Syntax: get the systemAppearance
6+
7+
Summary:
8+
Determins if the system appearance is dark or light mode.
9+
10+
Introduced: 9.6
11+
12+
OS: mac, android, ios
13+
14+
Platforms: desktop, mobile
15+
16+
Example:
17+
if the systemAppearance is "dark" then
18+
set the backColor of me to "black"
19+
set the foreColor of me to "white"
20+
else
21+
set the backColor of me to "white"
22+
set the foreColor of me to "black"
23+
end if
24+
25+
Description:
26+
The <systemAppearance> property returns either "dark" or "light" depending on
27+
whether the application is running in a dark mode context or not. On windows
28+
and linux the property will return "light".
29+
30+
References: systemAppearanceChanged (message)

docs/notes/bugfix-22607.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Dark mode detection
2+
3+
A new `systemAppearance` property has been added which returns `dark` if
4+
the application is running in dark mode and `light` otherwise.
5+
6+
A new `systemAppearanceChanged` message is now sent to the current card of the
7+
defaultStack when the system appearance changes.

engine/src/desktop-dc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,13 @@ void MCScreenDC::closeIME()
944944

945945
////////////////////////////////////////////////////////////////////////////////
946946

947+
void MCScreenDC::getsystemappearance(MCSystemAppearance &r_appearance)
948+
{
949+
MCPlatformGetSystemProperty(kMCPlatformSystemPropertySystemAppearance, kMCPlatformPropertyTypeInt32, &r_appearance);
950+
}
951+
952+
////////////////////////////////////////////////////////////////////////////////
953+
947954
extern bool MCListSystemPrinters(MCStringRef &);
948955
extern MCPrinter *MCCreateSystemPrinter(void);
949956

engine/src/desktop-dc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ class MCScreenDC: public MCUIDC
142142

143143
// MW-2014-04-26: [[ Bug 5545 ]] Override this method to defer to the MCPlatform method.
144144
virtual void hidecursoruntilmousemoves(void);
145-
145+
146+
virtual void getsystemappearance(MCSystemAppearance &r_appearance);
147+
146148
//////////
147149

148150
bool isbackdrop(MCPlatformWindowRef window);

engine/src/desktop.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ void MCPlatformHandleScreenParametersChanged(void)
164164

165165
////////////////////////////////////////////////////////////////////////////////
166166

167+
void MCPlatformHandleSystemAppearanceChanged(void)
168+
{
169+
if (MCscreen == nil)
170+
return;
171+
172+
MCscreen -> delaymessage(MCdefaultstackptr -> getcurcard(), MCM_system_appearance_changed);
173+
}
174+
175+
////////////////////////////////////////////////////////////////////////////////
176+
167177
#if defined (FEATURE_PLATFORM_WINDOW)
168178
void MCPlatformHandleWindowCloseRequest(MCPlatformWindowRef p_window)
169179
{

engine/src/exec-interface2.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,21 @@ static MCExecEnumTypeInfo _kMCInterfaceSelectionModeTypeInfo =
432432
_kMCInterfaceSelectionModeElementInfo,
433433
};
434434

435+
//////////
436+
437+
static MCExecEnumTypeElementInfo _kMCInterfaceSystemAppearanceElementInfo[] =
438+
{
439+
{ "light", 0, false },
440+
{ "dark", 1, false },
441+
};
442+
443+
static MCExecEnumTypeInfo _kMCInterfaceSystemAppearanceTypeInfo =
444+
{
445+
"Interface.ProcessType",
446+
sizeof(_kMCInterfaceSystemAppearanceElementInfo) / sizeof(MCExecEnumTypeElementInfo),
447+
_kMCInterfaceSystemAppearanceElementInfo,
448+
};
449+
435450
////////////////////////////////////////////////////////////////////////////////
436451

437452
MCExecEnumTypeInfo *kMCInterfaceLookAndFeelTypeInfo = &_kMCInterfaceLookAndFeelTypeInfo;
@@ -441,6 +456,7 @@ MCExecEnumTypeInfo *kMCInterfacePaintCompressionTypeInfo = &_kMCInterfacePaintCo
441456
MCExecEnumTypeInfo *kMCInterfaceProcessTypeTypeInfo = &_kMCInterfaceProcessTypeTypeInfo;
442457
MCExecEnumTypeInfo *kMCInterfaceSelectionModeTypeInfo = &_kMCInterfaceSelectionModeTypeInfo;
443458
MCExecCustomTypeInfo *kMCInterfaceStackFileVersionTypeInfo = &_kMCInterfaceStackFileVersionTypeInfo;
459+
MCExecEnumTypeInfo *kMCInterfaceSystemAppearanceTypeInfo = &_kMCInterfaceSystemAppearanceTypeInfo;
444460

445461
////////////////////////////////////////////////////////////////////////////////
446462

@@ -1701,6 +1717,13 @@ void MCInterfaceSetSelectionMode(MCExecContext& ctxt, intenum_t p_value)
17011717
MCselectintersect = (Boolean)p_value;
17021718
}
17031719

1720+
void MCInterfaceGetSystemAppearance(MCExecContext& ctxt, intenum_t& r_value)
1721+
{
1722+
MCSystemAppearance t_appearance;
1723+
MCscreen->getsystemappearance(t_appearance);
1724+
r_value = (intenum_t)t_appearance;
1725+
}
1726+
17041727
void MCInterfaceGetSelectionHandleColor(MCExecContext& ctxt, MCInterfaceNamedColor& r_color)
17051728
{
17061729
get_interface_color(MCselectioncolor, MCselectioncolorname, r_color);

engine/src/exec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,7 @@ extern MCExecCustomTypeInfo *kMCInterfaceVisualEffectArgumentTypeInfo;
21822182
extern MCExecCustomTypeInfo *kMCInterfaceButtonIconTypeInfo;
21832183
extern MCExecCustomTypeInfo *kMCInterfaceTriStateTypeInfo;
21842184
extern MCExecCustomTypeInfo *kMCInterfaceStackFileVersionTypeInfo;
2185+
extern MCExecEnumTypeInfo *kMCInterfaceSystemAppearanceTypeInfo;
21852186

21862187
void MCInterfaceInitialize(MCExecContext& ctxt);
21872188
void MCInterfaceFinalize(MCExecContext& ctxt);
@@ -2645,6 +2646,7 @@ void MCInterfaceGetScreenGamma(MCExecContext& ctxt, double& r_value);
26452646
void MCInterfaceSetScreenGamma(MCExecContext& ctxt, double p_value);
26462647
void MCInterfaceGetSelectionMode(MCExecContext& ctxt, intenum_t& r_value);
26472648
void MCInterfaceSetSelectionMode(MCExecContext& ctxt, intenum_t p_value);
2649+
void MCInterfaceGetSystemAppearance(MCExecContext& ctxt, intenum_t& r_value);
26482650
void MCInterfaceGetSelectionHandleColor(MCExecContext& ctxt, MCInterfaceNamedColor& r_color);
26492651
void MCInterfaceSetSelectionHandleColor(MCExecContext& ctxt, const MCInterfaceNamedColor& p_color);
26502652
void MCInterfaceGetWindowBoundingRect(MCExecContext& ctxt, MCRectangle& r_value);

engine/src/java/com/runrev/android/Engine.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public class Engine extends View implements EngineApi
138138
private boolean m_new_intent;
139139

140140
private int m_photo_width, m_photo_height;
141+
142+
private int m_night_mode;
141143

142144
////////////////////////////////////////////////////////////////////////////////
143145

@@ -239,6 +241,10 @@ public void onScreenOrientationChanged(int orientation)
239241

240242
m_photo_width = 0;
241243
m_photo_height = 0;
244+
245+
m_night_mode =
246+
p_context.getResources().getConfiguration().uiMode &
247+
Configuration.UI_MODE_NIGHT_MASK;
242248
}
243249

244250
////////////////////////////////////////////////////////////////////////////////
@@ -356,6 +362,15 @@ public String loadExternalLibrary(String name)
356362

357363
public void onConfigurationChanged(Configuration p_new_config)
358364
{
365+
int t_night_mode =
366+
getContext().getResources().getConfiguration().uiMode &
367+
Configuration.UI_MODE_NIGHT_MASK;
368+
369+
if (t_night_mode != m_night_mode)
370+
{
371+
m_night_mode = t_night_mode;
372+
doSystemAppearanceChanged();
373+
}
359374
}
360375

361376
////////////////////////////////////////////////////////////////////////////////
@@ -3896,7 +3911,22 @@ public Class getServiceClass()
38963911
{
38973912
return ((LiveCodeActivity)getContext()).getServiceClass();
38983913
}
3899-
3914+
3915+
////////////////////////////////////////////////////////////////////////////////
3916+
3917+
public int getSystemAppearance()
3918+
{
3919+
switch (m_night_mode)
3920+
{
3921+
case Configuration.UI_MODE_NIGHT_YES:
3922+
return 1;
3923+
case Configuration.UI_MODE_NIGHT_NO:
3924+
case Configuration.UI_MODE_NIGHT_UNDEFINED:
3925+
default:
3926+
return 0;
3927+
}
3928+
}
3929+
39003930
////////////////////////////////////////////////////////////////////////////////
39013931

39023932
// url launch callback
@@ -3966,6 +3996,7 @@ public static native void doHeadingChanged(double p_heading, double p_magnetic_h
39663996
public static native void doShake(int action, long timestamp);
39673997

39683998
public static native void doOrientationChanged(int orientation);
3999+
public static native void doSystemAppearanceChanged();
39694000

39704001
public static native void doKeyboardShown(int height);
39714002
public static native void doKeyboardHidden();

engine/src/lextable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,8 @@ const LT factor_table[] =
16901690
{"syncrate", TT_PROPERTY, P_SYNC_RATE},
16911691
{"syserror", TT_FUNCTION, F_SYS_ERROR},
16921692
{"system", TT_PROPERTY, P_SYSTEM},
1693-
{"systemcolorselector", TT_PROPERTY, P_SYSTEM_CS},
1693+
{"systemappearance", TT_PROPERTY, P_SYSTEM_APPEARANCE},
1694+
{"systemcolorselector", TT_PROPERTY, P_SYSTEM_CS},
16941695
{"systemfileselector", TT_PROPERTY, P_SYSTEM_FS},
16951696
// IM-2013-12-04: [[ PixelScale ]] The "systemPixelScale" token
16961697
{"systempixelscale", TT_PROPERTY, P_SYSTEM_PIXEL_SCALE},

0 commit comments

Comments
 (0)