Changeset c0757e1f in mainline for uspace/app


Ignore:
Timestamp:
2023-04-19T11:13:06Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
37087c8
Parents:
ec8ef12
Message:

UI display configuration utility

In addition to the command-line utility 'disp', we introduce its UI
equivalent 'display-cfg'. Currently this allows the user to configure
seats in a very comfortable way.

Location:
uspace/app
Files:
11 added
3 edited

Legend:

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

    rec8ef12 rc0757e1f  
    5656        printf("  %s assign-dev <device> <seat>\n", NAME);
    5757        printf("  %s unassign-dev <device>\n", NAME);
     58        printf("  %s list-dev <seat>\n", NAME);
    5859}
    5960
     
    393394}
    394395
     396/** List dev subcommand.
     397 *
     398 * @param dcfg_svc Display configuration service name
     399 * @param argc Number of arguments
     400 * @param argv Arguments
     401 * @return EOK on success or an erro code
     402 */
     403static errno_t list_dev(const char *dcfg_svc, int argc, char *argv[])
     404{
     405        dispcfg_t *dispcfg;
     406        char *seat_name;
     407        sysarg_t seat_id;
     408        dispcfg_dev_list_t *dev_list;
     409        size_t i;
     410        char *svc_name;
     411        table_t *table = NULL;
     412        errno_t rc;
     413
     414        if (argc < 1) {
     415                printf(NAME ": Missing arguments.\n");
     416                print_syntax();
     417                return EINVAL;
     418        }
     419
     420        if (argc > 1) {
     421                printf(NAME ": Too many arguments.\n");
     422                print_syntax();
     423                return EINVAL;
     424        }
     425
     426        seat_name = argv[0];
     427
     428        rc = dispcfg_open(dcfg_svc, NULL, NULL, &dispcfg);
     429        if (rc != EOK) {
     430                printf(NAME ": Failed connecting to display configuration "
     431                    "service: %s.\n", str_error(rc));
     432                return rc;
     433        }
     434
     435        rc = seat_find_by_name(dispcfg, seat_name, &seat_id);
     436        if (rc != EOK) {
     437                printf(NAME ": Seat '%s' not found.\n", seat_name);
     438                dispcfg_close(dispcfg);
     439                return ENOENT;
     440        }
     441
     442        rc = dispcfg_get_asgn_dev_list(dispcfg, seat_id, &dev_list);
     443        if (rc != EOK) {
     444                printf(NAME ": Failed getting seat list.\n");
     445                dispcfg_close(dispcfg);
     446                return rc;
     447        }
     448
     449        rc = table_create(&table);
     450        if (rc != EOK) {
     451                printf("Memory allocation failed.\n");
     452                dispcfg_free_dev_list(dev_list);
     453                dispcfg_close(dispcfg);
     454                return rc;
     455        }
     456
     457        table_header_row(table);
     458        table_printf(table, "Device Name\n");
     459
     460        for (i = 0; i < dev_list->ndevs; i++) {
     461                rc = loc_service_get_name(dev_list->devs[i], &svc_name);
     462                if (rc != EOK) {
     463                        printf("Failed getting name of service %zu\n",
     464                            (size_t)dev_list->devs[i]);
     465                        continue;
     466                }
     467
     468                table_printf(table, "%s\n", svc_name);
     469                free(svc_name);
     470        }
     471
     472        if (dev_list->ndevs != 0) {
     473                rc = table_print_out(table, stdout);
     474                if (rc != EOK) {
     475                        printf("Error printing table.\n");
     476                        table_destroy(table);
     477                        dispcfg_free_dev_list(dev_list);
     478                        dispcfg_close(dispcfg);
     479                        return rc;
     480                }
     481        }
     482
     483        dispcfg_close(dispcfg);
     484        return EOK;
     485}
     486
    395487int main(int argc, char *argv[])
    396488{
     
    423515                if (rc != EOK)
    424516                        return 1;
     517        } else if (str_cmp(argv[1], "list-dev") == 0) {
     518                rc = list_dev(dispcfg_svc, argc - 2, argv + 2);
     519                if (rc != EOK)
     520                        return 1;
    425521        } else {
    426522                printf(NAME ": Unknown command '%s'.\n", argv[1]);
  • uspace/app/meson.build

    rec8ef12 rc0757e1f  
    4040        'df',
    4141        'disp',
     42        'display-cfg',
    4243        'dnscfg',
    4344        'dnsres',
  • uspace/app/uidemo/uidemo.c

    rec8ef12 rc0757e1f  
    5252#include <ui/promptdialog.h>
    5353#include <ui/resource.h>
     54#include <ui/selectdialog.h>
    5455#include <ui/tab.h>
    5556#include <ui/tabset.h>
     
    108109static void uidemo_file_exit(ui_menu_entry_t *, void *);
    109110static void uidemo_edit_modify(ui_menu_entry_t *, void *);
     111static void uidemo_edit_insert_character(ui_menu_entry_t *, void *);
    110112
    111113static void file_dialog_bok(ui_file_dialog_t *, void *, const char *);
     
    127129        .bcancel = prompt_dialog_bcancel,
    128130        .close = prompt_dialog_close
     131};
     132
     133static void select_dialog_bok(ui_select_dialog_t *, void *, void *);
     134static void select_dialog_bcancel(ui_select_dialog_t *, void *);
     135static void select_dialog_close(ui_select_dialog_t *, void *);
     136
     137static ui_select_dialog_cb_t select_dialog_cb = {
     138        .bok = select_dialog_bok,
     139        .bcancel = select_dialog_bcancel,
     140        .close = select_dialog_close
    129141};
    130142
     
    432444        rc = ui_prompt_dialog_create(demo->ui, &pdparams, &dialog);
    433445        if (rc != EOK) {
    434                 printf("Error creating message dialog.\n");
     446                printf("Error creating prompt dialog.\n");
    435447                return;
    436448        }
    437449
    438450        ui_prompt_dialog_set_cb(dialog, &prompt_dialog_cb, demo);
     451}
     452
     453/** Edit / Insert Character menu entry selected.
     454 *
     455 * @param mentry Menu entry
     456 * @param arg Argument (demo)
     457 */
     458static void uidemo_edit_insert_character(ui_menu_entry_t *mentry, void *arg)
     459{
     460        ui_demo_t *demo = (ui_demo_t *) arg;
     461        ui_select_dialog_params_t sdparams;
     462        ui_select_dialog_t *dialog;
     463        ui_list_entry_attr_t attr;
     464        errno_t rc;
     465
     466        ui_select_dialog_params_init(&sdparams);
     467        sdparams.caption = "Insert Character";
     468        sdparams.prompt = "Select character to insert";
     469
     470        rc = ui_select_dialog_create(demo->ui, &sdparams, &dialog);
     471        if (rc != EOK) {
     472                printf("Error creating select dialog.\n");
     473                return;
     474        }
     475
     476        ui_list_entry_attr_init(&attr);
     477        attr.caption = "Dollar sign ($)";
     478        attr.arg = (void *)'$';
     479        rc = ui_select_dialog_append(dialog, &attr);
     480        if (rc != EOK) {
     481                printf("Error appending entry to list.\n");
     482                return;
     483        }
     484
     485        ui_list_entry_attr_init(&attr);
     486        attr.caption = "Hash sign (#)";
     487        attr.arg = (void *)'#';
     488        rc = ui_select_dialog_append(dialog, &attr);
     489        if (rc != EOK) {
     490                printf("Error appending entry to list.\n");
     491                return;
     492        }
     493
     494        ui_list_entry_attr_init(&attr);
     495        attr.caption = "Question mark (?)";
     496        attr.arg = (void *)'?';
     497        rc = ui_select_dialog_append(dialog, &attr);
     498        if (rc != EOK) {
     499                printf("Error appending entry to list.\n");
     500                return;
     501        }
     502
     503        ui_select_dialog_set_cb(dialog, &select_dialog_cb, demo);
     504
     505        (void) ui_select_dialog_paint(dialog);
    439506}
    440507
     
    525592/** Prompt dialog cancel button press.
    526593 *
    527  * @param dialog File dialog
     594 * @param dialog Prompt dialog
    528595 * @param arg Argument (ui_demo_t *)
    529596 */
     
    538605/** Prompt dialog close request.
    539606 *
    540  * @param dialog File dialog
     607 * @param dialog Prompt dialog
    541608 * @param arg Argument (ui_demo_t *)
    542609 */
     
    547614        (void) demo;
    548615        ui_prompt_dialog_destroy(dialog);
     616}
     617
     618/** Select dialog OK button press.
     619 *
     620 * @param dialog Select dialog
     621 * @param arg Argument (ui_demo_t *)
     622 * @param text Submitted text
     623 */
     624static void select_dialog_bok(ui_select_dialog_t *dialog, void *arg,
     625    void *earg)
     626{
     627        ui_demo_t *demo = (ui_demo_t *) arg;
     628        char str[2];
     629
     630        ui_select_dialog_destroy(dialog);
     631        str[0] = (char)(intptr_t)earg;
     632        str[1] = '\0';
     633        (void) ui_entry_insert_str(demo->entry, str);
     634}
     635
     636/** Select dialog cancel button press.
     637 *
     638 * @param dialog Select dialog
     639 * @param arg Argument (ui_demo_t *)
     640 */
     641static void select_dialog_bcancel(ui_select_dialog_t *dialog, void *arg)
     642{
     643        ui_demo_t *demo = (ui_demo_t *) arg;
     644
     645        (void) demo;
     646        ui_select_dialog_destroy(dialog);
     647}
     648
     649/** Select dialog close request.
     650 *
     651 * @param dialog Select dialog
     652 * @param arg Argument (ui_demo_t *)
     653 */
     654static void select_dialog_close(ui_select_dialog_t *dialog, void *arg)
     655{
     656        ui_demo_t *demo = (ui_demo_t *) arg;
     657
     658        (void) demo;
     659        ui_select_dialog_destroy(dialog);
    549660}
    550661
     
    598709        ui_menu_entry_t *mexit;
    599710        ui_menu_entry_t *mmodify;
     711        ui_menu_entry_t *minsert_char;
    600712        ui_menu_entry_t *mabout;
    601713        ui_list_entry_attr_t eattr;
     
    719831
    720832        ui_menu_entry_set_cb(mmodify, uidemo_edit_modify, (void *) &demo);
     833
     834        rc = ui_menu_entry_create(demo.medit, "~I~nsert Character",
     835            "", &minsert_char);
     836        if (rc != EOK) {
     837                printf("Error creating menu.\n");
     838                return rc;
     839        }
     840
     841        ui_menu_entry_set_cb(minsert_char, uidemo_edit_insert_character,
     842            (void *) &demo);
    721843
    722844        rc = ui_menu_create(demo.mbar, "~P~references", &demo.mpreferences);
Note: See TracChangeset for help on using the changeset viewer.