@@ -94,6 +94,7 @@ pub enum UIEvent {
9494
9595 Update ( UIUpdateEvent ) ,
9696 ConnectionDlg ( ConnectionDlgEvent ) ,
97+ ReFrontAll ( WindowId ) ,
9798}
9899
99100#[ derive( Debug , Clone ) ]
@@ -168,9 +169,10 @@ struct WindowEdges {
168169 height : i32 ,
169170
170171 shown : bool ,
172+ wants_front : bool ,
171173}
172174impl WindowEdges {
173- fn update ( & mut self , win : & DoubleWindow ) {
175+ fn update ( & mut self , win : & mut DoubleWindow ) {
174176 self . left = win. x ( ) ;
175177 self . right = win. x ( ) + win. width ( ) ;
176178 self . top = win. y ( ) ;
@@ -179,20 +181,32 @@ impl WindowEdges {
179181 self . width = win. width ( ) ;
180182 self . height = win. height ( ) ;
181183
182- self . shown = win. visible ( ) ;
184+ self . shown = win. shown ( ) ;
185+ if self . wants_front && self . shown {
186+ win. show ( ) ;
187+ self . wants_front = false ;
188+ }
183189 }
184190}
185191
186192#[ derive( Default ) ]
187193struct AllWindowEdges ( [ WindowEdges ; 3 ] ) ;
188194impl AllWindowEdges {
189- fn update_window ( & mut self , id : WindowId , win : & DoubleWindow ) {
195+ fn update_window ( & mut self , id : WindowId , win : & mut DoubleWindow ) {
190196 self . 0 [ id as usize ] . update ( win) ;
191197 }
198+ fn front ( & mut self , id : WindowId ) {
199+ self . 0 [ id as usize ] . wants_front = true ;
200+ }
201+ fn front_all ( & mut self ) {
202+ for w in & mut self . 0 {
203+ w. wants_front = w. shown ;
204+ }
205+ }
192206}
193207
194- #[ derive( Clone , Copy ) ]
195- enum WindowId {
208+ #[ derive( Clone , Copy , PartialEq , Debug ) ]
209+ pub enum WindowId {
196210 Main = 0 ,
197211 Queue = 1 ,
198212 Connection = 2 ,
@@ -284,9 +298,9 @@ impl UIThread {
284298 }
285299
286300 let mut edges_state = AllWindowEdges :: default ( ) ;
287- edges_state. update_window ( WindowId :: Main , & self . gui . main_win ) ;
288- edges_state. update_window ( WindowId :: Queue , & self . queue_gui . main_win ) ;
289- edges_state. update_window ( WindowId :: Connection , & self . connection_gui . main_win ) ;
301+ edges_state. update_window ( WindowId :: Main , & mut self . gui . main_win ) ;
302+ edges_state. update_window ( WindowId :: Queue , & mut self . queue_gui . main_win ) ;
303+ edges_state. update_window ( WindowId :: Connection , & mut self . connection_gui . main_win ) ;
290304
291305 let e = Arc :: new ( RwLock :: new ( edges_state) ) ;
292306
@@ -368,26 +382,26 @@ impl UIThread {
368382 . unwrap ( ) ;
369383 edges_state
370384 . blocking_write ( )
371- . update_window ( WindowId :: Connection , & self . connection_gui . main_win ) ;
385+ . update_window ( WindowId :: Connection , & mut self . connection_gui . main_win ) ;
372386 }
373387 UIEvent :: BtnQueue => {
374388 self . queue_gui . main_win . show ( ) ;
375389 //ui_tx.send(UIEvent::Update(UIUpdateEvent::UpdateQueue(self.queue.clone())));
376390 edges_state
377391 . blocking_write ( )
378- . update_window ( WindowId :: Main , & self . queue_gui . main_win ) ;
392+ . update_window ( WindowId :: Main , & mut self . queue_gui . main_win ) ;
379393 }
380394 UIEvent :: HideQueue => {
381395 self . queue_gui . main_win . hide ( ) ;
382396 edges_state
383397 . blocking_write ( )
384- . update_window ( WindowId :: Queue , & self . queue_gui . main_win ) ;
398+ . update_window ( WindowId :: Queue , & mut self . queue_gui . main_win ) ;
385399 }
386400 UIEvent :: HideConnectionWindow => {
387401 self . connection_gui . main_win . hide ( ) ;
388402 edges_state
389403 . blocking_write ( )
390- . update_window ( WindowId :: Connection , & self . connection_gui . main_win ) ;
404+ . update_window ( WindowId :: Connection , & mut self . connection_gui . main_win ) ;
391405 }
392406 UIEvent :: ShowPrefsWindow => {
393407 self . prefs_gui . main_win . show ( ) ;
@@ -401,6 +415,30 @@ impl UIThread {
401415 UIEvent :: SwitchPrefsPage ( path) => {
402416 self . prefs_gui . switch_page ( & path) ;
403417 }
418+ UIEvent :: ReFrontAll ( from_id) => {
419+ let mut es = edges_state. blocking_write ( ) ;
420+ let all_ids = vec ! [
421+ ( WindowId :: Queue , & mut self . queue_gui. main_win) ,
422+ ( WindowId :: Connection , & mut self . connection_gui. main_win) ,
423+ ( WindowId :: Main , & mut self . gui. main_win) ,
424+ ] ;
425+ {
426+ let non_last_ids = all_ids. into_iter ( ) . filter ( |x| x. 0 != from_id) ;
427+
428+ for ( id, win) in non_last_ids {
429+ es. update_window ( id, win) ;
430+ }
431+ }
432+ // and then
433+ let all_ids = vec ! [
434+ ( WindowId :: Queue , & mut self . queue_gui. main_win) ,
435+ ( WindowId :: Connection , & mut self . connection_gui. main_win) ,
436+ ( WindowId :: Main , & mut self . gui. main_win) ,
437+ ] ;
438+ let ( last_id, last_win) =
439+ all_ids. into_iter ( ) . find ( |x| x. 0 == from_id) . unwrap ( ) ;
440+ es. update_window ( last_id, last_win) ;
441+ }
404442 UIEvent :: Quit => break ,
405443 _ => { }
406444 }
@@ -666,6 +704,12 @@ fn handle_window_drag(
666704 state. x = coords. 0 ;
667705 state. y = coords. 1 ;
668706
707+ if let Some ( id) = state. id {
708+ edges. blocking_write ( ) . front_all ( ) ;
709+ ui_send ! ( UIEvent :: ReFrontAll ( id) ) ;
710+ // bwehh i know.. sending ui events from a handler.. but how else do i get out of here
711+ }
712+
669713 true
670714 }
671715 fltk:: enums:: Event :: Drag => {
@@ -801,6 +845,7 @@ fn handle_window_drag(
801845 if let Some ( id) = state. id {
802846 let mut edges = edges. blocking_write ( ) ;
803847 edges. update_window ( id, w) ;
848+ edges. front ( id) ; // single front on drag seems to be needed for edge cases that idk
804849 }
805850
806851 true
0 commit comments