1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
mod dbus_ext;
mod dbus_interface;
mod freedesktop;
pub mod menu;
mod service;
mod tray;
pub use menu::{MenuItem, TextDirection};
pub use service::TrayService;
pub use tray::{Category, Icon, Status, ToolTip};
pub trait Tray: Sized {
/// Asks the status notifier item for activation, this is typically a
/// consequence of user input, such as mouse left click over the graphical
/// representation of the item.
/// The application will perform any task is considered appropriate as an
/// activation request.
///
/// the x and y parameters are in screen coordinates and is to be considered
/// an hint to the item where to show eventual windows (if any).
fn activate(&mut self, _x: i32, _y: i32) {}
/// Is to be considered a secondary and less important form of activation
/// compared to Activate.
/// This is typically a consequence of user input, such as mouse middle
/// click over the graphical representation of the item.
/// The application will perform any task is considered appropriate as an
/// activation request.
///
/// the x and y parameters are in screen coordinates and is to be considered
/// an hint to the item where to show eventual windows (if any).
fn secondary_activate(&mut self, _x: i32, _y: i32) {}
/// The user asked for a scroll action. This is caused from input such as
/// mouse wheel over the graphical representation of the item.
///
/// The delta parameter represent the amount of scroll, the orientation
/// parameter represent the horizontal or vertical orientation of the scroll
/// request and its legal values are horizontal and vertical.
fn scroll(&mut self, _delta: i32, _dir: &str) {}
/// Describes the category of this item.
fn category(&self) -> Category {
tray::Category::ApplicationStatus
}
/// It's a name that should be unique for this application and consistent
/// between sessions, such as the application name itself.
fn id(&self) -> String {
Default::default()
}
/// It's a name that describes the application, it can be more descriptive
/// than Id.
fn title(&self) -> String {
Default::default()
}
/// Describes the status of this item or of the associated application.
fn status(&self) -> Status {
tray::Status::Active
}
// NOTE: u32 in org.freedesktop.StatusNotifierItem
/// It's the windowing-system dependent identifier for a window, the
/// application can chose one of its windows to be available through this
/// property or just set 0 if it's not interested.
fn window_id(&self) -> i32 {
0
}
/// An additional path to add to the theme search path to find the icons.
fn icon_theme_path(&self) -> String {
Default::default()
}
/// The item only support the context menu, the visualization
/// should prefer showing the menu or sending ContextMenu()
/// instead of Activate()
// fn item_is_menu() -> bool { false }
/// The StatusNotifierItem can carry an icon that can be used by the
/// visualization to identify the item.
fn icon_name(&self) -> String {
Default::default()
}
/// Carries an ARGB32 binary representation of the icon
fn icon_pixmap(&self) -> Vec<Icon> {
Default::default()
}
/// The Freedesktop-compliant name of an icon. This can be used by the
/// visualization to indicate extra state information, for instance as an
/// overlay for the main icon.
fn overlay_icon_name(&self) -> String {
Default::default()
}
/// ARGB32 binary representation of the overlay icon described in the
/// previous paragraph.
fn overlay_icon_pixmap(&self) -> Vec<Icon> {
Default::default()
}
/// The Freedesktop-compliant name of an icon. this can be used by the
/// visualization to indicate that the item is in RequestingAttention state.
fn attention_icon_name(&self) -> String {
Default::default()
}
/// ARGB32 binary representation of the requesting attention icon describe in
/// the previous paragraph.
fn attention_icon_pixmap(&self) -> Vec<Icon> {
Default::default()
}
/// An item can also specify an animation associated to the
/// RequestingAttention state.
/// This should be either a Freedesktop-compliant icon name or a full path.
/// The visualization can chose between the movie or AttentionIconPixmap (or
/// using neither of those) at its discretion.
fn attention_movie_name(&self) -> String {
Default::default()
}
/// Data structure that describes extra information associated to this item,
/// that can be visualized for instance by a tooltip (or by any other mean
/// the visualization consider appropriate.
fn tool_tip(&self) -> ToolTip {
Default::default()
}
/// Represents the way the text direction of the application. This
/// allows the server to handle mismatches intelligently.
fn text_direction(&self) -> TextDirection {
menu::TextDirection::LeftToRight
}
fn menu(&self) -> Vec<MenuItem<Self>> {
Default::default()
}
}
pub struct State<T: ?Sized> {
state_changed: Arc<AtomicBool>,
inner: Arc<Mutex<T>>,
}
impl<T: Tray> State<T> {
pub fn update<F: Fn(&mut T)>(&self, f: F) {
{
let mut inner = self.inner.lock().unwrap();
(f)(&mut inner);
}
self.state_changed.store(true, Ordering::Release);
}
}
impl<T> Clone for State<T> {
fn clone(&self) -> Self {
State {
state_changed: self.state_changed.clone(),
inner: self.inner.clone(),
}
}
}