Skip to content

Commit ce8db9d

Browse files
committed
Merge branch 'window-icon' into 'main'
Add support for setting initial window icon See merge request verso-browser/verso!325
2 parents 3aafa40 + bcd7a43 commit ce8db9d

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ impl Config {
323323
let mut window_attributes = winit::window::Window::default_attributes()
324324
.with_transparent(config.transparent)
325325
.with_decorations(config.decorated)
326-
.with_title(config.title.unwrap_or("Verso".to_owned()));
326+
.with_title(config.title.unwrap_or("Verso".to_owned()))
327+
.with_window_icon(config.icon.and_then(|icon| {
328+
winit::window::Icon::from_rgba(icon.rgba, icon.width, icon.height).ok()
329+
}));
327330
// set min inner size
328331
// should be at least able to show the whole control panel
329332
// FIXME: url input has weird behavior that will expand lager when having long text

verso/src/builder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ impl VersoBuilder {
7474
self
7575
}
7676

77+
/// Sets the window icon.
78+
pub fn icon(mut self, icon: versoview_messages::Icon) -> Self {
79+
self.0.icon = Some(icon);
80+
self
81+
}
82+
7783
/// Port number to start a server to listen to remote Firefox devtools connections. 0 for random port.
7884
pub fn devtools_port(mut self, port: u16) -> Self {
7985
self.0.devtools_port = Some(port);

verso/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use std::{
99
process::Command,
1010
sync::{Arc, Mutex, mpsc::Sender as MpscSender},
1111
};
12-
pub use versoview_messages::{ConfigFromController as VersoviewSettings, ProfilerSettings};
12+
pub use versoview_messages::{
13+
ConfigFromController as VersoviewSettings, Icon, ProfilerSettings, UserScript,
14+
};
1315
use versoview_messages::{
1416
PositionType, SizeType, ToControllerMessage, ToVersoMessage, WebResourceRequest,
1517
WebResourceRequestResponse,

versoview_messages/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ pub struct ConfigFromController {
136136
pub transparent: bool,
137137
/// Title of the initial winit window in the title bar.
138138
pub title: Option<String>,
139+
/// Window icon of the initial winit window.
140+
pub icon: Option<Icon>,
139141
/// Port number to start a server to listen to remote Firefox devtools connections. 0 for random port.
140142
pub devtools_port: Option<u16>,
141143
/// Servo time profile settings
@@ -164,6 +166,7 @@ impl Default for ConfigFromController {
164166
decorated: false,
165167
transparent: true,
166168
title: None,
169+
icon: None,
167170
fullscreen: false,
168171
devtools_port: None,
169172
profiler_settings: None,
@@ -175,6 +178,16 @@ impl Default for ConfigFromController {
175178
}
176179
}
177180

181+
#[derive(Clone, Debug, Deserialize, Serialize)]
182+
pub struct Icon {
183+
/// RGBA bytes of the icon.
184+
pub rgba: Vec<u8>,
185+
/// Icon width.
186+
pub width: u32,
187+
/// Icon height.
188+
pub height: u32,
189+
}
190+
178191
#[derive(Clone, Debug, Deserialize, Serialize)]
179192
pub struct UserScript {
180193
pub script: String,

0 commit comments

Comments
 (0)