Skip to content

Commit

Permalink
Allow changing initial zoom level through cli (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master authored Nov 20, 2024
1 parent 5356411 commit 67c6d70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct CliArgs {
pub resource_dir: Option<PathBuf>,
/// Override the user agent
pub user_agent: Option<String>,
/// Initial window's zoom level
pub zoom_level: Option<f32>,
}

/// Configuration of Verso instance.
Expand Down Expand Up @@ -130,6 +132,8 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
"Launch the initial window without maximized",
);

opts.optopt("", "zoom", "Initial window's zoom level", "1.5");

let matches: getopts::Matches = opts.parse(&args[1..])?;
let url = matches
.opt_str("url")
Expand Down Expand Up @@ -219,6 +223,11 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
window_attributes = window_attributes.with_maximized(true);
}

let zoom_level = matches.opt_get::<f32>("zoom").unwrap_or_else(|e| {
log::error!("Failed to parse zoom command line argument: {e}");
None
});

Ok(CliArgs {
url,
resource_dir,
Expand All @@ -228,6 +237,7 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
devtools_port,
profiler_settings,
user_agent,
zoom_level,
})
}

Expand Down
7 changes: 6 additions & 1 deletion src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl Verso {
.clone()
.unwrap_or_else(|| default_user_agent_string().to_string())
.into();
let zoom_level = config.args.zoom_level;

config.init();
// Reserving a namespace to create TopLevelBrowsingContextId.
Expand Down Expand Up @@ -360,7 +361,7 @@ impl Verso {

// The compositor coordinates with the client window to create the final
// rendered page and display it somewhere.
let compositor = IOCompositor::new(
let mut compositor = IOCompositor::new(
window.id(),
window.size(),
Scale::new(window.scale_factor() as f32),
Expand All @@ -380,6 +381,10 @@ impl Verso {
opts.debug.convert_mouse_to_touch,
);

if let Some(zoom_level) = zoom_level {
compositor.on_zoom_window_event(zoom_level, &window);
}

if with_panel {
window.create_panel(&constellation_sender, initial_url);
} else if let Some(initial_url) = initial_url {
Expand Down

0 comments on commit 67c6d70

Please sign in to comment.