@@ -356,9 +356,9 @@ static int tmux_is_detached(void)
356
356
sample its state and update away status according to attached/detached state
357
357
of the mplex.
358
358
*/
359
- static int mplex_is_detached (void )
359
+ static bool mplex_is_detached (void )
360
360
{
361
- return gnu_screen_is_detached () || tmux_is_detached ();
361
+ return gnu_screen_is_detached () || tmux_is_detached ();
362
362
}
363
363
364
364
static void mplex_timer_handler (Toxic * toxic )
@@ -367,6 +367,15 @@ static void mplex_timer_handler(Toxic *toxic)
367
367
return ;
368
368
}
369
369
370
+ pthread_mutex_lock (& Winthread .lock );
371
+ const bool auto_away_enabled = toxic -> c_config -> mplex_away ;
372
+ pthread_mutex_unlock (& Winthread .lock );
373
+
374
+ // needed in case config is changed during a running session
375
+ if (!auto_away_enabled ) {
376
+ return ;
377
+ }
378
+
370
379
ToxWindow * home_window = toxic -> home_window ;
371
380
372
381
Tox_User_Status current_status , new_status ;
@@ -376,7 +385,7 @@ static void mplex_timer_handler(Toxic *toxic)
376
385
return ;
377
386
}
378
387
379
- int detached = mplex_is_detached ();
388
+ const bool detached = mplex_is_detached ();
380
389
381
390
pthread_mutex_lock (& Winthread .lock );
382
391
current_status = tox_self_get_status (toxic -> tox );
@@ -391,11 +400,11 @@ static void mplex_timer_handler(Toxic *toxic)
391
400
prev_status = current_status ;
392
401
new_status = TOX_USER_STATUS_AWAY ;
393
402
pthread_mutex_lock (& Winthread .lock );
394
- size_t slen = tox_self_get_status_message_size (toxic -> tox );
403
+ const size_t slen = tox_self_get_status_message_size (toxic -> tox );
395
404
tox_self_get_status_message (toxic -> tox , (uint8_t * ) prev_note );
396
405
prev_note [slen ] = '\0' ;
397
- pthread_mutex_unlock (& Winthread .lock );
398
406
new_note = toxic -> c_config -> mplex_away_note ;
407
+ pthread_mutex_unlock (& Winthread .lock );
399
408
} else {
400
409
return ;
401
410
}
@@ -414,7 +423,7 @@ static void mplex_timer_handler(Toxic *toxic)
414
423
}
415
424
416
425
/* Time in seconds between calls to mplex_timer_handler */
417
- #define MPLEX_TIMER_INTERVAL 5
426
+ #define MPLEX_TIMER_INTERVAL 2
418
427
419
428
_Noreturn static void * mplex_timer_thread (void * data )
420
429
{
@@ -432,6 +441,14 @@ int init_mplex_away_timer(Toxic *toxic)
432
441
return 0 ;
433
442
}
434
443
444
+ if (toxic == NULL ) {
445
+ return -1 ;
446
+ }
447
+
448
+ if (toxic -> client_data .mplex_auto_away_initialized ) {
449
+ return 0 ;
450
+ }
451
+
435
452
if (!toxic -> c_config -> mplex_away ) {
436
453
return 0 ;
437
454
}
@@ -445,5 +462,7 @@ int init_mplex_away_timer(Toxic *toxic)
445
462
return -1 ;
446
463
}
447
464
465
+ toxic -> client_data .mplex_auto_away_initialized = true;
466
+
448
467
return 0 ;
449
468
}
0 commit comments