@@ -19,69 +19,165 @@ use serde::Serialize;
19
19
use std:: path:: Path ;
20
20
pub use tray_icon:: TrayIconId ;
21
21
22
- /// Describes the click type that triggered this tray icon event .
22
+ /// Describes the mouse button state .
23
23
#[ derive( Clone , Copy , PartialEq , Eq , Debug , Serialize ) ]
24
- pub enum ClickType {
25
- /// Left mouse click.
24
+ pub enum MouseButtonState {
25
+ /// Mouse button pressed.
26
+ Up ,
27
+ /// Mouse button released.
28
+ Down ,
29
+ }
30
+
31
+ impl Default for MouseButtonState {
32
+ fn default ( ) -> Self {
33
+ Self :: Up
34
+ }
35
+ }
36
+
37
+ impl From < tray_icon:: MouseButtonState > for MouseButtonState {
38
+ fn from ( value : tray_icon:: MouseButtonState ) -> Self {
39
+ match value {
40
+ tray_icon:: MouseButtonState :: Up => MouseButtonState :: Up ,
41
+ tray_icon:: MouseButtonState :: Down => MouseButtonState :: Down ,
42
+ }
43
+ }
44
+ }
45
+
46
+ /// Describes which mouse button triggered the event..
47
+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Serialize ) ]
48
+ pub enum MouseButton {
49
+ /// Left mouse button.
26
50
Left ,
27
- /// Right mouse click .
51
+ /// Right mouse button .
28
52
Right ,
29
- /// Double left mouse click .
30
- Double ,
53
+ /// Middle mouse button .
54
+ Middle ,
31
55
}
32
56
33
- impl Default for ClickType {
57
+ impl Default for MouseButton {
34
58
fn default ( ) -> Self {
35
59
Self :: Left
36
60
}
37
61
}
38
62
39
- /// Describes a tray event emitted when a tray icon is clicked
63
+ impl From < tray_icon:: MouseButton > for MouseButton {
64
+ fn from ( value : tray_icon:: MouseButton ) -> Self {
65
+ match value {
66
+ tray_icon:: MouseButton :: Left => MouseButton :: Left ,
67
+ tray_icon:: MouseButton :: Right => MouseButton :: Right ,
68
+ tray_icon:: MouseButton :: Middle => MouseButton :: Middle ,
69
+ }
70
+ }
71
+ }
72
+
73
+ /// Describes a tray icon event.
40
74
///
41
75
/// ## Platform-specific:
42
76
///
43
- /// - **Linux**: Unsupported. The event is not emitted even though the icon is shown,
44
- /// the icon will still show a context menu on right click.
45
- #[ derive( Debug , Clone , Default , Serialize ) ]
77
+ /// - **Linux**: Unsupported. The event is not emmited even though the icon is shown
78
+ /// and will still show a context menu on right click.
79
+ #[ derive( Debug , Clone , Serialize ) ]
46
80
#[ serde( rename_all = "camelCase" ) ]
47
- pub struct TrayIconEvent {
48
- /// Id of the tray icon which triggered this event.
49
- pub id : TrayIconId ,
50
- /// Physical Position of the click the triggered this event.
51
- pub position : PhysicalPosition < f64 > ,
52
- /// Position and size of the tray icon
53
- pub icon_rect : Rect ,
54
- /// The click type that triggered this event.
55
- pub click_type : ClickType ,
81
+ #[ non_exhaustive]
82
+ pub enum TrayIconEvent {
83
+ /// A click happened on the tray icon.
84
+ Click {
85
+ /// Id of the tray icon which triggered this event.
86
+ id : TrayIconId ,
87
+ /// Physical Position of this event.
88
+ position : PhysicalPosition < f64 > ,
89
+ /// Position and size of the tray icon.
90
+ rect : Rect ,
91
+ /// Mouse button that triggered this event.
92
+ button : MouseButton ,
93
+ /// Mouse button state when this event was triggered.
94
+ button_state : MouseButtonState ,
95
+ } ,
96
+ /// The mouse entered the tray icon region.
97
+ Enter {
98
+ /// Id of the tray icon which triggered this event.
99
+ id : TrayIconId ,
100
+ /// Physical Position of this event.
101
+ position : PhysicalPosition < f64 > ,
102
+ /// Position and size of the tray icon.
103
+ rect : Rect ,
104
+ } ,
105
+ /// The mouse moved over the tray icon region.
106
+ Move {
107
+ /// Id of the tray icon which triggered this event.
108
+ id : TrayIconId ,
109
+ /// Physical Position of this event.
110
+ position : PhysicalPosition < f64 > ,
111
+ /// Position and size of the tray icon.
112
+ rect : Rect ,
113
+ } ,
114
+ /// The mouse left the tray icon region.
115
+ Leave {
116
+ /// Id of the tray icon which triggered this event.
117
+ id : TrayIconId ,
118
+ /// Physical Position of this event.
119
+ position : PhysicalPosition < f64 > ,
120
+ /// Position and size of the tray icon.
121
+ rect : Rect ,
122
+ } ,
56
123
}
57
124
58
125
impl TrayIconEvent {
59
- /// Returns the id of the tray icon which triggered this event.
126
+ /// Get the id of the tray icon that triggered this event.
60
127
pub fn id ( & self ) -> & TrayIconId {
61
- & self . id
62
- }
63
- }
64
-
65
- impl From < tray_icon:: ClickType > for ClickType {
66
- fn from ( value : tray_icon:: ClickType ) -> Self {
67
- match value {
68
- tray_icon:: ClickType :: Left => Self :: Left ,
69
- tray_icon:: ClickType :: Right => Self :: Right ,
70
- tray_icon:: ClickType :: Double => Self :: Double ,
128
+ match self {
129
+ TrayIconEvent :: Click { id, .. } => id,
130
+ TrayIconEvent :: Enter { id, .. } => id,
131
+ TrayIconEvent :: Move { id, .. } => id,
132
+ TrayIconEvent :: Leave { id, .. } => id,
71
133
}
72
134
}
73
135
}
74
136
75
137
impl From < tray_icon:: TrayIconEvent > for TrayIconEvent {
76
138
fn from ( value : tray_icon:: TrayIconEvent ) -> Self {
77
- Self {
78
- id : value. id ,
79
- position : value. position ,
80
- icon_rect : Rect {
81
- position : value. icon_rect . position . into ( ) ,
82
- size : value. icon_rect . size . into ( ) ,
139
+ match value {
140
+ tray_icon:: TrayIconEvent :: Click {
141
+ id,
142
+ position,
143
+ rect,
144
+ button,
145
+ button_state,
146
+ } => TrayIconEvent :: Click {
147
+ id,
148
+ position,
149
+ rect : Rect {
150
+ position : rect. position . into ( ) ,
151
+ size : rect. size . into ( ) ,
152
+ } ,
153
+ button : button. into ( ) ,
154
+ button_state : button_state. into ( ) ,
155
+ } ,
156
+ tray_icon:: TrayIconEvent :: Enter { id, position, rect } => TrayIconEvent :: Enter {
157
+ id,
158
+ position,
159
+ rect : Rect {
160
+ position : rect. position . into ( ) ,
161
+ size : rect. size . into ( ) ,
162
+ } ,
163
+ } ,
164
+ tray_icon:: TrayIconEvent :: Move { id, position, rect } => TrayIconEvent :: Move {
165
+ id,
166
+ position,
167
+ rect : Rect {
168
+ position : rect. position . into ( ) ,
169
+ size : rect. size . into ( ) ,
170
+ } ,
171
+ } ,
172
+ tray_icon:: TrayIconEvent :: Leave { id, position, rect } => TrayIconEvent :: Leave {
173
+ id,
174
+ position,
175
+ rect : Rect {
176
+ position : rect. position . into ( ) ,
177
+ size : rect. size . into ( ) ,
178
+ } ,
83
179
} ,
84
- click_type : value . click_type . into ( ) ,
180
+ _ => todo ! ( ) ,
85
181
}
86
182
}
87
183
}
0 commit comments