瀏覽代碼

Merge pull request #16762 from RandomShaper/improve-fullscreen-2.1

Improve/fix fullscreen on X11 (2.1)
Rémi Verschelde 7 年之前
父節點
當前提交
aed100a3c3
共有 1 個文件被更改,包括 15 次插入6 次删除
  1. 15 6
      platform/x11/os_x11.cpp

+ 15 - 6
platform/x11/os_x11.cpp

@@ -691,10 +691,14 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
 	hints.decorations = 0;
 	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);
-	XWindowAttributes xwa;
-	XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
-	XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height);
+	if (p_enabled) {
+		XMapRaised(x11_display, x11_window);
+		XWindowAttributes xwa;
+		XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
+		XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height);
+	} else {
+		XResizeWindow(x11_display, x11_window, current_videomode.width, current_videomode.height);
+	}
 
 	// code for netwm-compliants
 	XEvent xev;
@@ -706,12 +710,17 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
 	xev.xclient.window = x11_window;
 	xev.xclient.message_type = wm_state;
 	xev.xclient.format = 32;
-	xev.xclient.data.l[0] = 1;
+	xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
 	xev.xclient.data.l[1] = fullscreen;
 	xev.xclient.data.l[2] = 0;
 
 	XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev);
 
+	// set bypass compositor hint
+	Atom bypass_compositor = XInternAtom(x11_display, "_NET_WM_BYPASS_COMPOSITOR", False);
+	unsigned long compositing_disable_on = p_enabled ? 1 : 0;
+	XChangeProperty(x11_display, x11_window, bypass_compositor, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&compositing_disable_on, 1);
+
 	XFlush(x11_display);
 
 	if (!p_enabled && !is_window_resizable()) {
@@ -900,7 +909,7 @@ Size2 OS_X11::get_real_window_size() const {
 	unsigned long remaining;
 	unsigned char *data = NULL;
 	if (XGetWindowProperty(x11_display, x11_window, prop, 0, 4, False, AnyPropertyType, &type, &format, &len, &remaining, &data) == Success) {
-		long *extents = (long*) data;
+		long *extents = (long *)data;
 		w += extents[0] + extents[1]; // left, right
 		h += extents[2] + extents[3]; // top, bottom
 	}