Changeset bb65ccb3 in mainline


Ignore:
Timestamp:
2023-04-14T13:05:15Z (13 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.

Location:
uspace/app/taskbar
Files:
4 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 {
  • uspace/app/taskbar/clock.h

    r4bfb5a0 rbb65ccb3  
    5454extern void taskbar_clock_set_rect(taskbar_clock_t *, gfx_rect_t *);
    5555
     56void american_clock_format(struct tm time, char *buf, size_t bsize);
     57void american_seconds_clock_format(struct tm time, char *buf, size_t bsize);
     58void italian_clock_format(struct tm time, char *buf, size_t bsize);
     59void italian_seconds_clock_format(struct tm time, char *buf, size_t bsize);
     60void set_clock_format(void);
     61
     62typedef void (*ClockFormat)(struct tm, char *, size_t);
     63
    5664#endif
    5765
  • uspace/app/taskbar/taskbar.c

    r4bfb5a0 rbb65ccb3  
    3838#include <stdlib.h>
    3939#include <str.h>
     40#include <str_error.h>
    4041#include <ui/fixed.h>
    4142#include <ui/label.h>
     
    4748#include "taskbar.h"
    4849#include "wndlist.h"
     50#include <task.h>
     51
     52#define NAME  "taskbar"
     53
     54static const char *display_spec = UI_DISPLAY_DEFAULT;
     55
     56bool TaskLauncherIsOpen = false;
     57task_id_t TaskLauncherid;
    4958
    5059static void taskbar_wnd_close(ui_window_t *, void *);
     
    5564        .pos = taskbar_wnd_pos
    5665};
     66
     67static void buttonApps_clicked(ui_pbutton_t *, void *);
     68
     69static ui_pbutton_cb_t buttonApps_cb = {
     70        .clicked = buttonApps_clicked
     71};
     72
     73static int app_launchl(const char *, ...);
    5774
    5875/** Window close button was clicked.
     
    129146        ui_wnd_params_init(&params);
    130147        params.caption = "Task Bar";
    131         params.placement = ui_wnd_place_bottom_left;
     148        params.placement = ui_wnd_place_bottom_left_absolute;
    132149
    133150        /* Window has no titlebar */
     
    169186        }
    170187
    171         rc = ui_label_create(ui_res, "HelenOS", &taskbar->label);
    172         if (rc != EOK) {
    173                 printf("Error creating label.\n");
    174                 goto error;
    175         }
     188        rc = ui_pbutton_create(ui_res, "Apps", &taskbar->buttonApps);
     189        if (rc != EOK) {
     190                printf("Error creating Application Menu.\n");
     191                goto error;
     192        }
     193       
     194        ui_pbutton_set_cb(taskbar->buttonApps, &buttonApps_cb, NULL);
    176195
    177196        ui_window_get_app_rect(taskbar->window, &rect);
    178197        if (ui_is_textmode(taskbar->ui)) {
    179198                rect.p0.x += 1;
     199                rect.p1.x = rect.p0.x + 71;
    180200        } else {
    181201                rect.p0.x += 10;
    182         }
    183         ui_label_set_rect(taskbar->label, &rect);
    184         ui_label_set_halign(taskbar->label, gfx_halign_left);
    185         ui_label_set_valign(taskbar->label, gfx_valign_center);
    186 
    187         rc = ui_fixed_add(taskbar->fixed, ui_label_ctl(taskbar->label));
    188         if (rc != EOK) {
    189                 printf("Error adding control to layout.\n");
    190                 ui_label_destroy(taskbar->label);
     202                rect.p1.x = rect.p0.x +70;
     203        }
     204        ui_pbutton_set_rect(taskbar->buttonApps, &rect);
     205        ui_pbutton_set_default(taskbar->buttonApps, true);
     206
     207        rc = ui_fixed_add(taskbar->fixed, ui_pbutton_ctl(taskbar->buttonApps));
     208        if (rc != EOK) {
     209                printf("Error adding Application Menu control to layout.\n");
     210                ui_pbutton_destroy(taskbar->buttonApps);
    191211                goto error;
    192212        }
     
    274294}
    275295
     296/** Application Menu was clicked.
     297 *
     298 * @param pbutton Application Menu button
     299 * @param arg Argument
     300 */
     301static void buttonApps_clicked(ui_pbutton_t *pbutton, void *arg)
     302{
     303        //taskbar_t *taskbar = (taskbar_t *) arg;
     304       
     305        if(!TaskLauncherIsOpen)
     306        {
     307                if(app_launchl("/app/appslauncher", NULL) == EOK)
     308                {
     309                        /*if(ui_pbutton_set_caption(pbutton, "Close") != EOK)
     310                                printf("Error changing entry text.\n");
     311                        ui_pbutton_paint(pbutton);*/
     312                }
     313                else
     314                {
     315                        printf("Can't open launcher.\n");
     316                        //return;
     317                }
     318        }
     319        else
     320        {
     321                if (task_kill(TaskLauncherid) == EOK)
     322                {
     323                        /*if(ui_pbutton_set_caption(pbutton, "Apps") != EOK)
     324                                printf("Error changing entry text.\n");
     325                        ui_pbutton_paint(pbutton);*/
     326                }
     327                else
     328                {
     329                        printf("Can't kill launcher.\n");
     330                }
     331        }
     332       
     333        TaskLauncherIsOpen = !TaskLauncherIsOpen;
     334}
     335
     336static int app_launchl(const char *app, ...)
     337{
     338        errno_t rc;
     339        task_id_t id;
     340        task_wait_t wait;
     341        va_list ap;
     342        const char *arg;
     343        const char **argv;
     344        const char **argp;
     345        int cnt = 0;
     346        int i;
     347
     348        va_start(ap, app);
     349        do {
     350                arg = va_arg(ap, const char *);
     351                cnt++;
     352        } while (arg != NULL);
     353        va_end(ap);
     354
     355        argv = calloc(cnt + 4, sizeof(const char *));
     356        if (argv == NULL)
     357                return -1;
     358
     359        task_exit_t texit;
     360        int retval;
     361
     362        argp = argv;
     363        *argp++ = app;
     364
     365        if (str_cmp(display_spec, UI_DISPLAY_DEFAULT) != 0) {
     366                *argp++ = "-d";
     367                *argp++ = display_spec;
     368        }
     369
     370        va_start(ap, app);
     371        do {
     372                arg = va_arg(ap, const char *);
     373                *argp++ = arg;
     374        } while (arg != NULL);
     375        va_end(ap);
     376
     377        *argp++ = NULL;
     378
     379        printf("%s: Spawning %s", NAME, app);
     380        for (i = 0; argv[i] != NULL; i++) {
     381                printf(" %s", argv[i]);
     382        }
     383        printf("\n");
     384
     385        rc = task_spawnv(&id, &wait, app, argv);
     386        if (rc != EOK) {
     387                TaskLauncherid = -1;
     388                printf("%s: Error spawning %s (%s)\n", NAME, app, str_error(rc));
     389                return -1;
     390        }
     391       
     392        TaskLauncherid = id;
     393
     394        rc = task_wait(&wait, &texit, &retval);
     395        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
     396                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
     397                    app, str_error(rc));
     398                return -1;
     399        }
     400
     401        return retval;
     402}
     403
    276404/** @}
    277405 */
  • uspace/app/taskbar/types/taskbar.h

    r4bfb5a0 rbb65ccb3  
    3939#include <types/common.h>
    4040#include <ui/fixed.h>
    41 #include <ui/label.h>
     41#include <ui/pbutton.h>
    4242#include <ui/ui.h>
    4343#include <ui/window.h>
     
    5353        /** Fixed layout */
    5454        ui_fixed_t *fixed;
    55         ui_label_t *label;
     55        /** Taskbar Application Menu */
     56        ui_pbutton_t *buttonApps;
    5657        /** Window list */
    5758        wndlist_t *wndlist;
Note: See TracChangeset for help on using the changeset viewer.