window icon

This commit is contained in:
Dongdong Zhou 2022-05-20 13:50:53 +01:00
parent 4f697e4aaa
commit dea7cac564
3 changed files with 216 additions and 8 deletions

191
Cargo.lock generated
View File

@ -188,6 +188,12 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb"
[[package]]
name = "bit_field"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -765,7 +771,7 @@ dependencies = [
[[package]] [[package]]
name = "druid" name = "druid"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/lapce/druid?branch=shell_opengl#e4ddc00f428d88b5e5845c29750903d9f8815773" source = "git+https://github.com/lapce/druid?branch=shell_opengl#fda8c4dcd7244dcffc3b0a7e39b12f5115d32de0"
dependencies = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"druid-derive", "druid-derive",
@ -788,7 +794,7 @@ dependencies = [
[[package]] [[package]]
name = "druid-derive" name = "druid-derive"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/lapce/druid?branch=shell_opengl#e4ddc00f428d88b5e5845c29750903d9f8815773" source = "git+https://github.com/lapce/druid?branch=shell_opengl#fda8c4dcd7244dcffc3b0a7e39b12f5115d32de0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -798,7 +804,7 @@ dependencies = [
[[package]] [[package]]
name = "druid-shell" name = "druid-shell"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/lapce/druid?branch=shell_opengl#e4ddc00f428d88b5e5845c29750903d9f8815773" source = "git+https://github.com/lapce/druid?branch=shell_opengl#fda8c4dcd7244dcffc3b0a7e39b12f5115d32de0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bitflags", "bitflags",
@ -810,6 +816,7 @@ dependencies = [
"core-foundation", "core-foundation",
"core-graphics", "core-graphics",
"foreign-types", "foreign-types",
"gdk-pixbuf",
"gdk-sys", "gdk-sys",
"gl_loader", "gl_loader",
"glib-sys", "glib-sys",
@ -904,6 +911,22 @@ dependencies = [
"num-traits 0.2.14", "num-traits 0.2.14",
] ]
[[package]]
name = "exr"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14cc0e06fb5f67e5d6beadf3a382fec9baca1aa751c6d5368fdeee7e5932c215"
dependencies = [
"bit_field",
"deflate",
"flume",
"half",
"inflate",
"lebe",
"smallvec",
"threadpool",
]
[[package]] [[package]]
name = "fallible-iterator" name = "fallible-iterator"
version = "0.2.0" version = "0.2.0"
@ -1029,6 +1052,19 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "flume"
version = "0.10.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a"
dependencies = [
"futures-core",
"futures-sink",
"nanorand",
"pin-project",
"spin 0.9.3",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -1233,6 +1269,12 @@ version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "futures-sink"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
[[package]] [[package]]
name = "futures-task" name = "futures-task"
version = "0.3.21" version = "0.3.21"
@ -1358,13 +1400,15 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.3" version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"js-sys",
"libc", "libc",
"wasi 0.10.0+wasi-snapshot-preview1", "wasi 0.10.0+wasi-snapshot-preview1",
"wasm-bindgen",
] ]
[[package]] [[package]]
@ -1653,6 +1697,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "half"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.11.2" version = "0.11.2"
@ -1755,6 +1805,26 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "image"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28edd9d7bc256be2502e325ac0628bde30b7001b9b52e0abe31a1a9dc2701212"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"exr",
"gif",
"jpeg-decoder",
"num-iter",
"num-rational",
"num-traits 0.2.14",
"png",
"scoped_threadpool",
"tiff",
]
[[package]] [[package]]
name = "include_dir" name = "include_dir"
version = "0.6.1" version = "0.6.1"
@ -1790,6 +1860,15 @@ dependencies = [
"serde 1.0.130", "serde 1.0.130",
] ]
[[package]]
name = "inflate"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff"
dependencies = [
"adler32",
]
[[package]] [[package]]
name = "inotify" name = "inotify"
version = "0.7.1" version = "0.7.1"
@ -1891,6 +1970,9 @@ name = "jpeg-decoder"
version = "0.2.4" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "744c24117572563a98a7e9168a5ac1ee4a1ca7f702211258797bbe0ed0346c3c" checksum = "744c24117572563a98a7e9168a5ac1ee4a1ca7f702211258797bbe0ed0346c3c"
dependencies = [
"rayon",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
@ -2134,6 +2216,7 @@ dependencies = [
"fuzzy-matcher", "fuzzy-matcher",
"hashbrown", "hashbrown",
"im", "im",
"image",
"include_dir", "include_dir",
"indexmap", "indexmap",
"itertools", "itertools",
@ -2180,6 +2263,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "lebe"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7efd1d698db0759e6ef11a7cd44407407399a910c774dd804c64c032da7826ff"
[[package]] [[package]]
name = "lexical-core" name = "lexical-core"
version = "0.7.6" version = "0.7.6"
@ -2553,6 +2642,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389"
[[package]]
name = "nanorand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "net2" name = "net2"
version = "0.2.37" version = "0.2.37"
@ -2644,6 +2742,28 @@ dependencies = [
"num-traits 0.2.14", "num-traits 0.2.14",
] ]
[[package]]
name = "num-iter"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.14",
]
[[package]]
name = "num-rational"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.14",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.1.43" version = "0.1.43"
@ -2940,6 +3060,26 @@ dependencies = [
"usvg 0.22.0", "usvg 0.22.0",
] ]
[[package]]
name = "pin-project"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.7" version = "0.2.7"
@ -3234,7 +3374,7 @@ dependencies = [
"cc", "cc",
"libc", "libc",
"once_cell", "once_cell",
"spin", "spin 0.5.2",
"untrusted", "untrusted",
"web-sys", "web-sys",
"winapi 0.3.9", "winapi 0.3.9",
@ -3384,6 +3524,12 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "scoped_threadpool"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -3652,9 +3798,9 @@ dependencies = [
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.6.1" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]] [[package]]
name = "spin" name = "spin"
@ -3662,6 +3808,15 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d"
dependencies = [
"lock_api",
]
[[package]] [[package]]
name = "spsc-buffer" name = "spsc-buffer"
version = "0.1.1" version = "0.1.1"
@ -3919,6 +4074,26 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "threadpool"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
dependencies = [
"num_cpus",
]
[[package]]
name = "tiff"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cfada0986f446a770eca461e8c6566cb879682f7d687c8348aa0c857bd52286"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.1.44" version = "0.1.44"

View File

@ -5,6 +5,7 @@ authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2021" edition = "2021"
[dependencies] [dependencies]
image = "0.24"
chrono = "0.4.19" chrono = "0.4.19"
log = "0.4.14" log = "0.4.14"
fern = "0.6.0" fern = "0.6.0"

View File

@ -12,6 +12,9 @@
use crate::logging::override_log_levels; use crate::logging::override_log_levels;
use crate::window::LapceWindowNew; use crate::window::LapceWindowNew;
const LOGO_PNG: &[u8] = include_bytes!("../../extra/images/logo.png");
const LOGO_ICO: &[u8] = include_bytes!("../../extra/windows/lapce.ico");
pub fn build_window(data: &LapceWindowData) -> impl Widget<LapceData> { pub fn build_window(data: &LapceWindowData) -> impl Widget<LapceData> {
LapceWindowNew::new(data).lens(LapceWindowLens(data.window_id)) LapceWindowNew::new(data).lens(LapceWindowLens(data.window_id))
} }
@ -68,6 +71,10 @@ fn new_window_desc<W, T: druid::Data>(
.window_size(size) .window_size(size)
.set_position(pos); .set_position(pos);
if let Some(icon) = window_icon() {
desc = desc.with_window_icon(icon);
}
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
if true { if true {
desc = macos_window_desc(desc); desc = macos_window_desc(desc);
@ -76,6 +83,31 @@ fn new_window_desc<W, T: druid::Data>(
desc desc
} }
#[cfg(target_os = "macos")]
fn window_icon() -> Option<druid::Icon> {
None
}
#[cfg(target_os = "linux")]
fn window_icon() -> Option<druid::Icon> {
let image = image::load_from_memory(LOGO_PNG)
.expect("Invalid Icon")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
Some(druid::Icon::from_rgba(rgba, width, height).expect("Failed to open icon"))
}
#[cfg(target_os = "windows")]
fn window_icon() -> Option<druid::Icon> {
let image = image::load_from_memory(LOGO_ICO)
.expect("Invalid Icon")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
Some(druid::Icon::from_rgba(rgba, width, height).expect("Failed to open icon"))
}
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn macos_window_desc<T: druid::Data>(desc: WindowDesc<T>) -> WindowDesc<T> { fn macos_window_desc<T: druid::Data>(desc: WindowDesc<T>) -> WindowDesc<T> {
desc.show_titlebar(false).menu(|_, _, _| { desc.show_titlebar(false).menu(|_, _, _| {