Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/launcher/launcher.c

    r552b69f rd8ddf7a  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2020 Jiri Svoboda
    33 * Copyright (c) 2012 Petr Koupy
    44 * All rights reserved.
     
    5656#define NAME  "launcher"
    5757
    58 static const char *display_spec = UI_DISPLAY_DEFAULT;
     58static char *display_spec = UI_DISPLAY_DEFAULT;
    5959
    6060static void wnd_close(ui_window_t *, void *);
     
    7070};
    7171
    72 static int app_launchl(const char *, ...);
     72static int app_launch(const char *, const char *);
    7373
    7474/** Window close button was clicked.
     
    9494
    9595        if (pbutton == launcher->pb1) {
    96                 app_launchl("/app/terminal", "-c", "/app/nav", NULL);
     96                app_launch("/app/terminal", NULL);
    9797        } else if (pbutton == launcher->pb2) {
    98                 app_launchl("/app/terminal", "-c", "/app/edit", NULL);
     98                app_launch("/app/calculator", NULL);
    9999        } else if (pbutton == launcher->pb3) {
    100                 app_launchl("/app/terminal", NULL);
     100                app_launch("/app/uidemo", NULL);
    101101        } else if (pbutton == launcher->pb4) {
    102                 app_launchl("/app/calculator", NULL);
    103         } else if (pbutton == launcher->pb5) {
    104                 app_launchl("/app/uidemo", NULL);
    105         } else if (pbutton == launcher->pb6) {
    106                 app_launchl("/app/gfxdemo", "ui", NULL);
    107         }
    108 }
    109 
    110 static int app_launchl(const char *app, ...)
     102                app_launch("/app/gfxdemo", "ui");
     103        }
     104}
     105
     106static int app_launch(const char *app, const char *arg)
    111107{
    112108        errno_t rc;
    113109        task_id_t id;
    114110        task_wait_t wait;
    115         va_list ap;
    116         const char *arg;
    117         const char **argv;
    118         const char **argp;
    119         int cnt = 0;
    120         int i;
    121 
    122         va_start(ap, app);
    123         do {
    124                 arg = va_arg(ap, const char *);
    125                 cnt++;
    126         } while (arg != NULL);
    127         va_end(ap);
    128 
    129         argv = calloc(cnt + 4, sizeof(const char *));
    130         if (argv == NULL)
     111
     112        if (display_spec != UI_DISPLAY_DEFAULT) {
     113                printf("%s: Spawning %s -d %s\n", NAME, app, display_spec);
     114                rc = task_spawnl(&id, &wait, app, app, "-d", display_spec,
     115                    arg, NULL);
     116        } else {
     117                printf("%s: Spawning %s\n", NAME, app);
     118                rc = task_spawnl(&id, &wait, app, app, arg, NULL);
     119        }
     120
     121        if (rc != EOK) {
     122                printf("%s: Error spawning %s %s (%s)\n", NAME, app,
     123                    display_spec != DISPLAY_DEFAULT ? display_spec :
     124                    "<default>", str_error(rc));
    131125                return -1;
     126        }
    132127
    133128        task_exit_t texit;
    134129        int retval;
    135 
    136         argp = argv;
    137         *argp++ = app;
    138 
    139         if (str_cmp(display_spec, UI_DISPLAY_DEFAULT) != 0) {
    140                 *argp++ = "-d";
    141                 *argp++ = display_spec;
    142         }
    143 
    144         va_start(ap, app);
    145         do {
    146                 arg = va_arg(ap, const char *);
    147                 *argp++ = arg;
    148         } while (arg != NULL);
    149         va_end(ap);
    150 
    151         *argp++ = NULL;
    152 
    153         printf("%s: Spawning %s", NAME, app);
    154         for (i = 0; argv[i] != NULL; i++) {
    155                 printf(" %s", argv[i]);
    156         }
    157         printf("\n");
    158 
    159         rc = task_spawnv(&id, &wait, app, argv);
    160         if (rc != EOK) {
    161                 printf("%s: Error spawning %s (%s)\n", NAME, app, str_error(rc));
    162                 return -1;
    163         }
    164 
    165130        rc = task_wait(&wait, &texit, &retval);
    166131        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
     
    224189        params.rect.p0.y = 0;
    225190        params.rect.p1.x = 210;
    226         params.rect.p1.y = 345;
     191        params.rect.p1.y = 300;
    227192
    228193        memset((void *) &launcher, 0, sizeof(launcher));
     
    298263        }
    299264
    300         /* Navigator */
    301 
    302         rc = ui_pbutton_create(ui_res, "Navigator", &launcher.pb1);
     265        rc = ui_pbutton_create(ui_res, "Terminal", &launcher.pb1);
    303266        if (rc != EOK) {
    304267                printf("Error creating button.\n");
     
    311274        rect.p0.y = 130;
    312275        rect.p1.x = 190;
    313         rect.p1.y = rect.p0.y + 28;
     276        rect.p1.y = 158;
    314277        ui_pbutton_set_rect(launcher.pb1, &rect);
    315278
     
    320283        }
    321284
    322         /* Text Editor */
    323 
    324         rc = ui_pbutton_create(ui_res, "Text Editor", &launcher.pb2);
     285        rc = ui_pbutton_create(ui_res, "Calculator", &launcher.pb2);
    325286        if (rc != EOK) {
    326287                printf("Error creating button.\n");
     
    331292
    332293        rect.p0.x = 15;
    333         rect.p0.y = 130 + 35;
     294        rect.p0.y = 170;
    334295        rect.p1.x = 190;
    335         rect.p1.y = rect.p0.y + 28;
     296        rect.p1.y = 198;
    336297        ui_pbutton_set_rect(launcher.pb2, &rect);
    337298
     
    342303        }
    343304
    344         /* Terminal */
    345 
    346         rc = ui_pbutton_create(ui_res, "Terminal", &launcher.pb3);
     305        rc = ui_pbutton_create(ui_res, "UI Demo", &launcher.pb3);
    347306        if (rc != EOK) {
    348307                printf("Error creating button.\n");
     
    353312
    354313        rect.p0.x = 15;
    355         rect.p0.y = 130 + 2 * 35;
     314        rect.p0.y = 210;
    356315        rect.p1.x = 190;
    357         rect.p1.y = rect.p0.y + 28;
     316        rect.p1.y = 238;
    358317        ui_pbutton_set_rect(launcher.pb3, &rect);
    359318
     
    364323        }
    365324
    366         /* Calculator */
    367 
    368         rc = ui_pbutton_create(ui_res, "Calculator", &launcher.pb4);
     325        rc = ui_pbutton_create(ui_res, "GFX Demo", &launcher.pb4);
    369326        if (rc != EOK) {
    370327                printf("Error creating button.\n");
     
    375332
    376333        rect.p0.x = 15;
    377         rect.p0.y = 130 + 3 * 35;
     334        rect.p0.y = 250;
    378335        rect.p1.x = 190;
    379         rect.p1.y = rect.p0.y + 28;
     336        rect.p1.y = 278;
    380337        ui_pbutton_set_rect(launcher.pb4, &rect);
    381338
     
    386343        }
    387344
    388         /* UI Demo */
    389 
    390         rc = ui_pbutton_create(ui_res, "UI Demo", &launcher.pb5);
    391         if (rc != EOK) {
    392                 printf("Error creating button.\n");
    393                 return rc;
    394         }
    395 
    396         ui_pbutton_set_cb(launcher.pb5, &pbutton_cb, (void *) &launcher);
    397 
    398         rect.p0.x = 15;
    399         rect.p0.y = 130 + 4 * 35;
    400         rect.p1.x = 190;
    401         rect.p1.y = rect.p0.y + 28;
    402         ui_pbutton_set_rect(launcher.pb5, &rect);
    403 
    404         rc = ui_fixed_add(launcher.fixed, ui_pbutton_ctl(launcher.pb5));
    405         if (rc != EOK) {
    406                 printf("Error adding control to layout.\n");
    407                 return rc;
    408         }
    409 
    410         /* GFX Demo */
    411 
    412         rc = ui_pbutton_create(ui_res, "GFX Demo", &launcher.pb6);
    413         if (rc != EOK) {
    414                 printf("Error creating button.\n");
    415                 return rc;
    416         }
    417 
    418         ui_pbutton_set_cb(launcher.pb6, &pbutton_cb, (void *) &launcher);
    419 
    420         rect.p0.x = 15;
    421         rect.p0.y = 130 + 5 * 35;
    422         rect.p1.x = 190;
    423         rect.p1.y = rect.p0.y + 28;
    424         ui_pbutton_set_rect(launcher.pb6, &rect);
    425 
    426         rc = ui_fixed_add(launcher.fixed, ui_pbutton_ctl(launcher.pb6));
    427         if (rc != EOK) {
    428                 printf("Error adding control to layout.\n");
    429                 return rc;
    430         }
    431 
    432345        ui_window_add(window, ui_fixed_ctl(launcher.fixed));
     346
     347        (void) ui_res;
     348        (void) app_launch;
    433349
    434350        rc = ui_window_paint(window);
Note: See TracChangeset for help on using the changeset viewer.