From 3dea5fd631c9513ed09b876f25e8bf6deff49683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 14 Feb 2020 13:43:28 +0100 Subject: [PATCH] Remove incomplete battery status/power API It was initially implemented in #5871 for Godot 3.0, but never really completed or thoroughly tested for most platforms. It then stayed in limbo and nobody seems really keen to finish it, so it's better to remove it in 4.0, and re-add eventually (possibly with a different API) if there's demand and an implementation confirmed working on all platforms. Closes #8770. --- COPYRIGHT.txt | 10 - core/bind/core_bind.cpp | 22 - core/bind/core_bind.h | 13 - core/os/os.cpp | 10 - core/os/os.h | 14 - doc/classes/OS.xml | 39 -- platform/android/SCsub | 1 - platform/android/export/export.cpp | 2 +- platform/android/os_android.cpp | 2 - platform/android/os_android.h | 3 - platform/android/power_android.cpp | 255 ------------ platform/android/power_android.h | 80 ---- platform/haiku/os_haiku.cpp | 15 - platform/haiku/os_haiku.h | 4 - platform/iphone/power_iphone.cpp | 70 ---- platform/iphone/power_iphone.h | 53 --- platform/javascript/os_javascript.cpp | 18 - platform/javascript/os_javascript.h | 4 - platform/osx/SCsub | 1 - platform/osx/os_osx.h | 7 - platform/osx/os_osx.mm | 14 - platform/osx/power_osx.cpp | 252 ----------- platform/osx/power_osx.h | 59 --- platform/server/SCsub | 2 - platform/server/os_server.cpp | 20 - platform/server/os_server.h | 11 - platform/uwp/SCsub | 1 - platform/uwp/os_uwp.cpp | 14 - platform/uwp/os_uwp.h | 7 - platform/uwp/power_uwp.cpp | 77 ---- platform/uwp/power_uwp.h | 56 --- platform/windows/SCsub | 1 - platform/windows/os_windows.cpp | 14 - platform/windows/os_windows.h | 7 - platform/windows/power_windows.cpp | 131 ------ platform/windows/power_windows.h | 58 --- platform/x11/SCsub | 1 - platform/x11/os_x11.cpp | 16 - platform/x11/os_x11.h | 7 - platform/x11/power_x11.cpp | 577 -------------------------- platform/x11/power_x11.h | 66 --- 41 files changed, 1 insertion(+), 2013 deletions(-) delete mode 100644 platform/android/power_android.cpp delete mode 100644 platform/android/power_android.h delete mode 100644 platform/iphone/power_iphone.cpp delete mode 100644 platform/iphone/power_iphone.h delete mode 100644 platform/osx/power_osx.cpp delete mode 100644 platform/osx/power_osx.h delete mode 100644 platform/uwp/power_uwp.cpp delete mode 100644 platform/uwp/power_uwp.h delete mode 100644 platform/windows/power_windows.cpp delete mode 100644 platform/windows/power_windows.h delete mode 100644 platform/x11/power_x11.cpp delete mode 100644 platform/x11/power_x11.h diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index de9936d96b..cdc59a4596 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -71,16 +71,6 @@ Comment: The Android Open Source Project Copyright: 2002, Google Inc. License: Apache-2.0 -Files: ./platform/android/power_android.cpp - ./platform/osx/power_osx.cpp - ./platform/windows/power_windows.cpp - ./platform/x11/power_x11.cpp -Comment: Simple DirectMedia Layer -Copyright: 1997-2017, Sam Lantinga - 2007-2020, Juan Linietsky, Ariel Manzur. - 2014-2020, Godot Engine contributors. -License: Expat and Zlib - Files: ./scene/animation/tween_interpolaters.cpp Comment: Penner Easing Copyright: 2001, Robert Penner diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 9413772f84..d7614c5a82 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -587,18 +587,6 @@ bool _OS::is_vsync_via_compositor_enabled() const { return OS::get_singleton()->is_vsync_via_compositor_enabled(); } -_OS::PowerState _OS::get_power_state() { - return _OS::PowerState(OS::get_singleton()->get_power_state()); -} - -int _OS::get_power_seconds_left() { - return OS::get_singleton()->get_power_seconds_left(); -} - -int _OS::get_power_percent_left() { - return OS::get_singleton()->get_power_percent_left(); -} - bool _OS::has_feature(const String &p_feature) const { return OS::get_singleton()->has_feature(p_feature); @@ -1348,10 +1336,6 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &_OS::has_feature); - ClassDB::bind_method(D_METHOD("get_power_state"), &_OS::get_power_state); - ClassDB::bind_method(D_METHOD("get_power_seconds_left"), &_OS::get_power_seconds_left); - ClassDB::bind_method(D_METHOD("get_power_percent_left"), &_OS::get_power_percent_left); - ClassDB::bind_method(D_METHOD("request_permission", "name"), &_OS::request_permission); ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions); ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions); @@ -1439,12 +1423,6 @@ void _OS::_bind_methods() { BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC); BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES); BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES); - - BIND_ENUM_CONSTANT(POWERSTATE_UNKNOWN); - BIND_ENUM_CONSTANT(POWERSTATE_ON_BATTERY); - BIND_ENUM_CONSTANT(POWERSTATE_NO_BATTERY); - BIND_ENUM_CONSTANT(POWERSTATE_CHARGING); - BIND_ENUM_CONSTANT(POWERSTATE_CHARGED); } _OS::_OS() { diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 18bb1408e3..39bed791d0 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -105,14 +105,6 @@ public: VIDEO_DRIVER_VULKAN, }; - enum PowerState { - POWERSTATE_UNKNOWN, // Cannot determine power status. - POWERSTATE_ON_BATTERY, // Not plugged in, running on the battery. - POWERSTATE_NO_BATTERY, // Plugged in, no battery available. - POWERSTATE_CHARGING, // Plugged in, charging battery. - POWERSTATE_CHARGED // Plugged in, battery charged. - }; - enum Weekday { DAY_SUNDAY, DAY_MONDAY, @@ -346,10 +338,6 @@ public: void set_vsync_via_compositor(bool p_enable); bool is_vsync_via_compositor_enabled() const; - PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); - bool has_feature(const String &p_feature) const; bool request_permission(const String &p_name); @@ -362,7 +350,6 @@ public: }; VARIANT_ENUM_CAST(_OS::VideoDriver); -VARIANT_ENUM_CAST(_OS::PowerState); VARIANT_ENUM_CAST(_OS::Weekday); VARIANT_ENUM_CAST(_OS::Month); VARIANT_ENUM_CAST(_OS::SystemDir); diff --git a/core/os/os.cpp b/core/os/os.cpp index 13be4a5c37..d1b6ccab54 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -586,16 +586,6 @@ bool OS::is_vsync_via_compositor_enabled() const { return _vsync_via_compositor; } -OS::PowerState OS::get_power_state() { - return POWERSTATE_UNKNOWN; -} -int OS::get_power_seconds_left() { - return -1; -} -int OS::get_power_percent_left() { - return -1; -} - void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) { has_server_feature_callback = p_callback; diff --git a/core/os/os.h b/core/os/os.h index 1bb910cb0d..e4661e4583 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -78,14 +78,6 @@ public: typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection); typedef bool (*HasServerFeatureCallback)(const String &p_feature); - enum PowerState { - POWERSTATE_UNKNOWN, /**< cannot determine power status */ - POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ - POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ - POWERSTATE_CHARGING, /**< Plugged in, charging battery */ - POWERSTATE_CHARGED /**< Plugged in, battery charged */ - }; - enum RenderThreadMode { RENDER_THREAD_UNSAFE, @@ -517,10 +509,6 @@ public: void set_vsync_via_compositor(bool p_enable); bool is_vsync_via_compositor_enabled() const; - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - virtual void force_process_input(){}; bool has_feature(const String &p_feature); @@ -542,6 +530,4 @@ public: virtual ~OS(); }; -VARIANT_ENUM_CAST(OS::PowerState); - #endif diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index b3b77b0b26..d361ea83e6 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -280,30 +280,6 @@ Returns the name of the host OS. Possible values are: [code]"Android"[/code], [code]"Haiku"[/code], [code]"iOS"[/code], [code]"HTML5"[/code], [code]"OSX"[/code], [code]"Server"[/code], [code]"Windows"[/code], [code]"UWP"[/code], [code]"X11"[/code]. - - - - - Returns the amount of battery left in the device as a percentage. Returns [code]-1[/code] if power state is unknown. - [b]Note:[/b] This method is implemented on Linux, macOS and Windows. - - - - - - - Returns an estimate of the time left in seconds before the device runs out of battery. Returns [code]-1[/code] if power state is unknown. - [b]Note:[/b] This method is implemented on Linux, macOS and Windows. - - - - - - - Returns the current state of the device regarding battery and power. See [enum PowerState] constants. - [b]Note:[/b] This method is implemented on Linux, macOS and Windows. - - @@ -1081,20 +1057,5 @@ Ringtones directory path. - - Unknown powerstate. - - - Unplugged, running on battery. - - - Plugged in, no battery available. - - - Plugged in, battery charging. - - - Plugged in, battery fully charged. - diff --git a/platform/android/SCsub b/platform/android/SCsub index 3ff5b8278a..fd2a774c71 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -18,7 +18,6 @@ android_files = [ 'java_class_wrapper.cpp', 'java_godot_wrapper.cpp', 'java_godot_io_wrapper.cpp', - #'power_android.cpp' ] env_android = env.Clone() diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 642b045f5b..952bc3d28f 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -385,7 +385,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { ea->device_lock->unlock(); } - uint64_t sleep = OS::get_singleton()->get_power_state() == OS::POWERSTATE_ON_BATTERY ? 1000 : 100; + uint64_t sleep = 200; uint64_t wait = 3000000; uint64_t time = OS::get_singleton()->get_ticks_usec(); while (OS::get_singleton()->get_ticks_usec() - time < wait) { diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index e86e373630..15e3ac48c7 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -152,8 +152,6 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int input = memnew(InputDefault); input->set_fallback_mapping(godot_java->get_input_fallback_mapping()); - //power_manager = memnew(PowerAndroid); - return OK; } diff --git a/platform/android/os_android.h b/platform/android/os_android.h index c2f9a0992f..ec6ffe5438 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -37,7 +37,6 @@ #include "core/os/main_loop.h" #include "drivers/unix/os_unix.h" #include "main/input_default.h" -//#include "power_android.h" #include "servers/audio_server.h" #include "servers/visual/rasterizer.h" @@ -93,8 +92,6 @@ private: GodotJavaWrapper *godot_java; GodotIOJavaWrapper *godot_io_java; - //PowerAndroid *power_manager_func; - int video_driver_index; public: diff --git a/platform/android/power_android.cpp b/platform/android/power_android.cpp deleted file mode 100644 index b0a90312e5..0000000000 --- a/platform/android/power_android.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/*************************************************************************/ -/* power_android.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -/* -Adapted from corresponding SDL 2.0 code. -*/ - -/* - Simple DirectMedia Layer - Copyright (C) 1997-2017 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "power_android.h" - -#include "core/error_macros.h" - -static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder) { - if (refholder->m_env) { - JNIEnv *env = refholder->m_env; - (*env)->PopLocalFrame(env, NULL); - --s_active; - } -} - -static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func) { - struct LocalReferenceHolder refholder; - refholder.m_env = NULL; - refholder.m_func = func; - return refholder; -} - -static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env) { - const int capacity = 16; - if ((*env)->PushLocalFrame(env, capacity) < 0) { - return false; - } - ++s_active; - refholder->m_env = env; - return true; -} - -static SDL_bool LocalReferenceHolder_IsActive(void) { - return s_active > 0; -} - -ANativeWindow *Android_JNI_GetNativeWindow(void) { - ANativeWindow *anw; - jobject s; - JNIEnv *env = Android_JNI_GetEnv(); - - s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface); - anw = ANativeWindow_fromSurface(env, s); - (*env)->DeleteLocalRef(env, s); - - return anw; -} - -/* - * CODE CHUNK IMPORTED FROM SDL 2.0 - * returns 0 on success or -1 on error (others undefined then) - * returns truthy or falsy value in plugged, charged and battery - * returns the value in seconds and percent or -1 if not available - */ -int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seconds, int *percent) { - env = Android_JNI_GetEnv(); - refs = LocalReferenceHolder_Setup(__FUNCTION__); - - if (!LocalReferenceHolder_Init(&refs, env)) { - LocalReferenceHolder_Cleanup(&refs); - return -1; - } - mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;"); - context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid); - action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED"); - cls = (*env)->FindClass(env, "android/content/IntentFilter"); - mid = (*env)->GetMethodID(env, cls, "", "(Ljava/lang/String;)V"); - filter = (*env)->NewObject(env, cls, mid, action); - (*env)->DeleteLocalRef(env, action); - mid = (*env)->GetMethodID(env, mActivityClass, "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;"); - intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter); - (*env)->DeleteLocalRef(env, filter); - cls = (*env)->GetObjectClass(env, intent); - imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I"); -// Watch out for C89 scoping rules because of the macro -#define GET_INT_EXTRA(var, key) \ - int var; \ - iname = (*env)->NewStringUTF(env, key); \ - var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \ - (*env)->DeleteLocalRef(env, iname); - bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z"); -// Watch out for C89 scoping rules because of the macro -#define GET_BOOL_EXTRA(var, key) \ - int var; \ - bname = (*env)->NewStringUTF(env, key); \ - var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \ - (*env)->DeleteLocalRef(env, bname); - if (plugged) { - // Watch out for C89 scoping rules because of the macro - GET_INT_EXTRA(plug, "plugged") // == BatteryManager.EXTRA_PLUGGED (API 5) - if (plug == -1) { - LocalReferenceHolder_Cleanup(&refs); - return -1; - } - // 1 == BatteryManager.BATTERY_PLUGGED_AC - // 2 == BatteryManager.BATTERY_PLUGGED_USB - *plugged = (0 < plug) ? 1 : 0; - } - if (charged) { - // Watch out for C89 scoping rules because of the macro - GET_INT_EXTRA(status, "status") // == BatteryManager.EXTRA_STATUS (API 5) - if (status == -1) { - LocalReferenceHolder_Cleanup(&refs); - return -1; - } - // 5 == BatteryManager.BATTERY_STATUS_FULL - *charged = (status == 5) ? 1 : 0; - } - if (battery) { - GET_BOOL_EXTRA(present, "present") // == BatteryManager.EXTRA_PRESENT (API 5) - *battery = present ? 1 : 0; - } - if (seconds) { - *seconds = -1; // not possible - } - if (percent) { - int level; - int scale; - // Watch out for C89 scoping rules because of the macro - { - GET_INT_EXTRA(level_temp, "level") // == BatteryManager.EXTRA_LEVEL (API 5) - level = level_temp; - } - // Watch out for C89 scoping rules because of the macro - { - GET_INT_EXTRA(scale_temp, "scale") // == BatteryManager.EXTRA_SCALE (API 5) - scale = scale_temp; - } - if ((level == -1) || (scale == -1)) { - LocalReferenceHolder_Cleanup(&refs); - return -1; - } - *percent = level * 100 / scale; - } - (*env)->DeleteLocalRef(env, intent); - LocalReferenceHolder_Cleanup(&refs); - - return 0; -} - -bool PowerAndroid::GetPowerInfo_Android() { - int battery; - int plugged; - int charged; - - if (Android_JNI_GetPowerInfo(&plugged, &charged, &battery, &this->nsecs_left, &this->percent_left) != -1) { - if (plugged) { - if (charged) { - this->power_state = OS::POWERSTATE_CHARGED; - } else if (battery) { - this->power_state = OS::POWERSTATE_CHARGING; - } else { - this->power_state = OS::POWERSTATE_NO_BATTERY; - this->nsecs_left = -1; - this->percent_left = -1; - } - } else { - this->power_state = OS::POWERSTATE_ON_BATTERY; - } - } else { - this->power_state = OS::POWERSTATE_UNKNOWN; - this->nsecs_left = -1; - this->percent_left = -1; - } - - return true; -} - -OS::PowerState PowerAndroid::get_power_state() { - if (GetPowerInfo_Android()) { - return power_state; - } else { - WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); - return OS::POWERSTATE_UNKNOWN; - } -} - -int PowerAndroid::get_power_seconds_left() { - if (GetPowerInfo_Android()) { - return nsecs_left; - } else { - WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); - return -1; - } -} - -int PowerAndroid::get_power_percent_left() { - if (GetPowerInfo_Android()) { - return percent_left; - } else { - WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); - return -1; - } -} - -PowerAndroid::PowerAndroid() : - nsecs_left(-1), - percent_left(-1), - power_state(OS::POWERSTATE_UNKNOWN) { -} - -PowerAndroid::~PowerAndroid() { -} diff --git a/platform/android/power_android.h b/platform/android/power_android.h deleted file mode 100644 index 9f77f3fc6b..0000000000 --- a/platform/android/power_android.h +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************/ -/* power_android.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef POWER_ANDROID_H -#define POWER_ANDROID_H - -#include "core/os/os.h" - -#include - -class PowerAndroid { - - struct LocalReferenceHolder { - JNIEnv *m_env; - const char *m_func; - }; - -private: - static struct LocalReferenceHolder refs; - static JNIEnv *env; - static jmethodID mid; - static jobject context; - static jstring action; - static jclass cls; - static jobject filter; - static jobject intent; - static jstring iname; - static jmethodID imid; - static jstring bname; - static jmethodID bmid; - - int nsecs_left; - int percent_left; - OS::PowerState power_state; - - bool GetPowerInfo_Android(); - bool UpdatePowerInfo(); - -public: - static int s_active; - - PowerAndroid(); - virtual ~PowerAndroid(); - static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env); - static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func); - static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder); - - OS::PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); -}; - -#endif // POWER_ANDROID_H diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 2e4bb2ff26..a082ba53f9 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -360,18 +360,3 @@ String OS_Haiku::get_cache_path() const { return get_config_path(); } } - -OS::PowerState OS_Haiku::get_power_state() { - WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); - return OS::POWERSTATE_UNKNOWN; -} - -int OS_Haiku::get_power_seconds_left() { - WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); - return -1; -} - -int OS_Haiku::get_power_percent_left() { - WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); - return -1; -} diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index c99147198d..fc8cb77a91 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -113,10 +113,6 @@ public: virtual void get_fullscreen_mode_list(List *p_list, int p_screen = 0) const; virtual String get_executable_path() const; - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - virtual bool _check_internal_feature_support(const String &p_feature); virtual String get_config_path() const; diff --git a/platform/iphone/power_iphone.cpp b/platform/iphone/power_iphone.cpp deleted file mode 100644 index 36bac8da38..0000000000 --- a/platform/iphone/power_iphone.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************/ -/* power_iphone.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "power_iphone.h" - -bool PowerIphone::UpdatePowerInfo() { - return false; -} - -OS::PowerState PowerIphone::get_power_state() { - if (UpdatePowerInfo()) { - return power_state; - } else { - return OS::POWERSTATE_UNKNOWN; - } -} - -int PowerIphone::get_power_seconds_left() { - if (UpdatePowerInfo()) { - return nsecs_left; - } else { - return -1; - } -} - -int PowerIphone::get_power_percent_left() { - if (UpdatePowerInfo()) { - return percent_left; - } else { - return -1; - } -} - -PowerIphone::PowerIphone() : - nsecs_left(-1), - percent_left(-1), - power_state(OS::POWERSTATE_UNKNOWN) { - // TODO Auto-generated constructor stub -} - -PowerIphone::~PowerIphone() { - // TODO Auto-generated destructor stub -} diff --git a/platform/iphone/power_iphone.h b/platform/iphone/power_iphone.h deleted file mode 100644 index 47a4508509..0000000000 --- a/platform/iphone/power_iphone.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************/ -/* power_iphone.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef POWER_IPHONE_H -#define POWER_IPHONE_H - -#include - -class PowerIphone { -private: - int nsecs_left; - int percent_left; - OS::PowerState power_state; - - bool UpdatePowerInfo(); - -public: - PowerIphone(); - virtual ~PowerIphone(); - - OS::PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); -}; - -#endif // POWER_IPHONE_H diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index d22e53e7ea..8ba2b39c85 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -1244,24 +1244,6 @@ String OS_JavaScript::get_resource_dir() const { return "/"; } -OS::PowerState OS_JavaScript::get_power_state() { - - WARN_PRINT("Power management is not supported for the HTML5 platform, defaulting to POWERSTATE_UNKNOWN"); - return OS::POWERSTATE_UNKNOWN; -} - -int OS_JavaScript::get_power_seconds_left() { - - WARN_PRINT("Power management is not supported for the HTML5 platform, defaulting to -1"); - return -1; -} - -int OS_JavaScript::get_power_percent_left() { - - WARN_PRINT("Power management is not supported for the HTML5 platform, defaulting to -1"); - return -1; -} - void OS_JavaScript::file_access_close_callback(const String &p_file, int p_flags) { OS_JavaScript *os = get_singleton(); diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 65a18830ed..5319ea121c 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -160,10 +160,6 @@ public: virtual String get_resource_dir() const; virtual String get_user_data_dir() const; - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - void set_idb_available(bool p_idb_available); virtual bool is_userfs_persistent() const; diff --git a/platform/osx/SCsub b/platform/osx/SCsub index 09f213cb0e..d764ac4b50 100644 --- a/platform/osx/SCsub +++ b/platform/osx/SCsub @@ -12,7 +12,6 @@ files = [ 'semaphore_osx.cpp', 'dir_access_osx.mm', 'joypad_osx.cpp', - 'power_osx.cpp', 'vulkan_context_osx.mm', 'context_gl_osx.mm' ] diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index bfd13be43a..75a56bd82c 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -40,7 +40,6 @@ #include "drivers/unix/os_unix.h" #include "joypad_osx.h" #include "main/input_default.h" -#include "power_osx.h" #include "servers/audio_server.h" #include "servers/visual/rasterizer.h" #include "servers/visual/visual_server_wrap_mt.h" @@ -147,8 +146,6 @@ public: Size2 min_size; Size2 max_size; - PowerOSX *power_manager; - CrashHandler crash_handler; float _mouse_scale(float p_scale) { @@ -304,10 +301,6 @@ public: virtual String get_unique_id() const; - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - virtual bool _check_internal_feature_support(const String &p_feature); virtual void _set_use_vsync(bool p_enable); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 87ab8b3420..ca29c95f57 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1628,8 +1628,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a input = memnew(InputDefault); joypad_osx = memnew(JoypadOSX); - power_manager = memnew(PowerOSX); - _ensure_user_data_dir(); restore_rect = Rect2(get_window_position(), get_window_size()); @@ -2973,18 +2971,6 @@ String OS_OSX::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } -OS::PowerState OS_OSX::get_power_state() { - return power_manager->get_power_state(); -} - -int OS_OSX::get_power_seconds_left() { - return power_manager->get_power_seconds_left(); -} - -int OS_OSX::get_power_percent_left() { - return power_manager->get_power_percent_left(); -} - Error OS_OSX::move_to_trash(const String &p_path) { NSFileManager *fm = [NSFileManager defaultManager]; NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())]; diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp deleted file mode 100644 index 6d7667c5e8..0000000000 --- a/platform/osx/power_osx.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/*************************************************************************/ -/* power_osx.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -/* -Adapted from corresponding SDL 2.0 code. -*/ - -/* - Simple DirectMedia Layer - Copyright (C) 1997-2017 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "power_osx.h" - -#include -#include -#include - -// CODE CHUNK IMPORTED FROM SDL 2.0 - -/* CoreFoundation is so verbose... */ -#define STRMATCH(a, b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo) -#define GETVAL(k, v) \ - CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **)v) - -/* Note that AC power sources also include a laptop battery it is charging. */ -void PowerOSX::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) { - CFStringRef strval; /* don't CFRelease() this. */ - CFBooleanRef bval; - CFNumberRef numval; - bool charge = false; - bool choose = false; - bool is_ac = false; - int secs = -1; - int maxpct = -1; - int pct = -1; - - if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) { - return; /* nothing to see here. */ - } - - if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) { - return; - } - - if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) { - is_ac = *have_ac = true; - } else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) { - return; /* not a battery? */ - } - - if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) { - charge = true; - } - - if (GETVAL(kIOPSMaxCapacityKey, &numval)) { - SInt32 val = -1; - CFNumberGetValue(numval, kCFNumberSInt32Type, &val); - if (val > 0) { - *have_battery = true; - maxpct = (int)val; - } - } - - if (GETVAL(kIOPSMaxCapacityKey, &numval)) { - SInt32 val = -1; - CFNumberGetValue(numval, kCFNumberSInt32Type, &val); - if (val > 0) { - *have_battery = true; - maxpct = (int)val; - } - } - - if (GETVAL(kIOPSTimeToEmptyKey, &numval)) { - SInt32 val = -1; - CFNumberGetValue(numval, kCFNumberSInt32Type, &val); - - /* Mac OS X reports 0 minutes until empty if you're plugged in. :( */ - if ((val == 0) && (is_ac)) { - val = -1; /* !!! FIXME: calc from timeToFull and capacity? */ - } - - secs = (int)val; - if (secs > 0) { - secs *= 60; /* value is in minutes, so convert to seconds. */ - } - } - - if (GETVAL(kIOPSCurrentCapacityKey, &numval)) { - SInt32 val = -1; - CFNumberGetValue(numval, kCFNumberSInt32Type, &val); - pct = (int)val; - } - - if ((pct > 0) && (maxpct > 0)) { - pct = (int)((((double)pct) / ((double)maxpct)) * 100.0); - } - - if (pct > 100) { - pct = 100; - } - - /* - * We pick the battery that claims to have the most minutes left. - * (failing a report of minutes, we'll take the highest percent.) - */ - if ((secs < 0) && (nsecs_left < 0)) { - if ((pct < 0) && (percent_left < 0)) { - choose = true; /* at least we know there's a battery. */ - } - if (pct > percent_left) { - choose = true; - } - } else if (secs > nsecs_left) { - choose = true; - } - - if (choose) { - nsecs_left = secs; - percent_left = pct; - *charging = charge; - } -} - -#undef GETVAL -#undef STRMATCH - -// CODE CHUNK IMPORTED FROM SDL 2.0 -bool PowerOSX::GetPowerInfo_MacOSX() { - CFTypeRef blob = IOPSCopyPowerSourcesInfo(); - - nsecs_left = -1; - percent_left = -1; - power_state = OS::POWERSTATE_UNKNOWN; - - if (blob != NULL) { - CFArrayRef list = IOPSCopyPowerSourcesList(blob); - if (list != NULL) { - /* don't CFRelease() the list items, or dictionaries! */ - bool have_ac = false; - bool have_battery = false; - bool charging = false; - const CFIndex total = CFArrayGetCount(list); - CFIndex i; - for (i = 0; i < total; i++) { - CFTypeRef ps = (CFTypeRef)CFArrayGetValueAtIndex(list, i); - CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps); - if (dict != NULL) { - checkps(dict, &have_ac, &have_battery, &charging); - } - } - - if (!have_battery) { - power_state = OS::POWERSTATE_NO_BATTERY; - } else if (charging) { - power_state = OS::POWERSTATE_CHARGING; - } else if (have_ac) { - power_state = OS::POWERSTATE_CHARGED; - } else { - power_state = OS::POWERSTATE_ON_BATTERY; - } - - CFRelease(list); - } - CFRelease(blob); - } - - return true; /* always the definitive answer on Mac OS X. */ -} - -bool PowerOSX::UpdatePowerInfo() { - if (GetPowerInfo_MacOSX()) { - return true; - } - return false; -} - -OS::PowerState PowerOSX::get_power_state() { - if (UpdatePowerInfo()) { - return power_state; - } else { - return OS::POWERSTATE_UNKNOWN; - } -} - -int PowerOSX::get_power_seconds_left() { - if (UpdatePowerInfo()) { - return nsecs_left; - } else { - return -1; - } -} - -int PowerOSX::get_power_percent_left() { - if (UpdatePowerInfo()) { - return percent_left; - } else { - return -1; - } -} - -PowerOSX::PowerOSX() : - nsecs_left(-1), - percent_left(-1), - power_state(OS::POWERSTATE_UNKNOWN) { -} - -PowerOSX::~PowerOSX() { -} diff --git a/platform/osx/power_osx.h b/platform/osx/power_osx.h deleted file mode 100644 index 6f9b213439..0000000000 --- a/platform/osx/power_osx.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* power_osx.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef POWER_OSX_H -#define POWER_OSX_H - -#include "core/os/file_access.h" -#include "core/os/os.h" -#include "dir_access_osx.h" - -#include - -class PowerOSX { - -private: - int nsecs_left; - int percent_left; - OS::PowerState power_state; - void checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging); - bool GetPowerInfo_MacOSX(/*PowerState * state, int *seconds, int *percent*/); - bool UpdatePowerInfo(); - -public: - PowerOSX(); - virtual ~PowerOSX(); - - OS::PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); -}; - -#endif // POWER_OSX_H diff --git a/platform/server/SCsub b/platform/server/SCsub index f977275595..e8538f03a6 100644 --- a/platform/server/SCsub +++ b/platform/server/SCsub @@ -10,10 +10,8 @@ common_server = [\ if sys.platform == "darwin": common_server.append("#platform/osx/crash_handler_osx.mm") - common_server.append("#platform/osx/power_osx.cpp") common_server.append("#platform/osx/semaphore_osx.cpp") else: common_server.append("#platform/x11/crash_handler_x11.cpp") - common_server.append("#platform/x11/power_x11.cpp") prog = env.add_program('#bin/godot_server', ['godot_server.cpp'] + common_server) diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index 498fd01b5e..c0a4813596 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -92,12 +92,6 @@ Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int input = memnew(InputDefault); -#ifdef __APPLE__ - power_manager = memnew(PowerOSX); -#else - power_manager = memnew(PowerX11); -#endif - _ensure_user_data_dir(); resource_loader_dummy.instance(); @@ -117,8 +111,6 @@ void OS_Server::finalize() { memdelete(input); - memdelete(power_manager); - ResourceLoader::remove_resource_format_loader(resource_loader_dummy); resource_loader_dummy.unref(); @@ -198,18 +190,6 @@ String OS_Server::get_name() const { void OS_Server::move_window_to_foreground() { } -OS::PowerState OS_Server::get_power_state() { - return power_manager->get_power_state(); -} - -int OS_Server::get_power_seconds_left() { - return power_manager->get_power_seconds_left(); -} - -int OS_Server::get_power_percent_left() { - return power_manager->get_power_percent_left(); -} - bool OS_Server::_check_internal_feature_support(const String &p_feature) { return p_feature == "pc"; } diff --git a/platform/server/os_server.h b/platform/server/os_server.h index 46ca9cb6d1..7584293722 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -36,11 +36,9 @@ #include "main/input_default.h" #ifdef __APPLE__ #include "platform/osx/crash_handler_osx.h" -#include "platform/osx/power_osx.h" #include "platform/osx/semaphore_osx.h" #else #include "platform/x11/crash_handler_x11.h" -#include "platform/x11/power_x11.h" #endif #include "servers/audio_server.h" #include "servers/visual/rasterizer.h" @@ -63,12 +61,6 @@ class OS_Server : public OS_Unix { InputDefault *input; -#ifdef __APPLE__ - PowerOSX *power_manager; -#else - PowerX11 *power_manager; -#endif - CrashHandler crash_handler; int video_driver_index; @@ -112,9 +104,6 @@ public: void run(); - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); virtual bool _check_internal_feature_support(const String &p_feature); virtual String get_config_path() const; diff --git a/platform/uwp/SCsub b/platform/uwp/SCsub index c14290f0c4..620d8c3c3a 100644 --- a/platform/uwp/SCsub +++ b/platform/uwp/SCsub @@ -7,7 +7,6 @@ files = [ '#platform/windows/key_mapping_windows.cpp', '#platform/windows/windows_terminal_logger.cpp', 'joypad_uwp.cpp', - 'power_uwp.cpp', 'context_egl_uwp.cpp', 'app.cpp', 'os_uwp.cpp', diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 9748c1ef9f..3cd7a02a94 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -271,8 +271,6 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a AudioDriverManager::initialize(p_audio_driver); - power_manager = memnew(PowerUWP); - managed_object->update_clipboard(); Clipboard::ContentChanged += ref new EventHandler(managed_object, &ManagedType::on_clipboard_changed); @@ -854,18 +852,6 @@ bool OS_UWP::_check_internal_feature_support(const String &p_feature) { return p_feature == "pc"; } -OS::PowerState OS_UWP::get_power_state() { - return power_manager->get_power_state(); -} - -int OS_UWP::get_power_seconds_left() { - return power_manager->get_power_seconds_left(); -} - -int OS_UWP::get_power_percent_left() { - return power_manager->get_power_percent_left(); -} - OS_UWP::OS_UWP() { key_event_pos = 0; diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index fb43ab382e..32b899c0da 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -39,7 +39,6 @@ #include "drivers/xaudio2/audio_driver_xaudio2.h" #include "joypad_uwp.h" #include "main/input_default.h" -#include "power_uwp.h" #include "servers/audio_server.h" #include "servers/visual/rasterizer.h" #include "servers/visual_server.h" @@ -102,8 +101,6 @@ private: AudioDriverXAudio2 audio_driver; - PowerUWP *power_manager; - MouseMode mouse_mode; bool alt_mem; bool gr_mem; @@ -254,10 +251,6 @@ public: void input_event(const Ref &p_event); - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - void queue_key_event(KeyEvent &p_event); OS_UWP(); diff --git a/platform/uwp/power_uwp.cpp b/platform/uwp/power_uwp.cpp deleted file mode 100644 index c6b4359392..0000000000 --- a/platform/uwp/power_uwp.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************/ -/* power_uwp.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "power_uwp.h" - -PowerUWP::PowerUWP() : - nsecs_left(-1), - percent_left(-1), - power_state(OS::POWERSTATE_UNKNOWN) { -} - -PowerUWP::~PowerUWP() { -} - -bool PowerUWP::UpdatePowerInfo() { - // TODO, WinRT: Battery info is available on at least one WinRT platform (Windows Phone 8). Implement UpdatePowerInfo as appropriate. */ - /* Notes from SDL: - - the Win32 function, GetSystemPowerStatus, is not available for use on WinRT - - Windows Phone 8 has a 'Battery' class, which is documented as available for C++ - - More info on WP8's Battery class can be found at http://msdn.microsoft.com/library/windowsphone/develop/jj207231 - */ - return false; -} - -OS::PowerState PowerUWP::get_power_state() { - if (UpdatePowerInfo()) { - return power_state; - } else { - WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); - return OS::POWERSTATE_UNKNOWN; - } -} - -int PowerUWP::get_power_seconds_left() { - if (UpdatePowerInfo()) { - return nsecs_left; - } else { - WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); - return -1; - } -} - -int PowerUWP::get_power_percent_left() { - if (UpdatePowerInfo()) { - return percent_left; - } else { - WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); - return -1; - } -} diff --git a/platform/uwp/power_uwp.h b/platform/uwp/power_uwp.h deleted file mode 100644 index 5e28cf65e5..0000000000 --- a/platform/uwp/power_uwp.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************/ -/* power_uwp.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef POWER_UWP_H -#define POWER_UWP_H - -#include "core/os/dir_access.h" -#include "core/os/file_access.h" -#include "core/os/os.h" - -class PowerUWP { - -private: - int nsecs_left; - int percent_left; - OS::PowerState power_state; - - bool UpdatePowerInfo(); - -public: - PowerUWP(); - virtual ~PowerUWP(); - - OS::PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); -}; - -#endif // POWER_UWP_H diff --git a/platform/windows/SCsub b/platform/windows/SCsub index 6f01460025..8e94c7b35d 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -12,7 +12,6 @@ common_win = [ "os_windows.cpp", "key_mapping_windows.cpp", "joypad_windows.cpp", - "power_windows.cpp", "windows_terminal_logger.cpp", "vulkan_context_win.cpp", "context_gl_windows.cpp" diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 133dc9004d..cdcdf65e21 100755 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1492,8 +1492,6 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int input = memnew(InputDefault); joypad = memnew(JoypadWindows(input, &hWnd)); - power_manager = memnew(PowerWindows); - AudioDriverManager::initialize(p_audio_driver); TRACKMOUSEEVENT tme; @@ -3334,18 +3332,6 @@ void OS_Windows::_set_use_vsync(bool p_enable) { #endif } -OS::PowerState OS_Windows::get_power_state() { - return power_manager->get_power_state(); -} - -int OS_Windows::get_power_seconds_left() { - return power_manager->get_power_seconds_left(); -} - -int OS_Windows::get_power_percent_left() { - return power_manager->get_power_percent_left(); -} - bool OS_Windows::_check_internal_feature_support(const String &p_feature) { return p_feature == "pc"; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 89b67f8d91..6c3769c98c 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -40,7 +40,6 @@ #include "drivers/winmidi/midi_driver_winmidi.h" #include "key_mapping_windows.h" #include "main/input_default.h" -#include "power_windows.h" #include "servers/audio_server.h" #include "servers/visual/rasterizer.h" #include "servers/visual_server.h" @@ -239,8 +238,6 @@ class OS_Windows : public OS { JoypadWindows *joypad; Map touch_state; - PowerWindows *power_manager; - int video_driver_index; #ifdef WASAPI_ENABLED AudioDriverWASAPI driver_wasapi; @@ -433,10 +430,6 @@ public: virtual void _set_use_vsync(bool p_enable); //virtual bool is_vsync_enabled() const; - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - virtual bool _check_internal_feature_support(const String &p_feature); void disable_crash_handler(); diff --git a/platform/windows/power_windows.cpp b/platform/windows/power_windows.cpp deleted file mode 100644 index aea06da413..0000000000 --- a/platform/windows/power_windows.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************/ -/* power_windows.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -/* -Adapted from corresponding SDL 2.0 code. -*/ - -/* - Simple DirectMedia Layer - Copyright (C) 1997-2017 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "power_windows.h" - -// CODE CHUNK IMPORTED FROM SDL 2.0 - -bool PowerWindows::GetPowerInfo_Windows() { - SYSTEM_POWER_STATUS status; - bool need_details = FALSE; - - /* This API should exist back to Win95. */ - if (!GetSystemPowerStatus(&status)) { - /* !!! FIXME: push GetLastError() into GetError() */ - power_state = OS::POWERSTATE_UNKNOWN; - } else if (status.BatteryFlag == 0xFF) { /* unknown state */ - power_state = OS::POWERSTATE_UNKNOWN; - } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ - power_state = OS::POWERSTATE_NO_BATTERY; - } else if (status.BatteryFlag & (1 << 3)) { /* charging */ - power_state = OS::POWERSTATE_CHARGING; - need_details = TRUE; - } else if (status.ACLineStatus == 1) { - power_state = OS::POWERSTATE_CHARGED; /* on AC, not charging. */ - need_details = TRUE; - } else { - power_state = OS::POWERSTATE_ON_BATTERY; /* not on AC. */ - need_details = TRUE; - } - - percent_left = -1; - nsecs_left = -1; - if (need_details) { - const int pct = (int)status.BatteryLifePercent; - const int secs = (int)status.BatteryLifeTime; - - if (pct != 255) { /* 255 == unknown */ - percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ - } - if (secs != (int)0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ - nsecs_left = secs; - } - } - - return TRUE; /* always the definitive answer on Windows. */ -} - -OS::PowerState PowerWindows::get_power_state() { - if (GetPowerInfo_Windows()) { - return power_state; - } else { - return OS::POWERSTATE_UNKNOWN; - } -} - -int PowerWindows::get_power_seconds_left() { - if (GetPowerInfo_Windows()) { - return nsecs_left; - } else { - return -1; - } -} - -int PowerWindows::get_power_percent_left() { - if (GetPowerInfo_Windows()) { - return percent_left; - } else { - return -1; - } -} - -PowerWindows::PowerWindows() : - nsecs_left(-1), - percent_left(-1), - power_state(OS::POWERSTATE_UNKNOWN) { -} - -PowerWindows::~PowerWindows() { -} diff --git a/platform/windows/power_windows.h b/platform/windows/power_windows.h deleted file mode 100644 index 80d86a12c5..0000000000 --- a/platform/windows/power_windows.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************/ -/* power_windows.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef POWER_WINDOWS_H -#define POWER_WINDOWS_H - -#include "core/os/dir_access.h" -#include "core/os/file_access.h" -#include "core/os/os.h" - -#include - -class PowerWindows { - -private: - int nsecs_left; - int percent_left; - OS::PowerState power_state; - - bool GetPowerInfo_Windows(); - -public: - PowerWindows(); - virtual ~PowerWindows(); - - OS::PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); -}; - -#endif // POWER_WINDOWS_H diff --git a/platform/x11/SCsub b/platform/x11/SCsub index 9027c244be..2268e4cc3d 100644 --- a/platform/x11/SCsub +++ b/platform/x11/SCsub @@ -12,7 +12,6 @@ common_x11 = [ "os_x11.cpp", "key_mapping_x11.cpp", "joypad_linux.cpp", - "power_x11.cpp", "detect_prime.cpp" ] diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 1fd91ec3c1..26170a8335 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -659,8 +659,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a #endif _ensure_user_data_dir(); - power_manager = memnew(PowerX11); - if (p_desired.layered) { set_window_per_pixel_transparency_enabled(true); } @@ -870,8 +868,6 @@ void OS_X11::finalize() { visual_server->finish(); memdelete(visual_server); - memdelete(power_manager); - #if defined(OPENGL_ENABLED) if (video_driver_index == VIDEO_DRIVER_GLES2) { @@ -3389,18 +3385,6 @@ void OS_X11::set_context(int p_context) { } } -OS::PowerState OS_X11::get_power_state() { - return power_manager->get_power_state(); -} - -int OS_X11::get_power_seconds_left() { - return power_manager->get_power_seconds_left(); -} - -int OS_X11::get_power_percent_left() { - return power_manager->get_power_percent_left(); -} - void OS_X11::disable_crash_handler() { crash_handler.disable(); } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index fd8a981763..55d24d64a3 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -39,7 +39,6 @@ #include "drivers/unix/os_unix.h" #include "joypad_linux.h" #include "main/input_default.h" -#include "power_x11.h" #include "servers/audio_server.h" #include "servers/visual/rasterizer.h" #include "servers/visual_server.h" @@ -200,8 +199,6 @@ class OS_X11 : public OS_Unix { AudioDriverPulseAudio driver_pulseaudio; #endif - PowerX11 *power_manager; - bool layered_window; CrashHandler crash_handler; @@ -323,10 +320,6 @@ public: virtual void _set_use_vsync(bool p_enable); //virtual bool is_vsync_enabled() const; - virtual OS::PowerState get_power_state(); - virtual int get_power_seconds_left(); - virtual int get_power_percent_left(); - virtual bool _check_internal_feature_support(const String &p_feature); virtual void force_process_input(); diff --git a/platform/x11/power_x11.cpp b/platform/x11/power_x11.cpp deleted file mode 100644 index 5ac5e8e87b..0000000000 --- a/platform/x11/power_x11.cpp +++ /dev/null @@ -1,577 +0,0 @@ -/*************************************************************************/ -/* power_x11.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -/* -Adapted from corresponding SDL 2.0 code. -*/ - -/* - Simple DirectMedia Layer - Copyright (C) 1997-2017 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "power_x11.h" - -#include -#include - -#include "core/error_macros.h" -#include -#include -#include -#include - -// CODE CHUNK IMPORTED FROM SDL 2.0 - -static const char *proc_apm_path = "/proc/apm"; -static const char *proc_acpi_battery_path = "/proc/acpi/battery"; -static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter"; -static const char *sys_class_power_supply_path = "/sys/class/power_supply"; - -FileAccessRef PowerX11::open_power_file(const char *base, const char *node, const char *key) { - String path = String(base) + String("/") + String(node) + String("/") + String(key); - FileAccessRef f = FileAccess::open(path, FileAccess::READ); - return f; -} - -bool PowerX11::read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen) { - ssize_t br = 0; - FileAccessRef fd = open_power_file(base, node, key); - if (!fd) { - return false; - } - br = fd->get_buffer(reinterpret_cast(buf), buflen - 1); - fd->close(); - if (br < 0) { - return false; - } - buf[br] = '\0'; // null-terminate the string - return true; -} - -bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val) { - char *ptr = *_ptr; - - while (*ptr == ' ') { - ptr++; /* skip whitespace. */ - } - - if (*ptr == '\0') { - return false; /* EOF. */ - } - - *_key = ptr; - - while ((*ptr != ':') && (*ptr != '\0')) { - ptr++; - } - - if (*ptr == '\0') { - return false; /* (unexpected) EOF. */ - } - - *(ptr++) = '\0'; /* terminate the key. */ - - while (*ptr == ' ') { - ptr++; /* skip whitespace. */ - } - - if (*ptr == '\0') { - return false; /* (unexpected) EOF. */ - } - - *_val = ptr; - - while ((*ptr != '\n') && (*ptr != '\0')) { - ptr++; - } - - if (*ptr != '\0') { - *(ptr++) = '\0'; /* terminate the value. */ - } - - *_ptr = ptr; /* store for next time. */ - return true; -} - -void PowerX11::check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging) { - const char *base = proc_acpi_battery_path; - char info[1024]; - char state[1024]; - char *ptr = NULL; - char *key = NULL; - char *val = NULL; - bool charge = false; - bool choose = false; - int maximum = -1; - int remaining = -1; - int secs = -1; - int pct = -1; - - if (!read_power_file(base, node, "state", state, sizeof(state))) { - return; - } else { - if (!read_power_file(base, node, "info", info, sizeof(info))) - return; - } - - ptr = &state[0]; - while (make_proc_acpi_key_val(&ptr, &key, &val)) { - if (String(key) == "present") { - if (String(val) == "yes") { - *have_battery = true; - } - } else if (String(key) == "charging state") { - /* !!! FIXME: what exactly _does_ charging/discharging mean? */ - if (String(val) == "charging/discharging") { - charge = true; - } else if (String(val) == "charging") { - charge = true; - } - } else if (String(key) == "remaining capacity") { - String sval = val; - const int cvt = sval.to_int(); - remaining = cvt; - } - } - - ptr = &info[0]; - while (make_proc_acpi_key_val(&ptr, &key, &val)) { - if (String(key) == "design capacity") { - String sval = val; - const int cvt = sval.to_int(); - maximum = cvt; - } - } - - if ((maximum >= 0) && (remaining >= 0)) { - pct = (int)((((float)remaining) / ((float)maximum)) * 100.0f); - if (pct < 0) { - pct = 0; - } else if (pct > 100) { - pct = 100; - } - } - - /* !!! FIXME: calculate (secs). */ - - /* - * We pick the battery that claims to have the most minutes left. - * (failing a report of minutes, we'll take the highest percent.) - */ - // -- GODOT start -- - //if ((secs < 0) && (this->nsecs_left < 0)) { - if (this->nsecs_left < 0) { - // -- GODOT end -- - if ((pct < 0) && (this->percent_left < 0)) { - choose = true; /* at least we know there's a battery. */ - } - if (pct > this->percent_left) { - choose = true; - } - } else if (secs > this->nsecs_left) { - choose = true; - } - - if (choose) { - this->nsecs_left = secs; - this->percent_left = pct; - *charging = charge; - } -} - -void PowerX11::check_proc_acpi_ac_adapter(const char *node, bool *have_ac) { - const char *base = proc_acpi_ac_adapter_path; - char state[256]; - char *ptr = NULL; - char *key = NULL; - char *val = NULL; - - if (!read_power_file(base, node, "state", state, sizeof(state))) { - return; - } - - ptr = &state[0]; - while (make_proc_acpi_key_val(&ptr, &key, &val)) { - String skey = key; - if (skey == "state") { - String sval = val; - if (sval == "on-line") { - *have_ac = true; - } - } - } -} - -bool PowerX11::GetPowerInfo_Linux_proc_acpi() { - String node; - DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - bool have_battery = false; - bool have_ac = false; - bool charging = false; - - this->nsecs_left = -1; - this->percent_left = -1; - this->power_state = OS::POWERSTATE_UNKNOWN; - - dirp->change_dir(proc_acpi_battery_path); - Error err = dirp->list_dir_begin(); - - if (err != OK) { - return false; /* can't use this interface. */ - } else { - node = dirp->get_next(); - while (node != "") { - check_proc_acpi_battery(node.utf8().get_data(), &have_battery, &charging /*, seconds, percent*/); - node = dirp->get_next(); - } - } - dirp->change_dir(proc_acpi_ac_adapter_path); - err = dirp->list_dir_begin(); - if (err != OK) { - return false; /* can't use this interface. */ - } else { - node = dirp->get_next(); - while (node != "") { - check_proc_acpi_ac_adapter(node.utf8().get_data(), &have_ac); - node = dirp->get_next(); - } - } - - if (!have_battery) { - this->power_state = OS::POWERSTATE_NO_BATTERY; - } else if (charging) { - this->power_state = OS::POWERSTATE_CHARGING; - } else if (have_ac) { - this->power_state = OS::POWERSTATE_CHARGED; - } else { - this->power_state = OS::POWERSTATE_ON_BATTERY; - } - - memdelete(dirp); - return true; /* definitive answer. */ -} - -bool PowerX11::next_string(char **_ptr, char **_str) { - char *ptr = *_ptr; - char *str = *_str; - - while (*ptr == ' ') { /* skip any spaces... */ - ptr++; - } - - if (*ptr == '\0') { - return false; - } - - str = ptr; - while ((*ptr != ' ') && (*ptr != '\n') && (*ptr != '\0')) - ptr++; - - if (*ptr != '\0') - *(ptr++) = '\0'; - - *_str = str; - *_ptr = ptr; - return true; -} - -bool PowerX11::int_string(char *str, int *val) { - String sval = str; - *val = sval.to_int(); - return (*str != '\0'); -} - -/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */ -bool PowerX11::GetPowerInfo_Linux_proc_apm() { - bool need_details = false; - int ac_status = 0; - int battery_status = 0; - int battery_flag = 0; - int battery_percent = 0; - int battery_time = 0; - FileAccessRef fd = FileAccess::open(proc_apm_path, FileAccess::READ); - char buf[128]; - char *ptr = &buf[0]; - char *str = NULL; - ssize_t br; - - if (!fd) { - return false; /* can't use this interface. */ - } - - br = fd->get_buffer(reinterpret_cast(buf), sizeof(buf) - 1); - fd->close(); - - if (br < 0) { - return false; - } - - buf[br] = '\0'; /* null-terminate the string. */ - if (!next_string(&ptr, &str)) { /* driver version */ - return false; - } - if (!next_string(&ptr, &str)) { /* BIOS version */ - return false; - } - if (!next_string(&ptr, &str)) { /* APM flags */ - return false; - } - - if (!next_string(&ptr, &str)) { /* AC line status */ - return false; - } else if (!int_string(str, &ac_status)) { - return false; - } - - if (!next_string(&ptr, &str)) { /* battery status */ - return false; - } else if (!int_string(str, &battery_status)) { - return false; - } - if (!next_string(&ptr, &str)) { /* battery flag */ - return false; - } else if (!int_string(str, &battery_flag)) { - return false; - } - if (!next_string(&ptr, &str)) { /* remaining battery life percent */ - return false; - } - String sstr = str; - if (sstr[sstr.length() - 1] == '%') { - sstr[sstr.length() - 1] = '\0'; - } - if (!int_string(str, &battery_percent)) { - return false; - } - - if (!next_string(&ptr, &str)) { /* remaining battery life time */ - return false; - } else if (!int_string(str, &battery_time)) { - return false; - } - - if (!next_string(&ptr, &str)) { /* remaining battery life time units */ - return false; - } else if (String(str) == "min") { - battery_time *= 60; - } - - if (battery_flag == 0xFF) { /* unknown state */ - this->power_state = OS::POWERSTATE_UNKNOWN; - } else if (battery_flag & (1 << 7)) { /* no battery */ - this->power_state = OS::POWERSTATE_NO_BATTERY; - } else if (battery_flag & (1 << 3)) { /* charging */ - this->power_state = OS::POWERSTATE_CHARGING; - need_details = true; - } else if (ac_status == 1) { - this->power_state = OS::POWERSTATE_CHARGED; /* on AC, not charging. */ - need_details = true; - } else { - this->power_state = OS::POWERSTATE_ON_BATTERY; - need_details = true; - } - - this->percent_left = -1; - this->nsecs_left = -1; - if (need_details) { - const int pct = battery_percent; - const int secs = battery_time; - - if (pct >= 0) { /* -1 == unknown */ - this->percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ - } - if (secs >= 0) { /* -1 == unknown */ - this->nsecs_left = secs; - } - } - - return true; -} - -/* !!! FIXME: implement d-bus queries to org.freedesktop.UPower. */ - -bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, int *seconds, int *percent*/) { - const char *base = sys_class_power_supply_path; - String name; - - DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - dirp->change_dir(base); - Error err = dirp->list_dir_begin(); - - if (err != OK) { - return false; - } - - this->power_state = OS::POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */ - this->nsecs_left = -1; - this->percent_left = -1; - - name = dirp->get_next(); - - while (name != "") { - bool choose = false; - char str[64]; - OS::PowerState st; - int secs; - int pct; - - if ((name == ".") || (name == "..")) { - name = dirp->get_next(); - continue; //skip these, of course. - } else { - if (!read_power_file(base, name.utf8().get_data(), "type", str, sizeof(str))) { - name = dirp->get_next(); - continue; // Don't know _what_ we're looking at. Give up on it. - } else { - if (String(str) != "Battery\n") { - name = dirp->get_next(); - continue; // we don't care about UPS and such. - } - } - } - - /* some drivers don't offer this, so if it's not explicitly reported assume it's present. */ - if (read_power_file(base, name.utf8().get_data(), "present", str, sizeof(str)) && (String(str) == "0\n")) { - st = OS::POWERSTATE_NO_BATTERY; - } else if (!read_power_file(base, name.utf8().get_data(), "status", str, sizeof(str))) { - st = OS::POWERSTATE_UNKNOWN; /* uh oh */ - } else if (String(str) == "Charging\n") { - st = OS::POWERSTATE_CHARGING; - } else if (String(str) == "Discharging\n") { - st = OS::POWERSTATE_ON_BATTERY; - } else if ((String(str) == "Full\n") || (String(str) == "Not charging\n")) { - st = OS::POWERSTATE_CHARGED; - } else { - st = OS::POWERSTATE_UNKNOWN; /* uh oh */ - } - - if (!read_power_file(base, name.utf8().get_data(), "capacity", str, sizeof(str))) { - pct = -1; - } else { - pct = String(str).to_int(); - pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ - } - - if (!read_power_file(base, name.utf8().get_data(), "time_to_empty_now", str, sizeof(str))) { - secs = -1; - } else { - secs = String(str).to_int(); - secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */ - } - - /* - * We pick the battery that claims to have the most minutes left. - * (failing a report of minutes, we'll take the highest percent.) - */ - if ((secs < 0) && (this->nsecs_left < 0)) { - if ((pct < 0) && (this->percent_left < 0)) { - choose = true; /* at least we know there's a battery. */ - } else if (pct > this->percent_left) { - choose = true; - } - } else if (secs > this->nsecs_left) { - choose = true; - } - - if (choose) { - this->nsecs_left = secs; - this->percent_left = pct; - this->power_state = st; - } - - name = dirp->get_next(); - } - - memdelete(dirp); - return true; /* don't look any further*/ -} - -bool PowerX11::UpdatePowerInfo() { - if (GetPowerInfo_Linux_sys_class_power_supply()) { // try method 1 - return true; - } - if (GetPowerInfo_Linux_proc_acpi()) { // try further - return true; - } - if (GetPowerInfo_Linux_proc_apm()) { // try even further - return true; - } - return false; -} - -PowerX11::PowerX11() : - nsecs_left(-1), - percent_left(-1), - power_state(OS::POWERSTATE_UNKNOWN) { -} - -PowerX11::~PowerX11() { -} - -OS::PowerState PowerX11::get_power_state() { - if (UpdatePowerInfo()) { - return power_state; - } else { - return OS::POWERSTATE_UNKNOWN; - } -} - -int PowerX11::get_power_seconds_left() { - if (UpdatePowerInfo()) { - return nsecs_left; - } else { - return -1; - } -} - -int PowerX11::get_power_percent_left() { - if (UpdatePowerInfo()) { - return percent_left; - } else { - return -1; - } -} diff --git a/platform/x11/power_x11.h b/platform/x11/power_x11.h deleted file mode 100644 index 76f20c68e8..0000000000 --- a/platform/x11/power_x11.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************/ -/* power_x11.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef POWER_X11_H -#define POWER_X11_H - -#include "core/os/dir_access.h" -#include "core/os/file_access.h" -#include "core/os/os.h" - -class PowerX11 { - -private: - int nsecs_left; - int percent_left; - OS::PowerState power_state; - - FileAccessRef open_power_file(const char *base, const char *node, const char *key); - bool read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen); - bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val); - void check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging); - void check_proc_acpi_ac_adapter(const char *node, bool *have_ac); - bool GetPowerInfo_Linux_proc_acpi(); - bool next_string(char **_ptr, char **_str); - bool int_string(char *str, int *val); - bool GetPowerInfo_Linux_proc_apm(); - bool GetPowerInfo_Linux_sys_class_power_supply(); - bool UpdatePowerInfo(); - -public: - PowerX11(); - virtual ~PowerX11(); - - OS::PowerState get_power_state(); - int get_power_seconds_left(); - int get_power_percent_left(); -}; - -#endif // POWER_X11_H