Changeset 8a9a41e in mainline for uspace/lib/ui/src/window.c


Ignore:
Timestamp:
2021-10-24T08:28:43Z (2 years ago)
Author:
GitHub <noreply@…>
Children:
f628215
Parents:
2ce943a (diff), cd981f2a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Erik Kučák <35500848+Riko196@…> (2021-10-24 08:28:43)
git-committer:
GitHub <noreply@…> (2021-10-24 08:28:43)
Message:

Merge branch 'HelenOS:master' into master

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/window.c

    r2ce943a r8a9a41e  
    3939#include <gfx/bitmap.h>
    4040#include <gfx/context.h>
     41#include <gfx/cursor.h>
    4142#include <gfx/render.h>
    4243#include <io/kbd_event.h>
     
    8889static void ui_window_invalidate(void *, gfx_rect_t *);
    8990static void ui_window_update(void *);
     91static errno_t ui_window_cursor_get_pos(void *, gfx_coord2_t *);
     92static errno_t ui_window_cursor_set_pos(void *, gfx_coord2_t *);
     93static errno_t ui_window_cursor_set_visible(void *, bool);
     94
     95/** Window memory GC callbacks */
     96static mem_gc_cb_t ui_window_mem_gc_cb = {
     97        .invalidate = ui_window_invalidate,
     98        .update = ui_window_update,
     99        .cursor_get_pos = ui_window_cursor_get_pos,
     100        .cursor_set_pos = ui_window_cursor_set_pos,
     101        .cursor_set_visible = ui_window_cursor_set_visible
     102};
     103
    90104static void ui_window_app_invalidate(void *, gfx_rect_t *);
    91105static void ui_window_app_update(void *);
     106
     107/** Application area memory GC callbacks */
     108static mem_gc_cb_t ui_window_app_mem_gc_cb = {
     109        .invalidate = ui_window_app_invalidate,
     110        .update = ui_window_app_update
     111};
     112
    92113static void ui_window_expose_cb(void *);
    93114
     
    111132/** Compute where window should be placed on the screen.
    112133 *
    113  * This only applies to windows that do not use default placement.
    114  *
    115  * @param window Window
    116  * @param display Display
    117  * @param info Display info
     134 * This only applies to windows that do not use default placement or
     135 * if we are running in full-screen mode.
     136 *
     137 * @param window Window
     138 * @param drect Display rectangle
    118139 * @param params Window parameters
    119140 * @param pos Place to store position of top-left corner
    120141 */
    121 static void ui_window_place(ui_window_t *window, display_t *display,
    122     display_info_t *info, ui_wnd_params_t *params, gfx_coord2_t *pos)
    123 {
    124         assert(params->placement != ui_wnd_place_default);
     142static void ui_window_place(ui_window_t *window, gfx_rect_t *drect,
     143    ui_wnd_params_t *params, gfx_coord2_t *pos)
     144{
     145        gfx_coord2_t dims;
     146
     147        assert(params->placement != ui_wnd_place_default ||
     148            ui_is_fullscreen(window->ui));
    125149
    126150        pos->x = 0;
     
    129153        switch (params->placement) {
    130154        case ui_wnd_place_default:
    131                 assert(false);
     155                assert(ui_is_fullscreen(window->ui));
     156                /* Center window */
     157                gfx_rect_dims(&params->rect, &dims);
     158                pos->x = (drect->p0.x + drect->p1.x) / 2 - dims.x / 2;
     159                pos->y = (drect->p0.y + drect->p1.y) / 2 - dims.y / 2;
     160                break;
    132161        case ui_wnd_place_top_left:
    133162        case ui_wnd_place_full_screen:
    134                 pos->x = info->rect.p0.x - params->rect.p0.x;
    135                 pos->y = info->rect.p0.y - params->rect.p0.y;
     163                pos->x = drect->p0.x - params->rect.p0.x;
     164                pos->y = drect->p0.y - params->rect.p0.y;
    136165                break;
    137166        case ui_wnd_place_top_right:
    138                 pos->x = info->rect.p1.x - params->rect.p1.x;
    139                 pos->y = info->rect.p0.y - params->rect.p0.y;
     167                pos->x = drect->p1.x - params->rect.p1.x;
     168                pos->y = drect->p0.y - params->rect.p0.y;
    140169                break;
    141170        case ui_wnd_place_bottom_left:
    142                 pos->x = info->rect.p0.x - params->rect.p0.x;
    143                 pos->y = info->rect.p1.y - params->rect.p1.y;
     171                pos->x = drect->p0.x - params->rect.p0.x;
     172                pos->y = drect->p1.y - params->rect.p1.y;
    144173                break;
    145174        case ui_wnd_place_bottom_right:
    146                 pos->x = info->rect.p1.x - params->rect.p1.x;
    147                 pos->y = info->rect.p1.y - params->rect.p1.y;
     175                pos->x = drect->p1.x - params->rect.p1.x;
     176                pos->y = drect->p1.y - params->rect.p1.y;
    148177                break;
    149178        case ui_wnd_place_popup:
     
    176205        gfx_bitmap_alloc_t alloc;
    177206        gfx_bitmap_t *bmp = NULL;
     207        gfx_coord2_t off;
    178208        mem_gc_t *memgc = NULL;
     209        xlate_gc_t *xgc = NULL;
    179210        errno_t rc;
    180211
     
    182213        if (window == NULL)
    183214                return ENOMEM;
     215
     216        window->ui = ui;
    184217
    185218        display_wnd_params_init(&dparams);
     
    207240                if (params->placement != ui_wnd_place_default) {
    208241                        /* Set initial display window position */
    209                         ui_window_place(window, ui->display, &info,
    210                             params, &dparams.pos);
     242                        ui_window_place(window, &info.rect, params,
     243                            &dparams.pos);
    211244
    212245                        dparams.flags |= wndf_setpos;
     
    223256        } else if (ui->console != NULL) {
    224257                gc = console_gc_get_ctx(ui->cgc);
     258
     259                if (params->placement == ui_wnd_place_full_screen) {
     260                        /* Make window the size of the screen */
     261                        gfx_rect_dims(&ui->rect, &scr_dims);
     262                        gfx_coord2_add(&dparams.rect.p0, &scr_dims,
     263                            &dparams.rect.p1);
     264                }
    225265        } else {
    226266                /* Needed for unit tests */
     
    242282
    243283        /* Move rectangle so that top-left corner is 0,0 */
    244         gfx_rect_rtranslate(&params->rect.p0, &params->rect, &bparams.rect);
     284        gfx_rect_rtranslate(&dparams.rect.p0, &dparams.rect, &bparams.rect);
    245285
    246286        rc = gfx_bitmap_create(gc, &bparams, NULL, &bmp);
     
    255295        }
    256296
    257         rc = mem_gc_create(&bparams.rect, &alloc, ui_window_invalidate,
    258             ui_window_update, (void *) window, &memgc);
     297        rc = mem_gc_create(&bparams.rect, &alloc, &ui_window_mem_gc_cb,
     298            (void *) window, &memgc);
    259299        if (rc != EOK) {
    260300                gfx_bitmap_destroy(window->app_bmp);
     
    266306        window->gc = mem_gc_get_ctx(memgc);
    267307        window->realgc = gc;
     308        (void) off;
    268309#else
    269         (void) ui_window_update;
    270         (void) ui_window_invalidate;
     310        /* Server-side rendering */
     311
     312        /* Full-screen mode? */
     313        if (ui->display == NULL) {
     314                /* Create translating GC to translate window contents */
     315                off.x = 0;
     316                off.y = 0;
     317                rc = xlate_gc_create(&off, gc, &xgc);
     318                if (rc != EOK)
     319                        goto error;
     320
     321                window->xgc = xgc;
     322                window->gc = xlate_gc_get_ctx(xgc);
     323                window->realgc = gc;
     324        } else {
     325                window->gc = gc;
     326        }
     327
     328        (void) ui_window_mem_gc_cb;
    271329        (void) alloc;
    272330        (void) bparams;
    273         window->gc = gc;
    274331#endif
     332        if (ui->display == NULL) {
     333                ui_window_place(window, &ui->rect, params, &window->dpos);
     334
     335                if (window->xgc != NULL)
     336                        xlate_gc_set_off(window->xgc, &window->dpos);
     337        }
    275338
    276339        rc = ui_resource_create(window->gc, ui_is_textmode(ui), &res);
     
    288351        ui_resource_set_expose_cb(res, ui_window_expose_cb, (void *) window);
    289352
    290         window->ui = ui;
    291353        window->rect = dparams.rect;
    292 
    293354        window->res = res;
    294355        window->wdecor = wdecor;
     
    305366        if (memgc != NULL)
    306367                mem_gc_delete(memgc);
     368        if (xgc != NULL)
     369                xlate_gc_delete(xgc);
    307370        if (bmp != NULL)
    308371                gfx_bitmap_destroy(bmp);
     
    340403        if (window->bmp != NULL)
    341404                gfx_bitmap_destroy(window->bmp);
    342         gfx_context_delete(window->gc);
    343405        if (window->dwindow != NULL)
    344406                display_window_destroy(window->dwindow);
     
    539601}
    540602
     603/** Get window's containing UI.
     604 *
     605 * @param window Window
     606 * @return Containing UI
     607 */
     608ui_t *ui_window_get_ui(ui_window_t *window)
     609{
     610        return window->ui;
     611}
     612
    541613/** Get UI resource from window.
    542614 *
     
    574646                        return rc;
    575647        } else {
    576                 pos->x = 0;
    577                 pos->y = 0;
     648                *pos = window->dpos;
    578649        }
    579650
     
    618689                }
    619690
    620                 rc = mem_gc_create(&params.rect, &alloc, ui_window_app_invalidate,
    621                     ui_window_app_update, (void *) window, &memgc);
     691                rc = mem_gc_create(&params.rect, &alloc,
     692                    &ui_window_app_mem_gc_cb, (void *) window, &memgc);
    622693                if (rc != EOK) {
    623694                        gfx_bitmap_destroy(window->app_bmp);
     
    871942        if (window->cb != NULL && window->cb->kbd != NULL)
    872943                window->cb->kbd(window, window->arg, kbd);
     944        else
     945                return ui_window_def_kbd(window, kbd);
    873946}
    874947
     
    909982}
    910983
     984/** Default window keyboard event routine.
     985 *
     986 * @param window Window
     987 */
     988void ui_window_def_kbd(ui_window_t *window, kbd_event_t *kbd)
     989{
     990        if (window->control != NULL)
     991                ui_control_kbd_event(window->control, kbd);
     992}
     993
    911994/** Default window paint routine.
    912995 *
     
    9821065        ui_window_t *window = (ui_window_t *) arg;
    9831066
    984         if (!gfx_rect_is_empty(&window->dirty_rect))
    985                 (void) gfx_bitmap_render(window->bmp, &window->dirty_rect, NULL);
     1067        if (!gfx_rect_is_empty(&window->dirty_rect)) {
     1068                (void) gfx_bitmap_render(window->bmp, &window->dirty_rect,
     1069                    &window->dpos);
     1070        }
    9861071
    9871072        window->dirty_rect.p0.x = 0;
     
    9891074        window->dirty_rect.p1.x = 0;
    9901075        window->dirty_rect.p1.y = 0;
     1076}
     1077
     1078/** Window cursor get position callback
     1079 *
     1080 * @param arg Argument (ui_window_t *)
     1081 * @param pos Place to store position
     1082 */
     1083static errno_t ui_window_cursor_get_pos(void *arg, gfx_coord2_t *pos)
     1084{
     1085        ui_window_t *window = (ui_window_t *) arg;
     1086        gfx_coord2_t cpos;
     1087        errno_t rc;
     1088
     1089        rc = gfx_cursor_get_pos(window->realgc, &cpos);
     1090        if (rc != EOK)
     1091                return rc;
     1092
     1093        pos->x = cpos.x - window->dpos.x;
     1094        pos->y = cpos.y - window->dpos.y;
     1095        return EOK;
     1096}
     1097
     1098/** Window cursor set position callback
     1099 *
     1100 * @param arg Argument (ui_window_t *)
     1101 * @param pos New position
     1102 */
     1103static errno_t ui_window_cursor_set_pos(void *arg, gfx_coord2_t *pos)
     1104{
     1105        ui_window_t *window = (ui_window_t *) arg;
     1106        gfx_coord2_t cpos;
     1107
     1108        cpos.x = pos->x + window->dpos.x;
     1109        cpos.y = pos->y + window->dpos.y;
     1110
     1111        return gfx_cursor_set_pos(window->realgc, &cpos);
     1112}
     1113
     1114/** Window cursor set visibility callback
     1115 *
     1116 * @param arg Argument (ui_window_t *)
     1117 * @param visible @c true iff cursor is to be made visible
     1118 */
     1119static errno_t ui_window_cursor_set_visible(void *arg, bool visible)
     1120{
     1121        ui_window_t *window = (ui_window_t *) arg;
     1122
     1123        return gfx_cursor_set_visible(window->realgc, visible);
    9911124}
    9921125
Note: See TracChangeset for help on using the changeset viewer.