Changeset f2cb80a in mainline for uspace


Ignore:
Timestamp:
2024-02-23T17:57:23Z (20 months ago)
Author:
GitHub <noreply@…>
Children:
192019f
Parents:
86f862c (diff), 90ba06c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2024-02-23 17:57:23)
git-committer:
GitHub <noreply@…> (2024-02-23 17:57:23)
Message:

Merge branch 'HelenOS:master' into topic/packet-capture

Location:
uspace
Files:
24 edited
4 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/display-cfg/main.c

    r86f862c rf2cb80a  
    7878
    7979        rc = display_cfg_open(dcfg, DISPCFG_DEFAULT);
    80         if (rc != EOK)
     80        if (rc != EOK) {
     81                display_cfg_destroy(dcfg);
     82                printf("Error opening display configuration service '%s'.\n",
     83                    DISPCFG_DEFAULT);
    8184                return 1;
     85        }
    8286
    8387        rc = display_cfg_populate(dcfg);
    84         if (rc != EOK)
     88        if (rc != EOK) {
     89                display_cfg_destroy(dcfg);
     90                printf("Error reading display configuration.\n");
    8591                return 1;
     92        }
    8693
    8794        ui_run(dcfg->ui);
  • uspace/app/taskbar-cfg/smeedit.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <stdio.h>
    3737#include <stdlib.h>
     38#include <ui/checkbox.h>
    3839#include <ui/fixed.h>
    3940#include <ui/resource.h>
     
    9495        const char *cmd;
    9596        const char *caption;
     97        bool terminal;
    9698        errno_t rc;
    9799
     
    101103                cmd = smenu_entry_get_cmd(smentry->entry);
    102104                caption = smenu_entry_get_caption(smentry->entry);
     105                terminal = smenu_entry_get_terminal(smentry->entry);
    103106        } else {
    104107                cmd = "";
    105108                caption = "";
     109                terminal = false;
    106110        }
    107111
     
    116120
    117121        ui_wnd_params_init(&params);
    118         params.caption = smentry != NULL ? "Edit Start Menu Entry"
    119             : "Create Start Menu Entry";
     122        params.caption = smentry != NULL ? "Edit Start Menu Entry" :
     123            "Create Start Menu Entry";
    120124        if (ui_is_textmode(ui)) {
    121125                params.rect.p0.x = 0;
    122126                params.rect.p0.y = 0;
    123127                params.rect.p1.x = 50;
    124                 params.rect.p1.y = 12;
     128                params.rect.p1.y = 13;
    125129        } else {
    126130                params.rect.p0.x = 0;
    127131                params.rect.p0.y = 0;
    128132                params.rect.p1.x = 370;
    129                 params.rect.p1.y = 200;
     133                params.rect.p1.y = 230;
    130134        }
    131135
     
    255259        }
    256260
     261        /* Start in terminal checkbox */
     262
     263        rc = ui_checkbox_create(res, "Start in terminal", &smee->cbterminal);
     264        if (rc != EOK)
     265                goto error;
     266
     267        /* FIXME: Auto layout */
     268        if (ui_is_textmode(ui)) {
     269                rect.p0.x = 3;
     270                rect.p0.y = 8;
     271                rect.p1.x = 6;
     272                rect.p1.y = 9;
     273        } else {
     274                rect.p0.x = 10;
     275                rect.p0.y = 155;
     276                rect.p1.x = 360;
     277                rect.p1.y = 170;
     278        }
     279
     280        ui_checkbox_set_rect(smee->cbterminal, &rect);
     281        ui_checkbox_set_checked(smee->cbterminal, terminal);
     282
     283        rc = ui_fixed_add(smee->fixed, ui_checkbox_ctl(smee->cbterminal));
     284        if (rc != EOK) {
     285                printf("Error adding control to layout.\n");
     286                goto error;
     287        }
     288
    257289        /* OK button */
    258290
     
    264296        if (ui_is_textmode(ui)) {
    265297                rect.p0.x = 23;
    266                 rect.p0.y = 9;
     298                rect.p0.y = 10;
    267299                rect.p1.x = 35;
    268                 rect.p1.y = 10;
     300                rect.p1.y = 11;
    269301        } else {
    270302                rect.p0.x = 190;
    271                 rect.p0.y = 155;
     303                rect.p0.y = 190;
    272304                rect.p1.x = 270;
    273                 rect.p1.y = 180;
     305                rect.p1.y = 215;
    274306        }
    275307
     
    293325        if (ui_is_textmode(ui)) {
    294326                rect.p0.x = 36;
    295                 rect.p0.y = 9;
     327                rect.p0.y = 10;
    296328                rect.p1.x = 48;
    297                 rect.p1.y = 10;
     329                rect.p1.y = 11;
    298330        } else {
    299331                rect.p0.x = 280;
    300                 rect.p0.y = 155;
     332                rect.p0.y = 190;
    301333                rect.p1.x = 360;
    302                 rect.p1.y = 180;
     334                rect.p1.y = 215;
    303335        }
    304336
     
    345377{
    346378        smeedit_t *smee;
     379        smenu_entry_t *entry;
     380        startmenu_entry_t *smentry;
    347381        const char *cmd;
    348382        const char *caption;
     383        bool terminal;
    349384        errno_t rc;
    350385
     
    354389        cmd = ui_entry_get_text(smee->ecmd);
    355390        caption = ui_entry_get_text(smee->ecaption);
     391        terminal = ui_checkbox_get_checked(smee->cbterminal);
    356392
    357393        if (smee->smentry == NULL) {
    358394                /* Create new entry */
    359395                rc = smenu_entry_create(smee->startmenu->tbarcfg->tbarcfg,
    360                     caption, cmd);
     396                    caption, cmd, terminal, &entry);
    361397                if (rc != EOK)
    362398                        return;
     399
     400                rc = startmenu_insert(smee->startmenu, entry, &smentry);
     401                if (rc != EOK)
     402                        return;
     403
     404                startmenu_repaint(smee->startmenu);
    363405        } else {
    364406                /* Edit existing entry */
    365 
    366 
    367407                rc = smenu_entry_set_cmd(smee->smentry->entry, cmd);
    368408                if (rc != EOK)
     
    370410
    371411                smenu_entry_set_caption(smee->smentry->entry, caption);
     412                if (rc != EOK)
     413                        return;
     414
     415                smenu_entry_set_terminal(smee->smentry->entry, terminal);
    372416                if (rc != EOK)
    373417                        return;
  • uspace/app/taskbar-cfg/startmenu.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5454static void startmenu_delete_entry_clicked(ui_pbutton_t *, void *);
    5555static void startmenu_edit_entry_clicked(ui_pbutton_t *, void *);
     56static void startmenu_sep_entry_clicked(ui_pbutton_t *, void *);
     57static void startmenu_up_entry_clicked(ui_pbutton_t *, void *);
     58static void startmenu_down_entry_clicked(ui_pbutton_t *, void *);
    5659
    5760/** Entry list callbacks */
     
    7376ui_pbutton_cb_t startmenu_edit_entry_button_cb = {
    7477        .clicked = startmenu_edit_entry_clicked
     78};
     79
     80/** Separator entry button callbacks */
     81ui_pbutton_cb_t startmenu_sep_entry_button_cb = {
     82        .clicked = startmenu_sep_entry_clicked
     83};
     84
     85/** Move entry up button callbacks */
     86ui_pbutton_cb_t startmenu_up_entry_button_cb = {
     87        .clicked = startmenu_up_entry_clicked
     88};
     89
     90/** Move entry down button callbacks */
     91ui_pbutton_cb_t startmenu_down_entry_button_cb = {
     92        .clicked = startmenu_down_entry_clicked
    7593};
    7694
     
    151169                rect.p0.y = 5;
    152170                rect.p1.x = 56;
    153                 rect.p1.y = 10;
     171                rect.p1.y = 20;
    154172        } else {
    155173                rect.p0.x = 20;
    156174                rect.p0.y = 80;
    157175                rect.p1.x = 360;
    158                 rect.p1.y = 180;
     176                rect.p1.y = 330;
    159177        }
    160178
     
    263281            &startmenu_edit_entry_button_cb, (void *)smenu);
    264282
     283        /* Separator entry button */
     284
     285        rc = ui_pbutton_create(ui_res, "Separator", &smenu->sep_entry);
     286        if (rc != EOK) {
     287                printf("Error creating button.\n");
     288                goto error;
     289        }
     290
     291        if (ui_resource_is_textmode(ui_res)) {
     292                rect.p0.x = 58;
     293                rect.p0.y = 11;
     294                rect.p1.x = 68;
     295                rect.p1.y = 12;
     296        } else {
     297                rect.p0.x = 370;
     298                rect.p0.y = 170;
     299                rect.p1.x = 450;
     300                rect.p1.y = 195;
     301        }
     302
     303        ui_pbutton_set_rect(smenu->sep_entry, &rect);
     304
     305        rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->sep_entry));
     306        if (rc != EOK) {
     307                printf("Error adding control to layout.\n");
     308                goto error;
     309        }
     310
     311        ui_pbutton_set_cb(smenu->sep_entry,
     312            &startmenu_sep_entry_button_cb, (void *)smenu);
     313
     314        /* Move entry up button */
     315
     316        rc = ui_pbutton_create(ui_res, "Up", &smenu->up_entry);
     317        if (rc != EOK) {
     318                printf("Error creating button.\n");
     319                goto error;
     320        }
     321
     322        if (ui_resource_is_textmode(ui_res)) {
     323                rect.p0.x = 58;
     324                rect.p0.y = 13;
     325                rect.p1.x = 68;
     326                rect.p1.y = 14;
     327        } else {
     328                rect.p0.x = 370;
     329                rect.p0.y = 220;
     330                rect.p1.x = 450;
     331                rect.p1.y = 245;
     332        }
     333
     334        ui_pbutton_set_rect(smenu->up_entry, &rect);
     335
     336        rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->up_entry));
     337        if (rc != EOK) {
     338                printf("Error adding control to layout.\n");
     339                goto error;
     340        }
     341
     342        ui_pbutton_set_cb(smenu->up_entry,
     343            &startmenu_up_entry_button_cb, (void *)smenu);
     344
     345        /* Move entry down button */
     346
     347        rc = ui_pbutton_create(ui_res, "Down", &smenu->down_entry);
     348        if (rc != EOK) {
     349                printf("Error creating button.\n");
     350                goto error;
     351        }
     352
     353        if (ui_resource_is_textmode(ui_res)) {
     354                rect.p0.x = 58;
     355                rect.p0.y = 15;
     356                rect.p1.x = 68;
     357                rect.p1.y = 16;
     358        } else {
     359                rect.p0.x = 370;
     360                rect.p0.y = 250;
     361                rect.p1.x = 450;
     362                rect.p1.y = 275;
     363        }
     364
     365        ui_pbutton_set_rect(smenu->down_entry, &rect);
     366
     367        rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->down_entry));
     368        if (rc != EOK) {
     369                printf("Error adding control to layout.\n");
     370                goto error;
     371        }
     372
     373        ui_pbutton_set_cb(smenu->down_entry,
     374            &startmenu_down_entry_button_cb, (void *)smenu);
     375
    265376        ui_tab_add(smenu->tab, ui_fixed_ctl(smenu->fixed));
    266377
     
    268379        return EOK;
    269380error:
     381        if (smenu->down_entry != NULL)
     382                ui_pbutton_destroy(smenu->down_entry);
     383        if (smenu->up_entry != NULL)
     384                ui_pbutton_destroy(smenu->up_entry);
    270385        if (smenu->delete_entry != NULL)
    271386                ui_pbutton_destroy(smenu->delete_entry);
     
    340455        startmenu_entry_t *smentry;
    341456        ui_list_entry_attr_t attr;
     457        bool separator;
    342458        errno_t rc;
    343459
     
    350466
    351467        ui_list_entry_attr_init(&attr);
    352         attr.caption = smenu_entry_get_caption(entry);
     468        separator = smenu_entry_get_separator(entry);
     469        if (separator)
     470                attr.caption = "-- Separator --";
     471        else
     472                attr.caption = smenu_entry_get_caption(entry);
     473
    353474        attr.arg = (void *)smentry;
     475
    354476        rc = ui_list_entry_append(smenu->entries_list, &attr, &smentry->lentry);
    355477        if (rc != EOK) {
     
    395517}
    396518
     519/** Create new separator menu entry.
     520 *
     521 * @param smenu Start menu
     522 */
     523void startmenu_sep_entry(startmenu_t *smenu)
     524{
     525        startmenu_entry_t *smentry = NULL;
     526        smenu_entry_t *entry;
     527        errno_t rc;
     528
     529        rc = smenu_entry_sep_create(smenu->tbarcfg->tbarcfg, &entry);
     530        if (rc != EOK)
     531                return;
     532
     533        (void)startmenu_insert(smenu, entry, &smentry);
     534        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
     535}
     536
    397537/** Edit selected menu entry.
    398538 *
     
    409549                return;
    410550
     551        /* Do not edit separator entries */
     552        if (smenu_entry_get_separator(smentry->entry))
     553                return;
     554
    411555        rc = smeedit_create(smenu, smentry, &smee);
    412556        if (rc != EOK)
     
    429573}
    430574
     575/** Repaint start menu entry list.
     576 *
     577 * When editing an entry the entry's label might change. We need
     578 * to update the list entry caption to reflect that.
     579 *
     580 * @param smenu Start menu
     581 */
     582void startmenu_repaint(startmenu_t *smenu)
     583{
     584        (void) ui_control_paint(ui_list_ctl(smenu->entries_list));
     585}
     586
    431587/** Entry in entry list is selected.
    432588 *
     
    476632        ui_list_entry_delete(smentry->lentry);
    477633        free(smentry);
    478         (void) ui_control_paint(ui_list_ctl(smenu->entries_list));
     634        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
    479635}
    480636
     
    492648}
    493649
     650/** Separator entry button clicked.
     651 *
     652 * @param pbutton Push button
     653 * @param arg Argument (startmenu_t *)
     654 */
     655static void startmenu_sep_entry_clicked(ui_pbutton_t *pbutton, void *arg)
     656{
     657        startmenu_t *smenu = (startmenu_t *)arg;
     658
     659        (void)pbutton;
     660        startmenu_sep_entry(smenu);
     661}
     662
     663/** Up entry button clicked.
     664 *
     665 * @param pbutton Push button
     666 * @param arg Argument (startmenu_t *)
     667 */
     668static void startmenu_up_entry_clicked(ui_pbutton_t *pbutton, void *arg)
     669{
     670        startmenu_t *smenu = (startmenu_t *)arg;
     671        startmenu_entry_t *smentry;
     672        errno_t rc;
     673
     674        (void)pbutton;
     675
     676        smentry = startmenu_get_selected(smenu);
     677        if (smentry == NULL)
     678                return;
     679
     680        rc = smenu_entry_move_up(smentry->entry);
     681        if (rc != EOK)
     682                return;
     683
     684        ui_list_entry_move_up(smentry->lentry);
     685
     686        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
     687}
     688
     689/** Down entry button clicked.
     690 *
     691 * @param pbutton Push button
     692 * @param arg Argument (startmenu_t *)
     693 */
     694static void startmenu_down_entry_clicked(ui_pbutton_t *pbutton, void *arg)
     695{
     696        startmenu_t *smenu = (startmenu_t *)arg;
     697        startmenu_entry_t *smentry;
     698        errno_t rc;
     699
     700        (void)pbutton;
     701
     702        smentry = startmenu_get_selected(smenu);
     703        if (smentry == NULL)
     704                return;
     705
     706        rc = smenu_entry_move_up(smentry->entry);
     707        if (rc != EOK)
     708                return;
     709
     710        ui_list_entry_move_down(smentry->lentry);
     711
     712        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
     713}
     714
    494715/** @}
    495716 */
  • uspace/app/taskbar-cfg/startmenu.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848extern startmenu_entry_t *startmenu_get_selected(startmenu_t *);
    4949extern void startmenu_new_entry(startmenu_t *);
     50extern void startmenu_sep_entry(startmenu_t *);
    5051extern void startmenu_edit(startmenu_t *);
    5152extern errno_t startmenu_entry_update(startmenu_entry_t *);
     53extern void startmenu_repaint(startmenu_t *);
    5254
    5355#endif
  • uspace/app/taskbar-cfg/types/smeedit.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#define TYPES_SMEEDIT_H
    3838
     39#include <ui/checkbox.h>
    3940#include <ui/fixed.h>
    4041#include <ui/label.h>
     
    6162        /** Command entry */
    6263        ui_entry_t *ecmd;
    63         /** OK buttion */
     64        /** Start in terminal checkbox */
     65        ui_checkbox_t *cbterminal;
     66        /** OK button */
    6467        ui_pbutton_t *bok;
    6568        /** Cancel button */
  • uspace/app/taskbar-cfg/types/startmenu.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6262        /** Edit entry button */
    6363        ui_pbutton_t *edit_entry;
     64        /** Separator entry button */
     65        ui_pbutton_t *sep_entry;
     66        /** Move entry up button */
     67        ui_pbutton_t *up_entry;
     68        /** Move entry down button */
     69        ui_pbutton_t *down_entry;
    6470} startmenu_t;
    6571
  • uspace/app/taskbar/taskbar.sif

    r86f862c rf2cb80a  
    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]=[Co~m~mand Line][cmd]=[/app/bdsh][terminal]=[y]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo][terminal]=[n]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo ui][terminal]=[n]){}[entry]([caption]=[~B~arber Pole][cmd]=[/app/barber][terminal]=[n]){}[entry]([caption]=[~T~etris][cmd]=[/app/tetris][terminal]=[y]){}[entry]([separator]=[y]){}[entry]([caption]=[~D~isplay Configuration][cmd]=[/app/display-cfg][terminal]=[n]){}[entry]([caption]=[Ta~s~kbar Configuration][cmd]=[/app/taskbar-cfg][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[Tas~k~ Monitor (top)][cmd]=[/app/top][terminal]=[y]){}[entry]([caption]=[~F~disk Disk Editor][cmd]=[/app/fdisk][terminal]=[y]){}}}
  • uspace/app/taskbar/tbsmenu.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    129129        tbarcfg_t *tbcfg = NULL;
    130130        smenu_entry_t *sme;
     131        bool separator;
    131132        const char *caption;
    132133        const char *cmd;
     134        bool terminal;
    133135        errno_t rc;
    134136
     
    139141        sme = tbarcfg_smenu_first(tbcfg);
    140142        while (sme != NULL) {
    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;
     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                }
    147158
    148159                (void)tentry;
     
    226237 * @param caption Caption
    227238 * @param cmd Command to run
     239 * @param terminal Start in terminal
    228240 * @param entry Start menu entry
    229241 * @return @c EOK on success or an error code
    230242 */
    231243errno_t tbsmenu_add(tbsmenu_t *tbsmenu, const char *caption,
    232     const char *cmd, tbsmenu_entry_t **rentry)
     244    const char *cmd, bool terminal, tbsmenu_entry_t **rentry)
    233245{
    234246        errno_t rc;
     
    250262                goto error;
    251263        }
     264
     265        entry->terminal = terminal;
    252266
    253267        rc = ui_menu_entry_create(tbsmenu->smenu, caption, "", &entry->mentry);
     
    271285}
    272286
     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 */
     293errno_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;
     313error:
     314        free(entry);
     315        return rc;
     316}
     317
    273318/** Remove entry from start menu.
    274319 *
     
    438483        }
    439484
     485        cmd->argv[cnt] = NULL;
     486
    440487        return EOK;
    441488}
     
    465512        int retval;
    466513        bool suspended;
     514        int i;
     515        int cnt;
     516        char **cp;
     517        const char **targv = NULL;
    467518        errno_t rc;
    468519        ui_t *ui;
     
    482533        suspended = true;
    483534
    484         rc = task_spawnv(&id, &wait, cmd.argv[0], (const char *const *)
    485             cmd.argv);
    486         if (rc != EOK)
    487                 goto error;
     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        }
    488567
    489568        rc = task_wait(&wait, &texit, &retval);
     
    499578        return EOK;
    500579error:
     580        if (targv != NULL)
     581                free(targv);
    501582        tbsmenu_cmd_fini(&cmd);
    502         if (suspended)
    503                 (void) ui_resume(ui);
     583        if (suspended) {
     584                rc = ui_resume(ui);
     585                if (rc != EOK) {
     586                        printf("Failed to resume UI.\n");
     587                        exit(1);
     588                }
     589        }
    504590        (void) ui_paint(ui);
    505591        return rc;
  • uspace/app/taskbar/tbsmenu.h

    r86f862c rf2cb80a  
    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 **);
     57extern errno_t tbsmenu_add_sep(tbsmenu_t *, tbsmenu_entry_t **);
    5758extern void tbsmenu_remove(tbsmenu_t *, tbsmenu_entry_t *, bool);
    5859extern tbsmenu_entry_t *tbsmenu_first(tbsmenu_t *);
  • uspace/app/taskbar/types/tbsmenu.h

    r86f862c rf2cb80a  
    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
  • uspace/lib/c/meson.build

    r86f862c rf2cb80a  
    5353        _sdir = meson.current_source_dir() / idir
    5454        uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/libc"'.format(_sdir)
     55        exported_devel_files += ['include', _sdir, 'libc']
    5556endforeach
    5657
     
    209210        pic: false,
    210211)
     212exported_devel_files += ['staticlib', libstartfiles, 'libstartfiles.a']
    211213
    212214if CONFIG_DEVEL_FILES
  • uspace/lib/clui/meson.build

    r86f862c rf2cb80a  
    2929deps = [ 'clipboard', 'console' ]
    3030src = files(
    31         'nchoice.c',
    32         'tinput.c',
     31        'src/nchoice.c',
     32        'src/tinput.c',
    3333)
  • uspace/lib/meson.build

    r86f862c rf2cb80a  
    181181                if run_command('[', '-d', incdir, ']').returncode() == 0
    182182                        includes += include_directories(incdir)
     183                        _sdir = meson.current_source_dir() / l / 'include'
    183184
    184185                        if installed_libs.contains(l)
    185                                 _sdir = meson.current_source_dir() / l / 'include'
    186186                                uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
    187187                        endif
     188
     189                        exported_devel_files += ['include', _sdir, 'lib' + l]
    188190                else
    189191                        includes += include_directories(l)
     
    294296                        install_deps += [ _static_lib ]
    295297                endif
     298
     299                exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a']
    296300
    297301                _static_dep = declare_dependency(
  • uspace/lib/posix/meson.build

    r86f862c rf2cb80a  
    6767uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/libposix"'.format(_sdir)
    6868uspace_lib_devel_install_script_text += 'ln -s -r "${DESTDIR}include/libc" "${DESTDIR}/include/common"'
     69
     70exported_devel_files += [ 'include', meson.current_source_dir() / 'include' / 'posix', 'libposix' ]
     71exported_devel_files += [ 'includesymlink', 'libc', 'libposix' ]
  • uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <errno.h>
    4040#include <sif.h>
     41#include <stdbool.h>
    4142#include <types/tbarcfg/tbarcfg.h>
    4243
     
    4647extern smenu_entry_t *tbarcfg_smenu_first(tbarcfg_t *);
    4748extern smenu_entry_t *tbarcfg_smenu_next(smenu_entry_t *);
     49extern smenu_entry_t *tbarcfg_smenu_last(tbarcfg_t *);
     50extern smenu_entry_t *tbarcfg_smenu_prev(smenu_entry_t *);
    4851extern const char *smenu_entry_get_caption(smenu_entry_t *);
    4952extern const char *smenu_entry_get_cmd(smenu_entry_t *);
     53extern bool smenu_entry_get_terminal(smenu_entry_t *);
     54extern bool smenu_entry_get_separator(smenu_entry_t *);
    5055extern errno_t smenu_entry_set_caption(smenu_entry_t *, const char *);
    5156extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *);
     57extern void smenu_entry_set_terminal(smenu_entry_t *, bool);
    5258extern errno_t smenu_entry_save(smenu_entry_t *);
    53 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *);
     59extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *,
     60    bool, smenu_entry_t **);
     61extern errno_t smenu_entry_sep_create(tbarcfg_t *, smenu_entry_t **);
    5462extern errno_t smenu_entry_destroy(smenu_entry_t *);
     63extern errno_t smenu_entry_move_up(smenu_entry_t *);
     64extern errno_t smenu_entry_move_down(smenu_entry_t *);
    5565
    5666#endif
  • uspace/lib/tbarcfg/private/tbarcfg.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4040#include <adt/list.h>
    4141#include <sif.h>
     42#include <stdbool.h>
    4243#include <types/tbarcfg/tbarcfg.h>
    4344
     
    6061        /** SIF node (persistent storage) */
    6162        sif_node_t *nentry;
     63        /** Is this a separator entry */
     64        bool separator;
    6265        /** Entry caption (with accelerator markup) */
    6366        char *caption;
    6467        /** Command to run */
    6568        char *cmd;
     69        /** Start in terminal */
     70        bool terminal;
    6671};
    6772
    6873extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *,
    69     const char *);
     74    const char *, bool, smenu_entry_t **);
     75extern errno_t smenu_entry_sep_new(tbarcfg_t *, sif_node_t *, smenu_entry_t **);
    7076extern void smenu_entry_delete(smenu_entry_t *);
    7177
  • uspace/lib/tbarcfg/src/tbarcfg.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    108108        sif_node_t *nentry;
    109109        const char *ntype;
     110        const char *separator;
    110111        const char *caption;
    111112        const char *cmd;
     113        const char *terminal = NULL;
    112114        errno_t rc;
    113115
     
    142144                }
    143145
    144                 caption = sif_node_get_attr(nentry, "caption");
    145                 if (caption == NULL) {
     146                separator = sif_node_get_attr(nentry, "separator");
     147                if (separator != NULL && str_cmp(separator, "y") != 0) {
    146148                        rc = EIO;
    147149                        goto error;
    148150                }
    149151
    150                 cmd = sif_node_get_attr(nentry, "cmd");
    151                 if (cmd == NULL) {
    152                         rc = EIO;
    153                         goto error;
     152                if (separator == NULL) {
     153                        caption = sif_node_get_attr(nentry, "caption");
     154                        if (caption == NULL) {
     155                                rc = EIO;
     156                                goto error;
     157                        }
     158
     159                        cmd = sif_node_get_attr(nentry, "cmd");
     160                        if (cmd == NULL) {
     161                                rc = EIO;
     162                                goto error;
     163                        }
     164
     165                        terminal = sif_node_get_attr(nentry, "terminal");
     166                        if (terminal == NULL)
     167                                terminal = "n";
     168
     169                        rc = smenu_entry_new(tbcfg, nentry, caption, cmd,
     170                            str_cmp(terminal, "y") == 0, NULL);
     171                        if (rc != EOK)
     172                                goto error;
     173                } else {
     174                        rc = smenu_entry_sep_new(tbcfg, nentry, NULL);
     175                        if (rc != EOK)
     176                                goto error;
    154177                }
    155 
    156                 rc = smenu_entry_new(tbcfg, nentry, caption, cmd);
    157                 if (rc != EOK)
    158                         goto error;
    159178
    160179                nentry = sif_node_next_child(nentry);
     
    221240}
    222241
     242/** Get last start menu entry.
     243 *
     244 * @param tbcfg Taskbar configuration
     245 * @return Previous entry or @c NULL if the menu is empty
     246 */
     247smenu_entry_t *tbarcfg_smenu_last(tbarcfg_t *tbcfg)
     248{
     249        link_t *link;
     250
     251        link = list_last(&tbcfg->entries);
     252        if (link == NULL)
     253                return NULL;
     254
     255        return list_get_instance(link, smenu_entry_t, lentries);
     256}
     257
     258/** Get previous start menu entry.
     259 *
     260 * @param cur Current entry
     261 * @return Previous entry or @c NULL if @a cur is the last entry
     262 */
     263smenu_entry_t *tbarcfg_smenu_prev(smenu_entry_t *cur)
     264{
     265        link_t *link;
     266
     267        link = list_prev(&cur->lentries, &cur->smenu->entries);
     268        if (link == NULL)
     269                return NULL;
     270
     271        return list_get_instance(link, smenu_entry_t, lentries);
     272}
     273
    223274/** Get start menu entry caption.
    224275 *
     
    228279const char *smenu_entry_get_caption(smenu_entry_t *entry)
    229280{
     281        assert(!entry->separator);
    230282        return entry->caption;
    231283}
     
    233285/** Get start menu entry command.
    234286 *
    235  * @param entr Start menu entry
     287 * @param entry Start menu entry
    236288 * @return Command to run
    237289 */
    238290const char *smenu_entry_get_cmd(smenu_entry_t *entry)
    239291{
     292        assert(!entry->separator);
    240293        return entry->cmd;
     294}
     295
     296/** Get start menu entry start in terminal flag.
     297 *
     298 * @param entry Start menu entry
     299 * @return Start in terminal flag
     300 */
     301bool smenu_entry_get_terminal(smenu_entry_t *entry)
     302{
     303        assert(!entry->separator);
     304        return entry->terminal;
     305}
     306
     307/** Get start menu entry separator flag.
     308 *
     309 * @param entry Start menu entry
     310 * @return Separator flag
     311 */
     312bool smenu_entry_get_separator(smenu_entry_t *entry)
     313{
     314        return entry->separator;
    241315}
    242316
     
    253327{
    254328        char *dcap;
     329
     330        assert(!entry->separator);
    255331
    256332        dcap = str_dup(caption);
     
    276352        char *dcmd;
    277353
     354        assert(!entry->separator);
     355
    278356        dcmd = str_dup(cmd);
    279357        if (dcmd == NULL)
     
    285363}
    286364
     365/** Set start menu entry start in terminal flag.
     366 *
     367 * Note: To make the change visible to others and persistent,
     368 * you must call @c smenu_entry_save()
     369 *
     370 * @param entry Start menu entry
     371 * @param terminal Start in terminal flag
     372 */
     373void smenu_entry_set_terminal(smenu_entry_t *entry, bool terminal)
     374{
     375        assert(!entry->separator);
     376        entry->terminal = terminal;
     377}
     378
     379/** Save start menu entry using transaction.
     380 *
     381 * @param entry Start menu entry
     382 * @param trans Transaction
     383 */
     384static errno_t smenu_entry_save_trans(smenu_entry_t *entry, sif_trans_t *trans)
     385{
     386        errno_t rc;
     387
     388        if (entry->separator) {
     389                rc = sif_node_set_attr(trans, entry->nentry, "separator", "y");
     390                if (rc != EOK)
     391                        goto error;
     392        } else {
     393                sif_node_unset_attr(trans, entry->nentry, "separator");
     394
     395                rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd);
     396                if (rc != EOK)
     397                        goto error;
     398
     399                rc = sif_node_set_attr(trans, entry->nentry, "caption",
     400                    entry->caption);
     401                if (rc != EOK)
     402                        goto error;
     403
     404                rc = sif_node_set_attr(trans, entry->nentry, "terminal",
     405                    entry->terminal ? "y" : "n");
     406                if (rc != EOK)
     407                        goto error;
     408        }
     409
     410        return EOK;
     411error:
     412        return rc;
     413}
     414
    287415/** Save any changes to start menu entry.
    288416 *
     
    298426                goto error;
    299427
    300         rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd);
    301         if (rc != EOK)
    302                 goto error;
    303 
    304         rc = sif_node_set_attr(trans, entry->nentry, "caption", entry->caption);
     428        rc = smenu_entry_save_trans(entry, trans);
    305429        if (rc != EOK)
    306430                goto error;
     
    325449 * @param caption Caption
    326450 * @param cmd Command to run
     451 * @param terminal Start in terminal
     452 * @param rentry Place to store pointer to new entry or @c NULL
    327453 */
    328454errno_t smenu_entry_new(tbarcfg_t *smenu, sif_node_t *nentry,
    329     const char *caption, const char *cmd)
     455    const char *caption, const char *cmd, bool terminal, smenu_entry_t **rentry)
    330456{
    331457        smenu_entry_t *entry;
     
    352478        }
    353479
     480        entry->terminal = terminal;
     481
    354482        entry->smenu = smenu;
    355483        list_append(&entry->lentries, &smenu->entries);
     484        if (rentry != NULL)
     485                *rentry = entry;
    356486        return EOK;
    357487error:
     
    367497}
    368498
     499/** Allocate a start menu separator entry and append it to the start menu
     500 * (internal).
     501 *
     502 * This only creates the entry in memory, but does not update the repository.
     503 *
     504 * @param smenu Start menu
     505 * @param nentry Backing SIF node
     506 * @param rentry Place to store pointer to new entry or @c NULL
     507 */
     508errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry,
     509    smenu_entry_t **rentry)
     510{
     511        smenu_entry_t *entry;
     512        errno_t rc;
     513
     514        entry = calloc(1, sizeof(smenu_entry_t));
     515        if (entry == NULL) {
     516                rc = ENOMEM;
     517                goto error;
     518        }
     519
     520        entry->nentry = nentry;
     521        entry->separator = true;
     522
     523        entry->smenu = smenu;
     524        list_append(&entry->lentries, &smenu->entries);
     525        if (rentry != NULL)
     526                *rentry = entry;
     527
     528        return EOK;
     529error:
     530        return rc;
     531}
     532
    369533/** Delete start menu entry.
    370534 *
     
    377541{
    378542        list_remove(&entry->lentries);
    379         free(entry->caption);
    380         free(entry->cmd);
     543        if (entry->caption != NULL)
     544                free(entry->caption);
     545        if (entry->cmd != NULL)
     546                free(entry->cmd);
    381547        free(entry);
    382548}
     
    388554 * @param caption Caption
    389555 * @param cmd Command to run
     556 * @param terminal Start in terminal
     557 * @param rentry Place to store pointer to new entry or @c NULL
    390558 */
    391559errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,
    392     const char *cmd)
     560    const char *cmd, bool terminal, smenu_entry_t **rentry)
    393561{
    394562        sif_node_t *nentry;
     563        smenu_entry_t *entry;
    395564        errno_t rc;
    396565        sif_trans_t *trans = NULL;
     
    413582                goto error;
    414583
    415         rc = smenu_entry_new(smenu, nentry, caption, cmd);
     584        rc = sif_node_set_attr(trans, nentry, "terminal", terminal ? "y" : "n");
     585        if (rc != EOK)
     586                goto error;
     587
     588        rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal, &entry);
    416589        if (rc != EOK)
    417590                goto error;
     
    421594                goto error;
    422595
     596        if (rentry != NULL)
     597                *rentry = entry;
    423598        return EOK;
    424599error:
     
    428603}
    429604
    430 /** Destroy start menu entry..
    431  *
    432  * @param entry Start menu entry
    433  * @return EOK on success or an error code
    434  */
    435 errno_t smenu_entry_destroy(smenu_entry_t *entry)
    436 {
     605/** Create new start menu separator entry.
     606 *
     607 * @param smenu Start menu
     608 * @param nentry Backing SIF node
     609 * @param rentry Place to store pointer to new entry or @c NULL
     610 */
     611errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry)
     612{
     613        sif_node_t *nentry;
     614        smenu_entry_t *entry;
    437615        errno_t rc;
    438616        sif_trans_t *trans = NULL;
    439617
    440         rc = sif_trans_begin(entry->smenu->repo, &trans);
    441         if (rc != EOK)
    442                 goto error;
    443 
    444         sif_node_destroy(trans, entry->nentry);
     618        rc = sif_trans_begin(smenu->repo, &trans);
     619        if (rc != EOK)
     620                goto error;
     621
     622        rc = sif_node_append_child(trans, smenu->nentries, "entry",
     623            &nentry);
     624        if (rc != EOK)
     625                goto error;
     626
     627        rc = sif_node_set_attr(trans, nentry, "separator", "y");
     628        if (rc != EOK)
     629                goto error;
     630
     631        rc = smenu_entry_sep_new(smenu, nentry, &entry);
     632        if (rc != EOK)
     633                goto error;
    445634
    446635        rc = sif_trans_end(trans);
     
    448637                goto error;
    449638
    450         smenu_entry_delete(entry);
     639        if (rentry != NULL)
     640                *rentry = entry;
    451641        return EOK;
    452642error:
     
    456646}
    457647
     648/** Destroy start menu entry.
     649 *
     650 * @param entry Start menu entry
     651 * @return EOK on success or an error code
     652 */
     653errno_t smenu_entry_destroy(smenu_entry_t *entry)
     654{
     655        errno_t rc;
     656        sif_trans_t *trans = NULL;
     657
     658        rc = sif_trans_begin(entry->smenu->repo, &trans);
     659        if (rc != EOK)
     660                goto error;
     661
     662        sif_node_destroy(trans, entry->nentry);
     663
     664        rc = sif_trans_end(trans);
     665        if (rc != EOK)
     666                goto error;
     667
     668        smenu_entry_delete(entry);
     669        return EOK;
     670error:
     671        if (trans != NULL)
     672                sif_trans_abort(trans);
     673        return rc;
     674}
     675
     676/** Move start menu entry up.
     677 *
     678 * @param entry Start menu entry
     679 * @return EOK on success or an error code
     680 */
     681errno_t smenu_entry_move_up(smenu_entry_t *entry)
     682{
     683        errno_t rc;
     684        sif_trans_t *trans = NULL;
     685        sif_node_t *nnode = NULL;
     686        sif_node_t *old_node;
     687        smenu_entry_t *prev;
     688
     689        rc = sif_trans_begin(entry->smenu->repo, &trans);
     690        if (rc != EOK)
     691                goto error;
     692
     693        prev = tbarcfg_smenu_prev(entry);
     694        if (prev == NULL) {
     695                /* Entry is already at first position, nothing to do. */
     696                return EOK;
     697        }
     698
     699        rc = sif_node_insert_before(trans, prev->nentry, "entry", &nnode);
     700        if (rc != EOK)
     701                goto error;
     702
     703        old_node = entry->nentry;
     704        entry->nentry = nnode;
     705
     706        rc = smenu_entry_save_trans(entry, trans);
     707        if (rc != EOK) {
     708                entry->nentry = old_node;
     709                goto error;
     710        }
     711
     712        sif_node_destroy(trans, old_node);
     713
     714        rc = sif_trans_end(trans);
     715        if (rc != EOK) {
     716                entry->nentry = old_node;
     717                goto error;
     718        }
     719
     720        list_remove(&entry->lentries);
     721        list_insert_before(&entry->lentries, &prev->lentries);
     722        return EOK;
     723error:
     724        if (nnode != NULL)
     725                sif_node_destroy(trans, nnode);
     726        if (trans != NULL)
     727                sif_trans_abort(trans);
     728        return rc;
     729}
     730
     731/** Move start menu entry down.
     732 *
     733 * @param entry Start menu entry
     734 * @return EOK on success or an error code
     735 */
     736errno_t smenu_entry_move_down(smenu_entry_t *entry)
     737{
     738        errno_t rc;
     739        sif_trans_t *trans = NULL;
     740        sif_node_t *nnode = NULL;
     741        sif_node_t *old_node;
     742        smenu_entry_t *next;
     743
     744        rc = sif_trans_begin(entry->smenu->repo, &trans);
     745        if (rc != EOK)
     746                goto error;
     747
     748        next = tbarcfg_smenu_next(entry);
     749        if (next == NULL) {
     750                /* Entry is already at last position, nothing to do. */
     751                return EOK;
     752        }
     753
     754        rc = sif_node_insert_after(trans, next->nentry, "entry", &nnode);
     755        if (rc != EOK)
     756                goto error;
     757
     758        old_node = entry->nentry;
     759        entry->nentry = nnode;
     760
     761        rc = smenu_entry_save_trans(entry, trans);
     762        if (rc != EOK) {
     763                entry->nentry = old_node;
     764                goto error;
     765        }
     766
     767        sif_node_destroy(trans, old_node);
     768
     769        rc = sif_trans_end(trans);
     770        if (rc != EOK) {
     771                entry->nentry = old_node;
     772                goto error;
     773        }
     774
     775        list_remove(&entry->lentries);
     776        list_insert_after(&entry->lentries, &next->lentries);
     777        return EOK;
     778error:
     779        if (nnode != NULL)
     780                sif_node_destroy(trans, nnode);
     781        if (trans != NULL)
     782                sif_trans_abort(trans);
     783        return rc;
     784}
     785
    458786/** @}
    459787 */
  • uspace/lib/tbarcfg/test/tbarcfg.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6767        tbarcfg_t *tbcfg;
    6868        char fname[L_tmpnam], *p;
     69        smenu_entry_t *e1 = NULL, *e2 = NULL;
    6970        smenu_entry_t *e;
    7071
     
    7576        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    7677
    77         rc = smenu_entry_create(tbcfg, "A", "a");
    78         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    79 
    80         rc = smenu_entry_create(tbcfg, "B", "b");
     78        rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
     79        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     80        PCUT_ASSERT_NOT_NULL(e1);
     81
     82        rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
     83        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     84        PCUT_ASSERT_NOT_NULL(e2);
     85
     86        /* Create entry without getting a pointer to it */
     87        rc = smenu_entry_create(tbcfg, "C", "c", false, NULL);
    8188        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    8289
    8390        e = tbarcfg_smenu_first(tbcfg);
    84         PCUT_ASSERT_NOT_NULL(e);
     91        PCUT_ASSERT_EQUALS(e1, e);
     92        e = tbarcfg_smenu_next(e);
     93        PCUT_ASSERT_EQUALS(e2, e);
    8594        e = tbarcfg_smenu_next(e);
    8695        PCUT_ASSERT_NOT_NULL(e);
     
    92101}
    93102
     103/** Iterating over start menu entries backwards */
     104PCUT_TEST(last_prev)
     105{
     106        errno_t rc;
     107        tbarcfg_t *tbcfg;
     108        char fname[L_tmpnam], *p;
     109        smenu_entry_t *e1 = NULL, *e2 = NULL;
     110        smenu_entry_t *e;
     111
     112        p = tmpnam(fname);
     113        PCUT_ASSERT_NOT_NULL(p);
     114
     115        rc = tbarcfg_create(fname, &tbcfg);
     116        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     117
     118        rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
     119        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     120        PCUT_ASSERT_NOT_NULL(e1);
     121
     122        rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
     123        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     124        PCUT_ASSERT_NOT_NULL(e2);
     125
     126        e = tbarcfg_smenu_last(tbcfg);
     127        PCUT_ASSERT_EQUALS(e2, e);
     128        e = tbarcfg_smenu_prev(e);
     129        PCUT_ASSERT_EQUALS(e1, e);
     130        e = tbarcfg_smenu_prev(e);
     131        PCUT_ASSERT_NULL(e);
     132
     133        tbarcfg_close(tbcfg);
     134        remove(fname);
     135}
     136
     137/** Separator entry */
     138PCUT_TEST(separator)
     139{
     140        errno_t rc;
     141        tbarcfg_t *tbcfg;
     142        char fname[L_tmpnam], *p;
     143        const char *caption;
     144        const char *cmd;
     145        smenu_entry_t *e1 = NULL, *e2 = NULL;
     146        smenu_entry_t *e;
     147
     148        p = tmpnam(fname);
     149        PCUT_ASSERT_NOT_NULL(p);
     150
     151        rc = tbarcfg_create(fname, &tbcfg);
     152        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     153
     154        rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
     155        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     156        PCUT_ASSERT_NOT_NULL(e1);
     157
     158        rc = smenu_entry_sep_create(tbcfg, &e2);
     159        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     160        PCUT_ASSERT_NOT_NULL(e2);
     161
     162        PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1));
     163        PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2));
     164
     165        tbarcfg_close(tbcfg);
     166
     167        /* Re-open repository */
     168
     169        rc = tbarcfg_open(fname, &tbcfg);
     170        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     171
     172        e = tbarcfg_smenu_first(tbcfg);
     173        PCUT_ASSERT_NOT_NULL(e);
     174
     175        /* Check that new values of properties have persisted */
     176        PCUT_ASSERT_FALSE(smenu_entry_get_separator(e));
     177        caption = smenu_entry_get_caption(e);
     178        PCUT_ASSERT_STR_EQUALS("A", caption);
     179        cmd = smenu_entry_get_cmd(e);
     180        PCUT_ASSERT_STR_EQUALS("a", cmd);
     181
     182        e = tbarcfg_smenu_next(e);
     183
     184        /* Check that entry is still a separator */
     185        PCUT_ASSERT_TRUE(smenu_entry_get_separator(e));
     186
     187        tbarcfg_close(tbcfg);
     188        remove(fname);
     189}
     190
    94191/** Getting menu entry properties */
    95 PCUT_TEST(get_caption_cmd)
     192PCUT_TEST(get_caption_cmd_term)
    96193{
    97194        errno_t rc;
     
    101198        const char *caption;
    102199        const char *cmd;
    103 
    104         p = tmpnam(fname);
    105         PCUT_ASSERT_NOT_NULL(p);
    106 
    107         rc = tbarcfg_create(fname, &tbcfg);
    108         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    109 
    110         rc = smenu_entry_create(tbcfg, "A", "a");
    111         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    112 
    113         e = tbarcfg_smenu_first(tbcfg);
    114         PCUT_ASSERT_NOT_NULL(e);
     200        bool terminal;
     201
     202        p = tmpnam(fname);
     203        PCUT_ASSERT_NOT_NULL(p);
     204
     205        rc = tbarcfg_create(fname, &tbcfg);
     206        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     207
     208        rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
     209        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    115210
    116211        caption = smenu_entry_get_caption(e);
     
    118213        cmd = smenu_entry_get_cmd(e);
    119214        PCUT_ASSERT_STR_EQUALS("a", cmd);
     215        terminal = smenu_entry_get_terminal(e);
     216        PCUT_ASSERT_FALSE(terminal);
    120217
    121218        tbarcfg_close(tbcfg);
     
    124221
    125222/** Setting menu entry properties */
    126 PCUT_TEST(set_caption_cmd)
     223PCUT_TEST(set_caption_cmd_term)
    127224{
    128225        errno_t rc;
     
    132229        const char *caption;
    133230        const char *cmd;
    134 
    135         p = tmpnam(fname);
    136         PCUT_ASSERT_NOT_NULL(p);
    137 
    138         rc = tbarcfg_create(fname, &tbcfg);
    139         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    140 
    141         rc = smenu_entry_create(tbcfg, "A", "a");
    142         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    143 
    144         e = tbarcfg_smenu_first(tbcfg);
    145         PCUT_ASSERT_NOT_NULL(e);
     231        bool terminal;
     232
     233        p = tmpnam(fname);
     234        PCUT_ASSERT_NOT_NULL(p);
     235
     236        rc = tbarcfg_create(fname, &tbcfg);
     237        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     238
     239        rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
     240        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    146241
    147242        caption = smenu_entry_get_caption(e);
     
    149244        cmd = smenu_entry_get_cmd(e);
    150245        PCUT_ASSERT_STR_EQUALS("a", cmd);
     246        terminal = smenu_entry_get_terminal(e);
     247        PCUT_ASSERT_FALSE(terminal);
    151248
    152249        /* Set properties */
     
    155252        rc = smenu_entry_set_cmd(e, "b");
    156253        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     254        smenu_entry_set_terminal(e, true);
    157255
    158256        rc = smenu_entry_save(e);
     
    164262        cmd = smenu_entry_get_cmd(e);
    165263        PCUT_ASSERT_STR_EQUALS("b", cmd);
     264        terminal = smenu_entry_get_terminal(e);
     265        PCUT_ASSERT_TRUE(terminal);
    166266
    167267        tbarcfg_close(tbcfg);
     
    194294        const char *caption;
    195295        const char *cmd;
    196 
    197         p = tmpnam(fname);
    198         PCUT_ASSERT_NOT_NULL(p);
    199 
    200         rc = tbarcfg_create(fname, &tbcfg);
    201         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    202 
    203         rc = smenu_entry_create(tbcfg, "A", "a");
    204         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    205 
    206         e = tbarcfg_smenu_first(tbcfg);
     296        bool terminal;
     297
     298        p = tmpnam(fname);
     299        PCUT_ASSERT_NOT_NULL(p);
     300
     301        rc = tbarcfg_create(fname, &tbcfg);
     302        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     303
     304        rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
     305        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    207306        PCUT_ASSERT_NOT_NULL(e);
    208307
     
    211310        cmd = smenu_entry_get_cmd(e);
    212311        PCUT_ASSERT_STR_EQUALS("a", cmd);
     312        terminal = smenu_entry_get_terminal(e);
     313        PCUT_ASSERT_FALSE(terminal);
     314
     315        smenu_entry_destroy(e);
     316
     317        rc = smenu_entry_create(tbcfg, "B", "b", true, &e);
     318        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     319        PCUT_ASSERT_NOT_NULL(e);
     320
     321        caption = smenu_entry_get_caption(e);
     322        PCUT_ASSERT_STR_EQUALS("B", caption);
     323        cmd = smenu_entry_get_cmd(e);
     324        PCUT_ASSERT_STR_EQUALS("b", cmd);
     325        terminal = smenu_entry_get_terminal(e);
     326        PCUT_ASSERT_TRUE(terminal);
     327
     328        smenu_entry_destroy(e);
    213329
    214330        tbarcfg_close(tbcfg);
     
    222338        tbarcfg_t *tbcfg;
    223339        char fname[L_tmpnam], *p;
    224         smenu_entry_t *e;
    225 
    226         p = tmpnam(fname);
    227         PCUT_ASSERT_NOT_NULL(p);
    228 
    229         rc = tbarcfg_create(fname, &tbcfg);
    230         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    231 
    232         rc = smenu_entry_create(tbcfg, "A", "a");
    233         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    234 
    235         e = tbarcfg_smenu_first(tbcfg);
    236         PCUT_ASSERT_NOT_NULL(e);
     340        smenu_entry_t *e, *f;
     341
     342        p = tmpnam(fname);
     343        PCUT_ASSERT_NOT_NULL(p);
     344
     345        rc = tbarcfg_create(fname, &tbcfg);
     346        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     347
     348        rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
     349        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     350
     351        f = tbarcfg_smenu_first(tbcfg);
     352        PCUT_ASSERT_EQUALS(e, f);
    237353
    238354        rc = smenu_entry_destroy(e);
    239355        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    240356
    241         e = tbarcfg_smenu_first(tbcfg);
    242         PCUT_ASSERT_NULL(e);
     357        f = tbarcfg_smenu_first(tbcfg);
     358        PCUT_ASSERT_NULL(f);
     359
     360        tbarcfg_close(tbcfg);
     361        remove(fname);
     362}
     363
     364/** Move start menu entry up */
     365PCUT_TEST(entry_move_up)
     366{
     367        errno_t rc;
     368        tbarcfg_t *tbcfg;
     369        char fname[L_tmpnam], *p;
     370        smenu_entry_t *e1, *e2, *e3;
     371        smenu_entry_t *f;
     372        const char *caption;
     373        const char *cmd;
     374
     375        p = tmpnam(fname);
     376        PCUT_ASSERT_NOT_NULL(p);
     377
     378        rc = tbarcfg_create(fname, &tbcfg);
     379        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     380
     381        rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
     382        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     383
     384        rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
     385        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     386
     387        rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
     388        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     389
     390        f = tbarcfg_smenu_first(tbcfg);
     391        PCUT_ASSERT_EQUALS(e1, f);
     392
     393        /* Moving the first entry up should have no effect */
     394
     395        rc = smenu_entry_move_up(e1);
     396        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     397
     398        f = tbarcfg_smenu_first(tbcfg);
     399        PCUT_ASSERT_EQUALS(e1, f);
     400
     401        /* Moving the second entry up should move it to first position */
     402
     403        rc = smenu_entry_move_up(e2);
     404        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     405
     406        f = tbarcfg_smenu_first(tbcfg);
     407        PCUT_ASSERT_EQUALS(e2, f);
     408
     409        /* Moving the last entry up should move it to second position */
     410
     411        rc = smenu_entry_move_up(e3);
     412        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     413
     414        f = tbarcfg_smenu_first(tbcfg);
     415        PCUT_ASSERT_EQUALS(e2, f);
     416
     417        f = tbarcfg_smenu_next(f);
     418        PCUT_ASSERT_EQUALS(e3, f);
     419
     420        f = tbarcfg_smenu_next(f);
     421        PCUT_ASSERT_EQUALS(e1, f);
     422
     423        tbarcfg_close(tbcfg);
     424
     425        /* Re-open repository */
     426
     427        rc = tbarcfg_open(fname, &tbcfg);
     428        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     429
     430        /* Check that new order of entries persisted */
     431
     432        f = tbarcfg_smenu_first(tbcfg);
     433        PCUT_ASSERT_NOT_NULL(f);
     434
     435        caption = smenu_entry_get_caption(f);
     436        PCUT_ASSERT_STR_EQUALS("B", caption);
     437        cmd = smenu_entry_get_cmd(f);
     438        PCUT_ASSERT_STR_EQUALS("b", cmd);
     439
     440        f = tbarcfg_smenu_next(f);
     441        PCUT_ASSERT_NOT_NULL(f);
     442
     443        caption = smenu_entry_get_caption(f);
     444        PCUT_ASSERT_STR_EQUALS("C", caption);
     445        cmd = smenu_entry_get_cmd(f);
     446        PCUT_ASSERT_STR_EQUALS("c", cmd);
     447
     448        f = tbarcfg_smenu_next(f);
     449        PCUT_ASSERT_NOT_NULL(f);
     450
     451        caption = smenu_entry_get_caption(f);
     452        PCUT_ASSERT_STR_EQUALS("A", caption);
     453        cmd = smenu_entry_get_cmd(f);
     454        PCUT_ASSERT_STR_EQUALS("a", cmd);
     455
     456        tbarcfg_close(tbcfg);
     457        remove(fname);
     458}
     459
     460/** Move start menu entry down */
     461PCUT_TEST(entry_move_down)
     462{
     463        errno_t rc;
     464        tbarcfg_t *tbcfg;
     465        char fname[L_tmpnam], *p;
     466        smenu_entry_t *e1, *e2, *e3;
     467        smenu_entry_t *f;
     468        const char *caption;
     469        const char *cmd;
     470
     471        p = tmpnam(fname);
     472        PCUT_ASSERT_NOT_NULL(p);
     473
     474        rc = tbarcfg_create(fname, &tbcfg);
     475        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     476
     477        rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
     478        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     479
     480        rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
     481        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     482
     483        rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
     484        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     485
     486        f = tbarcfg_smenu_last(tbcfg);
     487        PCUT_ASSERT_EQUALS(e3, f);
     488
     489        /* Moving the last entry down should have no effect */
     490
     491        rc = smenu_entry_move_down(e3);
     492        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     493
     494        f = tbarcfg_smenu_last(tbcfg);
     495        PCUT_ASSERT_EQUALS(e3, f);
     496
     497        /* Moving the second entry down should move it to last position */
     498
     499        rc = smenu_entry_move_down(e2);
     500        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     501
     502        f = tbarcfg_smenu_last(tbcfg);
     503        PCUT_ASSERT_EQUALS(e2, f);
     504
     505        /* Moving the first entry down should move it to second position */
     506
     507        rc = smenu_entry_move_down(e1);
     508        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     509
     510        f = tbarcfg_smenu_last(tbcfg);
     511        PCUT_ASSERT_EQUALS(e2, f);
     512
     513        f = tbarcfg_smenu_prev(f);
     514        PCUT_ASSERT_EQUALS(e1, f);
     515
     516        f = tbarcfg_smenu_prev(f);
     517        PCUT_ASSERT_EQUALS(e3, f);
     518
     519        tbarcfg_close(tbcfg);
     520
     521        /* Re-open repository */
     522
     523        rc = tbarcfg_open(fname, &tbcfg);
     524        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     525
     526        /* Check that new order of entries persisted */
     527
     528        f = tbarcfg_smenu_first(tbcfg);
     529        PCUT_ASSERT_NOT_NULL(f);
     530
     531        caption = smenu_entry_get_caption(f);
     532        PCUT_ASSERT_STR_EQUALS("C", caption);
     533        cmd = smenu_entry_get_cmd(f);
     534        PCUT_ASSERT_STR_EQUALS("c", cmd);
     535
     536        f = tbarcfg_smenu_next(f);
     537        PCUT_ASSERT_NOT_NULL(f);
     538
     539        caption = smenu_entry_get_caption(f);
     540        PCUT_ASSERT_STR_EQUALS("A", caption);
     541        cmd = smenu_entry_get_cmd(f);
     542        PCUT_ASSERT_STR_EQUALS("a", cmd);
     543
     544        f = tbarcfg_smenu_next(f);
     545        PCUT_ASSERT_NOT_NULL(f);
     546
     547        caption = smenu_entry_get_caption(f);
     548        PCUT_ASSERT_STR_EQUALS("B", caption);
     549        cmd = smenu_entry_get_cmd(f);
     550        PCUT_ASSERT_STR_EQUALS("b", cmd);
    243551
    244552        tbarcfg_close(tbcfg);
  • uspace/lib/ui/include/ui/checkbox.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5252extern void ui_checkbox_set_cb(ui_checkbox_t *, ui_checkbox_cb_t *, void *);
    5353extern void ui_checkbox_set_rect(ui_checkbox_t *, gfx_rect_t *);
     54extern bool ui_checkbox_get_checked(ui_checkbox_t *);
     55extern void ui_checkbox_set_checked(ui_checkbox_t *, bool);
    5456extern errno_t ui_checkbox_paint(ui_checkbox_t *);
    5557extern void ui_checkbox_press(ui_checkbox_t *);
  • uspace/lib/ui/include/ui/list.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5757extern errno_t ui_list_entry_append(ui_list_t *,
    5858    ui_list_entry_attr_t *, ui_list_entry_t **);
     59extern void ui_list_entry_move_up(ui_list_entry_t *);
     60extern void ui_list_entry_move_down(ui_list_entry_t *);
    5961extern void ui_list_entry_delete(ui_list_entry_t *);
    6062extern void *ui_list_entry_get_arg(ui_list_entry_t *);
  • uspace/lib/ui/src/checkbox.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    139139}
    140140
    141 /** Set button rectangle.
    142  *
    143  * @param checkbox Button
    144  * @param rect New button rectangle
     141/** Set check box rectangle.
     142 *
     143 * @param checkbox Check box
     144 * @param rect New check box rectangle
    145145 */
    146146void ui_checkbox_set_rect(ui_checkbox_t *checkbox, gfx_rect_t *rect)
    147147{
    148148        checkbox->rect = *rect;
     149}
     150
     151/** Return if check box is checked.
     152 *
     153 * @param checkbox Check box
     154 * @return @c true iff check box is checked
     155 */
     156bool ui_checkbox_get_checked(ui_checkbox_t *checkbox)
     157{
     158        return checkbox->checked;
     159}
     160
     161/** Set check box checked state.
     162 *
     163 * @param checkbox Check box
     164 * @param checked @c true iff checkbox should be checked
     165 */
     166void ui_checkbox_set_checked(ui_checkbox_t *checkbox, bool checked)
     167{
     168        checkbox->checked = checked;
    149169}
    150170
  • uspace/lib/ui/src/list.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    711711}
    712712
     713/** Move UI list entry one position up.
     714 *
     715 * @parm entry UI list entry
     716 */
     717void ui_list_entry_move_up(ui_list_entry_t *entry)
     718{
     719        ui_list_t *list = entry->list;
     720        ui_list_entry_t *prev;
     721
     722        prev = ui_list_prev(entry);
     723        if (prev == NULL) {
     724                /* Entry is already on first position, nothing to do. */
     725                return;
     726        }
     727
     728        list_remove(&entry->lentries);
     729        list_insert_before(&entry->lentries, &prev->lentries);
     730
     731        /* Make sure page stays on the same position/idx as it was before */
     732        if (list->page == entry) {
     733                list->page = prev;
     734        } else if (list->page == prev) {
     735                list->page = entry;
     736        }
     737
     738        /*
     739         * Return cursor to the same position/idx as it was before,
     740         * but then move it using ui_list_cursor_move() to the new
     741         * position (this ensures scrolling when needed).
     742         */
     743        if (list->cursor == entry) {
     744                list->cursor = prev;
     745                ui_list_cursor_move(list, entry, list->cursor_idx - 1);
     746        } else if (list->cursor == prev) {
     747                list->cursor = entry;
     748                ui_list_cursor_move(list, prev, list->cursor_idx + 1);
     749        }
     750}
     751
     752/** Move UI list entry one position down.
     753 *
     754 * @parm entry UI list entry
     755 */
     756void ui_list_entry_move_down(ui_list_entry_t *entry)
     757{
     758        ui_list_t *list = entry->list;
     759        ui_list_entry_t *next;
     760
     761        next = ui_list_next(entry);
     762        if (next == NULL) {
     763                /* Entry is already on last position, nothing to do. */
     764                return;
     765        }
     766
     767        list_remove(&entry->lentries);
     768        list_insert_after(&entry->lentries, &next->lentries);
     769
     770        /* Make sure page stays on the same position/idx as it was before */
     771        if (list->page == entry) {
     772                list->page = next;
     773        } else if (list->page == next) {
     774                list->page = entry;
     775        }
     776
     777        /*
     778         * Return cursor to the same position/idx as it was before,
     779         * but then move it using ui_list_cursor_move() to the new
     780         * position (this ensures scrolling when needed).
     781         */
     782        if (list->cursor == entry) {
     783                list->cursor = next;
     784                ui_list_cursor_move(list, entry, list->cursor_idx + 1);
     785        } else if (list->cursor == next) {
     786                list->cursor = entry;
     787                ui_list_cursor_move(list, next, list->cursor_idx - 1);
     788        }
     789}
     790
    713791/** Destroy UI list entry.
    714792 *
  • uspace/lib/ui/test/checkbox.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    151151}
    152152
     153/** Get check box checked returns internal field */
     154PCUT_TEST(get_checked)
     155{
     156        ui_checkbox_t *checkbox;
     157        errno_t rc;
     158
     159        rc = ui_checkbox_create(NULL, "Hello", &checkbox);
     160        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     161
     162        checkbox->checked = false;
     163        PCUT_ASSERT_FALSE(ui_checkbox_get_checked(checkbox));
     164        checkbox->checked = true;
     165        PCUT_ASSERT_TRUE(ui_checkbox_get_checked(checkbox));
     166
     167        ui_checkbox_destroy(checkbox);
     168}
     169
     170/** Set check box checked sets internal field */
     171PCUT_TEST(set_checked)
     172{
     173        ui_checkbox_t *checkbox;
     174        errno_t rc;
     175
     176        rc = ui_checkbox_create(NULL, "Hello", &checkbox);
     177        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     178
     179        ui_checkbox_set_checked(checkbox, true);
     180        PCUT_ASSERT_TRUE(checkbox->checked);
     181        ui_checkbox_set_checked(checkbox, false);
     182        PCUT_ASSERT_FALSE(checkbox->checked);
     183
     184        ui_checkbox_destroy(checkbox);
     185}
     186
    153187/** Paint check box in graphics mode */
    154188PCUT_TEST(paint_gfx)
  • uspace/lib/ui/test/list.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    904904}
    905905
     906/** ui_list_entry_move_up() moves entry up */
     907PCUT_TEST(entry_move_up)
     908{
     909        ui_t *ui;
     910        ui_window_t *window;
     911        ui_wnd_params_t params;
     912        ui_list_t *list;
     913        ui_list_entry_attr_t attr;
     914        ui_list_entry_t *e1, *e2, *e3;
     915        ui_list_entry_t *e;
     916        errno_t rc;
     917
     918        rc = ui_create_disp(NULL, &ui);
     919        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     920
     921        ui_wnd_params_init(&params);
     922        params.caption = "Test";
     923
     924        rc = ui_window_create(ui, &params, &window);
     925        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     926
     927        rc = ui_list_create(window, true, &list);
     928        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     929
     930        ui_list_entry_attr_init(&attr);
     931
     932        /* Create entries */
     933
     934        attr.caption = "a";
     935        attr.arg = (void *)1;
     936        rc = ui_list_entry_append(list, &attr, &e1);
     937        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     938
     939        attr.caption = "b";
     940        attr.arg = (void *)2;
     941        rc = ui_list_entry_append(list, &attr, &e2);
     942        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     943
     944        attr.caption = "c";
     945        attr.arg = (void *)3;
     946        rc = ui_list_entry_append(list, &attr, &e3);
     947        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     948
     949        e = ui_list_first(list);
     950        PCUT_ASSERT_EQUALS(e1, e);
     951
     952        /* Moving first entry up should have no effect */
     953        ui_list_entry_move_up(e1);
     954
     955        e = ui_list_first(list);
     956        PCUT_ASSERT_EQUALS(e1, e);
     957
     958        e = ui_list_next(e);
     959        PCUT_ASSERT_EQUALS(e2, e);
     960
     961        e = ui_list_next(e);
     962        PCUT_ASSERT_EQUALS(e3, e);
     963
     964        e = ui_list_next(e);
     965        PCUT_ASSERT_NULL(e);
     966
     967        /* Move second entry up */
     968        ui_list_entry_move_up(e2);
     969
     970        e = ui_list_first(list);
     971        PCUT_ASSERT_EQUALS(e2, e);
     972
     973        e = ui_list_next(e);
     974        PCUT_ASSERT_EQUALS(e1, e);
     975
     976        e = ui_list_next(e);
     977        PCUT_ASSERT_EQUALS(e3, e);
     978
     979        e = ui_list_next(e);
     980        PCUT_ASSERT_NULL(e);
     981
     982        ui_list_destroy(list);
     983        ui_window_destroy(window);
     984        ui_destroy(ui);
     985}
     986
     987/** ui_list_entry_move_down() moves entry down */
     988PCUT_TEST(entry_move_down)
     989{
     990        ui_t *ui;
     991        ui_window_t *window;
     992        ui_wnd_params_t params;
     993        ui_list_t *list;
     994        ui_list_entry_attr_t attr;
     995        ui_list_entry_t *e1, *e2, *e3;
     996        ui_list_entry_t *e;
     997        errno_t rc;
     998
     999        rc = ui_create_disp(NULL, &ui);
     1000        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1001
     1002        ui_wnd_params_init(&params);
     1003        params.caption = "Test";
     1004
     1005        rc = ui_window_create(ui, &params, &window);
     1006        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1007
     1008        rc = ui_list_create(window, true, &list);
     1009        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1010
     1011        ui_list_entry_attr_init(&attr);
     1012
     1013        /* Create entries */
     1014
     1015        attr.caption = "a";
     1016        attr.arg = (void *)1;
     1017        rc = ui_list_entry_append(list, &attr, &e1);
     1018        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1019
     1020        attr.caption = "b";
     1021        attr.arg = (void *)2;
     1022        rc = ui_list_entry_append(list, &attr, &e2);
     1023        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1024
     1025        attr.caption = "c";
     1026        attr.arg = (void *)3;
     1027        rc = ui_list_entry_append(list, &attr, &e3);
     1028        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1029
     1030        e = ui_list_first(list);
     1031        PCUT_ASSERT_EQUALS(e1, e);
     1032
     1033        /* Moving last entry down should have no effect */
     1034        ui_list_entry_move_down(e3);
     1035
     1036        e = ui_list_first(list);
     1037        PCUT_ASSERT_EQUALS(e1, e);
     1038
     1039        e = ui_list_next(e);
     1040        PCUT_ASSERT_EQUALS(e2, e);
     1041
     1042        e = ui_list_next(e);
     1043        PCUT_ASSERT_EQUALS(e3, e);
     1044
     1045        e = ui_list_next(e);
     1046        PCUT_ASSERT_NULL(e);
     1047
     1048        /* Move second-to-last entry down */
     1049        ui_list_entry_move_down(e2);
     1050
     1051        e = ui_list_first(list);
     1052        PCUT_ASSERT_EQUALS(e1, e);
     1053
     1054        e = ui_list_next(e);
     1055        PCUT_ASSERT_EQUALS(e3, e);
     1056
     1057        e = ui_list_next(e);
     1058        PCUT_ASSERT_EQUALS(e2, e);
     1059
     1060        e = ui_list_next(e);
     1061        PCUT_ASSERT_NULL(e);
     1062
     1063        ui_list_destroy(list);
     1064        ui_window_destroy(window);
     1065        ui_destroy(ui);
     1066}
     1067
    9061068/** ui_list_entry_delete() deletes entry */
    9071069PCUT_TEST(entry_delete)
Note: See TracChangeset for help on using the changeset viewer.