From 47df0e9eaa7f1231a07f86fc44426936c7a2589a Mon Sep 17 00:00:00 2001 From: Adam Badawy Date: Mon, 26 Oct 2015 03:40:37 -0400 Subject: [PATCH] Fix misbehaving fullscreen window --- src/api/x11/window.rs | 59 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index b6a96219..2a0badef 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -436,14 +436,14 @@ impl Window { } // switching to fullscreen - if let Some(mut mode_to_switch_to) = mode_to_switch_to { - window_attributes |= ffi::CWOverrideRedirect; - unsafe { - (display.xf86vmode.XF86VidModeSwitchToMode)(display.display, screen_id, &mut mode_to_switch_to); - (display.xf86vmode.XF86VidModeSetViewPort)(display.display, screen_id, 0, 0); - set_win_attr.override_redirect = 1; - } - } + // if let Some(mut mode_to_switch_to) = mode_to_switch_to { + // window_attributes |= ffi::CWOverrideRedirect; + // unsafe { + // (display.xf86vmode.XF86VidModeSwitchToMode)(display.display, screen_id, &mut mode_to_switch_to); + // (display.xf86vmode.XF86VidModeSetViewPort)(display.display, screen_id, 0, 0); + // set_win_attr.override_redirect = 1; + // } + // } // finally creating the window let window = unsafe { @@ -527,6 +527,49 @@ impl Window { let is_fullscreen = window_attrs.monitor.is_some(); + if is_fullscreen { + let state_atom = unsafe { + with_c_str("_NET_WM_STATE", |state| + (display.xlib.XInternAtom)(display.display, state, 0) + ) + }; + let fs_atom = unsafe { + with_c_str("_NET_WM_STATE_FULLSCREEN", |state_fullscreen| + (display.xlib.XInternAtom)(display.display, state_fullscreen, 0) + ) + }; + + let client_message_event = ffi::XClientMessageEvent { + type_: ffi::ClientMessage, + serial: 0, + send_event: 1, + display: display.display, + window: window, + message_type: state_atom, + format: 32, + data: { + let mut data = unsafe { + mem::transmute::<[libc::c_long; 5], ffi::ClientMessageData>([0; 5]) + }; + data.set_long(0, 1); + data.set_long(1, fs_atom as i64); + data.set_long(2, 0); + data + } + }; + let mut x_event = ffi::XEvent::from(client_message_event); + + unsafe { + (display.xlib.XSendEvent)( + display.display, + root, + 0, + ffi::SubstructureRedirectMask | ffi::SubstructureNotifyMask, + &mut x_event as *mut _ + ); + } + } + // finish creating the OpenGL context let context = match context { Prototype::Glx(ctxt) => {