Hello here,
I'm using TrayItem object to display a systray application icon. It is working :
Cargo.toml
[package]
name = "demo"
version = "0.1.0"
edition = "2021"
[dependencies]
tray-item = "0.7.0"
gtk = "0.15.4"
main.rs
use tray_item::TrayItem;
fn main() {
gtk::init().unwrap();
let mut tray = TrayItem::new("Demo", "emblem-shared").unwrap();
tray.add_menu_item("Quitter", || {
gtk::main_quit();
})
.unwrap();
gtk::main();
}
My need is to change the systray icon during application running. But gtk::main();
line is blocking (doc).
So, I try to start a thread where I could manipulate tray
object :
let protected_tray = Arc::new(Mutex::new(tray));
let thread_tray = Arc::clone(&protected_tray);
thread::spawn(move || {
let mut tray__ = thread_tray.lock().unwrap();
tray__.set_icon("/path/to/my/icon.png").unwrap();
});
But this produce error :
Compiling demo v0.1.0 (/home/bastiensevajol/Projets/demo)
error[E0277]: `*mut libappindicator_sys::_AppIndicator` cannot be sent between threads safely
--> src/main.rs:18:5
|
18 | thread::spawn(move || {
| ^^^^^^^^^^^^^ `*mut libappindicator_sys::_AppIndicator` cannot be sent between threads safely
|
= help: within `TrayItem`, the trait `Send` is not implemented for `*mut libappindicator_sys::_AppIndicator`
= note: required because it appears within the type `libappindicator::AppIndicator`
= note: required because it appears within the type `tray_item::api::linux::TrayItemLinux`
= note: required because it appears within the type `TrayItem`
= note: required because of the requirements on the impl of `Sync` for `Mutex<TrayItem>`
= note: required because of the requirements on the impl of `Send` for `Arc<Mutex<TrayItem>>`
= note: required because it appears within the type `[closure@src/main.rs:18:19: 20:6]`
note: required by a bound in `spawn`
--> /home/bastiensevajol/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:646:8
|
646 | F: Send + 'static,
| ^^^^ required by this bound in `spawn`
error[E0277]: `NonNull<GObject>` cannot be sent between threads safely
--> src/main.rs:18:5
|
18 | thread::spawn(move || {
| ^^^^^^^^^^^^^ `NonNull<GObject>` cannot be sent between threads safely
|
= help: within `TrayItem`, the trait `Send` is not implemented for `NonNull<GObject>`
= note: required because it appears within the type `ObjectRef`
= note: required because it appears within the type `gtk::Menu`
= note: required because it appears within the type `tray_item::api::linux::TrayItemLinux`
= note: required because it appears within the type `TrayItem`
= note: required because of the requirements on the impl of `Sync` for `Mutex<TrayItem>`
= note: required because of the requirements on the impl of `Send` for `Arc<Mutex<TrayItem>>`
= note: required because it appears within the type `[closure@src/main.rs:18:19: 20:6]`
note: required by a bound in `spawn`
--> /home/bastiensevajol/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:646:8
|
646 | F: Send + 'static,
| ^^^^ required by this bound in `spawn`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `demo` due to 2 previous errors
Arc & Mutex are not a safe way to use object in threads ? My goal is possible to achieve ?
Thank you for reading me !