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

@ -260,6 +260,10 @@ impl Window {
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
unimplemented!();
}
#[inline]
pub fn set_fullscreen_windowed(&self, fullscreen: bool) {
}
}
unsafe impl Send for Window {}

View file

@ -97,7 +97,7 @@ pub enum DeviceId {
Wayland(wayland::DeviceId)
}
#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub enum MonitorId {
#[doc(hidden)]
X(x11::MonitorId),
@ -317,6 +317,14 @@ impl Window2 {
&Window2::Wayland(ref _w) => {},
}
}
#[inline]
pub fn set_fullscreen_windowed(&self, fullscreen: bool) {
match self {
&Window2::X(ref w) => w.set_fullscreen_windowed(fullscreen),
&Window2::Wayland(ref _w) => {},
}
}
}
unsafe extern "C" fn x_error_callback(dpy: *mut x11::ffi::Display, event: *mut x11::ffi::XErrorEvent)

View file

@ -359,6 +359,12 @@ pub struct MonitorId {
ctxt: Arc<WaylandContext>
}
impl PartialEq for MonitorId {
fn eq(&self, other: &MonitorId) -> bool {
self.id == other.id
}
}
impl MonitorId {
pub fn get_name(&self) -> Option<String> {
let mut guard = self.ctxt.evq.lock().unwrap();

View file

@ -54,7 +54,7 @@ impl Window {
*(decorated.handler()) = Some(DecoratedHandler::new());
// set fullscreen if necessary
if let Some(PlatformMonitorId::Wayland(ref monitor_id)) = attributes.monitor {
if let Some(PlatformMonitorId::Wayland(ref monitor_id)) = attributes.fullscreen.get_monitor() {
ctxt.with_output(monitor_id.clone(), |output| {
decorated.set_fullscreen(Some(output))
});

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);