From ce6fefced8b0ac6d3be886db5ee1234dba7ec544 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 21 Sep 2015 09:39:46 -0300 Subject: [PATCH] Properly implement OS.alert() from script, and use xmessage on X11 --- core/bind/core_bind.cpp | 6 ++++++ core/bind/core_bind.h | 3 +++ platform/x11/os_x11.cpp | 10 ++++++++++ platform/x11/os_x11.h | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index b4bf1ed4bd5..94557d149d1 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -732,6 +732,11 @@ int _OS::find_scancode_from_string(const String& p_code) const { return find_keycode(p_code); } +void _OS::alert(const String& p_alert,const String& p_title) { + + OS::get_singleton()->alert(p_alert,p_title); +} + _OS *_OS::singleton=NULL; void _OS::_bind_methods() { @@ -859,6 +864,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap); + ObjectTypeDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!")); BIND_CONSTANT( DAY_SUNDAY ); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index ed3db292595..24ea8107677 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -256,6 +256,9 @@ public: String get_data_dir() const; + void alert(const String& p_alert,const String& p_title="ALERT!"); + + void set_screen_orientation(ScreenOrientation p_orientation); ScreenOrientation get_screen_orientation() const; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 51f4392eb4f..ce8259eea05 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1866,6 +1866,16 @@ void OS_X11::swap_buffers() { context_gl->swap_buffers(); } +void OS_X11::alert(const String& p_alert,const String& p_title) { + + List args; + args.push_back("-center"); + args.push_back("-title"); + args.push_back(p_title); + args.push_back(p_alert); + + execute("/usr/bin/xmessage",args,true); +} void OS_X11::set_icon(const Image& p_icon) { if (!p_icon.empty()) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 12f0aec611a..cc6a90c6ddc 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -243,7 +243,7 @@ public: virtual bool is_window_maximized() const; virtual void move_window_to_foreground(); - + virtual void alert(const String& p_alert,const String& p_title="ALERT!"); void run(); OS_X11();