Implement the animation
This commit is contained in:
parent
02fb54aac4
commit
66871b07a9
|
@ -443,6 +443,7 @@ dependencies = [
|
|||
name = "parrotd"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"glib",
|
||||
"gtk",
|
||||
"libappindicator",
|
||||
]
|
||||
|
|
|
@ -8,3 +8,4 @@ edition = "2021"
|
|||
[dependencies]
|
||||
libappindicator = "0.7"
|
||||
gtk = "0.15"
|
||||
glib = "0.15"
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -7,13 +7,11 @@ pub use err::*;
|
|||
use libappindicator::*;
|
||||
use gtk::prelude::*;
|
||||
use pack::*;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn main() {
|
||||
gtk::init().unwrap();
|
||||
let mut icon_pack = IconPack::new("./res", "parrot", PackVariant::Dark).unwrap();
|
||||
fn init_indicator(icon_pack: &IconPack) -> AppIndicator {
|
||||
let mut indicator = AppIndicator::new("parrotd", "");
|
||||
indicator.set_icon_theme_path(icon_pack.pack_path());
|
||||
indicator.set_icon_full(icon_pack.next_icon_path(), "parrotd");
|
||||
indicator.set_status(AppIndicatorStatus::Active);
|
||||
let mut m = gtk::Menu::new();
|
||||
let mi = gtk::CheckMenuItem::with_label("I'm a parrot");
|
||||
|
@ -23,5 +21,25 @@ fn main() {
|
|||
m.append(&mi);
|
||||
indicator.set_menu(&mut m);
|
||||
m.show_all();
|
||||
return indicator;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
gtk::init().unwrap();
|
||||
|
||||
let mut icon_pack = IconPack::new("./res", "parrot", PackVariant::Dark).unwrap();
|
||||
let mut indicator = init_indicator(&icon_pack);
|
||||
|
||||
// Animation task
|
||||
let mut last_update = Instant::now();
|
||||
glib::timeout_add_local(Duration::from_millis(1000 / 60) /* maximum 60Hz */, move || {
|
||||
let now = Instant::now();
|
||||
if now - last_update >= Duration::from_millis(100) {
|
||||
indicator.set_icon(icon_pack.next_icon_path());
|
||||
last_update = now;
|
||||
}
|
||||
Continue(true)
|
||||
});
|
||||
|
||||
gtk::main();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue