- }
- animation_running = FALSE;
- animation_stop = FALSE;
- if( double_click_notif == FALSE ) {
- /* Before exiting, be sure to put NO MAIL image back in place... */
- DisplayClosedMailbox();
- }
- }
-
- /* If sleep() returns because the requested time has elapsed, the value returned will be
- * 0. If sleep() returns because of premature arousal due to delivery of a signal, the
- * return value will be the "unslept" amount (the requested time minus the time actually
- * slept) in seconds. */
-
- if( animation_running == FALSE ) {
- (void) sleep( wmnotify_infos.mail_check_interval );
- counter = 0;
- }
- else {
- NewMailAnimation();
- (void) usleep( NEW_MAIL_ANIMATION_DURATION );
- counter--;
- }
-
- if( wmnotify_infos.debug ) {
- printf( "%s: counter = %d\n", PACKAGE, counter );
- }
- } /* end while */
-
- if( wmnotify_infos.debug ) {
- printf( "%s: Error, TimerThread() exited abnormally\n", PACKAGE );
- }
-
- /* This code is never reached for now, because quit is always FALSE. */
- pthread_exit( NULL );
+}
+
+static void *TimerThread(void *arg)
+{
+ int new_messages = 0;
+ int counter = -1;
+ bool animation_running = false;
+
+ /*
+ * For catching the signal SIGUSR1. This signal is sent by the main
+ * program thread when the user is issuing a single-click to manually
+ * check for new mails.
+ */
+ (void) signal(SIGUSR1, CatchTimerSignal);
+
+ /*
+ * For catching the signal SIGUSR2. This signal is sent by the main
+ * program thread when the user is issuing a double-click to start their
+ * external mail client.
+ */
+ (void) signal(SIGUSR2, CatchTimerSignal);
+
+ while (quit == false) {
+ if (wmnotify_infos.debug)
+ printf("%s: Timer thread iteration.\n", PACKAGE);
+
+ if ((manual_check == true) || (counter == 0)) {
+ new_messages = CheckForNewMail(manual_check);
+ manual_check = false;
+
+ if (wmnotify_infos.debug) {
+ printf("%s: new messages = %d.\n", PACKAGE,
+ new_messages);
+ }
+
+ if (new_messages > 0) {
+ check_audio_notification(&animation_running);
+
+ /*
+ * Number of times to execute timer loop before
+ * checking again for new mails when the
+ * animation is running (when the animation is
+ * running, we sleep for
+ * NEW_MAIL_ANIMATION_DURATION instead of
+ * wmnotify_infos.mail_check_interval). We set
+ * the check interval to 30 seconds because we
+ * want the new mail condition to be removed as
+ * soon as possible when the new messages are
+ * checked.
+ */
+ counter = 30 * 1000000 /
+ NEW_MAIL_ANIMATION_DURATION;
+ }
+ }
+
+ if ((animation_stop == true) || (new_messages <= 0)) {
+ if (wmnotify_infos.debug) {
+ if (animation_stop != false) {
+ printf
+ ("%s: animation_stop is true\n",
+ PACKAGE);
+ }
+ }
+ animation_running = false;
+ animation_stop = false;
+ if (double_click_notif == false) {
+ /*
+ * Before exiting, be sure to put NO MAIL image
+ * back in place.
+ */
+ DisplayClosedMailbox();
+ }
+ }
+
+ /*
+ * If sleep() returns because the requested time has elapsed,
+ * the value returned will be 0. If sleep() returns because of
+ * premature arousal due to delivery of a signal, the return
+ * value will be the "unslept" amount (the requested time minus
+ * the time actually slept) in seconds.
+ */
+ if (animation_running == false) {
+ (void) sleep(wmnotify_infos.mail_check_interval);
+ counter = 0;
+ } else {
+ NewMailAnimation();
+ (void) usleep(NEW_MAIL_ANIMATION_DURATION);
+ counter--;
+ }
+
+ if (wmnotify_infos.debug)
+ printf("%s: counter = %d\n", PACKAGE, counter);
+ } /* end while */
+
+ if (wmnotify_infos.debug)
+ printf("%s: Error, TimerThread() exited abnormally\n", PACKAGE);
+
+ /* This code is never reached for now, because quit is always false. */
+ pthread_exit(NULL);