mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
Merge pull request #504 from tomaka/fix-fullscreen
Fix fullscreen mode on X11
This commit is contained in:
commit
3166f92a53
|
@ -365,29 +365,44 @@ impl Window {
|
||||||
preferred_fb
|
preferred_fb
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut best_mode = -1;
|
// finding the mode to switch to if necessary
|
||||||
let modes = unsafe {
|
let (mode_to_switch_to, xf86_desk_mode) = unsafe {
|
||||||
let mut mode_num: libc::c_int = mem::uninitialized();
|
let mut mode_num: libc::c_int = mem::uninitialized();
|
||||||
let mut modes: *mut *mut ffi::XF86VidModeModeInfo = mem::uninitialized();
|
let mut modes: *mut *mut ffi::XF86VidModeModeInfo = mem::uninitialized();
|
||||||
if (display.xf86vmode.XF86VidModeGetAllModeLines)(display.display, screen_id, &mut mode_num, &mut modes) == 0 {
|
if (display.xf86vmode.XF86VidModeGetAllModeLines)(display.display, screen_id, &mut mode_num, &mut modes) == 0 {
|
||||||
return Err(OsError(format!("Could not query the video modes")));
|
return Err(OsError(format!("Could not query the video modes")));
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..mode_num {
|
let xf86_desk_mode = *modes.offset(0);
|
||||||
let mode: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _);
|
|
||||||
if mode.hdisplay == dimensions.0 as u16 && mode.vdisplay == dimensions.1 as u16 {
|
|
||||||
best_mode = i;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if best_mode == -1 && builder.monitor.is_some() {
|
|
||||||
return Err(OsError(format!("Could not find a suitable graphics mode")));
|
|
||||||
}
|
|
||||||
|
|
||||||
modes
|
// FIXME: `XF86VidModeModeInfo` is missing its `hskew` field. Therefore we point to
|
||||||
|
// `vsyncstart` instead of `vdisplay` as a temporary hack.
|
||||||
|
|
||||||
|
let mode_to_switch_to = if builder.monitor.is_some() {
|
||||||
|
let matching_mode = (0 .. mode_num).map(|i| {
|
||||||
|
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
|
||||||
|
}).find(|m| m.hdisplay == dimensions.0 as u16 && m.vsyncstart == dimensions.1 as u16);
|
||||||
|
|
||||||
|
if let Some(matching_mode) = matching_mode {
|
||||||
|
Some(matching_mode)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let m = (0 .. mode_num).map(|i| {
|
||||||
|
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
|
||||||
|
}).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vsyncstart == dimensions.1 as u16);
|
||||||
|
|
||||||
|
match m {
|
||||||
|
Some(m) => Some(m),
|
||||||
|
None => return Err(OsError(format!("Could not find a suitable graphics mode")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let xf86_desk_mode = unsafe {
|
(display.xlib.XFree)(modes as *mut _);
|
||||||
*modes.offset(0)
|
|
||||||
|
(mode_to_switch_to, xf86_desk_mode)
|
||||||
};
|
};
|
||||||
|
|
||||||
// getting the visual infos
|
// getting the visual infos
|
||||||
|
@ -459,10 +474,11 @@ impl Window {
|
||||||
window_attributes |= ffi::CWBackPixel;
|
window_attributes |= ffi::CWBackPixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if builder.monitor.is_some() {
|
// switching to fullscreen
|
||||||
|
if let Some(mut mode_to_switch_to) = mode_to_switch_to {
|
||||||
window_attributes |= ffi::CWOverrideRedirect;
|
window_attributes |= ffi::CWOverrideRedirect;
|
||||||
unsafe {
|
unsafe {
|
||||||
(display.xf86vmode.XF86VidModeSwitchToMode)(display.display, screen_id, *modes.offset(best_mode as isize));
|
(display.xf86vmode.XF86VidModeSwitchToMode)(display.display, screen_id, &mut mode_to_switch_to);
|
||||||
(display.xf86vmode.XF86VidModeSetViewPort)(display.display, screen_id, 0, 0);
|
(display.xf86vmode.XF86VidModeSetViewPort)(display.display, screen_id, 0, 0);
|
||||||
set_win_attr.override_redirect = 1;
|
set_win_attr.override_redirect = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue