@@ -493,7 +493,11 @@ impl State {
493493 unsafe {
494494 debug ! ( "Loading settings." ) ;
495495
496- let global_timer = get_global_timer ( splits_path) ;
496+ let global_timer = get_global_timer (
497+ splits_path,
498+ #[ cfg( feature = "auto-splitting" ) ]
499+ & local_auto_splitter,
500+ ) ;
497501 global_timer
498502 . timer
499503 . auto_save
@@ -506,11 +510,6 @@ impl State {
506510 let texture = gs_texture_create ( width, height, GS_RGBA , 1 , ptr:: null_mut ( ) , GS_DYNAMIC ) ;
507511 obs_leave_graphics ( ) ;
508512
509- #[ cfg( feature = "auto-splitting" ) ]
510- if let Some ( local_auto_splitter) = & local_auto_splitter {
511- auto_splitter_load ( & global_timer, local_auto_splitter. clone ( ) )
512- }
513-
514513 Self {
515514 #[ cfg( feature = "auto-splitting" ) ]
516515 local_auto_splitter,
@@ -1838,23 +1837,62 @@ unsafe extern "C" fn update(data: *mut c_void, settings_obj: *mut obs_data_t) {
18381837 match & widget. kind {
18391838 WidgetKind :: Title { .. } => { }
18401839 WidgetKind :: Bool { default_value } => {
1841- let value = obs_data_get_bool ( settings_obj, data_key. as_ptr ( ) ) ;
1842- if value != * default_value {
1843- map. insert ( key. clone ( ) , Value :: Bool ( value) ) ;
1840+ let old_value = state
1841+ . auto_splitter_map
1842+ . get ( & key)
1843+ . and_then ( |v| v. to_bool ( ) )
1844+ . unwrap_or ( * default_value) ;
1845+ let asr_value = map
1846+ . get ( & key)
1847+ . and_then ( |v| v. to_bool ( ) )
1848+ . unwrap_or ( * default_value) ;
1849+ if asr_value != old_value {
1850+ obs_data_set_bool ( settings_obj, data_key. as_ptr ( ) , asr_value) ;
1851+ state
1852+ . auto_splitter_map
1853+ . insert ( key. clone ( ) , Value :: Bool ( asr_value) ) ;
18441854 } else {
18451855 map. remove ( key) ;
1856+ let obs_value = obs_data_get_bool ( settings_obj, data_key. as_ptr ( ) ) ;
1857+ if obs_value != * default_value {
1858+ map. insert ( key. clone ( ) , Value :: Bool ( obs_value) ) ;
1859+ } else {
1860+ map. remove ( key) ;
1861+ }
18461862 }
18471863 }
18481864 WidgetKind :: Choice {
18491865 default_option_key, ..
18501866 } => {
1851- if let Some ( value) =
1867+ let old_value = state
1868+ . auto_splitter_map
1869+ . get ( & key)
1870+ . and_then ( |v| v. as_string ( ) )
1871+ . unwrap_or ( default_option_key) ;
1872+ let asr_value = map
1873+ . get ( & key)
1874+ . and_then ( |v| v. as_string ( ) )
1875+ . unwrap_or ( default_option_key) ;
1876+ if asr_value != old_value {
1877+ if let Ok ( new_value) =
1878+ CString :: from_vec_with_nul ( format ! ( "{}\0 " , asr_value) . into ( ) )
1879+ {
1880+ obs_data_set_string (
1881+ settings_obj,
1882+ data_key. as_ptr ( ) ,
1883+ new_value. as_ptr ( ) ,
1884+ ) ;
1885+ }
1886+ state
1887+ . auto_splitter_map
1888+ . insert ( key. clone ( ) , Value :: String ( asr_value. clone ( ) ) ) ;
1889+ } else if let Some ( obs_value) =
18521890 CStr :: from_ptr ( obs_data_get_string ( settings_obj, data_key. as_ptr ( ) ) )
18531891 . to_str ( )
18541892 . ok ( )
18551893 . filter ( |v| * v != & * * default_option_key)
18561894 {
1857- map. insert ( key. clone ( ) , Value :: String ( Arc :: from ( value ) ) ) ;
1895+ map. insert ( key. clone ( ) , Value :: String ( Arc :: from ( obs_value ) ) ) ;
18581896 } else {
18591897 map. remove ( key) ;
18601898 }
@@ -1908,10 +1946,17 @@ unsafe extern "C" fn update(data: *mut c_void, settings_obj: *mut obs_data_t) {
19081946}
19091947
19101948fn handle_splits_path_change ( state : & mut State , splits_path : PathBuf ) {
1911- state. global_timer = get_global_timer ( splits_path) ;
1949+ state. global_timer = get_global_timer (
1950+ splits_path,
1951+ #[ cfg( feature = "auto-splitting" ) ]
1952+ & state. local_auto_splitter ,
1953+ ) ;
19121954}
19131955
1914- fn get_global_timer ( splits_path : PathBuf ) -> Arc < GlobalTimer > {
1956+ fn get_global_timer (
1957+ splits_path : PathBuf ,
1958+ #[ cfg( feature = "auto-splitting" ) ] local_auto_splitter : & Option < PathBuf > ,
1959+ ) -> Arc < GlobalTimer > {
19151960 let mut timers = TIMERS . lock ( ) . unwrap ( ) ;
19161961 timers. retain ( |timer| timer. strong_count ( ) > 0 ) ;
19171962 if let Some ( timer) = timers. iter ( ) . find_map ( |timer| {
@@ -1942,6 +1987,10 @@ fn get_global_timer(splits_path: PathBuf) -> Arc<GlobalTimer> {
19421987 #[ cfg( feature = "auto-splitting" ) ]
19431988 auto_splitter_is_enabled : AtomicBool :: new ( false ) ,
19441989 } ) ;
1990+ #[ cfg( feature = "auto-splitting" ) ]
1991+ if let Some ( local_auto_splitter) = local_auto_splitter {
1992+ auto_splitter_load ( & global_timer, local_auto_splitter. clone ( ) ) ;
1993+ }
19451994 timers. push ( Arc :: downgrade ( & global_timer) ) ;
19461995 global_timer
19471996 }
0 commit comments