get_screen() + set_screen() added

This commit is contained in:
hurikhan 2015-01-14 12:02:59 +08:00
parent f55c0e9285
commit 790d8ecbb9
8 changed files with 109 additions and 24 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -3,3 +3,7 @@
name="window_management"
main_scene="res://window_management.scn"
icon="icon.png"
[display]
fullscreen=true

View file

@ -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<count; i++) {
Point2i pos = get_screen_position(i);
Size2i size = get_screen_size(i);
if( (x >= pos.x && x <pos.x + size.width) && (y >= 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();

View file

@ -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();