Changeset 806d761 in mainline for uspace/app/taskbar


Ignore:
Timestamp:
2024-02-07T23:44:59Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
242e3c3
Parents:
74cb6610
Message:

Start menu should have 'open in terminal' functionality

Makes it easier for the user and if we are running in console mode,
we correctly start the application, instead of failing to start a
terminal.

Location:
uspace/app/taskbar
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar/taskbar.sif

    r74cb6610 r806d761  
    1 [sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/terminal -c /app/nav]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/terminal -c /app/edit]){}[entry]([caption]=[~T~erminal][cmd]=[/app/terminal]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo ui]){}}}
     1[sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/nav][terminal]=[y]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/edit][terminal]=[y]){}[entry]([caption]=[~T~erminal][cmd]=[/app/terminal][terminal]=[n]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator][terminal]=[n]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo][terminal]=[n]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo ui][terminal]=[n]){}}}
  • uspace/app/taskbar/tbsmenu.c

    r74cb6610 r806d761  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    131131        const char *caption;
    132132        const char *cmd;
     133        bool terminal;
    133134        errno_t rc;
    134135
     
    141142                caption = smenu_entry_get_caption(sme);
    142143                cmd = smenu_entry_get_cmd(sme);
    143 
    144                 rc = tbsmenu_add(tbsmenu, caption, cmd, &tentry);
     144                terminal = smenu_entry_get_terminal(sme);
     145
     146                rc = tbsmenu_add(tbsmenu, caption, cmd, terminal, &tentry);
    145147                if (rc != EOK)
    146148                        goto error;
     
    226228 * @param caption Caption
    227229 * @param cmd Command to run
     230 * @param terminal Start in terminal
    228231 * @param entry Start menu entry
    229232 * @return @c EOK on success or an error code
    230233 */
    231234errno_t tbsmenu_add(tbsmenu_t *tbsmenu, const char *caption,
    232     const char *cmd, tbsmenu_entry_t **rentry)
     235    const char *cmd, bool terminal, tbsmenu_entry_t **rentry)
    233236{
    234237        errno_t rc;
     
    250253                goto error;
    251254        }
     255
     256        entry->terminal = terminal;
    252257
    253258        rc = ui_menu_entry_create(tbsmenu->smenu, caption, "", &entry->mentry);
     
    438443        }
    439444
     445        cmd->argv[cnt] = NULL;
     446
    440447        return EOK;
    441448}
     
    465472        int retval;
    466473        bool suspended;
     474        int i;
     475        int cnt;
     476        char **cp;
     477        const char **targv = NULL;
    467478        errno_t rc;
    468479        ui_t *ui;
     
    482493        suspended = true;
    483494
    484         rc = task_spawnv(&id, &wait, cmd.argv[0], (const char *const *)
    485             cmd.argv);
    486         if (rc != EOK)
    487                 goto error;
     495        /* Don't start in terminal if not running in a window */
     496        if (entry->terminal && !ui_is_fullscreen(ui)) {
     497                cnt = 0;
     498                cp = cmd.argv;
     499                while (*cp != NULL) {
     500                        ++cnt;
     501                        ++cp;
     502                }
     503
     504                targv = calloc(cnt + 3, sizeof(char **));
     505                if (targv == NULL)
     506                        goto error;
     507
     508                targv[0] = "/app/terminal";
     509                targv[1] = "-c";
     510
     511                for (i = 0; i <= cnt; i++) {
     512                        if (cmd.argv[i] != NULL)
     513                                printf(" - '%s'\n", cmd.argv[i]);
     514                        else
     515                                printf(" - NULL\n");
     516
     517                        targv[2 + i] = cmd.argv[i];
     518                }
     519
     520                rc = task_spawnv(&id, &wait, targv[0], targv);
     521                if (rc != EOK)
     522                        goto error;
     523
     524                free(targv);
     525                targv = NULL;
     526        } else {
     527                rc = task_spawnv(&id, &wait, cmd.argv[0], (const char *const *)
     528                    cmd.argv);
     529                if (rc != EOK)
     530                        goto error;
     531        }
    488532
    489533        rc = task_wait(&wait, &texit, &retval);
     
    499543        return EOK;
    500544error:
     545        if (targv != NULL)
     546                free(targv);
    501547        tbsmenu_cmd_fini(&cmd);
    502548        if (suspended)
  • uspace/app/taskbar/tbsmenu.h

    r74cb6610 r806d761  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5353extern bool tbsmenu_is_open(tbsmenu_t *);
    5454extern void tbsmenu_destroy(tbsmenu_t *);
    55 extern errno_t tbsmenu_add(tbsmenu_t *, const char *, const char *,
     55extern errno_t tbsmenu_add(tbsmenu_t *, const char *, const char *, bool,
    5656    tbsmenu_entry_t **);
    5757extern void tbsmenu_remove(tbsmenu_t *, tbsmenu_entry_t *, bool);
  • uspace/app/taskbar/types/tbsmenu.h

    r74cb6610 r806d761  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4646#include <ui/window.h>
    4747
    48 /** Taskbar window list entry */
     48/** Taskbar start menu entry */
    4949typedef struct {
    5050        /** Containing start menu */
     
    5858        /** Command to run */
    5959        char *cmd;
     60        /** Start in terminal */
     61        bool terminal;
    6062} tbsmenu_entry_t;
    6163
Note: See TracChangeset for help on using the changeset viewer.