diff --git a/src/config.rs b/src/config.rs index 4c731cf6..43a8ddf7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,7 @@ use net_traits::{ ResourceFetchTiming, }; use servo_config::opts::{default_opts, set_options, Opts}; +use winit::{dpi, window::WindowAttributes}; /// Command line arguments. #[derive(Clone, Debug, Default)] @@ -19,6 +20,8 @@ pub struct CliArgs { pub ipc_channel: Option, /// Should launch without control panel pub no_panel: bool, + /// Window settings for the initial winit window + pub window_attributes: WindowAttributes, } /// Configuration of Verso instance. @@ -45,6 +48,19 @@ fn parse_cli_args() -> Result { ); opts.optflag("", "no-panel", "Launch Verso without control panel"); + opts.optopt( + "w", + "width", + "Initial window's width in physical unit, the height command line arg much also be set", + "", + ); + opts.optopt( + "h", + "height", + "Initial window's height in physical unit, the width command line arg much also be set", + "", + ); + let matches: getopts::Matches = opts.parse(&args[1..])?; let url = matches .opt_str("url") @@ -63,10 +79,38 @@ fn parse_cli_args() -> Result { let ipc_channel = matches.opt_str("ipc-channel"); let no_panel = matches.opt_present("no-panel"); + let width = matches.opt_get::("width").unwrap_or_else(|e| { + log::error!("Failed to parse width command line argument: {e}"); + None + }); + let height = matches.opt_get::("height").unwrap_or_else(|e| { + log::error!("Failed to parse height command line argument: {e}"); + None + }); + + let size = match (width, height) { + (None, Some(_height)) => { + log::error!("Invalid size command line argument, height is present but not width"); + None + } + (Some(_width), None) => { + log::error!("Invalid size command line argument, width is present but not height"); + None + } + (Some(width), Some(height)) => Some(dpi::PhysicalSize::new(width, height)), + _ => None, + }; + let mut window_attributes = winit::window::Window::default_attributes(); + + if let Some(size) = size { + window_attributes = window_attributes.with_inner_size(size); + } + Ok(CliArgs { url, ipc_channel, no_panel, + window_attributes, }) } diff --git a/src/verso.rs b/src/verso.rs index d4182b35..595497ea 100644 --- a/src/verso.rs +++ b/src/verso.rs @@ -108,11 +108,12 @@ impl Verso { let protocols = config.create_protocols(); let initial_url = config.args.url.clone(); let with_panel = !config.args.no_panel; + let window_settings = config.args.window_attributes.clone(); config.init(); // Reserving a namespace to create TopLevelBrowsingContextId. PipelineNamespace::install(PipelineNamespaceId(0)); - let (mut window, rendering_context) = Window::new(evl); + let (mut window, rendering_context) = Window::new(evl, window_settings); let event_loop_waker = Box::new(Waker(proxy)); let opts = opts::get(); diff --git a/src/window.rs b/src/window.rs index cb679c1f..a76c17c3 100644 --- a/src/window.rs +++ b/src/window.rs @@ -23,7 +23,7 @@ use winit::{ event::{ElementState, TouchPhase, WindowEvent}, event_loop::ActiveEventLoop, keyboard::ModifiersState, - window::{CursorIcon, Window as WinitWindow, WindowId}, + window::{CursorIcon, Window as WinitWindow, WindowAttributes, WindowId}, }; use crate::{ @@ -56,8 +56,11 @@ pub struct Window { impl Window { /// Create a Verso window from Winit window and return the rendering context. - pub fn new(evl: &ActiveEventLoop) -> (Self, RenderingContext) { - let window_attributes = WinitWindow::default_attributes() + pub fn new( + evl: &ActiveEventLoop, + window_attributes: WindowAttributes, + ) -> (Self, RenderingContext) { + let window_attributes = window_attributes .with_transparent(true) .with_decorations(false);