Changeset 77ffa01 in mainline


Ignore:
Timestamp:
2021-02-27T21:34:15Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9c7dc8e
Parents:
b433f68
Message:

Allow UI to run in the console

Note that everything is way too large.

Location:
uspace
Files:
8 edited

Legend:

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

    rb433f68 r77ffa01  
    843843        sysarg_t sy = -term->off.y;
    844844
    845         if (event->type == POS_PRESS) {
     845        if (event->type == POS_PRESS || event->type == POS_RELEASE) {
    846846                cevent.type = CEV_POS;
    847847                cevent.ev.pos.type = event->type;
  • uspace/lib/ui/include/types/ui/ui.h

    rb433f68 r77ffa01  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4545#define UI_DISPLAY_DEFAULT NULL
    4646
     47/** Window system */
     48typedef enum {
     49        /** Unknown */
     50        ui_ws_unknown,
     51        /** Display service */
     52        ui_ws_display,
     53        /** Console */
     54        ui_ws_console
     55} ui_winsys_t;
     56
    4757#endif
    4858
  • uspace/lib/ui/include/ui/ui.h

    rb433f68 r77ffa01  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <display.h>
    4040#include <errno.h>
     41#include <io/console.h>
    4142#include <types/ui/ui.h>
    4243
    4344extern errno_t ui_create(const char *, ui_t **);
     45extern errno_t ui_create_cons(console_ctrl_t *, ui_t **);
    4446extern errno_t ui_create_disp(display_t *, ui_t **);
    4547extern void ui_destroy(ui_t *);
  • uspace/lib/ui/meson.build

    rb433f68 r77ffa01  
    2727#
    2828
    29 deps = [ 'gfx', 'gfxfont', 'memgfx', 'display' ]
     29deps = [ 'gfx', 'gfxfont', 'memgfx', 'display', 'congfx' ]
    3030src = files(
    3131        'src/checkbox.c',
  • uspace/lib/ui/private/ui.h

    rb433f68 r77ffa01  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939
    4040#include <display.h>
     41#include <io/console.h>
    4142#include <stdbool.h>
    4243
     
    4647 */
    4748struct ui {
     49        /** Console */
     50        console_ctrl_t *console;
    4851        /** Display */
    4952        display_t *display;
     
    5255        /** @c true if terminating */
    5356        bool quit;
     57        /** Root window (in fullscreen/console mode) */
     58        struct ui_window *root_wnd;
    5459};
    5560
  • uspace/lib/ui/private/window.h

    rb433f68 r77ffa01  
    4444#include <io/pos_event.h>
    4545#include <memgfx/memgc.h>
     46#include <types/ui/cursor.h>
     47#include <types/ui/window.h>
    4648
    4749/** Actual structure of window.
  • uspace/lib/ui/src/ui.c

    rb433f68 r77ffa01  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434 */
    3535
     36#include <ctype.h>
    3637#include <display.h>
    3738#include <errno.h>
    3839#include <fibril.h>
     40#include <io/console.h>
    3941#include <stdlib.h>
     42#include <str.h>
    4043#include <task.h>
    4144#include <ui/ui.h>
     45#include <ui/wdecor.h>
     46#include "../private/window.h"
    4247#include "../private/ui.h"
     48
     49/** Parse output specification.
     50 *
     51 * Output specification has the form <proto>@<service> where proto is
     52 * eiher 'disp' for display service or 'cons' for console. Service
     53 * is a location ID service name (e.g. hid/display).
     54 *
     55 * @param ospec Output specification
     56 * @param ws Place to store window system type (protocol)
     57 * @param osvc Place to store pointer to output service name
     58 */
     59static void ui_ospec_parse(const char *ospec, ui_winsys_t *ws,
     60    const char **osvc)
     61{
     62        const char *cp;
     63
     64        if (ospec == UI_DISPLAY_DEFAULT) {
     65                *ws = ui_ws_display;
     66                *osvc = DISPLAY_DEFAULT;
     67                return;
     68        }
     69
     70        cp = ospec;
     71        while (isalpha(*cp))
     72                ++cp;
     73
     74        if (*cp == '@') {
     75                if (str_lcmp(ospec, "disp@", str_length("disp@")) == 0) {
     76                        *ws = ui_ws_display;
     77                } else if (str_lcmp(ospec, "cons@", str_length("cons@")) == 0) {
     78                        *ws = ui_ws_console;
     79                } else {
     80                        *ws = ui_ws_unknown;
     81                }
     82
     83                if (cp[1] != '\0')
     84                        *osvc = cp + 1;
     85                else
     86                        *osvc = NULL;
     87        } else {
     88                *ws = ui_ws_display;
     89                *osvc = ospec;
     90        }
     91}
    4392
    4493/** Create new user interface.
     
    53102        errno_t rc;
    54103        display_t *display;
     104        console_ctrl_t *console;
     105        ui_winsys_t ws;
     106        const char *osvc;
    55107        ui_t *ui;
    56108
    57         rc = display_open(ospec, &display);
    58         if (rc != EOK)
    59                 return rc;
    60 
    61         rc = ui_create_disp(display, &ui);
    62         if (rc != EOK) {
    63                 display_close(display);
    64                 return rc;
    65         }
    66 
    67         ui->display = display;
     109        ui_ospec_parse(ospec, &ws, &osvc);
     110
     111        if (ws == ui_ws_display) {
     112                rc = display_open(osvc, &display);
     113                if (rc != EOK)
     114                        return rc;
     115
     116                rc = ui_create_disp(display, &ui);
     117                if (rc != EOK) {
     118                        display_close(display);
     119                        return rc;
     120                }
     121        } else if (ws == ui_ws_console) {
     122                console = console_init(stdin, stdout);
     123                if (console == NULL)
     124                        return EIO;
     125
     126                /* ws == ui_ws_console */
     127                rc = ui_create_cons(console, &ui);
     128                if (rc != EOK) {
     129                        console_done(console);
     130                        return rc;
     131                }
     132        } else {
     133                return EINVAL;
     134        }
     135
    68136        ui->myoutput = true;
    69137        *rui = ui;
     
    71139}
    72140
     141/** Create new user interface using console service.
     142 *
     143 * @param rui Place to store pointer to new UI
     144 * @return EOK on success or an error code
     145 */
     146errno_t ui_create_cons(console_ctrl_t *console, ui_t **rui)
     147{
     148        ui_t *ui;
     149
     150        ui = calloc(1, sizeof(ui_t));
     151        if (ui == NULL)
     152                return ENOMEM;
     153
     154        ui->console = console;
     155        *rui = ui;
     156        return EOK;
     157}
     158
    73159/** Create new user interface using display service.
    74160 *
     
    99185                return;
    100186
    101         if (ui->myoutput)
    102                 display_close(ui->display);
     187        if (ui->myoutput) {
     188                if (ui->console != NULL)
     189                        console_done(ui->console);
     190                if (ui->display != NULL)
     191                        display_close(ui->display);
     192        }
     193
    103194        free(ui);
     195}
     196
     197static void ui_cons_event_process(ui_t *ui, cons_event_t *event)
     198{
     199        if (ui->root_wnd == NULL)
     200                return;
     201
     202        switch (event->type) {
     203        case CEV_KEY:
     204                ui_window_send_kbd(ui->root_wnd, &event->ev.key);
     205                break;
     206        case CEV_POS:
     207                ui_wdecor_pos_event(ui->root_wnd->wdecor, &event->ev.pos);
     208                ui_window_send_pos(ui->root_wnd, &event->ev.pos);
     209                break;
     210        }
    104211}
    105212
     
    113220void ui_run(ui_t *ui)
    114221{
    115         task_retval(0);
    116 
    117         while (!ui->quit)
    118                 fibril_usleep(100000);
     222        bool have_event;
     223        cons_event_t event;
     224        usec_t timeout;
     225
     226        /* Only return command prompt if we are running in a separate window */
     227        if (ui->display != NULL)
     228                task_retval(0);
     229
     230        while (!ui->quit) {
     231                if (ui->console != NULL) {
     232                        timeout = 100000;
     233                        have_event = console_get_event_timeout(ui->console,
     234                            &event, &timeout);
     235                        if (have_event)
     236                                ui_cons_event_process(ui, &event);
     237                } else {
     238                        fibril_usleep(100000);
     239                }
     240        }
    119241}
    120242
  • uspace/lib/ui/src/window.c

    rb433f68 r77ffa01  
    3434 */
    3535
     36#include <congfx/console.h>
    3637#include <display.h>
    3738#include <errno.h>
     
    130131        gfx_bitmap_t *bmp = NULL;
    131132        mem_gc_t *memgc = NULL;
     133        console_gc_t *cgc;
    132134        errno_t rc;
     135
     136        if (ui->root_wnd != NULL)
     137                return EEXIST;
    133138
    134139        window = calloc(1, sizeof(ui_window_t));
     
    194199                if (rc != EOK)
    195200                        goto error;
     201        } else if (ui->console != NULL) {
     202                rc = console_gc_create(ui->console, NULL, &cgc);
     203                if (rc != EOK)
     204                        goto error;
     205
     206                gc = console_gc_get_ctx(cgc);
    196207        } else {
    197208                /* Needed for unit tests */
     
    207218        gfx_bitmap_params_init(&bparams);
    208219#ifndef CONFIG_WIN_DOUBLE_BUF
    209         bparams.flags |= bmpf_direct_output;
     220        /* Console does not support direct output */
     221        if (ui->display != NULL)
     222                bparams.flags |= bmpf_direct_output;
    210223#endif
    211224
     
    262275        window->cursor = ui_curs_arrow;
    263276        *rwindow = window;
     277
     278        ui->root_wnd = window;
    264279        return EOK;
    265280error:
     
    303318                gfx_bitmap_destroy(window->bmp);
    304319        gfx_context_delete(window->gc);
    305         display_window_destroy(window->dwindow);
     320        if (window->dwindow != NULL)
     321                display_window_destroy(window->dwindow);
    306322        free(window);
    307323}
     
    650666        ui_window_t *window = (ui_window_t *) arg;
    651667
    652         (void) display_window_move_req(window->dwindow, pos);
     668        if (window->dwindow != NULL)
     669                (void) display_window_move_req(window->dwindow, pos);
    653670}
    654671
     
    665682        ui_window_t *window = (ui_window_t *) arg;
    666683
    667         (void) display_window_resize_req(window->dwindow, rsztype, pos);
     684        if (window->dwindow != NULL)
     685                (void) display_window_resize_req(window->dwindow, rsztype, pos);
    668686}
    669687
     
    703721        }
    704722
    705         (void) display_window_set_cursor(window->dwindow, dcursor);
     723        if (window->dwindow != NULL)
     724                (void) display_window_set_cursor(window->dwindow, dcursor);
    706725        window->cursor = cursor;
    707726}
Note: See TracChangeset for help on using the changeset viewer.