Implement Windowed Fullscreen

There are two kinds of fullscreen. One where you take over the whole
output the other where you just set the window size to the screen
size and get rid of decorations. The first one already existed,
implement the second which is more common for normal desktop apps.
Use an enum to consolidate all the fullscreen states.
This commit is contained in:
Pedro Côrte-Real 2017-08-28 00:22:26 +01:00
parent a4052b8693
commit 1d97a2a506
8 changed files with 81 additions and 14 deletions

View file

@ -6,6 +6,11 @@ use native_monitor::NativeMonitorId;
#[derive(Clone)]
pub struct MonitorId(pub Arc<XConnection>, pub u32);
impl PartialEq for MonitorId {
fn eq(&self, other: &MonitorId) -> bool {
self.1 == other.1
}
}
pub fn get_available_monitors(x: &Arc<XConnection>) -> VecDeque<MonitorId> {
let nb_monitors = unsafe { (x.xlib.XScreenCount)(x.display) };

View file

@ -11,6 +11,7 @@ use std::time::Duration;
use CursorState;
use WindowAttributes;
use FullScreenState;
use platform::PlatformSpecificWindowBuilderAttributes;
use platform::MonitorId as PlatformMonitorId;
@ -128,12 +129,14 @@ impl Window {
let screen_id = match pl_attribs.screen_id {
Some(id) => id,
None => match window_attrs.monitor {
Some(PlatformMonitorId::X(MonitorId(_, monitor))) => monitor as i32,
None => match window_attrs.fullscreen {
FullScreenState::Exclusive(PlatformMonitorId::X(MonitorId(_, monitor))) => monitor as i32,
_ => unsafe { (display.xlib.XDefaultScreen)(display.display) },
}
};
let is_fullscreen = window_attrs.fullscreen.get_monitor().is_some();
// finding the mode to switch to if necessary
let (mode_to_switch_to, xf86_desk_mode) = unsafe {
let mut mode_num: libc::c_int = mem::uninitialized();
@ -142,7 +145,7 @@ impl Window {
(None, None)
} else {
let xf86_desk_mode: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(0));
let mode_to_switch_to = if window_attrs.monitor.is_some() {
let mode_to_switch_to = if is_fullscreen {
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.vdisplay == dimensions.1 as u16);
@ -234,6 +237,10 @@ impl Window {
Window::set_netwm(display, window, root, "_NET_WM_STATE_MAXIMIZED_VERT", true);
}
if window_attrs.fullscreen == FullScreenState::Windowed {
Window::set_netwm(display, window, root, "_NET_WM_STATE_FULLSCREEN", true);
}
// set visibility
if window_attrs.visible {
unsafe {
@ -261,8 +268,6 @@ impl Window {
}
}
let is_fullscreen = window_attrs.monitor.is_some();
if is_fullscreen {
Window::set_netwm(display, window, root, "_NET_WM_STATE_FULLSCREEN", true);