summaryrefslogtreecommitdiffstats
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/display_server_android.cpp10
-rw-r--r--platform/android/display_server_android.h5
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.kt23
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java8
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java5
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java16
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java30
-rw-r--r--platform/android/java_godot_lib_jni.cpp7
-rw-r--r--platform/android/java_godot_lib_jni.h1
-rw-r--r--platform/ios/display_server_ios.h8
-rw-r--r--platform/ios/display_server_ios.mm10
-rw-r--r--platform/ios/godot_view.mm17
-rw-r--r--platform/linuxbsd/freedesktop_portal_desktop.cpp72
-rw-r--r--platform/linuxbsd/freedesktop_portal_desktop.h15
-rw-r--r--platform/linuxbsd/wayland/display_server_wayland.cpp4
-rw-r--r--platform/linuxbsd/wayland/display_server_wayland.h1
-rw-r--r--platform/linuxbsd/x11/display_server_x11.cpp4
-rw-r--r--platform/linuxbsd/x11/display_server_x11.h1
-rw-r--r--platform/macos/display_server_macos.h13
-rw-r--r--platform/macos/display_server_macos.mm61
-rw-r--r--platform/macos/godot_application_delegate.h2
-rw-r--r--platform/macos/godot_application_delegate.mm67
-rw-r--r--platform/macos/os_macos.mm1
-rw-r--r--platform/windows/display_server_windows.cpp19
-rw-r--r--platform/windows/display_server_windows.h4
25 files changed, 381 insertions, 23 deletions
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp
index b06164246e..01ecbc7164 100644
--- a/platform/android/display_server_android.cpp
+++ b/platform/android/display_server_android.cpp
@@ -127,6 +127,16 @@ bool DisplayServerAndroid::is_dark_mode() const {
return godot_java->is_dark_mode();
}
+void DisplayServerAndroid::set_system_theme_change_callback(const Callable &p_callable) {
+ system_theme_changed = p_callable;
+}
+
+void DisplayServerAndroid::emit_system_theme_changed() {
+ if (system_theme_changed.is_valid()) {
+ system_theme_changed.call_deferred();
+ }
+}
+
void DisplayServerAndroid::clipboard_set(const String &p_text) {
GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java();
ERR_FAIL_NULL(godot_java);
diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h
index b425b2d9ae..c95eaddf93 100644
--- a/platform/android/display_server_android.h
+++ b/platform/android/display_server_android.h
@@ -84,6 +84,8 @@ class DisplayServerAndroid : public DisplayServer {
Callable input_text_callback;
Callable rect_changed_callback;
+ Callable system_theme_changed;
+
void _window_callback(const Callable &p_callable, const Variant &p_arg, bool p_deferred = false) const;
static void _dispatch_input_events(const Ref<InputEvent> &p_event);
@@ -103,8 +105,11 @@ public:
virtual void tts_resume() override;
virtual void tts_stop() override;
+ void emit_system_theme_changed();
+
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual void clipboard_set(const String &p_text) override;
virtual String clipboard_get() const override;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
index da86e67c7d..a0e020b55e 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
@@ -149,6 +149,7 @@ class Godot(private val context: Context) : SensorEventListener {
private var useApkExpansion = false
private var useImmersive = false
private var useDebugOpengl = false
+ private var darkMode = false;
private var containerLayout: FrameLayout? = null
var renderView: GodotRenderView? = null
@@ -184,6 +185,8 @@ class Godot(private val context: Context) : SensorEventListener {
return
}
+ darkMode = context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
+
beginBenchmarkMeasure("Startup", "Godot::onCreate")
try {
this.primaryHost = primaryHost
@@ -560,6 +563,17 @@ class Godot(private val context: Context) : SensorEventListener {
}
/**
+ * Configuration change callback
+ */
+ fun onConfigurationChanged(newConfig: Configuration) {
+ var newDarkMode = newConfig.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
+ if (darkMode != newDarkMode) {
+ darkMode = newDarkMode
+ GodotLib.onNightModeChanged()
+ }
+ }
+
+ /**
* Activity result callback
*/
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -596,11 +610,13 @@ class Godot(private val context: Context) : SensorEventListener {
// These properties are defined after Godot setup completion, so we retrieve them here.
val longPressEnabled = java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/pointing/android/enable_long_press_as_right_click"))
val panScaleEnabled = java.lang.Boolean.parseBoolean(GodotLib.getGlobal("input_devices/pointing/android/enable_pan_and_scale_gestures"))
+ val rotaryInputAxis = java.lang.Integer.parseInt(GodotLib.getGlobal("input_devices/pointing/android/rotary_input_scroll_axis"));
runOnUiThread {
renderView?.inputHandler?.apply {
enableLongPress(longPressEnabled)
enablePanningAndScalingGestures(panScaleEnabled)
+ setRotaryInputAxis(rotaryInputAxis)
}
}
@@ -731,7 +747,7 @@ class Godot(private val context: Context) : SensorEventListener {
*/
@Keep
private fun isDarkModeSupported(): Boolean {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
+ return context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_UNDEFINED
}
/**
@@ -739,10 +755,7 @@ class Godot(private val context: Context) : SensorEventListener {
*/
@Keep
private fun isDarkMode(): Boolean {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- return context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
- }
- return false
+ return darkMode
}
fun hasClipboard(): Boolean {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
index 643c9a658e..a323045e1b 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
@@ -38,6 +38,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Messenger;
@@ -147,6 +148,13 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
@CallSuper
@Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ godot.onConfigurationChanged(newConfig);
+ }
+
+ @CallSuper
+ @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCallback != null) {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
index fee50e93c2..d0c3d4a687 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
@@ -220,6 +220,11 @@ public class GodotLib {
public static native void requestPermissionResult(String p_permission, boolean p_result);
/**
+ * Invoked on the theme light/dark mode change.
+ */
+ public static native void onNightModeChanged();
+
+ /**
* Invoked on the GL thread to configure the height of the virtual keyboard.
*/
public static native void setVirtualKeyboardHeight(int p_height);
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
index 3070a8a207..dc8a0e54bb 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
@@ -34,10 +34,13 @@ import org.godotengine.godot.*;
import android.content.Context;
import android.content.res.Configuration;
+import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.text.InputFilter;
import android.text.InputType;
+import android.text.TextUtils;
+import android.text.method.DigitsKeyListener;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
@@ -45,6 +48,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import java.lang.ref.WeakReference;
+import java.util.Locale;
public class GodotEditText extends EditText {
// ===========================================================
@@ -137,6 +141,7 @@ public class GodotEditText extends EditText {
}
int inputType = InputType.TYPE_CLASS_TEXT;
+ String acceptCharacters = null;
switch (edit.getKeyboardType()) {
case KEYBOARD_TYPE_DEFAULT:
inputType = InputType.TYPE_CLASS_TEXT;
@@ -148,7 +153,8 @@ public class GodotEditText extends EditText {
inputType = InputType.TYPE_CLASS_NUMBER;
break;
case KEYBOARD_TYPE_NUMBER_DECIMAL:
- inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
+ inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
+ acceptCharacters = "0123456789,.- ";
break;
case KEYBOARD_TYPE_PHONE:
inputType = InputType.TYPE_CLASS_PHONE;
@@ -165,6 +171,14 @@ public class GodotEditText extends EditText {
}
edit.setInputType(inputType);
+ if (!TextUtils.isEmpty(acceptCharacters)) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ edit.setKeyListener(DigitsKeyListener.getInstance(Locale.getDefault()));
+ } else {
+ edit.setKeyListener(DigitsKeyListener.getInstance(acceptCharacters));
+ }
+ }
+
edit.mInputWrapper.setOriginText(text);
edit.addTextChangedListener(edit.mInputWrapper);
final InputMethodManager imm = (InputMethodManager)mRenderView.getView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
index 38c115ad7f..fe971cf442 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
@@ -57,6 +57,9 @@ import java.util.Set;
public class GodotInputHandler implements InputManager.InputDeviceListener {
private static final String TAG = GodotInputHandler.class.getSimpleName();
+ private static final int ROTARY_INPUT_VERTICAL_AXIS = 1;
+ private static final int ROTARY_INPUT_HORIZONTAL_AXIS = 0;
+
private final SparseIntArray mJoystickIds = new SparseIntArray(4);
private final SparseArray<Joystick> mJoysticksDevices = new SparseArray<>(4);
@@ -71,6 +74,8 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
*/
private int lastSeenToolType = MotionEvent.TOOL_TYPE_UNKNOWN;
+ private static int rotaryInputAxis = ROTARY_INPUT_VERTICAL_AXIS;
+
public GodotInputHandler(GodotRenderView godotView) {
final Context context = godotView.getView().getContext();
mRenderView = godotView;
@@ -102,6 +107,13 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
this.godotGestureHandler.setPanningAndScalingEnabled(enable);
}
+ /**
+ * On Wear OS devices, sets which axis of the mouse wheel rotary input is mapped to. This is 1 (vertical axis) by default.
+ */
+ public void setRotaryInputAxis(int axis) {
+ rotaryInputAxis = axis;
+ }
+
private boolean isKeyEventGameDevice(int source) {
// Note that keyboards are often (SOURCE_KEYBOARD | SOURCE_DPAD)
if (source == (InputDevice.SOURCE_KEYBOARD | InputDevice.SOURCE_DPAD))
@@ -484,8 +496,22 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
final float tiltX = (float)-Math.sin(orientation) * tiltMult;
final float tiltY = (float)Math.cos(orientation) * tiltMult;
- final float verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
- final float horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
+ float verticalFactor = 0;
+ float horizontalFactor = 0;
+
+ // If event came from RotaryEncoder (Bezel or Crown rotate event on Wear OS smart watches),
+ // convert it to mouse wheel event.
+ if (event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)) {
+ if (rotaryInputAxis == ROTARY_INPUT_HORIZONTAL_AXIS) {
+ horizontalFactor = -event.getAxisValue(MotionEvent.AXIS_SCROLL);
+ } else {
+ // If rotaryInputAxis is not ROTARY_INPUT_HORIZONTAL_AXIS then use default ROTARY_INPUT_VERTICAL_AXIS axis.
+ verticalFactor = -event.getAxisValue(MotionEvent.AXIS_SCROLL);
+ }
+ } else {
+ verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
+ horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
+ }
boolean sourceMouseRelative = false;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
sourceMouseRelative = event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE);
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index 08e792cc04..85d5cf2796 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -487,6 +487,13 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *
Callable(obj, str_method).call_deferredp(argptrs, count);
}
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onNightModeChanged(JNIEnv *env, jclass clazz) {
+ DisplayServerAndroid *ds = (DisplayServerAndroid *)DisplayServer::get_singleton();
+ if (ds) {
+ ds->emit_system_theme_changed();
+ }
+}
+
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result) {
String permission = jstring_to_string(p_permission, env);
if (permission == "android.permission.RECORD_AUDIO" && p_result) {
diff --git a/platform/android/java_godot_lib_jni.h b/platform/android/java_godot_lib_jni.h
index 1ddda6c1c8..f32ffc291a 100644
--- a/platform/android/java_godot_lib_jni.h
+++ b/platform/android/java_godot_lib_jni.h
@@ -66,6 +66,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *en
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jclass clazz, jlong ID, jstring method, jobjectArray params);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onNightModeChanged(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz);
}
diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h
index 3efd2498d4..6f66783a47 100644
--- a/platform/ios/display_server_ios.h
+++ b/platform/ios/display_server_ios.h
@@ -77,6 +77,8 @@ class DisplayServerIOS : public DisplayServer {
Callable input_event_callback;
Callable input_text_callback;
+ Callable system_theme_changed;
+
int virtual_keyboard_height = 0;
void perform_event(const Ref<InputEvent> &p_event);
@@ -109,6 +111,8 @@ public:
void send_window_event(DisplayServer::WindowEvent p_event) const;
void _window_callback(const Callable &p_callable, const Variant &p_arg) const;
+ void emit_system_theme_changed();
+
// MARK: - Input
// MARK: Touches and Apple Pencil
@@ -145,6 +149,7 @@ public:
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual Rect2i get_display_safe_area() const override;
@@ -159,8 +164,7 @@ public:
virtual Vector<DisplayServer::WindowID> get_window_list() const override;
- virtual WindowID
- get_window_at_screen_position(const Point2i &p_position) const override;
+ virtual WindowID get_window_at_screen_position(const Point2i &p_position) const override;
virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override;
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 2895dffdfa..ed69b91fdd 100644
--- a/platform/ios/display_server_ios.mm
+++ b/platform/ios/display_server_ios.mm
@@ -387,6 +387,16 @@ bool DisplayServerIOS::is_dark_mode() const {
}
}
+void DisplayServerIOS::set_system_theme_change_callback(const Callable &p_callable) {
+ system_theme_changed = p_callable;
+}
+
+void DisplayServerIOS::emit_system_theme_changed() {
+ if (system_theme_changed.is_valid()) {
+ system_theme_changed.call();
+ }
+}
+
Rect2i DisplayServerIOS::get_display_safe_area() const {
UIEdgeInsets insets = UIEdgeInsetsZero;
UIView *view = AppDelegate.viewController.godotView;
diff --git a/platform/ios/godot_view.mm b/platform/ios/godot_view.mm
index ff8a4f8921..4b87863fc5 100644
--- a/platform/ios/godot_view.mm
+++ b/platform/ios/godot_view.mm
@@ -167,6 +167,23 @@ static const float earth_gravity = 9.80665;
}
}
+- (void)system_theme_changed {
+ DisplayServerIOS *ds = (DisplayServerIOS *)DisplayServer::get_singleton();
+ if (ds) {
+ ds->emit_system_theme_changed();
+ }
+}
+
+- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
+ if (@available(iOS 13.0, *)) {
+ [super traitCollectionDidChange:previousTraitCollection];
+
+ if ([UITraitCollection currentTraitCollection].userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
+ [self system_theme_changed];
+ }
+ }
+}
+
- (void)stopRendering {
if (!self.isActive) {
return;
diff --git a/platform/linuxbsd/freedesktop_portal_desktop.cpp b/platform/linuxbsd/freedesktop_portal_desktop.cpp
index a3633e72b7..cdebed58b2 100644
--- a/platform/linuxbsd/freedesktop_portal_desktop.cpp
+++ b/platform/linuxbsd/freedesktop_portal_desktop.cpp
@@ -528,10 +528,10 @@ void FreeDesktopPortalDesktop::_file_dialog_callback(const Callable &p_callable,
}
}
-void FreeDesktopPortalDesktop::_thread_file_dialog_monitor(void *p_ud) {
+void FreeDesktopPortalDesktop::_thread_monitor(void *p_ud) {
FreeDesktopPortalDesktop *portal = (FreeDesktopPortalDesktop *)p_ud;
- while (!portal->file_dialog_thread_abort.is_set()) {
+ while (!portal->monitor_thread_abort.is_set()) {
{
MutexLock lock(portal->file_dialog_mutex);
for (int i = portal->file_dialogs.size() - 1; i >= 0; i--) {
@@ -579,10 +579,44 @@ void FreeDesktopPortalDesktop::_thread_file_dialog_monitor(void *p_ud) {
}
}
}
+
+ if (portal->theme_connection) {
+ while (true) {
+ DBusMessage *msg = dbus_connection_pop_message(portal->theme_connection);
+ if (!msg) {
+ break;
+ } else if (dbus_message_is_signal(msg, "org.freedesktop.portal.Settings", "SettingChanged")) {
+ DBusMessageIter iter;
+ if (dbus_message_iter_init(msg, &iter)) {
+ const char *value;
+ dbus_message_iter_get_basic(&iter, &value);
+ String name_space = String::utf8(value);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &value);
+ String key = String::utf8(value);
+
+ if (name_space == "org.freedesktop.appearance" && key == "color-scheme") {
+ callable_mp(portal, &FreeDesktopPortalDesktop::_system_theme_changed_callback).call_deferred();
+ }
+ }
+ dbus_message_unref(msg);
+ break;
+ }
+ dbus_message_unref(msg);
+ }
+ dbus_connection_read_write(portal->theme_connection, 0);
+ }
+
usleep(50000);
}
}
+void FreeDesktopPortalDesktop::_system_theme_changed_callback() {
+ if (system_theme_changed.is_valid()) {
+ system_theme_changed.call();
+ }
+}
+
FreeDesktopPortalDesktop::FreeDesktopPortalDesktop() {
#ifdef SOWRAP_ENABLED
#ifdef DEBUG_ENABLED
@@ -611,17 +645,34 @@ FreeDesktopPortalDesktop::FreeDesktopPortalDesktop() {
unsupported = true;
}
+ DBusError err;
+ dbus_error_init(&err);
+ theme_connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ dbus_error_free(&err);
+ } else {
+ theme_path = "type='signal',sender='org.freedesktop.portal.Desktop',interface='org.freedesktop.portal.Settings',member='SettingChanged'";
+ dbus_bus_add_match(theme_connection, theme_path.utf8().get_data(), &err);
+ if (dbus_error_is_set(&err)) {
+ dbus_error_free(&err);
+ dbus_connection_unref(theme_connection);
+ theme_connection = nullptr;
+ }
+ dbus_connection_read_write(theme_connection, 0);
+ }
+
if (!unsupported) {
- file_dialog_thread_abort.clear();
- file_dialog_thread.start(FreeDesktopPortalDesktop::_thread_file_dialog_monitor, this);
+ monitor_thread_abort.clear();
+ monitor_thread.start(FreeDesktopPortalDesktop::_thread_monitor, this);
}
}
FreeDesktopPortalDesktop::~FreeDesktopPortalDesktop() {
- file_dialog_thread_abort.set();
- if (file_dialog_thread.is_started()) {
- file_dialog_thread.wait_to_finish();
+ monitor_thread_abort.set();
+ if (monitor_thread.is_started()) {
+ monitor_thread.wait_to_finish();
}
+
for (FreeDesktopPortalDesktop::FileDialogData &fd : file_dialogs) {
if (fd.connection) {
DBusError err;
@@ -631,6 +682,13 @@ FreeDesktopPortalDesktop::~FreeDesktopPortalDesktop() {
dbus_connection_unref(fd.connection);
}
}
+ if (theme_connection) {
+ DBusError err;
+ dbus_error_init(&err);
+ dbus_bus_remove_match(theme_connection, theme_path.utf8().get_data(), &err);
+ dbus_error_free(&err);
+ dbus_connection_unref(theme_connection);
+ }
}
#endif // DBUS_ENABLED
diff --git a/platform/linuxbsd/freedesktop_portal_desktop.h b/platform/linuxbsd/freedesktop_portal_desktop.h
index c9da387241..75afe02a26 100644
--- a/platform/linuxbsd/freedesktop_portal_desktop.h
+++ b/platform/linuxbsd/freedesktop_portal_desktop.h
@@ -34,6 +34,7 @@
#ifdef DBUS_ENABLED
#include "core/os/thread.h"
+#include "core/os/thread_safe.h"
#include "servers/display_server.h"
struct DBusMessage;
@@ -68,10 +69,15 @@ private:
Mutex file_dialog_mutex;
Vector<FileDialogData> file_dialogs;
- Thread file_dialog_thread;
- SafeFlag file_dialog_thread_abort;
+ Thread monitor_thread;
+ SafeFlag monitor_thread_abort;
- static void _thread_file_dialog_monitor(void *p_ud);
+ DBusConnection *theme_connection = nullptr;
+ String theme_path;
+ Callable system_theme_changed;
+ void _system_theme_changed_callback();
+
+ static void _thread_monitor(void *p_ud);
public:
FreeDesktopPortalDesktop();
@@ -86,6 +92,9 @@ public:
// 1: Prefer dark appearance.
// 2: Prefer light appearance.
uint32_t get_appearance_color_scheme();
+ void set_system_theme_change_callback(const Callable &p_system_theme_changed) {
+ system_theme_changed = p_system_theme_changed;
+ }
};
#endif // DBUS_ENABLED
diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp
index b8a10ea6b9..85bbfe546a 100644
--- a/platform/linuxbsd/wayland/display_server_wayland.cpp
+++ b/platform/linuxbsd/wayland/display_server_wayland.cpp
@@ -275,6 +275,10 @@ bool DisplayServerWayland::is_dark_mode() const {
}
}
+void DisplayServerWayland::set_system_theme_change_callback(const Callable &p_callable) {
+ portal_desktop->set_system_theme_change_callback(p_callable);
+}
+
Error DisplayServerWayland::file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) {
WindowID window_id = MAIN_WINDOW_ID;
// TODO: Use window IDs for multiwindow support.
diff --git a/platform/linuxbsd/wayland/display_server_wayland.h b/platform/linuxbsd/wayland/display_server_wayland.h
index 58c5dab586..d4da80a55f 100644
--- a/platform/linuxbsd/wayland/display_server_wayland.h
+++ b/platform/linuxbsd/wayland/display_server_wayland.h
@@ -171,6 +171,7 @@ public:
#ifdef DBUS_ENABLED
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) override;
virtual Error file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback) override;
diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp
index b838e4b870..35bfe81827 100644
--- a/platform/linuxbsd/x11/display_server_x11.cpp
+++ b/platform/linuxbsd/x11/display_server_x11.cpp
@@ -364,6 +364,10 @@ bool DisplayServerX11::is_dark_mode() const {
}
}
+void DisplayServerX11::set_system_theme_change_callback(const Callable &p_callable) {
+ portal_desktop->set_system_theme_change_callback(p_callable);
+}
+
Error DisplayServerX11::file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) {
WindowID window_id = last_focused_window;
diff --git a/platform/linuxbsd/x11/display_server_x11.h b/platform/linuxbsd/x11/display_server_x11.h
index 7c094d6a41..a5cbe34d26 100644
--- a/platform/linuxbsd/x11/display_server_x11.h
+++ b/platform/linuxbsd/x11/display_server_x11.h
@@ -400,6 +400,7 @@ public:
#if defined(DBUS_ENABLED)
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) override;
virtual Error file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback) override;
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index 10c8abe663..7373a40237 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -211,12 +211,17 @@ private:
IOPMAssertionID screen_keep_on_assertion = kIOPMNullAssertionID;
+ Callable help_search_callback;
+ Callable help_action_callback;
+
struct MenuCall {
Variant tag;
Callable callback;
};
List<MenuCall> deferred_menu_calls;
+ Callable system_theme_changed;
+
const NSMenu *_get_menu_root(const String &p_menu_root) const;
NSMenu *_get_menu_root(const String &p_menu_root);
bool _is_menu_opened(NSMenu *p_menu) const;
@@ -251,6 +256,8 @@ public:
void menu_open(NSMenu *p_menu);
void menu_close(NSMenu *p_menu);
+ void emit_system_theme_changed();
+
bool has_window(WindowID p_window) const;
WindowData &get_window(WindowID p_window);
@@ -282,6 +289,10 @@ public:
virtual bool has_feature(Feature p_feature) const override;
virtual String get_name() const override;
+ virtual void help_set_search_callbacks(const Callable &p_search_callback = Callable(), const Callable &p_action_callback = Callable()) override;
+ Callable _help_get_search_callback() const;
+ Callable _help_get_action_callback() const;
+
virtual void global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback = Callable(), const Callable &p_close_callback = Callable()) override;
virtual int global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index = -1) override;
@@ -351,6 +362,8 @@ public:
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
virtual Color get_accent_color() const override;
+ virtual Color get_base_color() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) override;
virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) override;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 19632dd799..344dc1a8f7 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -840,6 +840,7 @@ bool DisplayServerMacOS::has_feature(Feature p_feature) const {
case FEATURE_EXTEND_TO_TITLE:
case FEATURE_SCREEN_CAPTURE:
case FEATURE_STATUS_INDICATOR:
+ case FEATURE_NATIVE_HELP:
return true;
default: {
}
@@ -851,6 +852,19 @@ String DisplayServerMacOS::get_name() const {
return "macOS";
}
+void DisplayServerMacOS::help_set_search_callbacks(const Callable &p_search_callback, const Callable &p_action_callback) {
+ help_search_callback = p_search_callback;
+ help_action_callback = p_action_callback;
+}
+
+Callable DisplayServerMacOS::_help_get_search_callback() const {
+ return help_search_callback;
+}
+
+Callable DisplayServerMacOS::_help_get_action_callback() const {
+ return help_action_callback;
+}
+
bool DisplayServerMacOS::_is_menu_opened(NSMenu *p_menu) const {
if (submenu_inv.has(p_menu)) {
const MenuData &md = submenu[submenu_inv[p_menu]];
@@ -2037,7 +2051,42 @@ bool DisplayServerMacOS::is_dark_mode() const {
Color DisplayServerMacOS::get_accent_color() const {
if (@available(macOS 10.14, *)) {
- NSColor *color = [[NSColor controlAccentColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+ __block NSColor *color = nullptr;
+ if (@available(macOS 11.0, *)) {
+ [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
+ color = [[NSColor controlAccentColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+ }];
+ } else {
+ NSAppearance *saved_appearance = [NSAppearance currentAppearance];
+ [NSAppearance setCurrentAppearance:[NSApp effectiveAppearance]];
+ color = [[NSColor controlAccentColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+ [NSAppearance setCurrentAppearance:saved_appearance];
+ }
+ if (color) {
+ CGFloat components[4];
+ [color getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
+ return Color(components[0], components[1], components[2], components[3]);
+ } else {
+ return Color(0, 0, 0, 0);
+ }
+ } else {
+ return Color(0, 0, 0, 0);
+ }
+}
+
+Color DisplayServerMacOS::get_base_color() const {
+ if (@available(macOS 10.14, *)) {
+ __block NSColor *color = nullptr;
+ if (@available(macOS 11.0, *)) {
+ [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
+ color = [[NSColor controlColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+ }];
+ } else {
+ NSAppearance *saved_appearance = [NSAppearance currentAppearance];
+ [NSAppearance setCurrentAppearance:[NSApp effectiveAppearance]];
+ color = [[NSColor controlColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+ [NSAppearance setCurrentAppearance:saved_appearance];
+ }
if (color) {
CGFloat components[4];
[color getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
@@ -2050,6 +2099,16 @@ Color DisplayServerMacOS::get_accent_color() const {
}
}
+void DisplayServerMacOS::set_system_theme_change_callback(const Callable &p_callable) {
+ system_theme_changed = p_callable;
+}
+
+void DisplayServerMacOS::emit_system_theme_changed() {
+ if (system_theme_changed.is_valid()) {
+ system_theme_changed.call();
+ }
+}
+
Error DisplayServerMacOS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) {
_THREAD_SAFE_METHOD_
diff --git a/platform/macos/godot_application_delegate.h b/platform/macos/godot_application_delegate.h
index 2426fb0b1c..45bd85c45c 100644
--- a/platform/macos/godot_application_delegate.h
+++ b/platform/macos/godot_application_delegate.h
@@ -36,7 +36,7 @@
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
-@interface GodotApplicationDelegate : NSObject
+@interface GodotApplicationDelegate : NSObject <NSUserInterfaceItemSearching, NSApplicationDelegate>
- (void)forceUnbundledWindowActivationHackStep1;
- (void)forceUnbundledWindowActivationHackStep2;
- (void)forceUnbundledWindowActivationHackStep3;
diff --git a/platform/macos/godot_application_delegate.mm b/platform/macos/godot_application_delegate.mm
index c1de8ade58..2e76d4aa97 100644
--- a/platform/macos/godot_application_delegate.mm
+++ b/platform/macos/godot_application_delegate.mm
@@ -39,6 +39,59 @@
return YES;
}
+- (NSArray<NSString *> *)localizedTitlesForItem:(id)item {
+ NSArray *item_name = @[ item[1] ];
+ return item_name;
+}
+
+- (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems {
+ NSMutableArray *found_items = [[NSMutableArray alloc] init];
+
+ DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
+ if (ds && ds->_help_get_search_callback().is_valid()) {
+ Callable cb = ds->_help_get_search_callback();
+
+ Variant ret;
+ Variant search_string = String::utf8([searchString UTF8String]);
+ Variant result_limit = (uint64_t)resultLimit;
+ Callable::CallError ce;
+ const Variant *args[2] = { &search_string, &result_limit };
+
+ cb.callp(args, 2, ret, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ ERR_PRINT(vformat(RTR("Failed to execute help search callback: %s."), Variant::get_callable_error_text(cb, args, 2, ce)));
+ }
+ Dictionary results = ret;
+ for (const Variant *E = results.next(); E; E = results.next(E)) {
+ const String &key = *E;
+ const String &value = results[*E];
+ if (key.length() > 0 && value.length() > 0) {
+ NSArray *item = @[ [NSString stringWithUTF8String:key.utf8().get_data()], [NSString stringWithUTF8String:value.utf8().get_data()] ];
+ [found_items addObject:item];
+ }
+ }
+ }
+
+ handleMatchedItems(found_items);
+}
+
+- (void)performActionForItem:(id)item {
+ DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
+ if (ds && ds->_help_get_action_callback().is_valid()) {
+ Callable cb = ds->_help_get_action_callback();
+
+ Variant ret;
+ Variant item_string = String::utf8([item[0] UTF8String]);
+ Callable::CallError ce;
+ const Variant *args[1] = { &item_string };
+
+ cb.callp(args, 1, ret, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ ERR_PRINT(vformat(RTR("Failed to execute help action callback: %s."), Variant::get_callable_error_text(cb, args, 1, ce)));
+ }
+ }
+}
+
- (void)forceUnbundledWindowActivationHackStep1 {
// Step 1: Switch focus to macOS SystemUIServer process.
// Required to perform step 2, TransformProcessType will fail if app is already the in focus.
@@ -63,6 +116,13 @@
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}
+- (void)system_theme_changed:(NSNotification *)notification {
+ DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
+ if (ds) {
+ ds->emit_system_theme_changed();
+ }
+}
+
- (void)applicationDidFinishLaunching:(NSNotification *)notice {
NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *nsbundleid_env = [NSString stringWithUTF8String:getenv("__CFBundleIdentifier")];
@@ -71,6 +131,8 @@
// If the executable is started from terminal or is not bundled, macOS WindowServer won't register and activate app window correctly (menu and title bar are grayed out and input ignored).
[self performSelector:@selector(forceUnbundledWindowActivationHackStep1) withObject:nil afterDelay:0.02];
}
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(system_theme_changed:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(system_theme_changed:) name:@"AppleColorPreferencesChangedNotification" object:nil];
}
- (id)init {
@@ -83,6 +145,11 @@
return self;
}
+- (void)dealloc {
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:@"AppleInterfaceThemeChangedNotification" object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:@"AppleColorPreferencesChangedNotification" object:nil];
+}
+
- (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
OS_MacOS *os = (OS_MacOS *)OS::get_singleton();
if (!event || !os) {
diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm
index 000215ac46..80c9f1b422 100644
--- a/platform/macos/os_macos.mm
+++ b/platform/macos/os_macos.mm
@@ -830,6 +830,7 @@ OS_MacOS::OS_MacOS() {
id delegate = [[GodotApplicationDelegate alloc] init];
ERR_FAIL_NULL(delegate);
[NSApp setDelegate:delegate];
+ [NSApp registerUserInterfaceItemSearchHandler:delegate];
pre_wait_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, &pre_wait_observer_cb, nullptr);
CFRunLoopAddObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 96e2f95abd..7d96bded14 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -3494,13 +3494,17 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
case WM_PAINT: {
Main::force_redraw();
} break;
- case WM_SETTINGCHANGE: {
+ case WM_SETTINGCHANGE:
+ case WM_SYSCOLORCHANGE: {
if (lParam && CompareStringOrdinal(reinterpret_cast<LPCWCH>(lParam), -1, L"ImmersiveColorSet", -1, true) == CSTR_EQUAL) {
if (is_dark_mode_supported() && dark_title_available) {
BOOL value = is_dark_mode();
::DwmSetWindowAttribute(windows[window_id].hWnd, use_legacy_dark_mode_before_20H1 ? DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 : DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
}
}
+ if (system_theme_changed.is_valid()) {
+ system_theme_changed.call();
+ }
} break;
case WM_THEMECHANGED: {
if (is_dark_mode_supported() && dark_title_available) {
@@ -5058,6 +5062,19 @@ Color DisplayServerWindows::get_accent_color() const {
return Color((argb & 0xFF) / 255.f, ((argb & 0xFF00) >> 8) / 255.f, ((argb & 0xFF0000) >> 16) / 255.f, ((argb & 0xFF000000) >> 24) / 255.f);
}
+Color DisplayServerWindows::get_base_color() const {
+ if (!ux_theme_available) {
+ return Color(0, 0, 0, 0);
+ }
+
+ int argb = GetImmersiveColorFromColorSetEx((UINT)GetImmersiveUserColorSetPreference(false, false), GetImmersiveColorTypeFromName(ShouldAppsUseDarkMode() ? L"ImmersiveDarkChromeMediumLow" : L"ImmersiveLightChromeMediumLow"), false, 0);
+ return Color((argb & 0xFF) / 255.f, ((argb & 0xFF00) >> 8) / 255.f, ((argb & 0xFF0000) >> 16) / 255.f, ((argb & 0xFF000000) >> 24) / 255.f);
+}
+
+void DisplayServerWindows::set_system_theme_change_callback(const Callable &p_callable) {
+ system_theme_changed = p_callable;
+}
+
int DisplayServerWindows::tablet_get_driver_count() const {
return tablet_drivers.size();
}
diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h
index e66c533da5..81cddec49f 100644
--- a/platform/windows/display_server_windows.h
+++ b/platform/windows/display_server_windows.h
@@ -477,6 +477,8 @@ class DisplayServerWindows : public DisplayServer {
CursorShape cursor_shape = CursorShape::CURSOR_ARROW;
RBMap<CursorShape, Vector<Variant>> cursors_cache;
+ Callable system_theme_changed;
+
void _drag_event(WindowID p_window, float p_x, float p_y, int idx);
void _touch_event(WindowID p_window, bool p_pressed, float p_x, float p_y, int idx);
@@ -522,6 +524,8 @@ public:
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
virtual Color get_accent_color() const override;
+ virtual Color get_base_color() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) override;
virtual Error file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback) override;