summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorhurikhan <m4r10.5ch14ck@gmail.com>2015-01-14 12:02:59 +0800
committerhurikhan <m4r10.5ch14ck@gmail.com>2015-01-14 12:02:59 +0800
commit790d8ecbb9a0a0ac67520b84fc621c34f910d817 (patch)
tree3ddc9cc465c22758c8904fae31521268b4f402e4 /platform
parentf55c0e928580de63af55ac22f045bb4380a1df2e (diff)
get_screen() + set_screen() added
Diffstat (limited to 'platform')
-rw-r--r--platform/x11/os_x11.cpp71
-rw-r--r--platform/x11/os_x11.h7
2 files changed, 60 insertions, 18 deletions
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<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();
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();