Implement the animation

This commit is contained in:
Peter Cai 2022-11-20 21:02:17 -05:00
parent 02fb54aac4
commit 66871b07a9
3 changed files with 24 additions and 4 deletions

1
Cargo.lock generated
View File

@ -443,6 +443,7 @@ dependencies = [
name = "parrotd"
version = "0.1.0"
dependencies = [
"glib",
"gtk",
"libappindicator",
]

View File

@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
libappindicator = "0.7"
gtk = "0.15"
glib = "0.15"

View File

@ -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();
}