Merge pull request #36212 from akien-mga/remove-battery-power-api
Remove incomplete battery status/power API
This commit is contained in:
commit
09e5877ff5
41 changed files with 1 additions and 2013 deletions
|
@ -71,16 +71,6 @@ Comment: The Android Open Source Project
|
||||||
Copyright: 2002, Google Inc.
|
Copyright: 2002, Google Inc.
|
||||||
License: Apache-2.0
|
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
|
Files: ./scene/animation/tween_interpolaters.cpp
|
||||||
Comment: Penner Easing
|
Comment: Penner Easing
|
||||||
Copyright: 2001, Robert Penner
|
Copyright: 2001, Robert Penner
|
||||||
|
|
|
@ -587,18 +587,6 @@ bool _OS::is_vsync_via_compositor_enabled() const {
|
||||||
return OS::get_singleton()->is_vsync_via_compositor_enabled();
|
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 {
|
bool _OS::has_feature(const String &p_feature) const {
|
||||||
|
|
||||||
return OS::get_singleton()->has_feature(p_feature);
|
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("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_permission", "name"), &_OS::request_permission);
|
||||||
ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions);
|
ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions);
|
||||||
ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_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_MUSIC);
|
||||||
BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
|
BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
|
||||||
BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
|
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() {
|
_OS::_OS() {
|
||||||
|
|
|
@ -105,14 +105,6 @@ public:
|
||||||
VIDEO_DRIVER_VULKAN,
|
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 {
|
enum Weekday {
|
||||||
DAY_SUNDAY,
|
DAY_SUNDAY,
|
||||||
DAY_MONDAY,
|
DAY_MONDAY,
|
||||||
|
@ -346,10 +338,6 @@ public:
|
||||||
void set_vsync_via_compositor(bool p_enable);
|
void set_vsync_via_compositor(bool p_enable);
|
||||||
bool is_vsync_via_compositor_enabled() const;
|
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 has_feature(const String &p_feature) const;
|
||||||
|
|
||||||
bool request_permission(const String &p_name);
|
bool request_permission(const String &p_name);
|
||||||
|
@ -362,7 +350,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(_OS::VideoDriver);
|
VARIANT_ENUM_CAST(_OS::VideoDriver);
|
||||||
VARIANT_ENUM_CAST(_OS::PowerState);
|
|
||||||
VARIANT_ENUM_CAST(_OS::Weekday);
|
VARIANT_ENUM_CAST(_OS::Weekday);
|
||||||
VARIANT_ENUM_CAST(_OS::Month);
|
VARIANT_ENUM_CAST(_OS::Month);
|
||||||
VARIANT_ENUM_CAST(_OS::SystemDir);
|
VARIANT_ENUM_CAST(_OS::SystemDir);
|
||||||
|
|
|
@ -586,16 +586,6 @@ bool OS::is_vsync_via_compositor_enabled() const {
|
||||||
return _vsync_via_compositor;
|
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) {
|
void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
|
||||||
|
|
||||||
has_server_feature_callback = p_callback;
|
has_server_feature_callback = p_callback;
|
||||||
|
|
14
core/os/os.h
14
core/os/os.h
|
@ -78,14 +78,6 @@ public:
|
||||||
typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection);
|
typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection);
|
||||||
typedef bool (*HasServerFeatureCallback)(const String &p_feature);
|
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 {
|
enum RenderThreadMode {
|
||||||
|
|
||||||
RENDER_THREAD_UNSAFE,
|
RENDER_THREAD_UNSAFE,
|
||||||
|
@ -517,10 +509,6 @@ public:
|
||||||
void set_vsync_via_compositor(bool p_enable);
|
void set_vsync_via_compositor(bool p_enable);
|
||||||
bool is_vsync_via_compositor_enabled() const;
|
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(){};
|
virtual void force_process_input(){};
|
||||||
bool has_feature(const String &p_feature);
|
bool has_feature(const String &p_feature);
|
||||||
|
|
||||||
|
@ -542,6 +530,4 @@ public:
|
||||||
virtual ~OS();
|
virtual ~OS();
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(OS::PowerState);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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 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].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_power_percent_left">
|
|
||||||
<return type="int">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
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.
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="get_power_seconds_left">
|
|
||||||
<return type="int">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
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.
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="get_power_state">
|
|
||||||
<return type="int" enum="OS.PowerState">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
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.
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="get_process_id" qualifiers="const">
|
<method name="get_process_id" qualifiers="const">
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
|
@ -1081,20 +1057,5 @@
|
||||||
<constant name="SYSTEM_DIR_RINGTONES" value="7" enum="SystemDir">
|
<constant name="SYSTEM_DIR_RINGTONES" value="7" enum="SystemDir">
|
||||||
Ringtones directory path.
|
Ringtones directory path.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="POWERSTATE_UNKNOWN" value="0" enum="PowerState">
|
|
||||||
Unknown powerstate.
|
|
||||||
</constant>
|
|
||||||
<constant name="POWERSTATE_ON_BATTERY" value="1" enum="PowerState">
|
|
||||||
Unplugged, running on battery.
|
|
||||||
</constant>
|
|
||||||
<constant name="POWERSTATE_NO_BATTERY" value="2" enum="PowerState">
|
|
||||||
Plugged in, no battery available.
|
|
||||||
</constant>
|
|
||||||
<constant name="POWERSTATE_CHARGING" value="3" enum="PowerState">
|
|
||||||
Plugged in, battery charging.
|
|
||||||
</constant>
|
|
||||||
<constant name="POWERSTATE_CHARGED" value="4" enum="PowerState">
|
|
||||||
Plugged in, battery fully charged.
|
|
||||||
</constant>
|
|
||||||
</constants>
|
</constants>
|
||||||
</class>
|
</class>
|
||||||
|
|
|
@ -18,7 +18,6 @@ android_files = [
|
||||||
'java_class_wrapper.cpp',
|
'java_class_wrapper.cpp',
|
||||||
'java_godot_wrapper.cpp',
|
'java_godot_wrapper.cpp',
|
||||||
'java_godot_io_wrapper.cpp',
|
'java_godot_io_wrapper.cpp',
|
||||||
#'power_android.cpp'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
env_android = env.Clone()
|
env_android = env.Clone()
|
||||||
|
|
|
@ -385,7 +385,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
|
||||||
ea->device_lock->unlock();
|
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 wait = 3000000;
|
||||||
uint64_t time = OS::get_singleton()->get_ticks_usec();
|
uint64_t time = OS::get_singleton()->get_ticks_usec();
|
||||||
while (OS::get_singleton()->get_ticks_usec() - time < wait) {
|
while (OS::get_singleton()->get_ticks_usec() - time < wait) {
|
||||||
|
|
|
@ -152,8 +152,6 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||||
input = memnew(InputDefault);
|
input = memnew(InputDefault);
|
||||||
input->set_fallback_mapping(godot_java->get_input_fallback_mapping());
|
input->set_fallback_mapping(godot_java->get_input_fallback_mapping());
|
||||||
|
|
||||||
//power_manager = memnew(PowerAndroid);
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include "core/os/main_loop.h"
|
#include "core/os/main_loop.h"
|
||||||
#include "drivers/unix/os_unix.h"
|
#include "drivers/unix/os_unix.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
//#include "power_android.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/visual/rasterizer.h"
|
#include "servers/visual/rasterizer.h"
|
||||||
|
|
||||||
|
@ -93,8 +92,6 @@ private:
|
||||||
GodotJavaWrapper *godot_java;
|
GodotJavaWrapper *godot_java;
|
||||||
GodotIOJavaWrapper *godot_io_java;
|
GodotIOJavaWrapper *godot_io_java;
|
||||||
|
|
||||||
//PowerAndroid *power_manager_func;
|
|
||||||
|
|
||||||
int video_driver_index;
|
int video_driver_index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -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 <slouken@libsdl.org>
|
|
||||||
|
|
||||||
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, "<init>", "(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() {
|
|
||||||
}
|
|
|
@ -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 <android/native_window_jni.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -360,18 +360,3 @@ String OS_Haiku::get_cache_path() const {
|
||||||
return get_config_path();
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -113,10 +113,6 @@ public:
|
||||||
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
|
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
|
||||||
virtual String get_executable_path() 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 bool _check_internal_feature_support(const String &p_feature);
|
||||||
|
|
||||||
virtual String get_config_path() const;
|
virtual String get_config_path() const;
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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 <os/os.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -1244,24 +1244,6 @@ String OS_JavaScript::get_resource_dir() const {
|
||||||
return "/";
|
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) {
|
void OS_JavaScript::file_access_close_callback(const String &p_file, int p_flags) {
|
||||||
|
|
||||||
OS_JavaScript *os = get_singleton();
|
OS_JavaScript *os = get_singleton();
|
||||||
|
|
|
@ -160,10 +160,6 @@ public:
|
||||||
virtual String get_resource_dir() const;
|
virtual String get_resource_dir() const;
|
||||||
virtual String get_user_data_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);
|
void set_idb_available(bool p_idb_available);
|
||||||
virtual bool is_userfs_persistent() const;
|
virtual bool is_userfs_persistent() const;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ files = [
|
||||||
'semaphore_osx.cpp',
|
'semaphore_osx.cpp',
|
||||||
'dir_access_osx.mm',
|
'dir_access_osx.mm',
|
||||||
'joypad_osx.cpp',
|
'joypad_osx.cpp',
|
||||||
'power_osx.cpp',
|
|
||||||
'vulkan_context_osx.mm',
|
'vulkan_context_osx.mm',
|
||||||
'context_gl_osx.mm'
|
'context_gl_osx.mm'
|
||||||
]
|
]
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "drivers/unix/os_unix.h"
|
#include "drivers/unix/os_unix.h"
|
||||||
#include "joypad_osx.h"
|
#include "joypad_osx.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#include "power_osx.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/visual/rasterizer.h"
|
#include "servers/visual/rasterizer.h"
|
||||||
#include "servers/visual/visual_server_wrap_mt.h"
|
#include "servers/visual/visual_server_wrap_mt.h"
|
||||||
|
@ -147,8 +146,6 @@ public:
|
||||||
Size2 min_size;
|
Size2 min_size;
|
||||||
Size2 max_size;
|
Size2 max_size;
|
||||||
|
|
||||||
PowerOSX *power_manager;
|
|
||||||
|
|
||||||
CrashHandler crash_handler;
|
CrashHandler crash_handler;
|
||||||
|
|
||||||
float _mouse_scale(float p_scale) {
|
float _mouse_scale(float p_scale) {
|
||||||
|
@ -304,10 +301,6 @@ public:
|
||||||
|
|
||||||
virtual String get_unique_id() const;
|
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 bool _check_internal_feature_support(const String &p_feature);
|
||||||
|
|
||||||
virtual void _set_use_vsync(bool p_enable);
|
virtual void _set_use_vsync(bool p_enable);
|
||||||
|
|
|
@ -1628,8 +1628,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||||
input = memnew(InputDefault);
|
input = memnew(InputDefault);
|
||||||
joypad_osx = memnew(JoypadOSX);
|
joypad_osx = memnew(JoypadOSX);
|
||||||
|
|
||||||
power_manager = memnew(PowerOSX);
|
|
||||||
|
|
||||||
_ensure_user_data_dir();
|
_ensure_user_data_dir();
|
||||||
|
|
||||||
restore_rect = Rect2(get_window_position(), get_window_size());
|
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);
|
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) {
|
Error OS_OSX::move_to_trash(const String &p_path) {
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
|
NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
|
||||||
|
|
|
@ -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 <slouken@libsdl.org>
|
|
||||||
|
|
||||||
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 <CoreFoundation/CoreFoundation.h>
|
|
||||||
#include <IOKit/ps/IOPSKeys.h>
|
|
||||||
#include <IOKit/ps/IOPowerSources.h>
|
|
||||||
|
|
||||||
// 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() {
|
|
||||||
}
|
|
|
@ -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 <CoreFoundation/CoreFoundation.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -10,10 +10,8 @@ common_server = [\
|
||||||
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
common_server.append("#platform/osx/crash_handler_osx.mm")
|
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")
|
common_server.append("#platform/osx/semaphore_osx.cpp")
|
||||||
else:
|
else:
|
||||||
common_server.append("#platform/x11/crash_handler_x11.cpp")
|
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)
|
prog = env.add_program('#bin/godot_server', ['godot_server.cpp'] + common_server)
|
||||||
|
|
|
@ -92,12 +92,6 @@ Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||||
|
|
||||||
input = memnew(InputDefault);
|
input = memnew(InputDefault);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
power_manager = memnew(PowerOSX);
|
|
||||||
#else
|
|
||||||
power_manager = memnew(PowerX11);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_ensure_user_data_dir();
|
_ensure_user_data_dir();
|
||||||
|
|
||||||
resource_loader_dummy.instance();
|
resource_loader_dummy.instance();
|
||||||
|
@ -117,8 +111,6 @@ void OS_Server::finalize() {
|
||||||
|
|
||||||
memdelete(input);
|
memdelete(input);
|
||||||
|
|
||||||
memdelete(power_manager);
|
|
||||||
|
|
||||||
ResourceLoader::remove_resource_format_loader(resource_loader_dummy);
|
ResourceLoader::remove_resource_format_loader(resource_loader_dummy);
|
||||||
resource_loader_dummy.unref();
|
resource_loader_dummy.unref();
|
||||||
|
|
||||||
|
@ -198,18 +190,6 @@ String OS_Server::get_name() const {
|
||||||
void OS_Server::move_window_to_foreground() {
|
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) {
|
bool OS_Server::_check_internal_feature_support(const String &p_feature) {
|
||||||
return p_feature == "pc";
|
return p_feature == "pc";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,9 @@
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "platform/osx/crash_handler_osx.h"
|
#include "platform/osx/crash_handler_osx.h"
|
||||||
#include "platform/osx/power_osx.h"
|
|
||||||
#include "platform/osx/semaphore_osx.h"
|
#include "platform/osx/semaphore_osx.h"
|
||||||
#else
|
#else
|
||||||
#include "platform/x11/crash_handler_x11.h"
|
#include "platform/x11/crash_handler_x11.h"
|
||||||
#include "platform/x11/power_x11.h"
|
|
||||||
#endif
|
#endif
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/visual/rasterizer.h"
|
#include "servers/visual/rasterizer.h"
|
||||||
|
@ -63,12 +61,6 @@ class OS_Server : public OS_Unix {
|
||||||
|
|
||||||
InputDefault *input;
|
InputDefault *input;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
PowerOSX *power_manager;
|
|
||||||
#else
|
|
||||||
PowerX11 *power_manager;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CrashHandler crash_handler;
|
CrashHandler crash_handler;
|
||||||
|
|
||||||
int video_driver_index;
|
int video_driver_index;
|
||||||
|
@ -112,9 +104,6 @@ public:
|
||||||
|
|
||||||
void run();
|
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 bool _check_internal_feature_support(const String &p_feature);
|
||||||
|
|
||||||
virtual String get_config_path() const;
|
virtual String get_config_path() const;
|
||||||
|
|
|
@ -7,7 +7,6 @@ files = [
|
||||||
'#platform/windows/key_mapping_windows.cpp',
|
'#platform/windows/key_mapping_windows.cpp',
|
||||||
'#platform/windows/windows_terminal_logger.cpp',
|
'#platform/windows/windows_terminal_logger.cpp',
|
||||||
'joypad_uwp.cpp',
|
'joypad_uwp.cpp',
|
||||||
'power_uwp.cpp',
|
|
||||||
'context_egl_uwp.cpp',
|
'context_egl_uwp.cpp',
|
||||||
'app.cpp',
|
'app.cpp',
|
||||||
'os_uwp.cpp',
|
'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);
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
power_manager = memnew(PowerUWP);
|
|
||||||
|
|
||||||
managed_object->update_clipboard();
|
managed_object->update_clipboard();
|
||||||
|
|
||||||
Clipboard::ContentChanged += ref new EventHandler<Platform::Object ^>(managed_object, &ManagedType::on_clipboard_changed);
|
Clipboard::ContentChanged += ref new EventHandler<Platform::Object ^>(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";
|
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() {
|
OS_UWP::OS_UWP() {
|
||||||
|
|
||||||
key_event_pos = 0;
|
key_event_pos = 0;
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include "drivers/xaudio2/audio_driver_xaudio2.h"
|
#include "drivers/xaudio2/audio_driver_xaudio2.h"
|
||||||
#include "joypad_uwp.h"
|
#include "joypad_uwp.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#include "power_uwp.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/visual/rasterizer.h"
|
#include "servers/visual/rasterizer.h"
|
||||||
#include "servers/visual_server.h"
|
#include "servers/visual_server.h"
|
||||||
|
@ -102,8 +101,6 @@ private:
|
||||||
|
|
||||||
AudioDriverXAudio2 audio_driver;
|
AudioDriverXAudio2 audio_driver;
|
||||||
|
|
||||||
PowerUWP *power_manager;
|
|
||||||
|
|
||||||
MouseMode mouse_mode;
|
MouseMode mouse_mode;
|
||||||
bool alt_mem;
|
bool alt_mem;
|
||||||
bool gr_mem;
|
bool gr_mem;
|
||||||
|
@ -254,10 +251,6 @@ public:
|
||||||
|
|
||||||
void input_event(const Ref<InputEvent> &p_event);
|
void input_event(const Ref<InputEvent> &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);
|
void queue_key_event(KeyEvent &p_event);
|
||||||
|
|
||||||
OS_UWP();
|
OS_UWP();
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
|
@ -12,7 +12,6 @@ common_win = [
|
||||||
"os_windows.cpp",
|
"os_windows.cpp",
|
||||||
"key_mapping_windows.cpp",
|
"key_mapping_windows.cpp",
|
||||||
"joypad_windows.cpp",
|
"joypad_windows.cpp",
|
||||||
"power_windows.cpp",
|
|
||||||
"windows_terminal_logger.cpp",
|
"windows_terminal_logger.cpp",
|
||||||
"vulkan_context_win.cpp",
|
"vulkan_context_win.cpp",
|
||||||
"context_gl_windows.cpp"
|
"context_gl_windows.cpp"
|
||||||
|
|
|
@ -1492,8 +1492,6 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||||
input = memnew(InputDefault);
|
input = memnew(InputDefault);
|
||||||
joypad = memnew(JoypadWindows(input, &hWnd));
|
joypad = memnew(JoypadWindows(input, &hWnd));
|
||||||
|
|
||||||
power_manager = memnew(PowerWindows);
|
|
||||||
|
|
||||||
AudioDriverManager::initialize(p_audio_driver);
|
AudioDriverManager::initialize(p_audio_driver);
|
||||||
|
|
||||||
TRACKMOUSEEVENT tme;
|
TRACKMOUSEEVENT tme;
|
||||||
|
@ -3334,18 +3332,6 @@ void OS_Windows::_set_use_vsync(bool p_enable) {
|
||||||
#endif
|
#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) {
|
bool OS_Windows::_check_internal_feature_support(const String &p_feature) {
|
||||||
|
|
||||||
return p_feature == "pc";
|
return p_feature == "pc";
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "drivers/winmidi/midi_driver_winmidi.h"
|
#include "drivers/winmidi/midi_driver_winmidi.h"
|
||||||
#include "key_mapping_windows.h"
|
#include "key_mapping_windows.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#include "power_windows.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/visual/rasterizer.h"
|
#include "servers/visual/rasterizer.h"
|
||||||
#include "servers/visual_server.h"
|
#include "servers/visual_server.h"
|
||||||
|
@ -239,8 +238,6 @@ class OS_Windows : public OS {
|
||||||
JoypadWindows *joypad;
|
JoypadWindows *joypad;
|
||||||
Map<int, Vector2> touch_state;
|
Map<int, Vector2> touch_state;
|
||||||
|
|
||||||
PowerWindows *power_manager;
|
|
||||||
|
|
||||||
int video_driver_index;
|
int video_driver_index;
|
||||||
#ifdef WASAPI_ENABLED
|
#ifdef WASAPI_ENABLED
|
||||||
AudioDriverWASAPI driver_wasapi;
|
AudioDriverWASAPI driver_wasapi;
|
||||||
|
@ -433,10 +430,6 @@ public:
|
||||||
virtual void _set_use_vsync(bool p_enable);
|
virtual void _set_use_vsync(bool p_enable);
|
||||||
//virtual bool is_vsync_enabled() const;
|
//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 bool _check_internal_feature_support(const String &p_feature);
|
||||||
|
|
||||||
void disable_crash_handler();
|
void disable_crash_handler();
|
||||||
|
|
|
@ -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 <slouken@libsdl.org>
|
|
||||||
|
|
||||||
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() {
|
|
||||||
}
|
|
|
@ -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 <windows.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -12,7 +12,6 @@ common_x11 = [
|
||||||
"os_x11.cpp",
|
"os_x11.cpp",
|
||||||
"key_mapping_x11.cpp",
|
"key_mapping_x11.cpp",
|
||||||
"joypad_linux.cpp",
|
"joypad_linux.cpp",
|
||||||
"power_x11.cpp",
|
|
||||||
"detect_prime.cpp"
|
"detect_prime.cpp"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -659,8 +659,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
||||||
#endif
|
#endif
|
||||||
_ensure_user_data_dir();
|
_ensure_user_data_dir();
|
||||||
|
|
||||||
power_manager = memnew(PowerX11);
|
|
||||||
|
|
||||||
if (p_desired.layered) {
|
if (p_desired.layered) {
|
||||||
set_window_per_pixel_transparency_enabled(true);
|
set_window_per_pixel_transparency_enabled(true);
|
||||||
}
|
}
|
||||||
|
@ -870,8 +868,6 @@ void OS_X11::finalize() {
|
||||||
visual_server->finish();
|
visual_server->finish();
|
||||||
memdelete(visual_server);
|
memdelete(visual_server);
|
||||||
|
|
||||||
memdelete(power_manager);
|
|
||||||
|
|
||||||
#if defined(OPENGL_ENABLED)
|
#if defined(OPENGL_ENABLED)
|
||||||
if (video_driver_index == VIDEO_DRIVER_GLES2) {
|
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() {
|
void OS_X11::disable_crash_handler() {
|
||||||
crash_handler.disable();
|
crash_handler.disable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include "drivers/unix/os_unix.h"
|
#include "drivers/unix/os_unix.h"
|
||||||
#include "joypad_linux.h"
|
#include "joypad_linux.h"
|
||||||
#include "main/input_default.h"
|
#include "main/input_default.h"
|
||||||
#include "power_x11.h"
|
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
#include "servers/visual/rasterizer.h"
|
#include "servers/visual/rasterizer.h"
|
||||||
#include "servers/visual_server.h"
|
#include "servers/visual_server.h"
|
||||||
|
@ -200,8 +199,6 @@ class OS_X11 : public OS_Unix {
|
||||||
AudioDriverPulseAudio driver_pulseaudio;
|
AudioDriverPulseAudio driver_pulseaudio;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PowerX11 *power_manager;
|
|
||||||
|
|
||||||
bool layered_window;
|
bool layered_window;
|
||||||
|
|
||||||
CrashHandler crash_handler;
|
CrashHandler crash_handler;
|
||||||
|
@ -323,10 +320,6 @@ public:
|
||||||
virtual void _set_use_vsync(bool p_enable);
|
virtual void _set_use_vsync(bool p_enable);
|
||||||
//virtual bool is_vsync_enabled() const;
|
//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 bool _check_internal_feature_support(const String &p_feature);
|
||||||
|
|
||||||
virtual void force_process_input();
|
virtual void force_process_input();
|
||||||
|
|
|
@ -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 <slouken@libsdl.org>
|
|
||||||
|
|
||||||
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 <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "core/error_macros.h"
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
// 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<uint8_t *>(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<uint8_t *>(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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
Loading…
Reference in a new issue