@@ -5,6 +5,7 @@ use caw_viz_udp_app_lib::{
55 blink,
66 oscilloscope:: { self , OscilloscopeStyle } ,
77} ;
8+ use caw_window_utils:: persisten_window_position;
89use clap:: { Parser , Subcommand , ValueEnum } ;
910use lazy_static:: lazy_static;
1011use line_2d:: Coord ;
@@ -85,11 +86,11 @@ struct BlinkCommand {
8586 width : u32 ,
8687 #[ arg( long, default_value_t = 100 ) ]
8788 height : u32 ,
88- #[ arg( long, short, default_value_t = 0 ) ]
89+ #[ arg( long, short, default_value_t = 127 ) ]
8990 red : u8 ,
9091 #[ arg( long, short, default_value_t = 127 ) ]
9192 green : u8 ,
92- #[ arg( long, short, default_value_t = 0 ) ]
93+ #[ arg( long, short, default_value_t = 127 ) ]
9394 blue : u8 ,
9495}
9596
@@ -141,9 +142,25 @@ struct App {
141142 server : String ,
142143 canvas : Canvas < Window > ,
143144 event_pump : EventPump ,
145+ title : String ,
144146}
145147
146148impl App {
149+ fn handle_event_common ( event : Event , title : & str ) {
150+ match event {
151+ Event :: Quit { .. } => std:: process:: exit ( 0 ) ,
152+ Event :: Window {
153+ win_event : WindowEvent :: Moved ( x, y) ,
154+ ..
155+ } => {
156+ if let Err ( e) = persisten_window_position:: save ( title, x, y) {
157+ log:: warn!( "{}" , e) ;
158+ }
159+ }
160+ _ => ( ) ,
161+ }
162+ }
163+
147164 fn run_oscilloscope (
148165 mut self ,
149166 mut args : OscilloscopeCommand ,
@@ -152,8 +169,8 @@ impl App {
152169 let mut scope_state = ScopeState :: default ( ) ;
153170 loop {
154171 for event in self . event_pump . poll_iter ( ) {
172+ Self :: handle_event_common ( event. clone ( ) , self . title . as_str ( ) ) ;
155173 match event {
156- Event :: Quit { .. } => std:: process:: exit ( 0 ) ,
157174 Event :: MouseWheel { y, .. } => {
158175 let ratio = 1.1 ;
159176 if y > 0 {
@@ -381,10 +398,7 @@ impl App {
381398 let mut prev_mean = 0.0 ;
382399 loop {
383400 for event in self . event_pump . poll_iter ( ) {
384- match event {
385- Event :: Quit { .. } => std:: process:: exit ( 0 ) ,
386- _ => ( ) ,
387- }
401+ Self :: handle_event_common ( event. clone ( ) , self . title . as_str ( ) ) ;
388402 }
389403 let mut total = 0.0 ;
390404 let mut count = 0 ;
@@ -433,17 +447,30 @@ fn main() -> anyhow::Result<()> {
433447 } = Cli :: parse ( ) ;
434448 let sdl_context = sdl2:: init ( ) . map_err ( |e| anyhow ! ( e) ) ?;
435449 let video_subsystem = sdl_context. video ( ) . map_err ( |e| anyhow ! ( e) ) ?;
436- let window = match command {
437- Command :: Oscilloscope ( _) => video_subsystem
438- . window ( title. as_str ( ) , command. width ( ) , command. height ( ) )
439- . always_on_top ( )
440- . resizable ( )
441- . build ( ) ?,
442- Command :: Blink ( _) => video_subsystem
443- . window ( "" , command. width ( ) , command. height ( ) )
444- . always_on_top ( )
445- . build ( ) ?,
450+ let mut window_builder = match command {
451+ Command :: Oscilloscope ( _) => {
452+ let mut wb = video_subsystem. window (
453+ title. as_str ( ) ,
454+ command. width ( ) ,
455+ command. height ( ) ,
456+ ) ;
457+ wb. resizable ( ) ;
458+ wb
459+ }
460+ Command :: Blink ( _) => {
461+ let mut wb =
462+ video_subsystem. window ( "" , command. width ( ) , command. height ( ) ) ;
463+ wb. always_on_top ( ) ;
464+ wb
465+ }
446466 } ;
467+ match persisten_window_position:: load ( & title) {
468+ Err ( e) => log:: warn!( "{}" , e) ,
469+ Ok ( ( x, y) ) => {
470+ window_builder. position ( x, y) ;
471+ }
472+ }
473+ let window = window_builder. build ( ) ?;
447474 let mut canvas = window
448475 . into_canvas ( )
449476 . target_texture ( )
@@ -455,6 +482,7 @@ fn main() -> anyhow::Result<()> {
455482 server,
456483 event_pump,
457484 canvas,
485+ title : title. clone ( ) ,
458486 } ;
459487 match command {
460488 Command :: Oscilloscope ( oscilloscope_command) => {
0 commit comments