瀏覽代碼

get_window_position() + set_window_position() added

hurikhan 10 年之前
父節點
當前提交
ac558c15ea
共有 6 個文件被更改,包括 74 次插入39 次删除
  1. 10 0
      core/bind/core_bind.cpp
  2. 2 0
      core/bind/core_bind.h
  3. 4 3
      core/os/os.h
  4. 0 6
      main/main.cpp
  5. 56 30
      platform/x11/os_x11.cpp
  6. 2 0
      platform/x11/os_x11.h

+ 10 - 0
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) {
 void _OS::set_fullscreen(bool p_enabled,int p_screen) {
 	OS::get_singleton()->set_fullscreen(p_enabled, 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));
 	ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
 
 
 	//MSC
 	//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("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0));
 	ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen);
 	ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen);
 
 

+ 2 - 0
core/bind/core_bind.h

@@ -109,6 +109,8 @@ public:
 	Array get_fullscreen_mode_list(int p_screen=0) const;
 	Array get_fullscreen_mode_list(int p_screen=0) const;
 
 
 	//MSC
 	//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);
 	void set_fullscreen(bool p_enabled, int p_screen=0);
 	bool is_fullscreen() const;
 	bool is_fullscreen() const;
 
 

+ 4 - 3
core/os/os.h

@@ -69,12 +69,11 @@ public:
 	};
 	};
 	struct VideoMode {
 	struct VideoMode {
 	
 	
-		int x,y,width,height;
+		int width,height;
 		bool fullscreen;
 		bool fullscreen;
 		bool resizable;
 		bool resizable;
 		float get_aspect() const { return (float)width/(float)height; }
 		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:
 protected:
 friend class Main;
 friend class Main;
@@ -152,6 +151,8 @@ public:
 	virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0;
 	virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0;
 
 
 	//MSC
 	//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 void set_fullscreen(bool p_enabled,int p_screen=0)=0;
 	virtual bool is_fullscreen() const=0;
 	virtual bool is_fullscreen() const=0;
 	
 	

+ 0 - 6
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
 	if (video_driver=="") // specified in engine.cfg
 		video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0)));
 		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"))
 	if (!force_res && use_custom_res && globals->has("display/width"))
 		video_mode.width=globals->get("display/width");
 		video_mode.width=globals->get("display/width");
 	if (!force_res &&use_custom_res && globals->has("display/height"))
 	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/width",video_mode.width);
 	GLOBAL_DEF("display/height",video_mode.height);
 	GLOBAL_DEF("display/height",video_mode.height);
 	GLOBAL_DEF("display/fullscreen",video_mode.fullscreen);
 	GLOBAL_DEF("display/fullscreen",video_mode.fullscreen);

+ 56 - 30
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 {
 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 {
 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
 	// maybe contextgl wants to be in charge of creating the window
 	//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
 	//print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height));
 #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED)
 #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 = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) );
 	context_gl->initialize();
 	context_gl->initialize();
@@ -516,7 +505,7 @@ void OS_X11::set_wm_border(bool p_enabled) {
 	property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
 	property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
 	XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
 	XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
 	XMapRaised(x11_display, x11_window);
 	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) {
 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);
 	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;
 		pre_videomode = current_videomode;
 
 
-		// Get Desktop resolutuion
+		XWindowAttributes xwa;
 		XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
 		XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
 
 
 		current_videomode.fullscreen = True;
 		current_videomode.fullscreen = True;
@@ -567,8 +595,6 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) {
 		set_wm_fullscreen(true);
 		set_wm_fullscreen(true);
 	} else {
 	} else {
 		current_videomode.fullscreen = False;
 		current_videomode.fullscreen = False;
-		current_videomode.x = pre_videomode.x;
-		current_videomode.y = pre_videomode.y;
 		current_videomode.width = pre_videomode.width;
 		current_videomode.width = pre_videomode.width;
 		current_videomode.height = pre_videomode.height;
 		current_videomode.height = pre_videomode.height;
 
 

+ 2 - 0
platform/x11/os_x11.h

@@ -217,6 +217,8 @@ public:
 	virtual VideoMode get_video_mode(int p_screen=0) const;
 	virtual VideoMode get_video_mode(int p_screen=0) const;
 	virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
 	virtual void get_fullscreen_mode_list(List<VideoMode> *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 void set_fullscreen(bool p_enabled,int p_screen=0);
 	virtual bool is_fullscreen() const;
 	virtual bool is_fullscreen() const;