Ignore:
File:
1 edited

Legend:

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

    re63e74a r95fc538  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    129129        tbarcfg_t *tbcfg = NULL;
    130130        smenu_entry_t *sme;
    131         bool separator;
    132131        const char *caption;
    133132        const char *cmd;
    134         bool terminal;
    135133        errno_t rc;
    136134
     
    141139        sme = tbarcfg_smenu_first(tbcfg);
    142140        while (sme != NULL) {
    143                 separator = smenu_entry_get_separator(sme);
    144                 if (separator == false) {
    145                         caption = smenu_entry_get_caption(sme);
    146                         cmd = smenu_entry_get_cmd(sme);
    147                         terminal = smenu_entry_get_terminal(sme);
    148 
    149                         rc = tbsmenu_add(tbsmenu, caption, cmd, terminal,
    150                             &tentry);
    151                         if (rc != EOK)
    152                                 goto error;
    153                 } else {
    154                         rc = tbsmenu_add_sep(tbsmenu, &tentry);
    155                         if (rc != EOK)
    156                                 goto error;
    157                 }
     141                caption = smenu_entry_get_caption(sme);
     142                cmd = smenu_entry_get_cmd(sme);
     143
     144                rc = tbsmenu_add(tbsmenu, caption, cmd, &tentry);
     145                if (rc != EOK)
     146                        goto error;
    158147
    159148                (void)tentry;
     
    237226 * @param caption Caption
    238227 * @param cmd Command to run
    239  * @param terminal Start in terminal
    240228 * @param entry Start menu entry
    241229 * @return @c EOK on success or an error code
    242230 */
    243231errno_t tbsmenu_add(tbsmenu_t *tbsmenu, const char *caption,
    244     const char *cmd, bool terminal, tbsmenu_entry_t **rentry)
     232    const char *cmd, tbsmenu_entry_t **rentry)
    245233{
    246234        errno_t rc;
     
    262250                goto error;
    263251        }
    264 
    265         entry->terminal = terminal;
    266252
    267253        rc = ui_menu_entry_create(tbsmenu->smenu, caption, "", &entry->mentry);
     
    285271}
    286272
    287 /** Add separator entry to start menu.
    288  *
    289  * @param tbsmenu Start menu
    290  * @param entry Start menu entry
    291  * @return @c EOK on success or an error code
    292  */
    293 errno_t tbsmenu_add_sep(tbsmenu_t *tbsmenu, tbsmenu_entry_t **rentry)
    294 {
    295         errno_t rc;
    296         tbsmenu_entry_t *entry;
    297 
    298         entry = calloc(1, sizeof(tbsmenu_entry_t));
    299         if (entry == NULL)
    300                 return ENOMEM;
    301 
    302         rc = ui_menu_entry_sep_create(tbsmenu->smenu, &entry->mentry);
    303         if (rc != EOK)
    304                 goto error;
    305 
    306         ui_menu_entry_set_cb(entry->mentry, tbsmenu_smenu_entry_cb,
    307             (void *)entry);
    308 
    309         entry->tbsmenu = tbsmenu;
    310         list_append(&entry->lentries, &tbsmenu->entries);
    311         *rentry = entry;
    312         return EOK;
    313 error:
    314         free(entry);
    315         return rc;
    316 }
    317 
    318273/** Remove entry from start menu.
    319274 *
     
    483438        }
    484439
    485         cmd->argv[cnt] = NULL;
    486 
    487440        return EOK;
    488441}
     
    512465        int retval;
    513466        bool suspended;
    514         int i;
    515         int cnt;
    516         char **cp;
    517         const char **targv = NULL;
    518467        errno_t rc;
    519468        ui_t *ui;
     
    533482        suspended = true;
    534483
    535         /* Don't start in terminal if not running in a window */
    536         if (entry->terminal && !ui_is_fullscreen(ui)) {
    537                 cnt = 0;
    538                 cp = cmd.argv;
    539                 while (*cp != NULL) {
    540                         ++cnt;
    541                         ++cp;
    542                 }
    543 
    544                 targv = calloc(cnt + 3, sizeof(char **));
    545                 if (targv == NULL)
    546                         goto error;
    547 
    548                 targv[0] = "/app/terminal";
    549                 targv[1] = "-c";
    550 
    551                 for (i = 0; i <= cnt; i++) {
    552                         targv[2 + i] = cmd.argv[i];
    553                 }
    554 
    555                 rc = task_spawnv(&id, &wait, targv[0], targv);
    556                 if (rc != EOK)
    557                         goto error;
    558 
    559                 free(targv);
    560                 targv = NULL;
    561         } else {
    562                 rc = task_spawnv(&id, &wait, cmd.argv[0], (const char *const *)
    563                     cmd.argv);
    564                 if (rc != EOK)
    565                         goto error;
    566         }
     484        rc = task_spawnv(&id, &wait, cmd.argv[0], (const char *const *)
     485            cmd.argv);
     486        if (rc != EOK)
     487                goto error;
    567488
    568489        rc = task_wait(&wait, &texit, &retval);
     
    578499        return EOK;
    579500error:
    580         if (targv != NULL)
    581                 free(targv);
    582501        tbsmenu_cmd_fini(&cmd);
    583         if (suspended) {
    584                 rc = ui_resume(ui);
    585                 if (rc != EOK) {
    586                         printf("Failed to resume UI.\n");
    587                         exit(1);
    588                 }
    589         }
     502        if (suspended)
     503                (void) ui_resume(ui);
    590504        (void) ui_paint(ui);
    591505        return rc;
Note: See TracChangeset for help on using the changeset viewer.