Skip to content

Commit

Permalink
Add fullscreen monitor selection support on Linux (#235)
Browse files Browse the repository at this point in the history
* Add fullscreen monitor support on Linux

* Add change file

* Remove todo on videomode

* Fix clippy
  • Loading branch information
Ngo Iok Ui (Wu Yu Wei) authored Nov 4, 2021
1 parent 25af2d8 commit 3772b80
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changes/linux-monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": patch
---

Add monitor selection when fullscreen on Linux and close possible way to create VideoMode on Linux since gtk doesn't acutally have such feature.

3 changes: 3 additions & 0 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ impl MonitorHandle {
}

/// Returns all fullscreen video modes supported by this monitor.
///
/// ## Platform-specific
/// - **Linux:** Unsupported. This will always return empty iterator.
#[inline]
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
self.inner.video_modes()
Expand Down
21 changes: 13 additions & 8 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
menu::{MenuItem, MenuType},
monitor::MonitorHandle as RootMonitorHandle,
platform_impl::platform::{window::hit_test, DEVICE_ID},
window::{CursorIcon, WindowId as RootWindowId},
window::{CursorIcon, Fullscreen, WindowId as RootWindowId},
};

use super::{
Expand Down Expand Up @@ -245,7 +245,13 @@ impl<T: 'static> EventLoop<T> {
}
}
WindowRequest::Fullscreen(fullscreen) => match fullscreen {
Some(_) => window.fullscreen(),
Some(f) => {
if let Fullscreen::Borderless(Some(monitor)) = f {
let number = monitor.inner.number;
let screen = window.display().default_screen();
window.fullscreen_on_monitor(&screen, number);
}
}
None => window.unfullscreen(),
},
WindowRequest::Decorations(decorations) => window.set_decorated(decorations),
Expand Down Expand Up @@ -838,14 +844,13 @@ impl<T: 'static> EventLoopProxy<T> {
}

fn assert_is_main_thread(suggested_method: &str) {
if !is_main_thread() {
panic!(
"Initializing the event loop outside of the main thread is a significant \
assert!(
is_main_thread(),
"Initializing the event loop outside of the main thread is a significant \
cross-platform compatibility hazard. If you really, absolutely need to create an \
EventLoop on a different thread, please use the `EventLoopExtUnix::{}` function.",
suggested_method
);
}
suggested_method
);
}

#[cfg(target_os = "linux")]
Expand Down
12 changes: 6 additions & 6 deletions src/platform_impl/linux/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct MonitorHandle {
// We have to store the monitor number in GdkScreen despite
// it's deprecated. Otherwise, there's no way to set it in
// GtkWindow in Gtk3.
number: i32,
pub(crate) number: i32,
}

impl MonitorHandle {
Expand Down Expand Up @@ -51,7 +51,7 @@ impl MonitorHandle {

#[inline]
pub fn video_modes(&self) -> Box<dyn Iterator<Item = RootVideoMode>> {
todo!()
Box::new(Vec::new().into_iter())
}
}

Expand All @@ -64,21 +64,21 @@ pub struct VideoMode;
impl VideoMode {
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
todo!()
panic!("VideoMode is unsupported on Linux.")
}

#[inline]
pub fn bit_depth(&self) -> u16 {
todo!()
panic!("VideoMode is unsupported on Linux.")
}

#[inline]
pub fn refresh_rate(&self) -> u16 {
todo!()
panic!("VideoMode is unsupported on Linux.")
}

#[inline]
pub fn monitor(&self) -> RootMonitorHandle {
todo!()
panic!("VideoMode is unsupported on Linux.")
}
}
7 changes: 4 additions & 3 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ impl Window {

// Rest attributes
window.set_title(&attributes.title);
// TODO set it with Fullscreen enum
if attributes.fullscreen.is_some() {
window.fullscreen();
if let Some(Fullscreen::Borderless(Some(f))) = &attributes.fullscreen {
let number = f.inner.number;
let screen = window.display().default_screen();
window.fullscreen_on_monitor(&screen, number);
}
if attributes.maximized {
window.maximize();
Expand Down

0 comments on commit 3772b80

Please sign in to comment.