From 790d8ecbb9a0a0ac67520b84fc621c34f910d817 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 12:02:59 +0800 Subject: [PATCH] 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 + .../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 a2aca7e11fe..48cd43ccdc9 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 9d9f25691ed..99ecb765c73 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 1ef05e45c8b..2d4e9379740 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 34df5dd92cb..ce17db6b006 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 7b6dddce965..44ad30ea14d 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 3a6426f3ee9d00f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p~ z-*9yXtKg`o2n!iCjFMJ(+EJpQ#fcUSu<4*S(_4MK2+L(n9>z+%W?MXY1-G#EZ?DT( z>xFyrGtLJup$QP?&twfnO(H3ZIRk+pah5SK zG8vqRsAmc$wQyTw~65F$w;rF4GfRoEba=%$#Mrr^d&_Ba@mI ziaUf{CFTH=S_Rp>Dsw0p8r5gCL?3)ZEykIQ2lZ)fP>;95m(?Q3;f>L(w80`lJ=7L2 zfsfS^Y|8Lz;owm%UIaI3PbP1I0bZDB5K0t$0jK#p{CNl`ilHTb0b=o=fvnaEn;}sr zG;uzB*MCm}kB`8k@fHZG4PY_E1_QpDaKMR}Lx`PL9fmMOel!ok`FKMVUQ!!ACD;)D z6n~!+(nqy0P}$&1m2bi)ao~9>V4nPhyn-OVhi2|j%~*zJg8}YEhV4+mi?I>GklOJn z?38D*46?Y5Zsh>x%iluDnT6XRmsg+!o4AC{kQbLAKQ7^6WLCv9AId4JaejzVT*X;A zhzb;O7oG(x?LF%>XjQ`VaS2MfG=Dkg&!X%4{BveK3cI-l`Z>cj=V8OT24CRYuzm3Y zZa7yBwt@em#hOvJflEp0;^GDHa@{#VrIh5a!yvu?VZt7ILj?@cd>bB#OR`znPpSpj z%gOJskN8^HPx~I_lCz)Mu7WC%f?=KopYSNiSCUqX%y2_yN^O#*lwT*y7|tgpc2ioQ z7#nGlUr*Mi!~+288n)9hla^G11ait1rNbrrQ?699F(vu{{1)2Tb(=I@VS13foNP{Y ztr91w5L-*Ol5R2O9{N<}z7b7sOLZ~uCp#=%W~a1h>E53VTe?@1jTQ(H>FJjVt_n{- z(VpcrJwkMkl4O>iKH_?o(%fh=&*FOb1L?;5mhRq8%Jp_ruJ>v>rzLk<$R4fK_HaMh z!%e6s>?AbLU)r=a3L-5#=nf?4= 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 ca35bf2c0ae..bb0fd383871 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();