@@ -107,13 +107,20 @@ impl<R: Runtime> WindowExt for Window<R> {
107107 } ,
108108 #[ cfg( feature = "system-tray" ) ]
109109 TrayLeft => {
110- if let Some ( ( tray_x, tray_y) ) = tray_position {
111- PhysicalPosition {
112- x : tray_x,
113- y : tray_y - window_size. height ,
114- }
110+ if let ( Some ( ( tray_x, tray_y) ) , Some ( ( _, _tray_height) ) ) =
111+ ( tray_position, tray_size)
112+ {
113+ let y = tray_y - window_size. height ;
114+ // Choose y value based on the target OS
115+ #[ cfg( target_os = "windows" ) ]
116+ let y = if y < 0 { tray_y + _tray_height } else { y } ;
117+
118+ #[ cfg( target_os = "macos" ) ]
119+ let y = if y < 0 { tray_y } else { y } ;
120+
121+ PhysicalPosition { x : tray_x, y }
115122 } else {
116- panic ! ( "tray position not set" ) ;
123+ panic ! ( "Tray position not set" ) ;
117124 }
118125 }
119126 #[ cfg( feature = "system-tray" ) ]
@@ -129,11 +136,20 @@ impl<R: Runtime> WindowExt for Window<R> {
129136 }
130137 #[ cfg( feature = "system-tray" ) ]
131138 TrayRight => {
132- if let ( Some ( ( tray_x, tray_y) ) , Some ( ( tray_width, _) ) ) = ( tray_position, tray_size)
139+ if let ( Some ( ( tray_x, tray_y) ) , Some ( ( tray_width, _tray_height) ) ) =
140+ ( tray_position, tray_size)
133141 {
142+ let y = tray_y - window_size. height ;
143+ // Choose y value based on the target OS
144+ #[ cfg( target_os = "windows" ) ]
145+ let y = if y < 0 { tray_y + _tray_height } else { y } ;
146+
147+ #[ cfg( target_os = "macos" ) ]
148+ let y = if y < 0 { tray_y } else { y } ;
149+
134150 PhysicalPosition {
135151 x : tray_x + tray_width,
136- y : tray_y - window_size . height ,
152+ y,
137153 }
138154 } else {
139155 panic ! ( "Tray position not set" ) ;
@@ -153,12 +169,19 @@ impl<R: Runtime> WindowExt for Window<R> {
153169 }
154170 #[ cfg( feature = "system-tray" ) ]
155171 TrayCenter => {
156- if let ( Some ( ( tray_x, tray_y) ) , Some ( ( tray_width, _) ) ) = ( tray_position, tray_size)
172+ if let ( Some ( ( tray_x, tray_y) ) , Some ( ( tray_width, _tray_height) ) ) =
173+ ( tray_position, tray_size)
157174 {
158- PhysicalPosition {
159- x : tray_x + ( tray_width / 2 ) - ( window_size. width / 2 ) ,
160- y : tray_y - window_size. height ,
161- }
175+ let x = tray_x + tray_width / 2 - window_size. width / 2 ;
176+ let y = tray_y - window_size. height ;
177+ // Choose y value based on the target OS
178+ #[ cfg( target_os = "windows" ) ]
179+ let y = if y < 0 { tray_y + _tray_height } else { y } ;
180+
181+ #[ cfg( target_os = "macos" ) ]
182+ let y = if y < 0 { tray_y } else { y } ;
183+
184+ PhysicalPosition { x, y }
162185 } else {
163186 panic ! ( "Tray position not set" ) ;
164187 }
0 commit comments