summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhurikhan <m4r10.5ch14ck@gmail.com>2015-01-13 21:01:24 +0800
committerhurikhan <m4r10.5ch14ck@gmail.com>2015-01-13 21:01:24 +0800
commitf55c0e928580de63af55ac22f045bb4380a1df2e (patch)
treec8bb97cb6d4a7d0cc56ed8463811f13a69e8601d
parentce7c7a862ebe37fada7708c342c07d70fa80465a (diff)
Using Xinerama extension for getting screen info
-rw-r--r--demos/misc/window_management/control.gd2
-rw-r--r--platform/x11/detect.py6
-rw-r--r--platform/x11/os_x11.cpp42
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;
}