Changeset dcfd422 in mainline


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

Location:
uspace
Files:
6 edited

Legend:

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

    r26653c9 rdcfd422  
    4040#define NAME  "terminal"
    4141
     42/** Print syntax. */
     43static void print_syntax(void)
     44{
     45        printf("Syntax: %s [-d <display>]\n", NAME);
     46}
     47
    4248int main(int argc, char *argv[])
    4349{
     50        const char *display_svc = DISPLAY_DEFAULT;
    4451        display_t *display = NULL;
    4552        terminal_t *terminal = NULL;
    4653        errno_t rc;
     54        int i;
    4755
    48         rc = display_open(DISPLAY_DEFAULT, &display);
     56        i = 1;
     57        while (i < argc && argv[i][0] == '-') {
     58                if (str_cmp(argv[i], "-d") == 0) {
     59                        ++i;
     60                        if (i >= argc) {
     61                                printf("Argument missing.\n");
     62                                print_syntax();
     63                                return 1;
     64                        }
     65
     66                        display_svc = argv[i++];
     67                } else {
     68                        printf("Invalid option '%s'.\n", argv[i]);
     69                        print_syntax();
     70                        return 1;
     71                }
     72        }
     73
     74        if (i < argc) {
     75                print_syntax();
     76                return 1;
     77        }
     78
     79        rc = display_open(display_svc, &display);
    4980        if (rc != EOK) {
    5081                printf("%s: Error opening display.\n", NAME);
  • 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);
  • uspace/app/terminal/terminal.h

    r26653c9 rdcfd422  
    5050#include <stdatomic.h>
    5151#include <str.h>
     52#include <ui/resource.h>
     53#include <ui/wdecor.h>
    5254
    5355#define UTF8_CHAR_BUFFER_SIZE  (STR_BOUNDS(1) + 1)
     
    6062        sysarg_t h;
    6163        gfx_rect_t update;
     64
     65        ui_resource_t *ui_res;
     66        ui_wdecor_t *wdecor;
    6267
    6368        fibril_mutex_t mtx;
  • uspace/lib/ui/include/ui/wdecor.h

    r26653c9 rdcfd422  
    5252extern errno_t ui_wdecor_paint(ui_wdecor_t *);
    5353extern void ui_wdecor_pos_event(ui_wdecor_t *, pos_event_t *);
     54extern void ui_wdecor_rect_from_app(gfx_rect_t *, gfx_rect_t *);
    5455
    5556#endif
  • uspace/lib/ui/src/wdecor.c

    r26653c9 rdcfd422  
    271271}
    272272
     273/** Get outer rectangle from application area rectangle.
     274 *
     275 * Note that this needs to work just based on a UI, without having an actual
     276 * window decoration, since we need it in order to create the window
     277 * and its decoration.
     278 *
     279 * @param app Application area rectangle
     280 * @param rect Place to store (outer) window decoration rectangle
     281 */
     282void ui_wdecor_rect_from_app(gfx_rect_t *app, gfx_rect_t *rect)
     283{
     284        rect->p0.x = app->p0.x - 4;
     285        rect->p0.y = app->p0.y - 22 - 4;
     286        rect->p1.x = app->p1.x + 4;
     287        rect->p1.y = app->p1.y + 4;
     288}
     289
    273290/** Handle window decoration position event.
    274291 *
  • uspace/lib/ui/test/wdecor.c

    r26653c9 rdcfd422  
    310310}
    311311
     312/** ui_wdecor_get_geom() produces the correct geometry */
    312313PCUT_TEST(get_geom)
    313314{
     
    349350
    350351        ui_wdecor_destroy(wdecor);
     352}
     353
     354/** ui_wdecor_rect_from_app() correctly converts application to window rect */
     355PCUT_TEST(rect_from_app)
     356{
     357        gfx_rect_t arect;
     358        gfx_rect_t rect;
     359
     360        arect.p0.x = 14;
     361        arect.p0.y = 46;
     362        arect.p1.x = 96;
     363        arect.p1.y = 196;
     364
     365        ui_wdecor_rect_from_app(&arect, &rect);
     366
     367        PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
     368        PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
     369        PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
     370        PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
    351371}
    352372
Note: See TracChangeset for help on using the changeset viewer.