Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servoshell: add fullscreen option #30614

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/config/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ pub struct Opts {

/// True to enable minibrowser
pub minibrowser: bool,

/// True to open the window in fullscreen mode
pub fullscreen: bool,
}

fn print_usage(app: &str, opts: &Options) {
Expand Down Expand Up @@ -430,6 +433,7 @@ pub fn default_opts() -> Opts {
local_script_source: None,
print_pwm: false,
minibrowser: true,
fullscreen: false,
}
}

Expand Down Expand Up @@ -556,7 +560,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
opts.optopt(
"",
"config-dir",
"config directory following xdg spec on linux platform",
"Config directory following xdg spec on linux platform",
"",
);
opts.optflag("v", "version", "Display servo version information");
Expand All @@ -569,6 +573,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
"",
);
opts.optflag("", "no-minibrowser", "Open minibrowser");
opts.optflag("", "fullscreen", "Open the window in fullscreen mode");

let opt_match = match opts.parse(args) {
Ok(m) => m,
Expand Down Expand Up @@ -785,6 +790,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
local_script_source: opt_match.opt_str("local-script-source"),
print_pwm: opt_match.opt_present("print-pwm"),
minibrowser: !opt_match.opt_present("no-minibrowser"),
fullscreen: opt_match.opt_present("fullscreen"),
};

set_options(opts);
Expand Down
7 changes: 4 additions & 3 deletions components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3702,6 +3702,10 @@ impl Document {

// https://fullscreen.spec.whatwg.org/#exit-fullscreen
pub fn exit_fullscreen(&self) -> Rc<Promise> {
// Send EmbedderMsg first
let event = EmbedderMsg::SetFullscreenState(false);
self.send_to_embedder(event);

let global = self.global();
// Step 1
let in_realm_proof = AlreadyInRealm::assert();
Expand All @@ -3718,9 +3722,6 @@ impl Document {

let window = self.window();
// Step 8
let event = EmbedderMsg::SetFullscreenState(false);
self.send_to_embedder(event);

// Step 9
let trusted_element = Trusted::new(&*element);
let trusted_promise = TrustedPromise::new(promise.clone());
Expand Down
20 changes: 12 additions & 8 deletions ports/servoshell/headed_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ impl Window {
// unstyled content is white and chrome often has a transparent background). See issue
// #9996.
let visible = opts.output_file.is_none() && !no_native_titlebar;
let primary_monitor = events_loop
.as_winit()
.available_monitors()
.nth(0)
.expect("No monitor detected");

let win_size: DeviceIntSize = (win_size.to_f32() * window_creation_scale_factor()).to_i32();
let width = win_size.to_untyped().width;
Expand All @@ -108,18 +113,16 @@ impl Window {
.build(events_loop.as_winit())
.expect("Failed to create window.");

if opts.fullscreen {
winit_window.set_decorations(false);
winit_window.set_inner_size(primary_monitor.size());
}
#[cfg(any(target_os = "linux", target_os = "windows"))]
{
let icon_bytes = include_bytes!("../../resources/servo_64.png");
winit_window.set_window_icon(Some(load_icon(icon_bytes)));
}

let primary_monitor = events_loop
.as_winit()
.available_monitors()
.nth(0)
.expect("No monitor detected");

let screen_size = winit_size_to_euclid_size(primary_monitor.size());
let inner_size = winit_size_to_euclid_size(winit_window.inner_size());

Expand All @@ -139,7 +142,7 @@ impl Window {
.expect("Failed to create WR surfman");

debug!("Created window {:?}", winit_window.id());
Window {
let window = Window {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is needed?

winit_window,
webrender_surfman,
event_queue: RefCell::new(vec![]),
Expand All @@ -157,7 +160,8 @@ impl Window {
xr_window_poses: RefCell::new(vec![]),
modifiers_state: Cell::new(ModifiersState::empty()),
toolbar_height: Cell::new(Default::default()),
}
};
window
}

fn handle_received_character(&self, mut ch: char) {
Expand Down