Changeset bb65ccb3 in mainline for uspace/app/taskbar/clock.c


Ignore:
Timestamp:
2023-04-14T13:05:15Z (17 months ago)
Author:
GitHub <noreply@…>
Children:
00ef082
Parents:
4bfb5a0
git-author:
SimonJRiddix <69309548+simonjriddix@…> (2023-04-14 13:05:15)
git-committer:
GitHub <noreply@…> (2023-04-14 13:05:15)
Message:

add application launcher button & 12/24 h formats

taskbar with button to start the application launcher, 12/24 hour date formats have also been added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar/clock.c

    r4bfb5a0 rbb65ccb3  
    6161};
    6262
     63ClockFormat function_clock_format = american_clock_format;
     64
     65usec_t clock_refresh_seconds = 5 * 1000 * 1000;
     66bool use_seconds = false;
     67bool italian_format = true;
     68
     69void american_clock_format(struct tm time, char *buf, size_t bsize)
     70{
     71        if(time.tm_hour == 0)
     72                snprintf(buf, bsize, "%02d:%02d PM", time.tm_hour, time.tm_min);
     73        else if(time.tm_hour > 12)
     74                snprintf(buf, bsize, "%02d:%02d PM", time.tm_hour % 12, time.tm_min);
     75        else
     76                snprintf(buf, bsize, "%02d:%02d AM", time.tm_hour, time.tm_min);
     77}
     78
     79void american_seconds_clock_format(struct tm time, char *buf, size_t bsize)
     80{
     81        if(time.tm_hour == 0)
     82                snprintf(buf, bsize, "%02d:%02d:%02d PM", time.tm_hour, time.tm_min, time.tm_sec);
     83        else if(time.tm_hour > 12)
     84                snprintf(buf, bsize, "%02d:%02d:%02d PM", time.tm_hour % 12, time.tm_min, time.tm_sec);
     85        else
     86                snprintf(buf, bsize, "%02d:%02d:%02d AM", time.tm_hour, time.tm_min, time.tm_sec);
     87}
     88
     89void italian_clock_format(struct tm time, char *buf, size_t bsize)
     90{
     91        snprintf(buf, bsize, "%02d:%02d", time.tm_hour, time.tm_min);
     92}
     93
     94void italian_seconds_clock_format(struct tm time, char *buf, size_t bsize)
     95{
     96        snprintf(buf, bsize, "%02d:%02d:%02d", time.tm_hour, time.tm_min, time.tm_sec);
     97}
     98
     99void set_clock_format(void)
     100{
     101        if(italian_format)
     102        {
     103                function_clock_format = (use_seconds) ? italian_seconds_clock_format : italian_clock_format;
     104        }
     105        else
     106        {
     107                function_clock_format = (use_seconds) ? american_seconds_clock_format : american_clock_format;
     108        }
     109}
     110
    63111/** Create task bar clock.
    64112 *
     
    71119        taskbar_clock_t *clock;
    72120        errno_t rc;
     121       
     122        set_clock_format();
    73123
    74124        clock = calloc(1, sizeof(taskbar_clock_t));
     
    91141        fibril_mutex_initialize(&clock->lock);
    92142        fibril_condvar_initialize(&clock->timer_done_cv);
    93         fibril_timer_set(clock->timer, 1000000, taskbar_clock_timer, clock);
     143        fibril_timer_set(clock->timer, clock_refresh_seconds, taskbar_clock_timer, clock);
    94144
    95145        clock->window = window;
     
    136186{
    137187        struct timespec ts;
    138         struct tm tm;
     188        struct tm time;
    139189        errno_t rc;
    140190
    141191        getrealtime(&ts);
    142         rc = time_utc2tm(ts.tv_sec, &tm);
     192        rc = time_utc2tm(ts.tv_sec, &time);
    143193        if (rc != EOK)
    144194                return rc;
    145195
    146         snprintf(buf, bsize, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
    147             tm.tm_sec);
     196        function_clock_format(time, buf, bsize);
     197       
    148198        return EOK;
    149199}
     
    327377
    328378        if (!clock->timer_cleanup) {
    329                 fibril_timer_set(clock->timer, 1000000, taskbar_clock_timer,
     379                fibril_timer_set(clock->timer, clock_refresh_seconds, taskbar_clock_timer,
    330380                    clock);
    331381        } else {
Note: See TracChangeset for help on using the changeset viewer.