Changeset f03d1308 in mainline for uspace/app/terminal/terminal.c


Ignore:
Timestamp:
2020-10-28T12:42:11Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8009dc27
Parents:
d284ce9
git-author:
Jiri Svoboda <jiri@…> (2020-10-28 12:41:11)
git-committer:
Jiri Svoboda <jiri@…> (2020-10-28 12:42:11)
Message:

Convert terminal to using ui_window

File:
1 edited

Legend:

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

    rd284ce9 rf03d1308  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2020 Jiri Svoboda
    33 * Copyright (c) 2012 Petr Koupy
    44 * All rights reserved.
     
    3232 */
    3333/**
    34  * @file Terminal application using display service for output
     34 * @file Terminal application
    3535 */
    3636
     
    5151#include <str.h>
    5252#include <ui/resource.h>
     53#include <ui/ui.h>
    5354#include <ui/wdecor.h>
     55#include <ui/window.h>
    5456
    5557#include "terminal.h"
     
    102104};
    103105
    104 static void terminal_close_event(void *);
    105 static void terminal_focus_event(void *);
    106 static void terminal_kbd_event(void *, kbd_event_t *);
    107 static void terminal_pos_event(void *, pos_event_t *);
    108 static void terminal_unfocus_event(void *);
    109 
    110 static display_wnd_cb_t terminal_wnd_cb = {
    111         .close_event = terminal_close_event,
    112         .focus_event = terminal_focus_event,
    113         .kbd_event = terminal_kbd_event,
    114         .pos_event = terminal_pos_event,
    115         .unfocus_event = terminal_unfocus_event
    116 };
    117 
    118 static void terminal_wd_close(ui_wdecor_t *, void *);
    119 static void terminal_wd_move(ui_wdecor_t *, void *, gfx_coord2_t *);
    120 
    121 static ui_wdecor_cb_t wdecor_cb = {
    122         .close = terminal_wd_close,
    123         .move = terminal_wd_move
     106static void terminal_close_event(ui_window_t *, void *);
     107static void terminal_focus_event(ui_window_t *, void *);
     108static void terminal_kbd_event(ui_window_t *, void *, kbd_event_t *);
     109static void terminal_pos_event(ui_window_t *, void *, pos_event_t *);
     110static void terminal_unfocus_event(ui_window_t *, void *);
     111
     112static ui_window_cb_t terminal_window_cb = {
     113        .close = terminal_close_event,
     114        .focus = terminal_focus_event,
     115        .kbd = terminal_kbd_event,
     116        .pos = terminal_pos_event,
     117        .unfocus = terminal_unfocus_event
    124118};
    125119
     
    677671
    678672/** Handle window close event. */
    679 static void terminal_close_event(void *arg)
     673static void terminal_close_event(ui_window_t *window, void *arg)
    680674{
    681675        terminal_t *term = (terminal_t *) arg;
     
    688682
    689683/** Handle window focus event. */
    690 static void terminal_focus_event(void *arg)
     684static void terminal_focus_event(ui_window_t *window, void *arg)
    691685{
    692686        terminal_t *term = (terminal_t *) arg;
    693687
    694         if (term->wdecor != NULL) {
    695                 ui_wdecor_set_active(term->wdecor, true);
    696                 ui_wdecor_paint(term->wdecor);
    697 
    698                 term->is_focused = true;
    699                 term_update(term);
    700         }
     688        term->is_focused = true;
     689        term_update(term);
    701690}
    702691
    703692/** Handle window keyboard event */
    704 static void terminal_kbd_event(void *arg, kbd_event_t *kbd_event)
     693static void terminal_kbd_event(ui_window_t *window, void *arg,
     694    kbd_event_t *kbd_event)
    705695{
    706696        terminal_t *term = (terminal_t *) arg;
     
    714704
    715705/** Handle window position event */
    716 static void terminal_pos_event(void *arg, pos_event_t *event)
     706static void terminal_pos_event(ui_window_t *window, void *arg, pos_event_t *event)
    717707{
    718708        cons_event_t cevent;
    719709        terminal_t *term = (terminal_t *) arg;
    720 
    721         /* Make sure we don't process events until fully initialized */
    722         if (term->wdecor == NULL)
    723                 return;
    724 
    725         ui_wdecor_pos_event(term->wdecor, event);
    726710
    727711        sysarg_t sx = -term->off.x;
     
    741725
    742726/** Handle window unfocus event. */
    743 static void terminal_unfocus_event(void *arg)
     727static void terminal_unfocus_event(ui_window_t *window, void *arg)
    744728{
    745729        terminal_t *term = (terminal_t *) arg;
    746730
    747         if (term->wdecor != NULL) {
    748                 ui_wdecor_set_active(term->wdecor, false);
    749                 ui_wdecor_paint(term->wdecor);
    750 
    751                 term->is_focused = false;
    752                 term_update(term);
    753         }
    754 }
    755 
    756 /** Window decoration requested window closure.
    757  *
    758  * @param wdecor Window decoration
    759  * @param arg Argument (demo)
    760  */
    761 static void terminal_wd_close(ui_wdecor_t *wdecor, void *arg)
    762 {
    763         terminal_t *term = (terminal_t *) arg;
    764 
    765         (void) term;
    766 
    767         // XXX This is not really a clean way of terminating
    768         exit(0);
    769 }
    770 
    771 /** Window decoration requested window move.
    772  *
    773  * @param wdecor Window decoration
    774  * @param arg Argument (demo)
    775  * @param pos Position where the title bar was pressed
    776  */
    777 static void terminal_wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
    778 {
    779         terminal_t *term = (terminal_t *) arg;
    780 
    781         if (term->window != NULL)
    782                 (void) display_window_move_req(term->window, pos);
     731        term->is_focused = false;
     732        term_update(term);
    783733}
    784734
     
    805755}
    806756
    807 errno_t terminal_create(display_t *display, sysarg_t width, sysarg_t height,
    808     terminal_t **rterm)
     757errno_t terminal_create(const char *display_spec, sysarg_t width,
     758    sysarg_t height, terminal_t **rterm)
    809759{
    810760        terminal_t *term;
    811761        gfx_bitmap_params_t params;
    812         display_wnd_params_t wparams;
     762        ui_wnd_params_t wparams;
    813763        gfx_rect_t rect;
    814764        gfx_coord2_t off;
     
    859809        rect.p1.y = height;
    860810
    861         display_wnd_params_init(&wparams);
     811        ui_wnd_params_init(&wparams);
     812        wparams.caption = "Terminal";
    862813
    863814        /*
     
    871822        term->off = off;
    872823
    873         rc = display_window_create(display, &wparams, &terminal_wnd_cb,
    874             (void *) term, &term->window);
     824        rc = ui_create(display_spec, &term->ui);
     825        if (rc != EOK) {
     826                printf("Error creating UI on %s.\n", display_spec);
     827                goto error;
     828        }
     829
     830        rc = ui_window_create(term->ui, &wparams, &term->window);
    875831        if (rc != EOK) {
    876832                printf("Error creating window.\n");
     
    878834        }
    879835
    880         rc = display_window_get_gc(term->window, &term->gc);
    881         if (rc != EOK) {
    882                 printf("Error getting window GC.\n");
    883                 goto error;
    884         }
    885 
    886         rc = ui_resource_create(term->gc, &term->ui_res);
    887         if (rc != EOK) {
    888                 printf("Error creating UI.\n");
    889                 goto error;
    890         }
    891 
    892         rc = ui_wdecor_create(term->ui_res, "Terminal", &term->wdecor);
    893         if (rc != EOK) {
    894                 printf("Error creating window decoration.\n");
    895                 goto error;
    896         }
    897 
    898         ui_wdecor_set_rect(term->wdecor, &wparams.rect);
    899         ui_wdecor_set_cb(term->wdecor, &wdecor_cb, (void *) term);
    900 
    901         (void) ui_wdecor_paint(term->wdecor);
     836        term->gc = ui_window_get_gc(term->window);
     837        term->ui_res = ui_window_get_res(term->window);
     838
     839        ui_window_set_cb(term->window, &terminal_window_cb, (void *) term);
    902840
    903841        gfx_bitmap_params_init(&params);
     
    943881        getterm(vc, "/app/bdsh");
    944882
     883        term->is_focused = true;
     884
    945885        term->update.p0.x = 0;
    946886        term->update.p0.y = 0;
     
    953893        return EOK;
    954894error:
    955         if (term->wdecor != NULL)
    956                 ui_wdecor_destroy(term->wdecor);
    957         if (term->ui_res != NULL)
    958                 ui_resource_destroy(term->ui_res);
    959         if (term->gc != NULL)
    960                 gfx_context_delete(term->gc);
    961895        if (term->window != NULL)
    962                 display_window_destroy(term->window);
     896                ui_window_destroy(term->window);
     897        if (term->ui != NULL)
     898                ui_destroy(term->ui);
    963899        if (term->frontbuf != NULL)
    964900                chargrid_destroy(term->frontbuf);
Note: See TracChangeset for help on using the changeset viewer.