From 97d290e466bfdf1bb0fa68d828c3a3cb13f138de Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 15:47:34 +0800 Subject: x11-fullscreen support through GDScript( OS.set_fullscreen(bool) ) --- core/bind/core_bind.cpp | 12 ++++++++++++ core/bind/core_bind.h | 4 ++++ core/os/os.h | 4 ++++ platform/x11/os_x11.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ platform/x11/os_x11.h | 3 +++ 5 files changed, 72 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 0c5d21b4f6..0d24486e90 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,14 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +void _OS::set_fullscreen(bool p_fullscreen) { + OS::get_singleton()->set_fullscreen(p_fullscreen); +} + +bool _OS::is_fullscreen() const { + return OS::get_singleton()->is_fullscreen(); +} + void _OS::set_use_file_access_save_and_swap(bool p_enable) { FileAccess::set_backup_save(p_enable); @@ -632,6 +640,10 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); + //MSC + ObjectTypeDB::bind_method(_MD("set_fullscreen","fullscreen"),&_OS::set_fullscreen); + ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); + ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second); ObjectTypeDB::bind_method(_MD("set_target_fps","target_fps"),&_OS::set_target_fps); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 12a4ae86eb..97aff87bca 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,6 +108,10 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; + //MSC + void set_fullscreen(bool p_fullscreen); + bool is_fullscreen() const; + Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); bool native_video_is_playing(); void native_video_pause(); diff --git a/core/os/os.h b/core/os/os.h index d4deff2f5e..e8de28e86a 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -149,6 +149,10 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0; virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; + + //MSC + virtual void set_fullscreen(bool fullscreen)=0; + virtual bool is_fullscreen() const=0; virtual void set_iterations_per_second(int p_ips); virtual int get_iterations_per_second() const; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index aa9e4c63c9..bf0bef15db 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -521,6 +521,55 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } +void OS_X11::set_fullscreen(bool p_fullscreen) { + + long wm_action; + + if(p_fullscreen) { + current_videomode.fullscreen = True; + wm_action = 1; + } else { + current_videomode.fullscreen = False; + wm_action = 0; + } + + /* + // MSC: Disabled until I can test it with lxde + // + // needed for lxde/openbox, possibly others + Hints hints; + Atom property; + hints.flags = 2; + hints.decorations = 0; + property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); + XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); + XMapRaised(x11_display, x11_window); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); + XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); + */ + + // code for netwm-compliants + XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom wm_fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = wm_action; + xev.xclient.data.l[1] = wm_fullscreen; + xev.xclient.data.l[2] = 0; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + + visual_server->init(); +} + +bool OS_X11::is_fullscreen() const { +} InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index dd2476ec1b..e92bd6e081 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -213,6 +213,9 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual void set_fullscreen(bool p_fullscreen); + virtual bool is_fullscreen() const; + virtual void move_window_to_foreground(); void run(); -- cgit v1.2.3 From cd90215ceca03b456aad761da935c92058b0da6a Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 16:01:01 +0800 Subject: Make GDScript-Function ( bool OS.is_fullscreen() ) work --- platform/x11/os_x11.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index bf0bef15db..79051b2ac5 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -569,6 +569,7 @@ void OS_X11::set_fullscreen(bool p_fullscreen) { } bool OS_X11::is_fullscreen() const { + return current_videomode.fullscreen; } InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { -- cgit v1.2.3 From 0d2ec19082e9ebff07ab1ab8e365e2db9ee3268b Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 18:38:30 +0800 Subject: API change to set_fullscreen(enabled,screen) --- core/bind/core_bind.cpp | 6 +++--- core/bind/core_bind.h | 2 +- core/os/os.h | 2 +- platform/x11/os_x11.cpp | 4 ++-- platform/x11/os_x11.h | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 0d24486e90..62d93745a0 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,8 +176,8 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } -void _OS::set_fullscreen(bool p_fullscreen) { - OS::get_singleton()->set_fullscreen(p_fullscreen); +void _OS::set_fullscreen(bool p_enabled,int p_screen) { + OS::get_singleton()->set_fullscreen(p_enabled, p_screen); } bool _OS::is_fullscreen() const { @@ -641,7 +641,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); //MSC - ObjectTypeDB::bind_method(_MD("set_fullscreen","fullscreen"),&_OS::set_fullscreen); + ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 97aff87bca..fedd03c3a9 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -109,7 +109,7 @@ public: Array get_fullscreen_mode_list(int p_screen=0) const; //MSC - void set_fullscreen(bool p_fullscreen); + void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index e8de28e86a..b86b122623 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -151,7 +151,7 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; //MSC - virtual void set_fullscreen(bool fullscreen)=0; + virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; virtual void set_iterations_per_second(int p_ips); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 79051b2ac5..6dd2d7426f 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -521,11 +521,11 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -void OS_X11::set_fullscreen(bool p_fullscreen) { +void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { long wm_action; - if(p_fullscreen) { + if(p_enabled) { current_videomode.fullscreen = True; wm_action = 1; } else { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index e92bd6e081..f382e21edc 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -166,8 +166,8 @@ protected: virtual const char * get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; - virtual int get_audio_driver_count() const; - virtual const char * get_audio_driver_name(int p_driver) const; + virtual int get_audio_driver_count() const; + virtual const char * get_audio_driver_name(int p_driver) const; virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); virtual void finalize(); @@ -213,7 +213,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; - virtual void set_fullscreen(bool p_fullscreen); + virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; virtual void move_window_to_foreground(); -- cgit v1.2.3 From 5d9de48d8d35961835135a7310840cdc9cbacb63 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 21:50:31 +0800 Subject: Make fullscreen-switching is working with LXDE/Openbox --- platform/x11/os_x11.cpp | 90 +++++++++++++++++++++++-------------------------- platform/x11/os_x11.h | 4 +++ 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 6dd2d7426f..707868ccb0 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -182,33 +182,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // borderless fullscreen window mode if (current_videomode.fullscreen) { - // needed for lxde/openbox, possibly others - Hints hints; - Atom property; - hints.flags = 2; - hints.decorations = 0; - property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); - XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); - XMapRaised(x11_display, x11_window); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); - XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); - - // code for netwm-compliants - XEvent xev; - Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); - Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); - - memset(&xev, 0, sizeof(xev)); - xev.type = ClientMessage; - xev.xclient.window = x11_window; - xev.xclient.message_type = wm_state; - xev.xclient.format = 32; - xev.xclient.data.l[0] = 1; - xev.xclient.data.l[1] = fullscreen; - xev.xclient.data.l[2] = 0; - - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + set_wm_border(false); + set_wm_fullscreen(true); } // disable resizeable window @@ -521,34 +496,19 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { - - long wm_action; - - if(p_enabled) { - current_videomode.fullscreen = True; - wm_action = 1; - } else { - current_videomode.fullscreen = False; - wm_action = 0; - } - - /* - // MSC: Disabled until I can test it with lxde - // +void OS_X11::set_wm_border(bool p_enabled) { // needed for lxde/openbox, possibly others Hints hints; Atom property; hints.flags = 2; - hints.decorations = 0; + hints.decorations = p_enabled ? 1L : 0L;; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); - XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); - */ + XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); +} +void OS_X11::set_wm_fullscreen(bool p_enabled) { // code for netwm-compliants XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); @@ -559,11 +519,45 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; - xev.xclient.data.l[0] = wm_action; + xev.xclient.data.l[0] = p_enabled ? 1L : 0L; xev.xclient.data.l[1] = wm_fullscreen; xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); +} + +void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { + + long wm_action; + long wm_decoration; + + if(p_enabled) { + wm_action = 1L; + wm_decoration = 0L; // Removes all decorations + + pre_videomode = current_videomode; + + // Get Desktop resolutuion + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); + + current_videomode.fullscreen = True; + current_videomode.width = xwa.width; + current_videomode.height = xwa.height; + + set_wm_border(false); + set_wm_fullscreen(true); + } else { + wm_action = 0L; + wm_decoration = 1L; // MWM_DECORE_ALL (1L << 0) + + current_videomode.fullscreen = False; + current_videomode.width = pre_videomode.width; + current_videomode.height = pre_videomode.height; + + set_wm_fullscreen(false); + set_wm_border(true); + } visual_server->init(); } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index f382e21edc..11842ace83 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -73,6 +73,7 @@ class OS_X11 : public OS_Unix { Rasterizer *rasterizer; VisualServer *visual_server; VideoMode current_videomode; + VideoMode pre_videomode; List args; Window x11_window; MainLoop *main_loop; @@ -159,6 +160,8 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; + void set_wm_border(bool p_enabled); + void set_wm_fullscreen(bool p_enabled); protected: @@ -178,6 +181,7 @@ protected: void process_joysticks(); void close_joystick(int p_id = -1); + public: virtual String get_name(); -- cgit v1.2.3 From a8e3c5c0b7fb202bcceb06b9373b5b6a4ff8f9b8 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 01:07:23 +0800 Subject: First attempt of restoring the window at the old position --- core/os/os.h | 5 +++-- main/main.cpp | 7 ++++++- platform/x11/os_x11.cpp | 40 +++++++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/core/os/os.h b/core/os/os.h index b86b122623..9de2e3556b 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -69,11 +69,12 @@ public: }; struct VideoMode { - int width,height; + int x,y,width,height; bool fullscreen; bool resizable; float get_aspect() const { return (float)width/(float)height; } - VideoMode(int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) { width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } + VideoMode(int p_x=0, int p_y=0,int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) + { x=p_x; y=p_y; width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } }; protected: friend class Main; diff --git a/main/main.cpp b/main/main.cpp index f0e376a045..b6638a3ad0 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -609,6 +609,10 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (video_driver=="") // specified in engine.cfg video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); + if (!force_res && use_custom_res && globals->has("display/x")) + video_mode.width=globals->get("display/y"); + if (!force_res && use_custom_res && globals->has("display/width")) + video_mode.width=globals->get("display/width"); if (!force_res && use_custom_res && globals->has("display/width")) video_mode.width=globals->get("display/width"); if (!force_res &&use_custom_res && globals->has("display/height")) @@ -627,7 +631,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } - + GLOBAL_DEF("display/x",video_mode.x); + GLOBAL_DEF("display/y",video_mode.y); GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 707868ccb0..9e02f54dd4 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -71,7 +71,7 @@ const char * OS_X11::get_video_driver_name(int p_driver) const { } OS::VideoMode OS_X11::get_default_video_mode() const { - return OS::VideoMode(800,600,false); + return OS::VideoMode(0,0,800,600,false); } int OS_X11::get_audio_driver_count() const { @@ -163,6 +163,18 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + if( current_videomode.x > current_videomode.width || + current_videomode.y > current_videomode.height || + current_videomode.width==0 || + current_videomode.height==0) { + + current_videomode.x = 0; + current_videomode.y = 0; + current_videomode.width = 640; + current_videomode.height = 480; + } + + context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); @@ -505,7 +517,7 @@ void OS_X11::set_wm_border(bool p_enabled) { property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); + XMoveResizeWindow(x11_display, x11_window, current_videomode.x, current_videomode.y, current_videomode.width, current_videomode.height); } void OS_X11::set_wm_fullscreen(bool p_enabled) { @@ -528,17 +540,24 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { - long wm_action; - long wm_decoration; - if(p_enabled) { - wm_action = 1L; - wm_decoration = 0L; // Removes all decorations + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, x11_window, &xwa); + + print_line(itos(xwa.x)); + print_line(itos(xwa.y)); + print_line(itos(xwa.width)); + print_line(itos(xwa.height)); + + current_videomode.x = xwa.x; + current_videomode.y = xwa.y; + current_videomode.width = xwa.width; + current_videomode.height = xwa.height; + pre_videomode = current_videomode; // Get Desktop resolutuion - XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); current_videomode.fullscreen = True; @@ -548,10 +567,9 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { set_wm_border(false); set_wm_fullscreen(true); } else { - wm_action = 0L; - wm_decoration = 1L; // MWM_DECORE_ALL (1L << 0) - current_videomode.fullscreen = False; + current_videomode.x = pre_videomode.x; + current_videomode.y = pre_videomode.y; current_videomode.width = pre_videomode.width; current_videomode.height = pre_videomode.height; -- cgit v1.2.3 From ac558c15eaeb45b3e7ae2604e26ca1dffb60b779 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 15:47:27 +0800 Subject: get_window_position() + set_window_position() added --- core/bind/core_bind.cpp | 10 ++++++ core/bind/core_bind.h | 2 ++ core/os/os.h | 7 ++-- main/main.cpp | 6 ---- platform/x11/os_x11.cpp | 86 ++++++++++++++++++++++++++++++++----------------- platform/x11/os_x11.h | 2 ++ 6 files changed, 74 insertions(+), 39 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 62d93745a0..3109b8bc84 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,14 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +Point2 _OS::get_window_position() const { + return OS::get_singleton()->get_window_position(); +} + +void _OS::set_window_position(const Point2& p_position) { + OS::get_singleton()->set_window_position(p_position); +} + void _OS::set_fullscreen(bool p_enabled,int p_screen) { OS::get_singleton()->set_fullscreen(p_enabled, p_screen); } @@ -641,6 +649,8 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); //MSC + ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); + ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index fedd03c3a9..92056aa0d6 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -109,6 +109,8 @@ public: Array get_fullscreen_mode_list(int p_screen=0) const; //MSC + virtual Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; diff --git a/core/os/os.h b/core/os/os.h index 9de2e3556b..9089e7de76 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -69,12 +69,11 @@ public: }; struct VideoMode { - int x,y,width,height; + int width,height; bool fullscreen; bool resizable; float get_aspect() const { return (float)width/(float)height; } - VideoMode(int p_x=0, int p_y=0,int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) - { x=p_x; y=p_y; width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } + VideoMode(int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) {width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } }; protected: friend class Main; @@ -152,6 +151,8 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; //MSC + virtual Point2 get_window_position() const=0; + virtual void set_window_position(const Point2& p_position)=0; virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; diff --git a/main/main.cpp b/main/main.cpp index b6638a3ad0..27d7d97e85 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -609,10 +609,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (video_driver=="") // specified in engine.cfg video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); - if (!force_res && use_custom_res && globals->has("display/x")) - video_mode.width=globals->get("display/y"); - if (!force_res && use_custom_res && globals->has("display/width")) - video_mode.width=globals->get("display/width"); if (!force_res && use_custom_res && globals->has("display/width")) video_mode.width=globals->get("display/width"); if (!force_res &&use_custom_res && globals->has("display/height")) @@ -631,8 +627,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } - GLOBAL_DEF("display/x",video_mode.x); - GLOBAL_DEF("display/y",video_mode.y); GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 5a05455918..502d510f5b 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -70,7 +70,7 @@ const char * OS_X11::get_video_driver_name(int p_driver) const { } OS::VideoMode OS_X11::get_default_video_mode() const { - return OS::VideoMode(0,0,800,600,false); + return OS::VideoMode(800,600,false); } int OS_X11::get_audio_driver_count() const { @@ -162,17 +162,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) - if( current_videomode.x > current_videomode.width || - current_videomode.y > current_videomode.height || - current_videomode.width==0 || - current_videomode.height==0) { - - current_videomode.x = 0; - current_videomode.y = 0; - current_videomode.width = 640; - current_videomode.height = 480; - } - context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); @@ -516,7 +505,7 @@ void OS_X11::set_wm_border(bool p_enabled) { property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XMoveResizeWindow(x11_display, x11_window, current_videomode.x, current_videomode.y, current_videomode.width, current_videomode.height); + XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); } void OS_X11::set_wm_fullscreen(bool p_enabled) { @@ -537,26 +526,65 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } -void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { +Point2 OS_X11::get_window_position() const { + int x,y; + XWindowAttributes xwa; + Window child; + XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); + XGetWindowAttributes(x11_display, x11_window, &xwa); - if(p_enabled) { - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, x11_window, &xwa); + return Point2i(x,y); +} - print_line(itos(xwa.x)); - print_line(itos(xwa.y)); - print_line(itos(xwa.width)); - print_line(itos(xwa.height)); - - current_videomode.x = xwa.x; - current_videomode.y = xwa.y; - current_videomode.width = xwa.width; - current_videomode.height = xwa.height; - +void OS_X11::set_window_position(const Point2& p_position) { + // _NET_FRAME_EXTENTS + Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = NULL; + //long *extends; + int result; + + result = XGetWindowProperty( + x11_display, + x11_window, + property, + 0, + 32, + False, + AnyPropertyType, + &type, + &format, + &len, + &remaining, + &data + ); + + long left = 0L; + long top = 0L; + + if( result == Success ) { + long *extends = (long *) data; + + left = extends[0]; + top = extends[2]; + + XFree(data); + data = NULL; + } + + XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); +} + +void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { + + if(p_enabled) { pre_videomode = current_videomode; - // Get Desktop resolutuion + XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); current_videomode.fullscreen = True; @@ -567,8 +595,6 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { set_wm_fullscreen(true); } else { current_videomode.fullscreen = False; - current_videomode.x = pre_videomode.x; - current_videomode.y = pre_videomode.y; current_videomode.width = pre_videomode.width; current_videomode.height = pre_videomode.height; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 11842ace83..ad7364f999 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -217,6 +217,8 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; -- cgit v1.2.3 From 466e251abecf3686f0caac40ab886155e43cc0a6 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 17:36:56 +0800 Subject: get_window_size() + set_window_size() added --- core/bind/core_bind.cpp | 11 ++++++++++- core/bind/core_bind.h | 3 ++- core/os/os.h | 3 ++- platform/x11/os_x11.cpp | 18 +++++++++++++++++- platform/x11/os_x11.h | 2 ++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3109b8bc84..2b4e2e1239 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -184,6 +184,14 @@ void _OS::set_window_position(const Point2& p_position) { OS::get_singleton()->set_window_position(p_position); } +Size2 _OS::get_window_size() const { + return OS::get_singleton()->get_window_size(); +} + +void _OS::set_window_size(const Size2& p_size) { + OS::get_singleton()->set_window_size(p_size); +} + void _OS::set_fullscreen(bool p_enabled,int p_screen) { OS::get_singleton()->set_fullscreen(p_enabled, p_screen); } @@ -648,9 +656,10 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); - //MSC ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); + ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); + ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 92056aa0d6..e60bb5e66a 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,9 +108,10 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; - //MSC virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; diff --git a/core/os/os.h b/core/os/os.h index 9089e7de76..7e9fdcc579 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,9 +150,10 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; - //MSC virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; + virtual Size2 get_window_size() const=0; + virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 502d510f5b..f21ea4c9a2 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -537,8 +537,11 @@ Point2 OS_X11::get_window_position() const { } void OS_X11::set_window_position(const Point2& p_position) { - // _NET_FRAME_EXTENTS + if( current_videomode.fullscreen ) + return; + + // _NET_FRAME_EXTENTS Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; int format; @@ -579,6 +582,19 @@ void OS_X11::set_window_position(const Point2& p_position) { XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); } +Size2 OS_X11::get_window_size() const { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, x11_window, &xwa); + return Size2i(xwa.width, xwa.height); +} + +void OS_X11::set_window_size(const Size2 p_size) { + if( current_videomode.fullscreen ) + return; + + XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); +} + void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { if(p_enabled) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index ad7364f999..1cedea4223 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -219,6 +219,8 @@ public: virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; -- cgit v1.2.3 From 3c8b047b111cf20b3823851e298ce42bdf941871 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 18:52:42 +0800 Subject: get_screen_count() added --- core/bind/core_bind.cpp | 5 +++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + platform/x11/os_x11.cpp | 7 +++++++ platform/x11/os_x11.h | 1 + 5 files changed, 15 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 2b4e2e1239..3f86efc879 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,10 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +int _OS::get_screen_count() const { + return OS::get_singleton()->get_screen_count(); +} + Point2 _OS::get_window_position() const { return OS::get_singleton()->get_window_position(); } @@ -656,6 +660,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index e60bb5e66a..cb9a5da479 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,6 +108,7 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; + virtual int get_screen_count() const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; diff --git a/core/os/os.h b/core/os/os.h index 7e9fdcc579..68769e7ad4 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,6 +150,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; + virtual int get_screen_count() const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; virtual Size2 get_window_size() const=0; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index f21ea4c9a2..c37358139c 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -526,6 +526,10 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } +int OS_X11::get_screen_count() const { + return XScreenCount(x11_display); +} + Point2 OS_X11::get_window_position() const { int x,y; XWindowAttributes xwa; @@ -597,6 +601,9 @@ void OS_X11::set_window_size(const Size2 p_size) { void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { + if(p_enabled && current_videomode.fullscreen) + return; + if(p_enabled) { pre_videomode = current_videomode; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 1cedea4223..f55b7dc0e3 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -217,6 +217,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual int get_screen_count() const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; -- cgit v1.2.3 From f9d0de0d2a82456f3553499fcbc1c487b59fed1c Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 19:35:53 +0800 Subject: get_screen_size() added --- core/bind/core_bind.cpp | 5 +++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + platform/x11/os_x11.cpp | 8 ++++++++ platform/x11/os_x11.h | 1 + 5 files changed, 16 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3f86efc879..47bfba1cbb 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -180,6 +180,10 @@ int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } +Size2 _OS::get_screen_size(int p_screen) const { + return OS::get_singleton()->get_screen_size(p_screen); +} + Point2 _OS::get_window_position() const { return OS::get_singleton()->get_window_position(); } @@ -661,6 +665,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); + ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index cb9a5da479..2a87f85ec7 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -109,6 +109,7 @@ public: Array get_fullscreen_mode_list(int p_screen=0) const; virtual int get_screen_count() const; + virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; diff --git a/core/os/os.h b/core/os/os.h index 68769e7ad4..edb5d57c5f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -151,6 +151,7 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; virtual int get_screen_count() const=0; + virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; virtual Size2 get_window_size() const=0; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index c37358139c..063fb17c26 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -530,6 +530,14 @@ int OS_X11::get_screen_count() const { return XScreenCount(x11_display); } +Size2 OS_X11::get_screen_size(int p_screen) const { + Window root = XRootWindow(x11_display, p_screen); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, root, &xwa); + return Size2i(xwa.width, xwa.height); +} + + Point2 OS_X11::get_window_position() const { int x,y; XWindowAttributes xwa; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index f55b7dc0e3..a38d511003 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -218,6 +218,7 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; virtual int get_screen_count() const; + virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; -- cgit v1.2.3 From 107d2a373a4a66bc237cc47128f815c2624c35bb Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 20:30:57 +0800 Subject: Demo misc/window_management added --- demos/misc/window_management/control.gd | 39 +++++++++++++++++++++ demos/misc/window_management/engine.cfg | 5 +++ demos/misc/window_management/icon.png | Bin 0 -> 3639 bytes demos/misc/window_management/icon.png.flags | 1 + demos/misc/window_management/window_management.scn | Bin 0 -> 3276 bytes 5 files changed, 45 insertions(+) create mode 100644 demos/misc/window_management/control.gd create mode 100644 demos/misc/window_management/engine.cfg create mode 100644 demos/misc/window_management/icon.png create mode 100644 demos/misc/window_management/icon.png.flags create mode 100644 demos/misc/window_management/window_management.scn diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd new file mode 100644 index 0000000000..3e74f24e42 --- /dev/null +++ b/demos/misc/window_management/control.gd @@ -0,0 +1,39 @@ + +extends Control + +func _fixed_process(delta): + if(OS.is_fullscreen()): + get_node("Label_Fullscreen").set_text("Mode:\nFullscreen") + else: + get_node("Label_Fullscreen").set_text("Mode:\nWindowed") + + get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) + + get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) + + get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + + get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) + + if(OS.get_screen_count() > 1): + get_node("Label_Screen1_Resolution").show() + get_node("Label_Screen1_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size(1) ) ) + + +func _ready(): + set_fixed_process(true) + + +func _on_Fullscreen_toggled( pressed ): + if(pressed): + OS.set_fullscreen(true) + else: + OS.set_fullscreen(false) + + +func _on_Button_MoveTo_pressed(): + OS.set_window_position( Vector2(100,100) ) + + +func _on_Button_Resize_pressed(): + OS.set_window_size( Vector2(1024,768) ) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg new file mode 100644 index 0000000000..7b6dddce96 --- /dev/null +++ b/demos/misc/window_management/engine.cfg @@ -0,0 +1,5 @@ +[application] + +name="window_management" +main_scene="res://window_management.scn" +icon="icon.png" diff --git a/demos/misc/window_management/icon.png b/demos/misc/window_management/icon.png new file mode 100644 index 0000000000..0c422e37b0 Binary files /dev/null and b/demos/misc/window_management/icon.png differ diff --git a/demos/misc/window_management/icon.png.flags b/demos/misc/window_management/icon.png.flags new file mode 100644 index 0000000000..5130fd1aab --- /dev/null +++ b/demos/misc/window_management/icon.png.flags @@ -0,0 +1 @@ +gen_mipmaps=false diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn new file mode 100644 index 0000000000..6eaf62ff9f Binary files /dev/null and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 16cf16da7e09909e3ebc668851205db823800866 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 22:02:18 +0800 Subject: Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 3456290f74..57068bf39c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ +### x11-window-management branch + +#### New GDScript Methods for the OS Class: +* int OS.get_screen_count() +* Vector2 OS.get_screen_size(int screen=0) +* Vector2 OS.get_window_position() +* void OS.set_window_position(Vector2 position) +* Vector2 OS.get_window_size() +* void OS.set_window_size(Vector2 size) +* void OS.set_fullscreen(bool enabled, int screen=0) +* bool OS.is_fullscreen() + +#### Demo +A demo/test is available at "demos/misc/window-management" + +#### Warning +Just only works for X11. It breaks other platforms at the moment. + ![GODOT](/logo.png) ### The Engine -- cgit v1.2.3 From c0d363266755de3ac87f61600f23921d881d99e2 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Tue, 13 Jan 2015 15:44:39 +0800 Subject: introduced the scons experimental_wm_api switch: ================================================ Usage: scons p=x11 experimental_wm_api=yes --- core/bind/core_bind.cpp | 4 ++++ core/bind/core_bind.h | 2 ++ core/os/os.h | 4 +++- platform/x11/detect.py | 4 ++++ platform/x11/os_x11.cpp | 32 ++++++++++++++++++++++++++++++++ platform/x11/os_x11.h | 7 +++++-- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 47bfba1cbb..b8fc63dc43 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,7 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +#ifdef EXPERIMENTAL_WM_API int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } @@ -207,6 +208,7 @@ void _OS::set_fullscreen(bool p_enabled,int p_screen) { bool _OS::is_fullscreen() const { return OS::get_singleton()->is_fullscreen(); } +#endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -664,6 +666,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); +#ifdef EXPERIMENTAL_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); @@ -672,6 +675,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); +#endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 2a87f85ec7..62f9913556 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,6 +108,7 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; +#ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; @@ -116,6 +117,7 @@ public: virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; +#endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); bool native_video_is_playing(); diff --git a/core/os/os.h b/core/os/os.h index edb5d57c5f..c2534287bc 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,6 +150,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; +#ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const=0; virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; @@ -158,7 +159,8 @@ public: virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; - +#endif + virtual void set_iterations_per_second(int p_ips); virtual int get_iterations_per_second() const; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 621a0c66a0..954e5270e8 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -47,6 +47,7 @@ def get_opts(): return [ ('use_llvm','Use llvm compiler','no'), ('use_sanitizer','Use llvm compiler sanitize address','no'), + ('experimental_wm_api', 'Use experimental window management API','no'), ] def get_flags(): @@ -148,3 +149,6 @@ def configure(env): env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) + if(env["experimental_wm_api"]=="yes"): + env.Append(CPPFLAGS=['-DEXPERIMENTAL_WM_API']) + diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 063fb17c26..e20d0731e1 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -182,8 +182,38 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // borderless fullscreen window mode if (current_videomode.fullscreen) { +#ifndef EXPERIMENTAL_WM_API + // needed for lxde/openbox, possibly others + Hints hints; + Atom property; + hints.flags = 2; + hints.decorations = 0; + property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); + XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); + XMapRaised(x11_display, x11_window); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); + XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); + + // code for netwm-compliants + XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = 1; + xev.xclient.data.l[1] = fullscreen; + xev.xclient.data.l[2] = 0; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); +#else set_wm_border(false); set_wm_fullscreen(true); +#endif } // disable resizeable window @@ -496,6 +526,7 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } +#ifdef EXPERIMENTAL_WM_API void OS_X11::set_wm_border(bool p_enabled) { // needed for lxde/openbox, possibly others Hints hints; @@ -639,6 +670,7 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { bool OS_X11::is_fullscreen() const { return current_videomode.fullscreen; } +#endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index a38d511003..4aca996fdc 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -73,7 +73,6 @@ class OS_X11 : public OS_Unix { Rasterizer *rasterizer; VisualServer *visual_server; VideoMode current_videomode; - VideoMode pre_videomode; List args; Window x11_window; MainLoop *main_loop; @@ -160,8 +159,11 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; +#ifdef EXPERIMENTAL_WM_API + VideoMode pre_videomode; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); +#endif protected: @@ -217,6 +219,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; +#ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; @@ -225,7 +228,7 @@ public: virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; - +#endif virtual void move_window_to_foreground(); void run(); -- cgit v1.2.3 From ce7c7a862ebe37fada7708c342c07d70fa80465a Mon Sep 17 00:00:00 2001 From: hurikhan Date: Tue, 13 Jan 2015 17:25:50 +0800 Subject: get_screen_position() added --- core/bind/core_bind.cpp | 5 +++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + demos/misc/window_management/control.gd | 11 ++++++++--- demos/misc/window_management/window_management.scn | Bin 3276 -> 3582 bytes platform/x11/os_x11.cpp | 12 ++++++++++++ platform/x11/os_x11.h | 1 + 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index b8fc63dc43..a2aca7e11f 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -181,6 +181,10 @@ int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } +Point2 _OS::get_screen_position(int p_screen) const { + return OS::get_singleton()->get_screen_position(p_screen); +} + Size2 _OS::get_screen_size(int p_screen) const { return OS::get_singleton()->get_screen_size(p_screen); } @@ -668,6 +672,7 @@ void _OS::_bind_methods() { #ifdef EXPERIMENTAL_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); + ObjectTypeDB::bind_method(_MD("get_screen_position"),&_OS::get_screen_position,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 62f9913556..9d9f25691e 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -110,6 +110,7 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); diff --git a/core/os/os.h b/core/os/os.h index c2534287bc..1ef05e45c8 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -152,6 +152,7 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const=0; + virtual Point2 get_screen_position(int p_screen=0) const=0; virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 3e74f24e42..ad15a74731 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -15,11 +15,16 @@ func _fixed_process(delta): get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) + get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + if(OS.get_screen_count() > 1): get_node("Label_Screen1_Resolution").show() - get_node("Label_Screen1_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size(1) ) ) - - + get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) + get_node("Label_Screen1_Position").show() + get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_size(1) ) ) + else: + get_node("Label_Screen1_Resolution").hide() + get_node("Label_Screen1_Position").hide() func _ready(): set_fixed_process(true) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 6eaf62ff9f..3a6426f3ee 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index e20d0731e1..01d62f333d 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -561,7 +561,19 @@ int OS_X11::get_screen_count() const { return XScreenCount(x11_display); } +Point2 OS_X11::get_screen_position(int p_screen) const { + if( p_screen >= XScreenCount(x11_display) ) + return Point2i(0,0); + + Window root = XRootWindow(x11_display, p_screen); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, root, &xwa); + return Point2i(xwa.x, xwa.y); +} + Size2 OS_X11::get_screen_size(int p_screen) const { + if( p_screen >= XScreenCount(x11_display) ) + return Size2i(0,0); Window root = XRootWindow(x11_display, p_screen); XWindowAttributes xwa; XGetWindowAttributes(x11_display, root, &xwa); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 4aca996fdc..ca35bf2c0a 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -221,6 +221,7 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); -- cgit v1.2.3 From f55c0e928580de63af55ac22f045bb4380a1df2e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Tue, 13 Jan 2015 21:01:24 +0800 Subject: Using Xinerama extension for getting screen info --- demos/misc/window_management/control.gd | 2 +- platform/x11/detect.py | 6 +++++ platform/x11/os_x11.cpp | 42 ++++++++++++++++++++++----------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index ad15a74731..34df5dd92c 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -21,7 +21,7 @@ func _fixed_process(delta): get_node("Label_Screen1_Resolution").show() get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").show() - get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_size(1) ) ) + get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) else: get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 954e5270e8..1eb615893b 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -38,6 +38,11 @@ def can_build(): if (x11_error): print("xcursor not found.. x11 disabled.") return False + + x11_error=os.system("pkg-config xinerama --modversion > /dev/null ") + if (x11_error): + print("xinerama not found.. x11 disabled.") + return False return True # X11 enabled @@ -151,4 +156,5 @@ def configure(env): if(env["experimental_wm_api"]=="yes"): env.Append(CPPFLAGS=['-DEXPERIMENTAL_WM_API']) + env.ParseConfig('pkg-config xinerama --cflags --libs') diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 01d62f333d..533e57d5c7 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -36,6 +36,9 @@ #include "servers/physics/physics_server_sw.h" #include "X11/Xutil.h" +#ifdef EXPERIMENTAL_WM_API +#include "X11/extensions/Xinerama.h" +#endif #include "main/main.h" @@ -558,26 +561,37 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { } int OS_X11::get_screen_count() const { - return XScreenCount(x11_display); + int event_base, error_base; + const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); + if( !ext_okay ) return 0; + int count; + XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); + XFree(xsi); + return count; } Point2 OS_X11::get_screen_position(int p_screen) const { - if( p_screen >= XScreenCount(x11_display) ) - return Point2i(0,0); - - Window root = XRootWindow(x11_display, p_screen); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, root, &xwa); - return Point2i(xwa.x, xwa.y); + int event_base, error_base; + const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); + if( !ext_okay ) return Point2i(0,0); + int count; + XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); + if( p_screen >= count ) return Point2i(0,0); + Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org); + XFree(xsi); + return position; } Size2 OS_X11::get_screen_size(int p_screen) const { - if( p_screen >= XScreenCount(x11_display) ) - return Size2i(0,0); - Window root = XRootWindow(x11_display, p_screen); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, root, &xwa); - return Size2i(xwa.width, xwa.height); + int event_base, error_base; + const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); + if( !ext_okay ) return Size2i(0,0); + int count; + XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); + if( p_screen >= count ) return Size2i(0,0); + Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height); + XFree(xsi); + return size; } -- cgit v1.2.3 From 790d8ecbb9a0a0ac67520b84fc621c34f910d817 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 12:02:59 +0800 Subject: get_screen() + set_screen() added --- core/bind/core_bind.cpp | 16 ++++- core/bind/core_bind.h | 4 +- core/os/os.h | 4 +- demos/misc/window_management/control.gd | 27 +++++++- demos/misc/window_management/engine.cfg | 4 ++ demos/misc/window_management/window_management.scn | Bin 3582 -> 3787 bytes platform/x11/os_x11.cpp | 71 ++++++++++++++++----- platform/x11/os_x11.h | 7 +- 8 files changed, 109 insertions(+), 24 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index a2aca7e11f..48cd43ccdc 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -181,6 +181,14 @@ int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } +int _OS::get_screen() const { + return OS::get_singleton()->get_screen(); +} + +void _OS::set_screen(int p_screen) { + OS::get_singleton()->set_screen(p_screen); +} + Point2 _OS::get_screen_position(int p_screen) const { return OS::get_singleton()->get_screen_position(p_screen); } @@ -205,8 +213,8 @@ void _OS::set_window_size(const Size2& p_size) { OS::get_singleton()->set_window_size(p_size); } -void _OS::set_fullscreen(bool p_enabled,int p_screen) { - OS::get_singleton()->set_fullscreen(p_enabled, p_screen); +void _OS::set_fullscreen(bool p_enabled) { + OS::get_singleton()->set_fullscreen(p_enabled); } bool _OS::is_fullscreen() const { @@ -672,13 +680,15 @@ void _OS::_bind_methods() { #ifdef EXPERIMENTAL_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); + ObjectTypeDB::bind_method(_MD("get_screen"),&_OS::get_screen); + ObjectTypeDB::bind_method(_MD("set_screen"),&_OS::set_screen); ObjectTypeDB::bind_method(_MD("get_screen_position"),&_OS::get_screen_position,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); - ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); #endif diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 9d9f25691e..99ecb765c7 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -110,13 +110,15 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual int get_screen() const; + virtual void set_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2& p_size); - void set_fullscreen(bool p_enabled, int p_screen=0); + void set_fullscreen(bool p_enabled); bool is_fullscreen() const; #endif diff --git a/core/os/os.h b/core/os/os.h index 1ef05e45c8..2d4e937974 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -152,13 +152,15 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const=0; + virtual int get_screen() const=0; + virtual void set_screen(int p_screen)=0; virtual Point2 get_screen_position(int p_screen=0) const=0; virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; virtual Size2 get_window_size() const=0; virtual void set_window_size(const Size2 p_size)=0; - virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; + virtual void set_fullscreen(bool p_enabled)=0; virtual bool is_fullscreen() const=0; #endif diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 34df5dd92c..ce17db6b00 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -13,18 +13,35 @@ func _fixed_process(delta): get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) + get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) if(OS.get_screen_count() > 1): + get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() - get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").show() + get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) else: + get_node("Button_Screen1").hide() get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() + + if( Input.is_action_pressed("ui_right")): + OS.set_screen(1) + + if( Input.is_action_pressed("ui_left")): + OS.set_screen(0) + + if( Input.is_action_pressed("ui_up")): + OS.set_fullscreen(true) + + if( Input.is_action_pressed("ui_down")): + OS.set_fullscreen(false) + func _ready(): set_fixed_process(true) @@ -42,3 +59,11 @@ func _on_Button_MoveTo_pressed(): func _on_Button_Resize_pressed(): OS.set_window_size( Vector2(1024,768) ) + + +func _on_Button_Screen0_pressed(): + OS.set_screen(0) + + +func _on_Button_Screen1_pressed(): + OS.set_screen(1) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 7b6dddce96..44ad30ea14 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -3,3 +3,7 @@ name="window_management" main_scene="res://window_management.scn" icon="icon.png" + +[display] + +fullscreen=true diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 3a6426f3ee..9d55174dce 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 533e57d5c7..0ed8c80162 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -214,6 +214,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); #else + old_window_position.x = 0; + old_window_position.y = 0; + old_window_size.width = 800; + old_window_size.height = 600; set_wm_border(false); set_wm_fullscreen(true); #endif @@ -539,7 +543,7 @@ void OS_X11::set_wm_border(bool p_enabled) { property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); + //XMoveResizeWindow(x11_display, x11_window, 0, 0, 800, 800); } void OS_X11::set_wm_fullscreen(bool p_enabled) { @@ -564,19 +568,55 @@ int OS_X11::get_screen_count() const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return 0; + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); XFree(xsi); return count; } +int OS_X11::get_screen() const { + int x,y; + Window child; + XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); + + int count = get_screen_count(); + for(int i=0; i= pos.x && x = pos.y && y < pos.y + size.height) ) + return i; + } + return 0; +} + +void OS_X11::set_screen(int p_screen) { + int count = get_screen_count(); + if(p_screen >= count) return; + + if( current_videomode.fullscreen ) { + Point2i position = get_screen_position(p_screen); + Size2i size = get_screen_size(p_screen); + + XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); + } + else { + if( p_screen != get_screen() ) { + Point2i position = get_screen_position(p_screen); + XMoveWindow(x11_display, x11_window, position.x, position.y); + } + } +} + Point2 OS_X11::get_screen_position(int p_screen) const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Point2i(0,0); + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); if( p_screen >= count ) return Point2i(0,0); + Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org); XFree(xsi); return position; @@ -586,9 +626,11 @@ Size2 OS_X11::get_screen_size(int p_screen) const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Size2i(0,0); + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); if( p_screen >= count ) return Size2i(0,0); + Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height); XFree(xsi); return size; @@ -597,11 +639,8 @@ Size2 OS_X11::get_screen_size(int p_screen) const { Point2 OS_X11::get_window_position() const { int x,y; - XWindowAttributes xwa; Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); - XGetWindowAttributes(x11_display, x11_window, &xwa); - return Point2i(x,y); } @@ -664,30 +703,30 @@ void OS_X11::set_window_size(const Size2 p_size) { XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); } -void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { +void OS_X11::set_fullscreen(bool p_enabled) { if(p_enabled && current_videomode.fullscreen) return; if(p_enabled) { - pre_videomode = current_videomode; + old_window_size = get_window_size(); + old_window_position = get_window_position(); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); - - current_videomode.fullscreen = True; - current_videomode.width = xwa.width; - current_videomode.height = xwa.height; + int screen = get_screen(); + Size2i size = get_screen_size(screen); + Point2i position = get_screen_position(screen); set_wm_border(false); set_wm_fullscreen(true); - } else { - current_videomode.fullscreen = False; - current_videomode.width = pre_videomode.width; - current_videomode.height = pre_videomode.height; + XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); + current_videomode.fullscreen = True; + } else { set_wm_fullscreen(false); set_wm_border(true); + XMoveResizeWindow(x11_display, x11_window, old_window_position.x, old_window_position.y, old_window_size.width, old_window_size.height); + + current_videomode.fullscreen = False; } visual_server->init(); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index ca35bf2c0a..bb0fd38387 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,7 +160,8 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API - VideoMode pre_videomode; + Point2i old_window_position; + Size2i old_window_size; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif @@ -221,13 +222,15 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual int get_screen() const; + virtual void set_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2 p_size); - virtual void set_fullscreen(bool p_enabled,int p_screen=0); + virtual void set_fullscreen(bool p_enabled); virtual bool is_fullscreen() const; #endif virtual void move_window_to_foreground(); -- cgit v1.2.3 From 7222e195e549cc9a08c06fb30fb4d3d9051c818e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 13:19:27 +0800 Subject: minor cleanup --- platform/x11/os_x11.cpp | 24 ++++++++++++++---------- platform/x11/os_x11.h | 6 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 0ed8c80162..d395e99210 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -214,10 +214,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); #else - old_window_position.x = 0; - old_window_position.y = 0; - old_window_size.width = 800; - old_window_size.height = 600; + window_data.position.x = 0; + window_data.position.y = 0; + window_data.size.width = 800; + window_data.size.height = 600; set_wm_border(false); set_wm_fullscreen(true); #endif @@ -709,8 +709,8 @@ void OS_X11::set_fullscreen(bool p_enabled) { return; if(p_enabled) { - old_window_size = get_window_size(); - old_window_position = get_window_position(); + window_data.size = get_window_size(); + window_data.position = get_window_position(); int screen = get_screen(); Size2i size = get_screen_size(screen); @@ -724,7 +724,11 @@ void OS_X11::set_fullscreen(bool p_enabled) { } else { set_wm_fullscreen(false); set_wm_border(true); - XMoveResizeWindow(x11_display, x11_window, old_window_position.x, old_window_position.y, old_window_size.width, old_window_size.height); + XMoveResizeWindow(x11_display, x11_window, + window_data.position.x, + window_data.position.y, + window_data.size.width, + window_data.size.height); current_videomode.fullscreen = False; } @@ -1072,7 +1076,7 @@ void OS_X11::process_xevents() { if (mouse_mode==MOUSE_MODE_CAPTURED) { #if 1 - Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2); + //Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2); if (pos==Point2i(current_videomode.width/2,current_videomode.height/2)) { //this sucks, it's a hack, etc and is a little inaccurate, etc. //but nothing I can do, X11 sucks. @@ -1081,9 +1085,9 @@ void OS_X11::process_xevents() { break; } - Point2i ncenter = pos; + Point2i new_center = pos; pos = last_mouse_pos + ( pos-center ); - center=ncenter; + center=new_center; do_mouse_warp=true; #else //Dear X11, thanks for making my life miserable diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index bb0fd38387..72d212c131 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,8 +160,10 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API - Point2i old_window_position; - Size2i old_window_size; + struct { + Point2i position; + Size2i size; + } window_data; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif -- cgit v1.2.3 From 2203ba5fe3f7cdca078dd557ec532b7f335d3670 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 13:27:03 +0800 Subject: don't start demo in fullscreen mode --- demos/misc/window_management/engine.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 44ad30ea14..bdc8ec3ed7 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -6,4 +6,5 @@ icon="icon.png" [display] -fullscreen=true +fullscreen=false +resizable=false -- cgit v1.2.3 From 1576dc5215c107e6966ceace2f3979ff12f2dd62 Mon Sep 17 00:00:00 2001 From: MSC Date: Wed, 14 Jan 2015 13:49:10 +0800 Subject: Update README.md --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57068bf39c..35841c8b29 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,22 @@ #### New GDScript Methods for the OS Class: * int OS.get_screen_count() +* int OS.get_screen() +* void OS.set_screen(int screen) +* Vector2 OS.get_screen_position(int screen=0) * Vector2 OS.get_screen_size(int screen=0) * Vector2 OS.get_window_position() * void OS.set_window_position(Vector2 position) * Vector2 OS.get_window_size() * void OS.set_window_size(Vector2 size) -* void OS.set_fullscreen(bool enabled, int screen=0) +* void OS.set_fullscreen(bool enabled) * bool OS.is_fullscreen() #### Demo A demo/test is available at "demos/misc/window-management" -#### Warning -Just only works for X11. It breaks other platforms at the moment. +#### Scons Commandline +'''scons p=x11 experimental_wm_api=yes''' ![GODOT](/logo.png) -- cgit v1.2.3 From 07b8d9136a6ccea1587d27ca30db1ec10aca0ed1 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 15:44:47 +0800 Subject: demo window set to resizeable (need a bugfix her) --- demos/misc/window_management/engine.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index bdc8ec3ed7..2accafe43e 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -7,4 +7,4 @@ icon="icon.png" [display] fullscreen=false -resizable=false +resizable=true -- cgit v1.2.3 From d269344bbd19d9653fff3c2a230261b8fa00d7f6 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 15 Jan 2015 22:50:23 +0900 Subject: WIP -- set_resizable() + is_resizable added --- core/bind/core_bind.cpp | 11 +++- core/bind/core_bind.h | 2 + core/os/os.h | 2 + demos/misc/window_management/control.gd | 28 +++++++++- demos/misc/window_management/window_management.scn | Bin 3787 -> 3897 bytes platform/x11/os_x11.cpp | 57 ++++++++++++++++----- platform/x11/os_x11.h | 9 +++- 7 files changed, 91 insertions(+), 18 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 48cd43ccdc..1fb6f96e71 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -220,6 +220,14 @@ void _OS::set_fullscreen(bool p_enabled) { bool _OS::is_fullscreen() const { return OS::get_singleton()->is_fullscreen(); } + +void _OS::set_resizable(bool p_enabled) { + OS::get_singleton()->set_resizable(p_enabled); +} + +bool _OS::is_resizable() const { + return OS::get_singleton()->is_resizable(); +} #endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -232,7 +240,6 @@ bool _OS::is_video_mode_resizable(int p_screen) const { OS::VideoMode vm; vm = OS::get_singleton()->get_video_mode(p_screen); return vm.resizable; - } Array _OS::get_fullscreen_mode_list(int p_screen) const { @@ -690,6 +697,8 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); + ObjectTypeDB::bind_method(_MD("set_resizable","enabled"),&_OS::set_resizable); + ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); #endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 99ecb765c7..7ffd7e9e7c 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -120,6 +120,8 @@ public: virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled); bool is_fullscreen() const; + void set_resizable(bool p_enabled); + bool is_resizable() const; #endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index 2d4e937974..f1a9de1edf 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -162,6 +162,8 @@ public: virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled)=0; virtual bool is_fullscreen() const=0; + virtual void set_resizable(bool p_enabled)=0; + virtual bool is_resizable() const=0; #endif virtual void set_iterations_per_second(int p_ips); diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index ce17db6b00..c867bd21db 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -2,10 +2,18 @@ extends Control func _fixed_process(delta): + + var modetext = "Mode:\n" + if(OS.is_fullscreen()): - get_node("Label_Fullscreen").set_text("Mode:\nFullscreen") + modetext += "Fullscreen\n" else: - get_node("Label_Fullscreen").set_text("Mode:\nWindowed") + modetext += "Windowed\n" + + if(!OS.is_resizable()): + modetext += "FixedSize\n" + + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) @@ -19,6 +27,7 @@ func _fixed_process(delta): get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + if(OS.get_screen_count() > 1): get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() @@ -42,6 +51,9 @@ func _fixed_process(delta): if( Input.is_action_pressed("ui_down")): OS.set_fullscreen(false) + get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) + + func _ready(): set_fixed_process(true) @@ -67,3 +79,15 @@ func _on_Button_Screen0_pressed(): func _on_Button_Screen1_pressed(): OS.set_screen(1) + + + + + +func _on_Button_FixedSize_pressed(): + if(OS.is_resizable()): + OS.set_resizable(false) + else: + OS.set_resizable(true) + + diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 9d55174dce..befc177b5e 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d395e99210..f33c2556ba 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -223,7 +223,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi #endif } - // disable resizeable window + // disable resizable window if (!current_videomode.resizable) { XSizeHints *xsh; xsh = XAllocSizeHints(); @@ -239,7 +239,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi xsh->min_height = xwa.height; xsh->max_height = xwa.height; XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); } + current_videomode.resizable; AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -277,19 +279,19 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); - XClassHint* classHint; + XClassHint* classHint; - /* set the titlebar name */ - XStoreName(x11_display, x11_window, "Godot"); + /* set the titlebar name */ + XStoreName(x11_display, x11_window, "Godot"); - /* set the name and class hints for the window manager to use */ - classHint = XAllocClassHint(); - if (classHint) { - classHint->res_name = "Godot"; - classHint->res_class = "Godot"; - } - XSetClassHint(x11_display, x11_window, classHint); - XFree(classHint); + /* set the name and class hints for the window manager to use */ + classHint = XAllocClassHint(); + if (classHint) { + classHint->res_name = "Godot"; + classHint->res_class = "Godot"; + } + XSetClassHint(x11_display, x11_window, classHint); + XFree(classHint); wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); @@ -708,6 +710,9 @@ void OS_X11::set_fullscreen(bool p_enabled) { if(p_enabled && current_videomode.fullscreen) return; + if(!current_videomode.resizable) + set_resizable(true); + if(p_enabled) { window_data.size = get_window_size(); window_data.position = get_window_position(); @@ -734,11 +739,37 @@ void OS_X11::set_fullscreen(bool p_enabled) { } visual_server->init(); + } bool OS_X11::is_fullscreen() const { return current_videomode.fullscreen; } + +void OS_X11::set_resizable(bool p_enabled) { + + if(!current_videomode.fullscreen) { + XSizeHints *xsh; + xsh = XAllocSizeHints(); + xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; + if(!p_enabled) { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + xsh->min_width = xwa.width; + xsh->max_width = xwa.width; + xsh->min_height = xwa.height; + xsh->max_height = xwa.height; + printf("%d %d\n", xwa.width, xwa.height); + } + XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); + current_videomode.resizable = p_enabled; + } +} + +bool OS_X11::is_resizable() const { + return current_videomode.resizable; +} #endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { @@ -1688,6 +1719,4 @@ OS_X11::OS_X11() { minimized = false; xim_style=NULL; mouse_mode=MOUSE_MODE_VISIBLE; - - }; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 72d212c131..d286efe7b8 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,10 +160,15 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API + // This struct saves the values of the window before going fullscreen + // to be able to restore the same state after leaving fullscreen struct { + bool resizable; Point2i position; Size2i size; - } window_data; + } window_data; + + bool maximized; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif @@ -234,6 +239,8 @@ public: virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled); virtual bool is_fullscreen() const; + virtual void set_resizable(bool p_enabled); + virtual bool is_resizable() const; #endif virtual void move_window_to_foreground(); -- cgit v1.2.3 From d42fa511a51db582849470316dfd1f0eee459350 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Fri, 16 Jan 2015 13:49:46 +0900 Subject: rearrange the demo --- demos/misc/window_management/control.gd | 4 +--- demos/misc/window_management/window_management.scn | Bin 3897 -> 3931 bytes 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index c867bd21db..043db8d489 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -19,9 +19,7 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) - get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) - - get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) + get_node("Label_Screen_Info").set_text( str("Screens:\n", OS.get_screen_count(),"\n\nCurrent:\n", OS.get_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index befc177b5e..a83897f9a0 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From f1b9953d0b321a5564109e11b5326efa4624c70c Mon Sep 17 00:00:00 2001 From: hurikhan Date: Fri, 16 Jan 2015 14:44:41 +0900 Subject: fixing the warnings in os_x11.cpp --- platform/x11/os_x11.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index f33c2556ba..c6fdc24768 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -59,7 +59,7 @@ #include -#include "os/pc_joystick_map.h" +//#include "os/pc_joystick_map.h" #undef CursorShape @@ -120,10 +120,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi if (xim == NULL) { WARN_PRINT("XOpenIM failed"); - xim_style=NULL; + xim_style=0L; } else { ::XIMStyles *xim_styles=NULL; - xim_style=0; + xim_style=0L; char *imvalret=NULL; imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL); if (imvalret != NULL || xim_styles == NULL) { @@ -131,7 +131,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } if (xim_styles) { - xim_style = 0; + xim_style = 0L; for (int i=0;icount_styles;i++) { if (xim_styles->supported_styles[i] == @@ -241,7 +241,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); } - current_videomode.resizable; AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -287,8 +286,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { - classHint->res_name = "Godot"; - classHint->res_class = "Godot"; + char wmclass[] = "Godot"; + classHint->res_name = wmclass; + classHint->res_class = wmclass; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); @@ -845,11 +845,9 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { KeySym keysym_keycode=0; // keysym used to find a keycode KeySym keysym_unicode=0; // keysym used to find unicode - int nbytes=0; // bytes the string takes - // XLookupString returns keysyms usable as nice scancodes/ char str[256+1]; - nbytes=XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL); + XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL); // Meanwhile, XLookupString returns keysyms useful for unicode. @@ -946,7 +944,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { ::Time tresh=ABS(peek_event.xkey.time-xkeyevent->time); if (peek_event.type == KeyPress && tresh<5 ) { KeySym rk; - nbytes=XLookupString((XKeyEvent*)&peek_event, str, 256, &rk, NULL); + XLookupString((XKeyEvent*)&peek_event, str, 256, &rk, NULL); if (rk==keysym_keycode) { XEvent event; XNextEvent(x11_display, &event); //erase next event @@ -1605,6 +1603,7 @@ void OS_X11::process_joysticks() { #endif }; + void OS_X11::set_cursor_shape(CursorShape p_shape) { ERR_FAIL_INDEX(p_shape,CURSOR_MAX); @@ -1717,6 +1716,7 @@ OS_X11::OS_X11() { #endif minimized = false; - xim_style=NULL; + xim_style=0L; mouse_mode=MOUSE_MODE_VISIBLE; }; + -- cgit v1.2.3 From 716971655eb9ab7909447e2f5d4911b6f45164bb Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 17 Jan 2015 00:18:45 +0900 Subject: added the following methods: * set_minimized(bool) * bool is_minimized() * set_maximized(bool) * bool is_maximized() --- core/bind/core_bind.cpp | 22 +++- core/bind/core_bind.h | 12 +- core/os/os.h | 4 + demos/misc/window_management/control.gd | 33 +++-- demos/misc/window_management/window_management.scn | Bin 3931 -> 4111 bytes platform/x11/os_x11.cpp | 137 ++++++++++++++++++++- platform/x11/os_x11.h | 4 + 7 files changed, 194 insertions(+), 18 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 1fb6f96e71..6919c70a5f 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -228,6 +228,22 @@ void _OS::set_resizable(bool p_enabled) { bool _OS::is_resizable() const { return OS::get_singleton()->is_resizable(); } + +void _OS::set_minimized(bool p_enabled) { + OS::get_singleton()->set_minimized(p_enabled); +} + +bool _OS::is_minimized() const { + return OS::get_singleton()->is_minimized(); +} + +void _OS::set_maximized(bool p_enabled) { + OS::get_singleton()->set_maximized(p_enabled); +} + +bool _OS::is_maximized() const { + return OS::get_singleton()->is_maximized(); +} #endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -698,7 +714,11 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); ObjectTypeDB::bind_method(_MD("set_resizable","enabled"),&_OS::set_resizable); - ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); + ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); + ObjectTypeDB::bind_method(_MD("set_minimized", "enabled"),&_OS::set_minimized); + ObjectTypeDB::bind_method(_MD("is_minimized"),&_OS::is_minimized); + ObjectTypeDB::bind_method(_MD("set_maximized", "enabled"),&_OS::set_maximized); + ObjectTypeDB::bind_method(_MD("is_maximized"),&_OS::is_maximized); #endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 7ffd7e9e7c..b6f4f8eef4 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -118,10 +118,14 @@ public: virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2& p_size); - void set_fullscreen(bool p_enabled); - bool is_fullscreen() const; - void set_resizable(bool p_enabled); - bool is_resizable() const; + virtual void set_fullscreen(bool p_enabled); + virtual bool is_fullscreen() const; + virtual void set_resizable(bool p_enabled); + virtual bool is_resizable() const; + virtual void set_minimized(bool p_enabled); + virtual bool is_minimized() const; + virtual void set_maximized(bool p_enabled); + virtual bool is_maximized() const; #endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index f1a9de1edf..c04a91e302 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -164,6 +164,10 @@ public: virtual bool is_fullscreen() const=0; virtual void set_resizable(bool p_enabled)=0; virtual bool is_resizable() const=0; + virtual void set_minimized(bool p_enabled)=0; + virtual bool is_minimized() const=0; + virtual void set_maximized(bool p_enabled)=0; + virtual bool is_maximized() const=0; #endif virtual void set_iterations_per_second(int p_ips); diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 043db8d489..fd746cf036 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -13,17 +13,25 @@ func _fixed_process(delta): if(!OS.is_resizable()): modetext += "FixedSize\n" + if(OS.is_minimized()): + modetext += "Minimized\n" + + if(OS.is_maximized()): + modetext += "Maximized\n" + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) - get_node("Label_Screen_Info").set_text( str("Screens:\n", OS.get_screen_count(),"\n\nCurrent:\n", OS.get_screen() ) ) + get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + + get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) - get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) ) if(OS.get_screen_count() > 1): @@ -50,8 +58,9 @@ func _fixed_process(delta): OS.set_fullscreen(false) get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) - - + get_node("Button_Minimized").set_pressed( OS.is_minimized() ) + get_node("Button_Maximized").set_pressed( OS.is_maximized() ) + func _ready(): set_fixed_process(true) @@ -79,9 +88,6 @@ func _on_Button_Screen1_pressed(): OS.set_screen(1) - - - func _on_Button_FixedSize_pressed(): if(OS.is_resizable()): OS.set_resizable(false) @@ -89,3 +95,16 @@ func _on_Button_FixedSize_pressed(): OS.set_resizable(true) + +func _on_Button_Minimized_pressed(): + if(OS.is_minimized()): + OS.set_minimized(false) + else: + OS.set_minimized(true) + + +func _on_Button_Maximized_pressed(): + if(OS.is_maximized()): + OS.set_maximized(false) + else: + OS.set_maximized(true) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index a83897f9a0..635f6f6f28 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index c6fdc24768..ef92d190c9 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -37,7 +37,16 @@ #include "X11/Xutil.h" #ifdef EXPERIMENTAL_WM_API +#include "X11/Xatom.h" #include "X11/extensions/Xinerama.h" +// ICCCM +#define WM_NormalState 1L // window normal state +#define WM_IconicState 3L // window minimized + +// EWMH +#define _NET_WM_STATE_REMOVE 0L // remove/unset property +#define _NET_WM_STATE_ADD 1L // add/set property +#define _NET_WM_STATE_TOGGLE 2L // toggle property #endif #include "main/main.h" @@ -214,6 +223,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); #else + minimized = false; + minimized = false; window_data.position.x = 0; window_data.position.y = 0; window_data.size.width = 800; @@ -549,7 +560,7 @@ void OS_X11::set_wm_border(bool p_enabled) { } void OS_X11::set_wm_fullscreen(bool p_enabled) { - // code for netwm-compliants + // Using EWMH -- Extened Window Manager Hints XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom wm_fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); @@ -559,7 +570,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; - xev.xclient.data.l[0] = p_enabled ? 1L : 0L; + xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; xev.xclient.data.l[1] = wm_fullscreen; xev.xclient.data.l[2] = 0; @@ -567,6 +578,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { } int OS_X11::get_screen_count() const { + // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return 0; @@ -611,6 +623,7 @@ void OS_X11::set_screen(int p_screen) { } Point2 OS_X11::get_screen_position(int p_screen) const { + // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Point2i(0,0); @@ -625,6 +638,7 @@ Point2 OS_X11::get_screen_position(int p_screen) const { } Size2 OS_X11::get_screen_size(int p_screen) const { + // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Size2i(0,0); @@ -651,14 +665,14 @@ void OS_X11::set_window_position(const Point2& p_position) { if( current_videomode.fullscreen ) return; - // _NET_FRAME_EXTENTS + // Using EWMH -- Extended Window Manager Hints + // to get the size of the decoration Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; int format; unsigned long len; unsigned long remaining; unsigned char *data = NULL; - //long *extends; int result; result = XGetWindowProperty( @@ -759,7 +773,6 @@ void OS_X11::set_resizable(bool p_enabled) { xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; - printf("%d %d\n", xwa.width, xwa.height); } XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); @@ -770,6 +783,119 @@ void OS_X11::set_resizable(bool p_enabled) { bool OS_X11::is_resizable() const { return current_videomode.resizable; } + +void OS_X11::set_minimized(bool p_enabled) { + // Using ICCCM -- Inter-Client Communication Conventions Manual + XEvent xev; + Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_change; + xev.xclient.format = 32; + xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); +} + +bool OS_X11::is_minimized() const { + // Using ICCCM -- Inter-Client Communication Conventions Manual + Atom property = XInternAtom(x11_display,"WM_STATE", True); + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = NULL; + + int result = XGetWindowProperty( + x11_display, + x11_window, + property, + 0, + 32, + False, + AnyPropertyType, + &type, + &format, + &len, + &remaining, + &data + ); + + if( result == Success ) { + long *state = (long *) data; + if( state[0] == 3L ) + return true; + } + return false; +} + +void OS_X11::set_maximized(bool p_enabled) { + // Using EWMH -- Extended Window Manager Hints + XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; + xev.xclient.data.l[1] = wm_max_horz; + xev.xclient.data.l[2] = wm_max_vert; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + + maximized = p_enabled; +} + +bool OS_X11::is_maximized() const { + // Using EWMH -- Extended Window Manager Hints + Atom property = XInternAtom(x11_display,"_NET_WM_STATE",False ); + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = NULL; + + int result = XGetWindowProperty( + x11_display, + x11_window, + property, + 0, + 1024, + False, + XA_ATOM, + &type, + &format, + &len, + &remaining, + &data + ); + + if(result == Success) { + Atom *atoms = (Atom*) data; + Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); + bool found_wm_max_horz = false; + bool found_wm_max_vert = false; + + for( unsigned int i=0; i < len; i++ ) { + if( atoms[i] == wm_max_horz ) + found_wm_max_horz = true; + if( atoms[i] == wm_max_vert ) + found_wm_max_vert = true; + + if( found_wm_max_horz && found_wm_max_vert ) + return true; + } + } + + return false; +} #endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { @@ -1719,4 +1845,3 @@ OS_X11::OS_X11() { xim_style=0L; mouse_mode=MOUSE_MODE_VISIBLE; }; - diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index d286efe7b8..557052ab69 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -241,6 +241,10 @@ public: virtual bool is_fullscreen() const; virtual void set_resizable(bool p_enabled); virtual bool is_resizable() const; + virtual void set_minimized(bool p_enabled); + virtual bool is_minimized() const; + virtual void set_maximized(bool p_enabled); + virtual bool is_maximized() const; #endif virtual void move_window_to_foreground(); -- cgit v1.2.3 From 6185949f6a4f6eae78d8afca2dd787dbf063d675 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 17 Jan 2015 02:36:07 +0900 Subject: Make it set_minimized() + set_maximized() work in both worlds: Unity and LXDE --- platform/x11/os_x11.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index ef92d190c9..fd2470a37a 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -552,7 +552,7 @@ void OS_X11::set_wm_border(bool p_enabled) { Hints hints; Atom property; hints.flags = 2; - hints.decorations = p_enabled ? 1L : 0L;; + hints.decorations = p_enabled ? 1L : 0L; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); @@ -700,7 +700,6 @@ void OS_X11::set_window_position(const Point2& p_position) { top = extends[2]; XFree(data); - data = NULL; } XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); @@ -785,6 +784,10 @@ bool OS_X11::is_resizable() const { } void OS_X11::set_minimized(bool p_enabled) { + + if( is_fullscreen() ) + set_fullscreen(false); + // Using ICCCM -- Inter-Client Communication Conventions Manual XEvent xev; Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); @@ -797,6 +800,20 @@ void OS_X11::set_minimized(bool p_enabled) { xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + + //XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom wm_hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = _NET_WM_STATE_ADD; + xev.xclient.data.l[1] = wm_hidden; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } bool OS_X11::is_minimized() const { @@ -825,7 +842,7 @@ bool OS_X11::is_minimized() const { if( result == Success ) { long *state = (long *) data; - if( state[0] == 3L ) + if( state[0] == WM_IconicState ) return true; } return false; @@ -847,7 +864,7 @@ void OS_X11::set_maximized(bool p_enabled) { xev.xclient.data.l[1] = wm_max_horz; xev.xclient.data.l[2] = wm_max_vert; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); maximized = p_enabled; } @@ -892,6 +909,7 @@ bool OS_X11::is_maximized() const { if( found_wm_max_horz && found_wm_max_vert ) return true; } + XFree(atoms); } return false; -- cgit v1.2.3 From f1dc00e380439078c93d00af2f85d138a9400b2e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 17 Jan 2015 19:43:12 +0900 Subject: * cleanup window state handling * first attemps in handling ALT+TABa (WIP) --- demos/misc/window_management/control.gd | 28 ++++++---- demos/misc/window_management/window_management.scn | Bin 4111 -> 4052 bytes platform/x11/os_x11.cpp | 62 ++++++++++----------- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index fd746cf036..4929b1376c 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -25,9 +25,9 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) - get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) - get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) + get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) @@ -35,12 +35,14 @@ func _fixed_process(delta): if(OS.get_screen_count() > 1): + get_node("Button_Screen0").show() get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() get_node("Label_Screen1_Position").show() get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) else: + get_node("Button_Screen0").hide() get_node("Button_Screen1").hide() get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() @@ -57,19 +59,14 @@ func _fixed_process(delta): if( Input.is_action_pressed("ui_down")): OS.set_fullscreen(false) + get_node("Button_Fullscreen").set_pressed( OS.is_fullscreen() ) get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) get_node("Button_Minimized").set_pressed( OS.is_minimized() ) get_node("Button_Maximized").set_pressed( OS.is_maximized() ) - -func _ready(): - set_fixed_process(true) -func _on_Fullscreen_toggled( pressed ): - if(pressed): - OS.set_fullscreen(true) - else: - OS.set_fullscreen(false) +func _ready(): + set_fixed_process(true) func _on_Button_MoveTo_pressed(): @@ -88,12 +85,18 @@ func _on_Button_Screen1_pressed(): OS.set_screen(1) +func _on_Button_Fullscreen_pressed(): + if(OS.is_fullscreen()): + OS.set_fullscreen(false) + else: + OS.set_fullscreen(true) + + func _on_Button_FixedSize_pressed(): if(OS.is_resizable()): OS.set_resizable(false) else: OS.set_resizable(true) - func _on_Button_Minimized_pressed(): @@ -108,3 +111,6 @@ func _on_Button_Maximized_pressed(): OS.set_maximized(false) else: OS.set_maximized(true) + + + diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 635f6f6f28..3d62d4ecc1 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index fd2470a37a..d4328d9da3 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -229,7 +229,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi window_data.position.y = 0; window_data.size.width = 800; window_data.size.height = 600; - set_wm_border(false); + //set_wm_border(false); set_wm_fullscreen(true); #endif } @@ -574,7 +574,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { xev.xclient.data.l[1] = wm_fullscreen; xev.xclient.data.l[2] = 0; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } int OS_X11::get_screen_count() const { @@ -661,10 +661,6 @@ Point2 OS_X11::get_window_position() const { } void OS_X11::set_window_position(const Point2& p_position) { - - if( current_videomode.fullscreen ) - return; - // Using EWMH -- Extended Window Manager Hints // to get the size of the decoration Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); @@ -712,14 +708,12 @@ Size2 OS_X11::get_window_size() const { } void OS_X11::set_window_size(const Size2 p_size) { - if( current_videomode.fullscreen ) - return; - XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); } void OS_X11::set_fullscreen(bool p_enabled) { +#if 0 if(p_enabled && current_videomode.fullscreen) return; @@ -750,6 +744,9 @@ void OS_X11::set_fullscreen(bool p_enabled) { current_videomode.fullscreen = False; } +#endif + set_wm_fullscreen(p_enabled); + current_videomode.fullscreen = p_enabled; visual_server->init(); @@ -760,23 +757,20 @@ bool OS_X11::is_fullscreen() const { } void OS_X11::set_resizable(bool p_enabled) { - - if(!current_videomode.fullscreen) { - XSizeHints *xsh; - xsh = XAllocSizeHints(); - xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; - if(!p_enabled) { - XWindowAttributes xwa; - XGetWindowAttributes(x11_display,x11_window,&xwa); - xsh->min_width = xwa.width; - xsh->max_width = xwa.width; - xsh->min_height = xwa.height; - xsh->max_height = xwa.height; - } - XSetWMNormalHints(x11_display, x11_window, xsh); - XFree(xsh); - current_videomode.resizable = p_enabled; + XSizeHints *xsh; + xsh = XAllocSizeHints(); + xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; + if(!p_enabled) { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + xsh->min_width = xwa.width; + xsh->max_width = xwa.width; + xsh->min_height = xwa.height; + xsh->max_height = xwa.height; } + XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); + current_videomode.resizable = p_enabled; } bool OS_X11::is_resizable() const { @@ -784,10 +778,6 @@ bool OS_X11::is_resizable() const { } void OS_X11::set_minimized(bool p_enabled) { - - if( is_fullscreen() ) - set_fullscreen(false); - // Using ICCCM -- Inter-Client Communication Conventions Manual XEvent xev; Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); @@ -799,7 +789,7 @@ void OS_X11::set_minimized(bool p_enabled) { xev.xclient.format = 32; xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); //XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); @@ -1152,13 +1142,16 @@ void OS_X11::process_xevents() { break; case VisibilityNotify: { - XVisibilityEvent * visibility = (XVisibilityEvent *)&event; minimized = (visibility->state == VisibilityFullyObscured); - } break; case FocusIn: + if(current_videomode.fullscreen) { + set_minimized(false); + set_wm_fullscreen(true); + visual_server->init(); + } main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); if (mouse_mode==MOUSE_MODE_CAPTURED) { XGrabPointer(x11_display, x11_window, True, @@ -1169,6 +1162,11 @@ void OS_X11::process_xevents() { break; case FocusOut: + if(current_videomode.fullscreen) { + set_wm_fullscreen(false); + set_minimized(true); + visual_server->init(); + } main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); if (mouse_mode==MOUSE_MODE_CAPTURED) { //dear X11, I try, I really try, but you never work, you do whathever you want. -- cgit v1.2.3 From dfb5a1d5e1318d91f26c0f7663afe861005104c8 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 18 Jan 2015 00:28:04 +0900 Subject: * multi_screen testing + bugfixes * ALT-TAB is working * tested on Ubuntu 14.10 Unity + LXDE * minor cleanup --- demos/misc/window_management/engine.cfg | 2 + demos/misc/window_management/window_management.scn | Bin 4052 -> 4030 bytes platform/x11/os_x11.cpp | 48 ++++++++++++++------- platform/x11/os_x11.h | 10 +---- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 2accafe43e..6ce3d51aee 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -8,3 +8,5 @@ icon="icon.png" fullscreen=false resizable=true +width=800 +height=600 diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 3d62d4ecc1..baf03bdfd1 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d4328d9da3..d711cea42e 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -42,7 +42,6 @@ // ICCCM #define WM_NormalState 1L // window normal state #define WM_IconicState 3L // window minimized - // EWMH #define _NET_WM_STATE_REMOVE 0L // remove/unset property #define _NET_WM_STATE_ADD 1L // add/set property @@ -192,9 +191,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } +#ifndef EXPERIMENTAL_WM_API // borderless fullscreen window mode if (current_videomode.fullscreen) { -#ifndef EXPERIMENTAL_WM_API // needed for lxde/openbox, possibly others Hints hints; Atom property; @@ -222,16 +221,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); -#else - minimized = false; - minimized = false; - window_data.position.x = 0; - window_data.position.y = 0; - window_data.size.width = 800; - window_data.size.height = 600; - //set_wm_border(false); - set_wm_fullscreen(true); -#endif } // disable resizable window @@ -252,6 +241,21 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); } +#else + if (current_videomode.fullscreen) { + minimized = false; + maximized = false; + //set_wm_border(false); + set_wm_fullscreen(true); + } + if (!current_videomode.resizable) { + int screen = get_screen(); + Size2i screen_size = get_screen_size(screen); + set_window_size(screen_size); + set_resizable(false); + } +#endif + AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -519,7 +523,6 @@ OS::MouseMode OS_X11::get_mouse_mode() const { int OS_X11::get_mouse_button_state() const { - return last_button_state; } @@ -547,6 +550,8 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } #ifdef EXPERIMENTAL_WM_API +#if 0 +// Just now not needed. Can be used for a possible OS.set_border(bool) method void OS_X11::set_wm_border(bool p_enabled) { // needed for lxde/openbox, possibly others Hints hints; @@ -558,6 +563,7 @@ void OS_X11::set_wm_border(bool p_enabled) { XMapRaised(x11_display, x11_window); //XMoveResizeWindow(x11_display, x11_window, 0, 0, 800, 800); } +#endif void OS_X11::set_wm_fullscreen(bool p_enabled) { // Using EWMH -- Extened Window Manager Hints @@ -657,7 +663,11 @@ Point2 OS_X11::get_window_position() const { int x,y; Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); - return Point2i(x,y); + + int screen = get_screen(); + Point2i screen_position = get_screen_position(screen); + + return Point2i(x-screen_position.x, y-screen_position.y); } void OS_X11::set_window_position(const Point2& p_position) { @@ -698,6 +708,12 @@ void OS_X11::set_window_position(const Point2& p_position) { XFree(data); } + int screen = get_screen(); + Point2i screen_position = get_screen_position(screen); + + left -= screen_position.x; + top -= screen_position.y; + XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); } @@ -1146,9 +1162,9 @@ void OS_X11::process_xevents() { minimized = (visibility->state == VisibilityFullyObscured); } break; - case FocusIn: + case FocusIn: + minimized = false; if(current_videomode.fullscreen) { - set_minimized(false); set_wm_fullscreen(true); visual_server->init(); } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 557052ab69..b47c5db069 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,16 +160,8 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API - // This struct saves the values of the window before going fullscreen - // to be able to restore the same state after leaving fullscreen - struct { - bool resizable; - Point2i position; - Size2i size; - } window_data; - bool maximized; - void set_wm_border(bool p_enabled); + //void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif -- cgit v1.2.3 From 94d94a08558c83fb6e447c3e1ed858cf39c0e1ba Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 22 Jan 2015 01:14:50 +0900 Subject: * fix compilation without scons experimental_wm_api=yes * Extended the demo with an addional MouseGrab Test --- demos/misc/window_management/control.gd | 6 ++++-- demos/misc/window_management/engine.cfg | 7 +++++++ demos/misc/window_management/window_management.scn | Bin 4030 -> 4268 bytes platform/x11/os_x11.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 4929b1376c..6dc9282149 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -33,7 +33,6 @@ func _fixed_process(delta): get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) ) - if(OS.get_screen_count() > 1): get_node("Button_Screen0").show() get_node("Button_Screen1").show() @@ -63,6 +62,7 @@ func _fixed_process(delta): get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) get_node("Button_Minimized").set_pressed( OS.is_minimized() ) get_node("Button_Maximized").set_pressed( OS.is_maximized() ) + get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) func _ready(): @@ -113,4 +113,6 @@ func _on_Button_Maximized_pressed(): OS.set_maximized(true) - +func _on_Button_Mouse_Grab_pressed(): + var observer = get_node("../Observer") + observer.state = observer.STATE_GRAB diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 6ce3d51aee..c53bd45fb7 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -10,3 +10,10 @@ fullscreen=false resizable=true width=800 height=600 + +[input] + +move_forward=[key(W)] +move_backwards=[key(S)] +move_left=[key(A)] +move_right=[key(D)] diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index baf03bdfd1..40e6e64cef 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d711cea42e..fa3701aeef 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -177,11 +177,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); - if (true) { - rasterizer = memnew( RasterizerGLES2 ); - } else { - //rasterizer = memnew( RasterizerGLES1 ); - }; + rasterizer = memnew( RasterizerGLES2 ); #endif visual_server = memnew( VisualServerRaster(rasterizer) ); @@ -1164,10 +1160,12 @@ void OS_X11::process_xevents() { case FocusIn: minimized = false; +#ifdef EXPERIMENTAL_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(true); visual_server->init(); } +#endif main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); if (mouse_mode==MOUSE_MODE_CAPTURED) { XGrabPointer(x11_display, x11_window, True, @@ -1178,11 +1176,13 @@ void OS_X11::process_xevents() { break; case FocusOut: +#ifdef EXPERIMENTAL_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(false); set_minimized(true); visual_server->init(); } +#endif main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); if (mouse_mode==MOUSE_MODE_CAPTURED) { //dear X11, I try, I really try, but you never work, you do whathever you want. -- cgit v1.2.3 From 2204914abfc939e16cc595a6b175ff74b6552a6c Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 22 Jan 2015 01:54:17 +0900 Subject: * observer scene for the demo --- demos/misc/window_management/observer/observer.gd | 78 ++++++++++++++++ demos/misc/window_management/observer/observer.scn | Bin 0 -> 1786 bytes .../window_management/observer/observer_hud.gd | 98 +++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 demos/misc/window_management/observer/observer.gd create mode 100644 demos/misc/window_management/observer/observer.scn create mode 100644 demos/misc/window_management/observer/observer_hud.gd diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd new file mode 100644 index 0000000000..7bec0f5301 --- /dev/null +++ b/demos/misc/window_management/observer/observer.gd @@ -0,0 +1,78 @@ + +extends Spatial + +var r_pos = Vector2() +var state + +const STATE_MENU=0 +const STATE_GRAB=1 + +func direction(vector): + var v = get_node("Camera").get_global_transform().basis * vector + v = v.normalized() + + return v + + +func impulse(event, action): + if(event.is_action(action) && event.is_pressed() && !event.is_echo()): + return true + else: + return false + + +func _fixed_process(delta): + + if(state != STATE_GRAB): + return + + if(Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED): + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + var dir = Vector3() + var cam = get_global_transform() + var org = get_translation() + + if (Input.is_action_pressed("move_forward")): + dir += direction(Vector3(0,0,-1)) + if (Input.is_action_pressed("move_backwards")): + dir += direction(Vector3(0,0,1)) + if (Input.is_action_pressed("move_left")): + dir += direction(Vector3(-1,0,0)) + if (Input.is_action_pressed("move_right")): + dir += direction(Vector3(1,0,0)) + + dir = dir.normalized() + + move(dir * 10 * delta) + var d = delta * 0.1 + + var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x) + set_transform(yaw) + + var cam = get_node("Camera") + var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y) + cam.set_transform(pitch) + + r_pos.x = 0.0 + r_pos.y = 0.0 + + +func _input( event ): + if(event.type == InputEvent.MOUSE_MOTION): + r_pos = event.relative_pos + + if(impulse(event, "ui_cancel")): + if(state == STATE_GRAB): + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + state = STATE_MENU + else: + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + state = STATE_GRAB + + +func _ready(): + set_fixed_process(true) + set_process_input(true) + + state = STATE_MENU diff --git a/demos/misc/window_management/observer/observer.scn b/demos/misc/window_management/observer/observer.scn new file mode 100644 index 0000000000..da29ad62b8 Binary files /dev/null and b/demos/misc/window_management/observer/observer.scn differ diff --git a/demos/misc/window_management/observer/observer_hud.gd b/demos/misc/window_management/observer/observer_hud.gd new file mode 100644 index 0000000000..24e81b02ba --- /dev/null +++ b/demos/misc/window_management/observer/observer_hud.gd @@ -0,0 +1,98 @@ +var parent + +func printdebug(): + + var s + + if(parent.state == parent.STATE_GAME): + s = str( "TIME_FPS: ", Performance.get_monitor(Performance.TIME_FPS), "\n") + s += str("OBJECT_COUNT: ", Performance.get_monitor(Performance.OBJECT_COUNT), "\n") + s += str("OBJECT_RESOURCE_COUNT : ", Performance.get_monitor(Performance.OBJECT_RESOURCE_COUNT), "\n") + s += str("OBJECT_NODE_COUNT : ", Performance.get_monitor(Performance.OBJECT_NODE_COUNT), "\n") + s += str("RENDER_OBJECTS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_OBJECTS_IN_FRAME), "\n") + s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") + s += str("RENDER_DRAW_CALLS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_DRAW_CALLS_IN_FRAME), "\n") + s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") + # s += str("RENDER_USAGE_VIDEO_MEM_TOTAL : ", Performance.get_monitor(Performance.RENDER_USAGE_VIDEO_MEM_TOTAL), "\n") + # s += str("RENDER_VIDEO_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED), "\n") + # s += str("RENDER_TEXTURE_MEM_USED : ", Performance.get_monitor(Performance.RENDER_TEXTURE_MEM_USED), "\n") + # s += str("RENDER_VERTEX_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VERTEX_MEM_USED), "\n") + s += str("CUBES: ", get_node("/root/World").world.size(), "\n") + else: + s = "" + + get_node("Label_Debug").set_text(s) + + +func _fixed_process(delta): + parent = get_parent() + + printdebug() + + if( parent.state == parent.STATE_MENU ): + get_node("Menu").show() + else: + get_node("Menu").hide() + + + +func _ready(): + set_fixed_process(true) + + +func _on_Fullscreen_toggled( pressed ): + if( pressed ): + OS.set_fullscreen(true) + else: + OS.set_fullscreen(false) + + +func _on_DebugInfo_toggled( pressed ): + if( pressed ): + get_node("Label_Debug").show() + else: + get_node("Label_Debug").hide() + + +func _on_Save_pressed(): + var file_dialog = get_node("Menu/SaveDialog") + file_dialog.clear_filters() + file_dialog.add_filter("*.json") + file_dialog.set_mode(3) + file_dialog.show() + file_dialog._update_file_list() + + +func _on_SaveDialog_file_selected( path ): + get_node("/root/World").save_world( path ) + + +func _on_Load_pressed(): + var file_dialog = get_node("Menu/LoadDialog") + file_dialog.clear_filters() + file_dialog.add_filter("*.json") + file_dialog.set_mode(0) + file_dialog.show() + file_dialog._update_file_list() + + +func _on_LoadDialog_file_selected( path ): + get_node("/root/World").load_world( path ) + + +func _on_Server_toggled( pressed ): + if pressed: + get_node("/root/World/Server").start() + get_node("Menu/Client").hide() + else: + get_node("/root/World/Server").stop() + get_node("Menu/Client").show() + + +func _on_Client_toggled( pressed ): + if pressed: + get_node("/root/World/Client").start() + get_node("Menu/Server").hide() + else: + get_node("/root/World/Client").stop() + get_node("Menu/Server").show() \ No newline at end of file -- cgit v1.2.3 From 03c453ac7dc2b22bfb864e563b7f3b8424bbcff4 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 22 Jan 2015 05:35:39 +0900 Subject: * Cleanup for PR * Demo shows a Dialog with not implemented methods at startup --- README.md | 21 ----- demos/misc/window_management/control.gd | 68 +++++++++++++- demos/misc/window_management/observer/observer.gd | 1 + .../window_management/observer/observer_hud.gd | 98 --------------------- demos/misc/window_management/window_management.scn | Bin 4268 -> 4744 bytes main/main.cpp | 1 + 6 files changed, 69 insertions(+), 120 deletions(-) delete mode 100644 demos/misc/window_management/observer/observer_hud.gd diff --git a/README.md b/README.md index 35841c8b29..3456290f74 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,3 @@ -### x11-window-management branch - -#### New GDScript Methods for the OS Class: -* int OS.get_screen_count() -* int OS.get_screen() -* void OS.set_screen(int screen) -* Vector2 OS.get_screen_position(int screen=0) -* Vector2 OS.get_screen_size(int screen=0) -* Vector2 OS.get_window_position() -* void OS.set_window_position(Vector2 position) -* Vector2 OS.get_window_size() -* void OS.set_window_size(Vector2 size) -* void OS.set_fullscreen(bool enabled) -* bool OS.is_fullscreen() - -#### Demo -A demo/test is available at "demos/misc/window-management" - -#### Scons Commandline -'''scons p=x11 experimental_wm_api=yes''' - ![GODOT](/logo.png) ### The Engine diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 6dc9282149..d329237aed 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -19,6 +19,9 @@ func _fixed_process(delta): if(OS.is_maximized()): modetext += "Maximized\n" + if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED): + modetext += "MouseGrab\n" + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) @@ -65,8 +68,71 @@ func _fixed_process(delta): get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) +func check_wm_api(): + var s = "" + if( !OS.has_method("get_screen_count") ): + s += " - get_screen_count()\n" + + if( !OS.has_method("get_screen") ): + s += " - get_screen()\n" + + if( !OS.has_method("set_screen") ): + s += " - set_screen()\n" + + if( !OS.has_method("get_screen_position") ): + s += " - get_screen_position()\n" + + if( !OS.has_method("get_screen_size") ): + s += " - get_screen_size()\n" + + if( !OS.has_method("get_window_position") ): + s += " - get_window_position()\n" + + if( !OS.has_method("set_window_position") ): + s += " - set_window_position()\n" + + if( !OS.has_method("get_window_size") ): + s += " - get_window_size()\n" + + if( !OS.has_method("set_window_size") ): + s += " - set_window_size()\n" + + if( !OS.has_method("set_fullscreen") ): + s += " - set_fullscreen()\n" + + if( !OS.has_method("is_fullscreen") ): + s += " - is_fullscreen()\n" + + if( !OS.has_method("set_resizable") ): + s += " - set_resizable()\n" + + if( !OS.has_method("is_resizable") ): + s += " - is_resizable()\n" + + if( !OS.has_method("set_minimized") ): + s += " - set_minimized()\n" + + if( !OS.has_method("is_minimized") ): + s += " - is_minimized()\n" + + if( !OS.has_method("set_maximized") ): + s += " - set_maximized()\n" + + if( !OS.has_method("is_maximized") ): + s += " - is_maximized()\n" + + if( s.length() == 0 ): + return true + else: + var text = get_node("ImplementationDialog/Text").get_text() + get_node("ImplementationDialog/Text").set_text( text + s ) + get_node("ImplementationDialog").show() + return false + + func _ready(): - set_fixed_process(true) + if( check_wm_api() ): + set_fixed_process(true) func _on_Button_MoveTo_pressed(): diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd index 7bec0f5301..d27912a670 100644 --- a/demos/misc/window_management/observer/observer.gd +++ b/demos/misc/window_management/observer/observer.gd @@ -76,3 +76,4 @@ func _ready(): set_process_input(true) state = STATE_MENU + diff --git a/demos/misc/window_management/observer/observer_hud.gd b/demos/misc/window_management/observer/observer_hud.gd deleted file mode 100644 index 24e81b02ba..0000000000 --- a/demos/misc/window_management/observer/observer_hud.gd +++ /dev/null @@ -1,98 +0,0 @@ -var parent - -func printdebug(): - - var s - - if(parent.state == parent.STATE_GAME): - s = str( "TIME_FPS: ", Performance.get_monitor(Performance.TIME_FPS), "\n") - s += str("OBJECT_COUNT: ", Performance.get_monitor(Performance.OBJECT_COUNT), "\n") - s += str("OBJECT_RESOURCE_COUNT : ", Performance.get_monitor(Performance.OBJECT_RESOURCE_COUNT), "\n") - s += str("OBJECT_NODE_COUNT : ", Performance.get_monitor(Performance.OBJECT_NODE_COUNT), "\n") - s += str("RENDER_OBJECTS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_OBJECTS_IN_FRAME), "\n") - s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") - s += str("RENDER_DRAW_CALLS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_DRAW_CALLS_IN_FRAME), "\n") - s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") - # s += str("RENDER_USAGE_VIDEO_MEM_TOTAL : ", Performance.get_monitor(Performance.RENDER_USAGE_VIDEO_MEM_TOTAL), "\n") - # s += str("RENDER_VIDEO_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED), "\n") - # s += str("RENDER_TEXTURE_MEM_USED : ", Performance.get_monitor(Performance.RENDER_TEXTURE_MEM_USED), "\n") - # s += str("RENDER_VERTEX_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VERTEX_MEM_USED), "\n") - s += str("CUBES: ", get_node("/root/World").world.size(), "\n") - else: - s = "" - - get_node("Label_Debug").set_text(s) - - -func _fixed_process(delta): - parent = get_parent() - - printdebug() - - if( parent.state == parent.STATE_MENU ): - get_node("Menu").show() - else: - get_node("Menu").hide() - - - -func _ready(): - set_fixed_process(true) - - -func _on_Fullscreen_toggled( pressed ): - if( pressed ): - OS.set_fullscreen(true) - else: - OS.set_fullscreen(false) - - -func _on_DebugInfo_toggled( pressed ): - if( pressed ): - get_node("Label_Debug").show() - else: - get_node("Label_Debug").hide() - - -func _on_Save_pressed(): - var file_dialog = get_node("Menu/SaveDialog") - file_dialog.clear_filters() - file_dialog.add_filter("*.json") - file_dialog.set_mode(3) - file_dialog.show() - file_dialog._update_file_list() - - -func _on_SaveDialog_file_selected( path ): - get_node("/root/World").save_world( path ) - - -func _on_Load_pressed(): - var file_dialog = get_node("Menu/LoadDialog") - file_dialog.clear_filters() - file_dialog.add_filter("*.json") - file_dialog.set_mode(0) - file_dialog.show() - file_dialog._update_file_list() - - -func _on_LoadDialog_file_selected( path ): - get_node("/root/World").load_world( path ) - - -func _on_Server_toggled( pressed ): - if pressed: - get_node("/root/World/Server").start() - get_node("Menu/Client").hide() - else: - get_node("/root/World/Server").stop() - get_node("Menu/Client").show() - - -func _on_Client_toggled( pressed ): - if pressed: - get_node("/root/World/Client").start() - get_node("Menu/Server").hide() - else: - get_node("/root/World/Client").stop() - get_node("Menu/Server").show() \ No newline at end of file diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 40e6e64cef..bf7a0871e7 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/main/main.cpp b/main/main.cpp index 27d7d97e85..f0e376a045 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -627,6 +627,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } + GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); -- cgit v1.2.3 From df7d26ff5b89ce9852813abd370d1357aab1501b Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 12 Feb 2015 15:58:00 +0100 Subject: cleanup + MouseGrab --- demos/misc/window_management/control.gd | 2 + demos/misc/window_management/window_management.scn | Bin 4744 -> 4850 bytes platform/x11/os_x11.cpp | 81 +++++++++------------ platform/x11/os_x11.h | 1 + 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index d329237aed..50fc3a3765 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -28,6 +28,8 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) + get_node("Label_MousePosition").set_text(str("Mouse Position:\n", Input.get_mouse_pos() ) ) + get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index bf7a0871e7..14d0da0415 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index fa3701aeef..9fb2a4c64d 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -238,9 +238,11 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XFree(xsh); } #else + capture_idle = 0; + minimized = false; + maximized = false; + if (current_videomode.fullscreen) { - minimized = false; - maximized = false; //set_wm_border(false); set_wm_fullscreen(true); } @@ -494,8 +496,9 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { center.y = current_videomode.height/2; XWarpPointer(x11_display, None, x11_window, 0,0,0,0, (int)center.x, (int)center.y); - } + input->set_mouse_pos(center); + } } void OS_X11::warp_mouse_pos(const Point2& p_to) { @@ -724,44 +727,10 @@ void OS_X11::set_window_size(const Size2 p_size) { } void OS_X11::set_fullscreen(bool p_enabled) { - -#if 0 - if(p_enabled && current_videomode.fullscreen) - return; - - if(!current_videomode.resizable) - set_resizable(true); - - if(p_enabled) { - window_data.size = get_window_size(); - window_data.position = get_window_position(); - - int screen = get_screen(); - Size2i size = get_screen_size(screen); - Point2i position = get_screen_position(screen); - - set_wm_border(false); - set_wm_fullscreen(true); - XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); - - current_videomode.fullscreen = True; - } else { - set_wm_fullscreen(false); - set_wm_border(true); - XMoveResizeWindow(x11_display, x11_window, - window_data.position.x, - window_data.position.y, - window_data.size.width, - window_data.size.height); - - current_videomode.fullscreen = False; - } -#endif set_wm_fullscreen(p_enabled); current_videomode.fullscreen = p_enabled; visual_server->init(); - } bool OS_X11::is_fullscreen() const { @@ -1209,7 +1178,7 @@ void OS_X11::process_xevents() { event.xbutton.x=last_mouse_pos.x; event.xbutton.y=last_mouse_pos.y; } - + InputEvent mouse_event; mouse_event.ID=++event_id; mouse_event.type = InputEvent::MOUSE_BUTTON; @@ -1244,7 +1213,7 @@ void OS_X11::process_xevents() { last_click_ms+=diff; last_click_pos = Point2(event.xbutton.x,event.xbutton.y); } - } + } input->parse_input_event( mouse_event); @@ -1254,11 +1223,10 @@ void OS_X11::process_xevents() { last_timestamp=event.xmotion.time; - + // Motion is also simple. // A little hack is in order // to be able to send relative motion events. - Point2i pos( event.xmotion.x, event.xmotion.y ); if (mouse_mode==MOUSE_MODE_CAPTURED) { @@ -1273,7 +1241,7 @@ void OS_X11::process_xevents() { } Point2i new_center = pos; - pos = last_mouse_pos + ( pos-center ); + pos = last_mouse_pos + ( pos - center ); center=new_center; do_mouse_warp=true; #else @@ -1287,9 +1255,7 @@ void OS_X11::process_xevents() { XWarpPointer(x11_display, None, x11_window, 0,0,0,0, (int)center.x, (int)center.y); #endif - } - if (!last_mouse_pos_valid) { @@ -1298,7 +1264,14 @@ void OS_X11::process_xevents() { } Point2i rel = pos - last_mouse_pos; - + +#ifdef EXPERIMENTAL_WM_API + if (mouse_mode==MOUSE_MODE_CAPTURED) { + pos.x = current_videomode.width / 2; + pos.y = current_videomode.height / 2; + } +#endif + InputEvent motion_event; motion_event.ID=++event_id; motion_event.type=InputEvent::MOUSE_MOTION; @@ -1309,7 +1282,7 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.x=pos.x; motion_event.mouse_motion.y=pos.y; input->set_mouse_pos(pos); - motion_event.mouse_motion.global_x=pos.x; + motion_event.mouse_motion.global_x=pos.y; motion_event.mouse_motion.global_y=pos.y; motion_event.mouse_motion.speed_x=input->get_mouse_speed().x; motion_event.mouse_motion.speed_y=input->get_mouse_speed().y; @@ -1318,6 +1291,8 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.relative_y=rel.y; last_mouse_pos=pos; + + // printf("rel: %d,%d\n", rel.x, rel.y ); input->parse_input_event( motion_event); @@ -1392,8 +1367,18 @@ void OS_X11::process_xevents() { if (do_mouse_warp) { XWarpPointer(x11_display, None, x11_window, - 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); - + 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); + + /* + Window root, child; + int root_x, root_y; + int win_x, win_y; + unsigned int mask; + XQueryPointer( x11_display, x11_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask ); + + printf("Root: %d,%d\n", root_x, root_y); + printf("Win: %d,%d\n", win_x, win_y); + */ } } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index b47c5db069..7518c93562 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,6 +160,7 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API + unsigned int capture_idle; bool maximized; //void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); -- cgit v1.2.3 From f5d2e1f42cca1c5b078073133fccda63c556a0da Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 15 Feb 2015 18:26:49 +0800 Subject: Renamed EXPERIMENTAL_WM_API to NEW_WM_API --- core/bind/core_bind.cpp | 4 ++-- core/bind/core_bind.h | 2 +- core/os/os.h | 2 +- platform/x11/detect.py | 6 +++--- platform/x11/os_x11.cpp | 12 ++++++------ platform/x11/os_x11.h | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 39c5761d67..858f5cec27 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,7 +176,7 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } @@ -706,7 +706,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_screen"),&_OS::get_screen); ObjectTypeDB::bind_method(_MD("set_screen"),&_OS::set_screen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index e77ed9e40f..1a80e35221 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,7 +108,7 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API virtual int get_screen_count() const; virtual int get_screen() const; virtual void set_screen(int p_screen); diff --git a/core/os/os.h b/core/os/os.h index c04a91e302..6301bd495f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,7 +150,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API virtual int get_screen_count() const=0; virtual int get_screen() const=0; virtual void set_screen(int p_screen)=0; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 0601c59981..2519dd6fdf 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -53,7 +53,7 @@ def get_opts(): ('use_llvm','Use llvm compiler','no'), ('use_sanitizer','Use llvm compiler sanitize address','no'), ('pulseaudio','Detect & Use pulseaudio','yes'), - ('experimental_wm_api', 'Use experimental window management API','no'), + ('new_wm_api', 'Use experimental window management API','no'), ] def get_flags(): @@ -153,7 +153,7 @@ def configure(env): env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) - if(env["experimental_wm_api"]=="yes"): - env.Append(CPPFLAGS=['-DEXPERIMENTAL_WM_API']) + if(env["new_wm_api"]=="yes"): + env.Append(CPPFLAGS=['-DNEW_WM_API']) env.ParseConfig('pkg-config xinerama --cflags --libs') diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 4c86f5a82f..8def564562 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -36,7 +36,7 @@ #include "servers/physics/physics_server_sw.h" #include "X11/Xutil.h" -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API #include "X11/Xatom.h" #include "X11/extensions/Xinerama.h" // ICCCM @@ -187,7 +187,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } -#ifndef EXPERIMENTAL_WM_API +#ifndef NEW_WM_API // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others @@ -552,7 +552,7 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API #if 0 // Just now not needed. Can be used for a possible OS.set_border(bool) method void OS_X11::set_wm_border(bool p_enabled) { @@ -1133,7 +1133,7 @@ void OS_X11::process_xevents() { case FocusIn: minimized = false; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(true); visual_server->init(); @@ -1149,7 +1149,7 @@ void OS_X11::process_xevents() { break; case FocusOut: -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(false); set_minimized(true); @@ -1269,7 +1269,7 @@ void OS_X11::process_xevents() { Point2i rel = pos - last_mouse_pos; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API if (mouse_mode==MOUSE_MODE_CAPTURED) { pos.x = current_videomode.width / 2; pos.y = current_videomode.height / 2; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 7518c93562..ffa1ce00b3 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -159,7 +159,7 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API unsigned int capture_idle; bool maximized; //void set_wm_border(bool p_enabled); @@ -220,7 +220,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API virtual int get_screen_count() const; virtual int get_screen() const; virtual void set_screen(int p_screen); -- cgit v1.2.3 From ba74e45027f795238323c3667dfdb660608d7484 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 01:27:36 -0600 Subject: added Label_MouseGrab_KeyInfo --- demos/misc/window_management/control.gd | 3 +++ demos/misc/window_management/window_management.scn | Bin 4850 -> 5072 bytes 2 files changed, 3 insertions(+) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 50fc3a3765..7f805a1a21 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -21,6 +21,9 @@ func _fixed_process(delta): if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED): modetext += "MouseGrab\n" + get_node("Label_MouseGrab_KeyInfo").show() + else: + get_node("Label_MouseGrab_KeyInfo").hide() get_node("Label_Mode").set_text(modetext) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 14d0da0415..0cb7030ffc 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 5241626dee5aa7f91da7d7ac5476fb76e1d0b89e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 03:32:13 -0500 Subject: fixing a typo in the demo --- demos/misc/window_management/window_management.scn | Bin 5072 -> 5068 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 0cb7030ffc..9b963a0a15 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 52a4e8495c6b9324f3c61f85c3ed3708c3e93213 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 04:24:21 -0500 Subject: fix introduced bug --- platform/x11/os_x11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 8def564562..8196281732 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1286,7 +1286,7 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.x=pos.x; motion_event.mouse_motion.y=pos.y; input->set_mouse_pos(pos); - motion_event.mouse_motion.global_x=pos.y; + motion_event.mouse_motion.global_x=pos.x; motion_event.mouse_motion.global_y=pos.y; motion_event.mouse_motion.speed_x=input->get_mouse_speed().x; motion_event.mouse_motion.speed_y=input->get_mouse_speed().y; -- cgit v1.2.3 From f7621810a2f072a5d77563b6018023c575f355bf Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 09:26:58 -0500 Subject: removed up, down, left, right keys from the demo. were used before for fast multiscreen setup testing. --- demos/misc/window_management/control.gd | 12 ------------ demos/misc/window_management/window_management.scn | Bin 5068 -> 5087 bytes 2 files changed, 12 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 7f805a1a21..bca13c5a0c 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -54,18 +54,6 @@ func _fixed_process(delta): get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() - if( Input.is_action_pressed("ui_right")): - OS.set_screen(1) - - if( Input.is_action_pressed("ui_left")): - OS.set_screen(0) - - if( Input.is_action_pressed("ui_up")): - OS.set_fullscreen(true) - - if( Input.is_action_pressed("ui_down")): - OS.set_fullscreen(false) - get_node("Button_Fullscreen").set_pressed( OS.is_fullscreen() ) get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) get_node("Button_Minimized").set_pressed( OS.is_minimized() ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 9b963a0a15..b8b0ee210b 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3