Ignore:
File:
1 edited

Legend:

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

    r211fd68 r77ffa01  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * Copyright (c) 2012 Petr Koupy
    44 * All rights reserved.
     
    4141#include <fbfont/font-8x16.h>
    4242#include <io/chargrid.h>
    43 #include <fibril.h>
    4443#include <gfx/bitmap.h>
    4544#include <gfx/context.h>
     
    8887static void term_set_rgb_color(con_srv_t *, pixel_t, pixel_t);
    8988static void term_set_cursor_visibility(con_srv_t *, bool);
    90 static errno_t term_set_caption(con_srv_t *, const char *);
    9189static errno_t term_get_event(con_srv_t *, cons_event_t *);
    9290static errno_t term_map(con_srv_t *, sysarg_t, sysarg_t, charfield_t **);
     
    110108        .set_rgb_color = term_set_rgb_color,
    111109        .set_cursor_visibility = term_set_cursor_visibility,
    112         .set_caption = term_set_caption,
    113110        .get_event = term_get_event,
    114111        .map = term_map,
     
    118115
    119116static void terminal_close_event(ui_window_t *, void *);
    120 static void terminal_focus_event(ui_window_t *, void *, unsigned);
     117static void terminal_focus_event(ui_window_t *, void *);
    121118static void terminal_kbd_event(ui_window_t *, void *, kbd_event_t *);
    122119static void terminal_pos_event(ui_window_t *, void *, pos_event_t *);
    123 static void terminal_unfocus_event(ui_window_t *, void *, unsigned);
     120static void terminal_unfocus_event(ui_window_t *, void *);
    124121
    125122static ui_window_cb_t terminal_window_cb = {
     
    131128};
    132129
    133 static errno_t terminal_wait_fibril(void *);
    134 
    135130static terminal_t *srv_to_terminal(con_srv_t *srv)
    136131{
     
    138133}
    139134
    140 static errno_t getterm(task_wait_t *wait, const char *svc, const char *app)
    141 {
    142         return task_spawnl(NULL, wait, APP_GETTERM, APP_GETTERM, svc,
     135static void getterm(const char *svc, const char *app)
     136{
     137        task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
    143138            LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL);
    144139}
     
    146141static pixel_t color_table[16] = {
    147142        [COLOR_BLACK]       = PIXEL(255, 0, 0, 0),
    148         [COLOR_BLUE]        = PIXEL(255, 0, 0, 170),
    149         [COLOR_GREEN]       = PIXEL(255, 0, 170, 0),
    150         [COLOR_CYAN]        = PIXEL(255, 0, 170, 170),
    151         [COLOR_RED]         = PIXEL(255, 170, 0, 0),
    152         [COLOR_MAGENTA]     = PIXEL(255, 170, 0, 170),
    153         [COLOR_YELLOW]      = PIXEL(255, 170, 85, 0),
    154         [COLOR_WHITE]       = PIXEL(255, 170, 170, 170),
    155 
    156         [COLOR_BLACK + 8]   = PIXEL(255, 85, 85, 85),
    157         [COLOR_BLUE + 8]    = PIXEL(255, 85, 85, 255),
    158         [COLOR_GREEN + 8]   = PIXEL(255, 85, 255, 85),
    159         [COLOR_CYAN + 8]    = PIXEL(255, 85, 255, 255),
    160         [COLOR_RED + 8]     = PIXEL(255, 255, 85, 85),
    161         [COLOR_MAGENTA + 8] = PIXEL(255, 255, 85, 255),
    162         [COLOR_YELLOW + 8]  = PIXEL(255, 255, 255, 85),
     143        [COLOR_BLUE]        = PIXEL(255, 0, 0, 240),
     144        [COLOR_GREEN]       = PIXEL(255, 0, 240, 0),
     145        [COLOR_CYAN]        = PIXEL(255, 0, 240, 240),
     146        [COLOR_RED]         = PIXEL(255, 240, 0, 0),
     147        [COLOR_MAGENTA]     = PIXEL(255, 240, 0, 240),
     148        [COLOR_YELLOW]      = PIXEL(255, 240, 240, 0),
     149        [COLOR_WHITE]       = PIXEL(255, 240, 240, 240),
     150
     151        [COLOR_BLACK + 8]   = PIXEL(255, 0, 0, 0),
     152        [COLOR_BLUE + 8]    = PIXEL(255, 0, 0, 255),
     153        [COLOR_GREEN + 8]   = PIXEL(255, 0, 255, 0),
     154        [COLOR_CYAN + 8]    = PIXEL(255, 0, 255, 255),
     155        [COLOR_RED + 8]     = PIXEL(255, 255, 0, 0),
     156        [COLOR_MAGENTA + 8] = PIXEL(255, 255, 0, 255),
     157        [COLOR_YELLOW + 8]  = PIXEL(255, 255, 255, 0),
    163158        [COLOR_WHITE + 8]   = PIXEL(255, 255, 255, 255),
    164159};
     
    170165                switch (attrs.val.style) {
    171166                case STYLE_NORMAL:
    172                         *bgcolor = color_table[COLOR_WHITE + 8];
     167                        *bgcolor = color_table[COLOR_WHITE];
    173168                        *fgcolor = color_table[COLOR_BLACK];
    174169                        break;
    175170                case STYLE_EMPHASIS:
    176                         *bgcolor = color_table[COLOR_WHITE + 8];
    177                         *fgcolor = color_table[COLOR_RED + 8];
     171                        *bgcolor = color_table[COLOR_WHITE];
     172                        *fgcolor = color_table[COLOR_RED];
    178173                        break;
    179174                case STYLE_INVERTED:
    180175                        *bgcolor = color_table[COLOR_BLACK];
    181                         *fgcolor = color_table[COLOR_WHITE + 8];
     176                        *fgcolor = color_table[COLOR_WHITE];
    182177                        break;
    183178                case STYLE_SELECTED:
    184                         *bgcolor = color_table[COLOR_RED + 8];
    185                         *fgcolor = color_table[COLOR_WHITE + 8];
     179                        *bgcolor = color_table[COLOR_RED];
     180                        *fgcolor = color_table[COLOR_WHITE];
    186181                        break;
    187182                }
    188183                break;
    189184        case CHAR_ATTR_INDEX:
    190                 *bgcolor = color_table[(attrs.val.index.bgcolor & 7)];
     185                *bgcolor = color_table[(attrs.val.index.bgcolor & 7) |
     186                    ((attrs.val.index.attr & CATTR_BRIGHT) ? 8 : 0)];
    191187                *fgcolor = color_table[(attrs.val.index.fgcolor & 7) |
    192188                    ((attrs.val.index.attr & CATTR_BRIGHT) ? 8 : 0)];
     
    647643}
    648644
    649 static errno_t term_set_caption(con_srv_t *srv, const char *caption)
    650 {
    651         terminal_t *term = srv_to_terminal(srv);
    652         const char *cap;
    653 
    654         fibril_mutex_lock(&term->mtx);
    655 
    656         if (str_size(caption) > 0)
    657                 cap = caption;
    658         else
    659                 cap = "Terminal";
    660 
    661         ui_window_set_caption(term->window, cap);
    662         fibril_mutex_unlock(&term->mtx);
    663 
    664         term_update(term);
    665         gfx_update(term->gc);
    666         return EOK;
    667 }
    668 
    669645static errno_t term_get_event(con_srv_t *srv, cons_event_t *event)
    670646{
     
    829805        terminal_t *term = (terminal_t *) arg;
    830806
    831         ui_quit(term->ui);
     807        (void) term;
     808
     809        // XXX This is not really a clean way of terminating
     810        exit(0);
    832811}
    833812
    834813/** Handle window focus event. */
    835 static void terminal_focus_event(ui_window_t *window, void *arg,
    836     unsigned nfocus)
     814static void terminal_focus_event(ui_window_t *window, void *arg)
    837815{
    838816        terminal_t *term = (terminal_t *) arg;
    839817
    840         (void)nfocus;
    841818        term->is_focused = true;
    842819        term_update(term);
     
    866843        sysarg_t sy = -term->off.y;
    867844
    868         if (event->type == POS_PRESS || event->type == POS_RELEASE ||
    869             event->type == POS_DCLICK) {
     845        if (event->type == POS_PRESS || event->type == POS_RELEASE) {
    870846                cevent.type = CEV_POS;
    871847                cevent.ev.pos.type = event->type;
     
    880856
    881857/** Handle window unfocus event. */
    882 static void terminal_unfocus_event(ui_window_t *window, void *arg,
    883     unsigned nfocus)
     858static void terminal_unfocus_event(ui_window_t *window, void *arg)
    884859{
    885860        terminal_t *term = (terminal_t *) arg;
    886861
    887         if (nfocus == 0) {
    888                 term->is_focused = false;
    889                 term_update(term);
    890                 gfx_update(term->gc);
    891         }
     862        term->is_focused = false;
     863        term_update(term);
     864        gfx_update(term->gc);
    892865}
    893866
     
    915888
    916889errno_t terminal_create(const char *display_spec, sysarg_t width,
    917     sysarg_t height, terminal_flags_t flags, const char *command,
    918     terminal_t **rterm)
     890    sysarg_t height, terminal_flags_t flags, terminal_t **rterm)
    919891{
    920892        terminal_t *term;
     
    974946                wparams.placement = ui_wnd_place_top_left;
    975947
     948        /*
     949         * Compute window rectangle such that application area corresponds
     950         * to rect
     951         */
     952        ui_wdecor_rect_from_app(wparams.style, &rect, &wrect);
     953        off = wrect.p0;
     954        gfx_rect_rtranslate(&off, &wrect, &wparams.rect);
     955
     956        term->off = off;
     957
    976958        rc = ui_create(display_spec, &term->ui);
    977959        if (rc != EOK) {
     
    979961                goto error;
    980962        }
    981 
    982         /*
    983          * Compute window rectangle such that application area corresponds
    984          * to rect
    985          */
    986         ui_wdecor_rect_from_app(term->ui, wparams.style, &rect, &wrect);
    987         off = wrect.p0;
    988         gfx_rect_rtranslate(&off, &wrect, &wparams.rect);
    989 
    990         term->off = off;
    991963
    992964        rc = ui_window_create(term->ui, &wparams, &term->window);
     
    1022994        term->srvs.sarg = term;
    1023995
    1024         rc = loc_server_register(NAME, &term->srv);
     996        rc = loc_server_register(NAME);
    1025997        if (rc != EOK) {
    1026998                printf("Error registering server.\n");
     
    10331005            task_get_id());
    10341006
    1035         rc = loc_service_register(term->srv, vc, &term->dsid);
     1007        rc = loc_service_register(vc, &term->dsid);
    10361008        if (rc != EOK) {
    10371009                printf("Error registering service.\n");
     
    10411013
    10421014        list_append(&term->link, &terms);
    1043         rc = getterm(&term->wait, vc, command);
    1044         if (rc != EOK)
    1045                 goto error;
    1046 
    1047         term->wfid = fibril_create(terminal_wait_fibril, term);
    1048         if (term->wfid == 0)
    1049                 goto error;
    1050 
    1051         fibril_add_ready(term->wfid);
     1015        getterm(vc, "/app/bdsh");
    10521016
    10531017        term->is_focused = true;
     
    10631027        return EOK;
    10641028error:
    1065         if (term->dsid != 0)
    1066                 loc_service_unregister(term->srv, term->dsid);
    1067         if (term->srv != NULL)
    1068                 loc_server_unregister(term->srv);
    10691029        if (term->window != NULL)
    10701030                ui_window_destroy(term->window);
     
    10791039}
    10801040
    1081 static errno_t terminal_wait_fibril(void *arg)
    1082 {
    1083         terminal_t *term = (terminal_t *)arg;
    1084         task_exit_t texit;
    1085         int retval;
    1086 
    1087         /*
    1088          * XXX There is no way to break the sleep if the task does not
    1089          * exit.
    1090          */
    1091         (void) task_wait(&term->wait, &texit, &retval);
    1092         ui_quit(term->ui);
    1093         return EOK;
    1094 }
    1095 
    10961041/** @}
    10971042 */
Note: See TracChangeset for help on using the changeset viewer.