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


Ignore:
Timestamp:
2020-10-23T13:45:18Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a43bd0
Parents:
26653c9
git-author:
Jiri Svoboda <jiri@…> (2020-10-22 19:44:59)
git-committer:
Jiri Svoboda <jiri@…> (2020-10-23 13:45:18)
Message:

Decorate terminal window

File:
1 edited

Legend:

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

    r26653c9 rdcfd422  
    5050#include <stdlib.h>
    5151#include <str.h>
     52#include <ui/resource.h>
     53#include <ui/wdecor.h>
    5254
    5355#include "terminal.h"
     
    100102};
    101103
     104static void terminal_close_event(void *);
     105static void terminal_focus_event(void *);
    102106static void terminal_kbd_event(void *, kbd_event_t *);
     107static void terminal_pos_event(void *, pos_event_t *);
     108static void terminal_unfocus_event(void *);
    103109
    104110static display_wnd_cb_t terminal_wnd_cb = {
    105         .kbd_event = terminal_kbd_event
     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
     118static void terminal_wd_close(ui_wdecor_t *, void *);
     119static void terminal_wd_move(ui_wdecor_t *, void *, gfx_coord2_t *);
     120
     121static ui_wdecor_cb_t wdecor_cb = {
     122        .close = terminal_wd_close,
     123        .move = terminal_wd_move
    106124};
    107125
     
    305323        pixelmap_t pixelmap;
    306324        gfx_bitmap_alloc_t alloc;
     325        gfx_coord2_t pos;
    307326        errno_t rc;
    308327
     
    360379
    361380        if (update) {
    362                 (void) gfx_bitmap_render(term->bmp, &term->update, NULL);
     381                pos.x = 4;
     382                pos.y = 26;
     383                (void) gfx_bitmap_render(term->bmp, &term->update, &pos);
    363384
    364385                term->update.p0.x = 0;
     
    655676}
    656677
    657 /* Got key press/release event */
     678/** Handle window close event. */
     679static void terminal_close_event(void *arg)
     680{
     681        terminal_t *term = (terminal_t *) arg;
     682
     683        (void) term;
     684
     685        // XXX This is not really a clean way of terminating
     686        exit(0);
     687}
     688
     689/** Handle window focus event. */
     690static void terminal_focus_event(void *arg)
     691{
     692        terminal_t *term = (terminal_t *) arg;
     693
     694        if (term->wdecor != NULL) {
     695                ui_wdecor_set_active(term->wdecor, true);
     696                ui_wdecor_paint(term->wdecor);
     697        }
     698}
     699
     700/** Handle window keyboard event */
    658701static void terminal_kbd_event(void *arg, kbd_event_t *kbd_event)
    659702{
     
    665708
    666709        terminal_queue_cons_event(term, &event);
     710}
     711
     712/** Handle window position event */
     713static void terminal_pos_event(void *arg, pos_event_t *event)
     714{
     715        terminal_t *term = (terminal_t *) arg;
     716
     717        /* Make sure we don't process events until fully initialized */
     718        if (term->wdecor == NULL)
     719                return;
     720
     721        ui_wdecor_pos_event(term->wdecor, event);
     722}
     723
     724/** Handle window unfocus event. */
     725static void terminal_unfocus_event(void *arg)
     726{
     727        terminal_t *term = (terminal_t *) arg;
     728
     729        if (term->wdecor != NULL) {
     730                ui_wdecor_set_active(term->wdecor, false);
     731                ui_wdecor_paint(term->wdecor);
     732        }
    667733}
    668734
     
    688754#endif
    689755
     756/** Window decoration requested window closure.
     757 *
     758 * @param wdecor Window decoration
     759 * @param arg Argument (demo)
     760 */
     761static 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 */
     777static 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);
     783}
     784
    690785static void term_connection(ipc_call_t *icall, void *arg)
    691786{
     
    716811        gfx_bitmap_params_t params;
    717812        display_wnd_params_t wparams;
     813        gfx_rect_t rect;
     814        gfx_coord2_t off;
     815        gfx_rect_t wrect;
    718816        errno_t rc;
    719817
     
    756854        }
    757855
     856        rect.p0.x = 0;
     857        rect.p0.y = 0;
     858        rect.p1.x = width;
     859        rect.p1.y = height;
     860
    758861        display_wnd_params_init(&wparams);
    759         wparams.rect.p0.x = 0;
    760         wparams.rect.p0.y = 0;
    761         wparams.rect.p1.x = width;
    762         wparams.rect.p1.y = height;
     862
     863        /*
     864         * Compute window rectangle such that application area corresponds
     865         * to rect
     866         */
     867        ui_wdecor_rect_from_app(&rect, &wrect);
     868        off = wrect.p0;
     869        gfx_rect_rtranslate(&off, &wrect, &wparams.rect);
    763870
    764871        rc = display_window_create(display, &wparams, &terminal_wnd_cb,
     
    775882        }
    776883
     884        rc = ui_resource_create(term->gc, &term->ui_res);
     885        if (rc != EOK) {
     886                printf("Error creating UI.\n");
     887                goto error;
     888        }
     889
     890        rc = ui_wdecor_create(term->ui_res, "Terminal", &term->wdecor);
     891        if (rc != EOK) {
     892                printf("Error creating window decoration.\n");
     893                goto error;
     894        }
     895
     896        ui_wdecor_set_rect(term->wdecor, &wparams.rect);
     897        ui_wdecor_set_cb(term->wdecor, &wdecor_cb, (void *) term);
     898
     899        (void) ui_wdecor_paint(term->wdecor);
     900
    777901        gfx_bitmap_params_init(&params);
    778902        params.rect.p0.x = 0;
     
    827951        return EOK;
    828952error:
     953        if (term->wdecor != NULL)
     954                ui_wdecor_destroy(term->wdecor);
     955        if (term->ui_res != NULL)
     956                ui_resource_destroy(term->ui_res);
    829957        if (term->gc != NULL)
    830958                gfx_context_delete(term->gc);
Note: See TracChangeset for help on using the changeset viewer.