@@ -123,12 +123,12 @@ pub enum ConnectionDlgEvent {
123123
124124#[ derive( Default ) ]
125125struct DragState {
126- id : Option < usize > ,
126+ id : Option < WindowId > ,
127127 x : i32 ,
128128 y : i32 ,
129129}
130130impl DragState {
131- fn with_id ( mut self , id : usize ) -> Self {
131+ fn with_id ( mut self , id : WindowId ) -> Self {
132132 self . id = Some ( id) ;
133133 self
134134 }
@@ -185,11 +185,18 @@ impl WindowEdges {
185185#[ derive( Default ) ]
186186struct AllWindowEdges ( [ WindowEdges ; 3 ] ) ;
187187impl AllWindowEdges {
188- fn update_window ( & mut self , id : usize , win : & DoubleWindow ) {
189- self . 0 [ id] . update ( win) ;
188+ fn update_window ( & mut self , id : WindowId , win : & DoubleWindow ) {
189+ self . 0 [ id as usize ] . update ( win) ;
190190 }
191191}
192192
193+ #[ derive( Clone , Copy ) ]
194+ enum WindowId {
195+ Main = 0 ,
196+ Queue = 1 ,
197+ Connection = 2 ,
198+ }
199+
193200impl UIThread {
194201 pub fn spawn ( state : Arc < RwLock < State > > ) -> mpsc:: UnboundedReceiver < UIEvent > {
195202 // from anywhere to ui (including ui to ui..?)
@@ -255,7 +262,7 @@ impl UIThread {
255262 fn handle_window (
256263 win : & mut DoubleWindow ,
257264 modal : bool ,
258- maybe_id : Option < usize > ,
265+ maybe_id : Option < WindowId > ,
259266 e : Arc < RwLock < AllWindowEdges > > ,
260267 ) {
261268 let mut drag_state = DragState :: default ( ) ;
@@ -276,15 +283,30 @@ impl UIThread {
276283 }
277284
278285 let mut edges_state = AllWindowEdges :: default ( ) ;
279- edges_state. update_window ( 0 , & self . gui . main_win ) ;
280- edges_state. update_window ( 1 , & self . queue_gui . main_win ) ;
281- edges_state. update_window ( 2 , & self . connection_gui . main_win ) ;
286+ edges_state. update_window ( WindowId :: Main , & self . gui . main_win ) ;
287+ edges_state. update_window ( WindowId :: Queue , & self . queue_gui . main_win ) ;
288+ edges_state. update_window ( WindowId :: Connection , & self . connection_gui . main_win ) ;
282289
283290 let e = Arc :: new ( RwLock :: new ( edges_state) ) ;
284291
285- handle_window ( & mut self . gui . main_win , false , Some ( 0 ) , e. clone ( ) ) ;
286- handle_window ( & mut self . queue_gui . main_win , false , Some ( 1 ) , e. clone ( ) ) ;
287- handle_window ( & mut self . connection_gui . main_win , false , Some ( 2 ) , e. clone ( ) ) ;
292+ handle_window (
293+ & mut self . gui . main_win ,
294+ false ,
295+ Some ( WindowId :: Main ) ,
296+ e. clone ( ) ,
297+ ) ;
298+ handle_window (
299+ & mut self . queue_gui . main_win ,
300+ false ,
301+ Some ( WindowId :: Queue ) ,
302+ e. clone ( ) ,
303+ ) ;
304+ handle_window (
305+ & mut self . connection_gui . main_win ,
306+ false ,
307+ Some ( WindowId :: Connection ) ,
308+ e. clone ( ) ,
309+ ) ;
288310 //handle_window(&mut self.prefs_gui.main_win, true, None, e.clone());
289311
290312 // i made the name short so it doesnt autoformat the lines above on to multiple lines
@@ -345,26 +367,26 @@ impl UIThread {
345367 . unwrap ( ) ;
346368 edges_state
347369 . blocking_write ( )
348- . update_window ( 2 , & self . connection_gui . main_win ) ;
370+ . update_window ( WindowId :: Connection , & self . connection_gui . main_win ) ;
349371 }
350372 UIEvent :: BtnQueue => {
351373 self . queue_gui . main_win . show ( ) ;
352374 //ui_tx.send(UIEvent::Update(UIUpdateEvent::UpdateQueue(self.queue.clone())));
353375 edges_state
354376 . blocking_write ( )
355- . update_window ( 1 , & self . queue_gui . main_win ) ;
377+ . update_window ( WindowId :: Main , & self . queue_gui . main_win ) ;
356378 }
357379 UIEvent :: HideQueue => {
358380 self . queue_gui . main_win . hide ( ) ;
359381 edges_state
360382 . blocking_write ( )
361- . update_window ( 1 , & self . queue_gui . main_win ) ;
383+ . update_window ( WindowId :: Queue , & self . queue_gui . main_win ) ;
362384 }
363385 UIEvent :: HideConnectionWindow => {
364386 self . connection_gui . main_win . hide ( ) ;
365387 edges_state
366388 . blocking_write ( )
367- . update_window ( 2 , & self . connection_gui . main_win ) ;
389+ . update_window ( WindowId :: Connection , & self . connection_gui . main_win ) ;
368390 }
369391 UIEvent :: ShowPrefsWindow => {
370392 self . prefs_gui . main_win . show ( ) ;
@@ -666,7 +688,7 @@ fn handle_window_drag(
666688 . iter ( )
667689 . enumerate ( )
668690 // don't snap to ourself
669- . filter_map ( |( i, o) | if i == id { None } else { Some ( o) } )
691+ . filter_map ( |( i, o) | if i == id as usize { None } else { Some ( o) } )
670692 // don't snap to non-visible windows
671693 . filter ( |e| e. shown ) ;
672694
0 commit comments