Changeset a35b458 in mainline for uspace/lib/gui


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/lib/gui
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gui/button.c

    r3061bc1 ra35b458  
    5050{
    5151        button_t *btn = (button_t *) widget;
    52        
     52
    5353        surface_t *surface = window_claim(btn->widget.window);
    5454        if (!surface)
    5555                window_yield(btn->widget.window);
    56        
     56
    5757        source_t source;
    5858        source_init(&source);
    59        
     59
    6060        drawctx_t drawctx;
    6161        drawctx_init(&drawctx, surface);
    62        
     62
    6363        drawctx_set_source(&drawctx, &btn->background);
    6464        drawctx_transfer(&drawctx, widget->hpos, widget->vpos,
    6565            widget->width, widget->height);
    66        
     66
    6767        if ((widget->width >= 8) && (widget->height >= 8)) {
    6868                drawctx_set_source(&drawctx, &source);
     
    7070                    widget->width - 6, widget->height - 6, color_highlight,
    7171                    color_shadow);
    72                
     72
    7373                drawctx_set_source(&drawctx, &btn->foreground);
    7474                drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4,
    7575                    widget->width - 8, widget->height - 8);
    7676        }
    77        
     77
    7878        sysarg_t cpt_width;
    7979        sysarg_t cpt_height;
    8080        font_get_box(btn->font, btn->caption, &cpt_width, &cpt_height);
    81        
     81
    8282        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
    8383                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
    8484                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
    85                
     85
    8686                drawctx_set_source(&drawctx, &btn->text);
    8787                drawctx_set_font(&drawctx, btn->font);
    88                
     88
    8989                if (btn->caption)
    9090                        drawctx_print(&drawctx, btn->caption, x, y);
    9191        }
    92        
     92
    9393        window_yield(btn->widget.window);
    9494}
     
    104104{
    105105        button_t *btn = (button_t *) widget;
    106        
     106
    107107        deinit_button(btn);
    108108        free(btn);
     
    130130{
    131131        button_t *btn = (button_t *) widget;
    132        
     132
    133133        if (event.key == KC_ENTER && event.type == KEY_PRESS)
    134134                sig_send(&btn->clicked, NULL);
     
    139139        button_t *btn = (button_t *) widget;
    140140        widget->window->focus = widget;
    141        
     141
    142142        // TODO make the click logic more robust (mouse grabbing, mouse moves)
    143143        if (event.btn_num == 1) {
     
    152152{
    153153        widget_init(&btn->widget, parent, data);
    154        
     154
    155155        btn->widget.destroy = button_destroy;
    156156        btn->widget.reconfigure = button_reconfigure;
     
    159159        btn->widget.handle_keyboard_event = button_handle_keyboard_event;
    160160        btn->widget.handle_position_event = button_handle_position_event;
    161        
     161
    162162        source_init(&btn->background);
    163163        source_set_color(&btn->background, background);
    164        
     164
    165165        source_init(&btn->foreground);
    166166        source_set_color(&btn->foreground, foreground);
    167        
     167
    168168        source_init(&btn->text);
    169169        source_set_color(&btn->text, text);
    170        
     170
    171171        if (caption == NULL)
    172172                btn->caption = NULL;
    173173        else
    174174                btn->caption = str_dup(caption);
    175        
     175
    176176        errno_t rc = embedded_font_create(&btn->font, points);
    177177        if (rc != EOK) {
     
    180180                return false;
    181181        }
    182        
     182
    183183        sysarg_t cpt_width;
    184184        sysarg_t cpt_height;
     
    188188        btn->widget.width_ideal = cpt_width + 30;
    189189        btn->widget.height_ideal = cpt_height + 10;
    190        
     190
    191191        return true;
    192192}
     
    198198        if (!btn)
    199199                return NULL;
    200        
     200
    201201        if (init_button(btn, parent, data, caption, points, background, foreground,
    202202            text))
    203203                return btn;
    204        
     204
    205205        free(btn);
    206206        return NULL;
  • uspace/lib/gui/canvas.c

    r3061bc1 ra35b458  
    4545{
    4646        canvas_t *canvas = (canvas_t *) widget;
    47        
     47
    4848        surface_t *surface = window_claim(canvas->widget.window);
    4949        if (!surface) {
    5050                window_yield(canvas->widget.window);
    5151        }
    52        
     52
    5353        transform_t transform;
    5454        transform_identity(&transform);
    5555        transform_translate(&transform, widget->hpos, widget->vpos);
    56        
     56
    5757        source_t source;
    5858        source_init(&source);
     
    6060        source_set_texture(&source, canvas->surface,
    6161            PIXELMAP_EXTEND_TRANSPARENT_BLACK);
    62        
     62
    6363        drawctx_t drawctx;
    6464        drawctx_init(&drawctx, surface);
    65        
     65
    6666        drawctx_set_source(&drawctx, &source);
    6767        drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width,
    6868            widget->height);
    69        
     69
    7070        window_yield(canvas->widget.window);
    7171}
     
    7979{
    8080        canvas_t *canvas = (canvas_t *) widget;
    81        
     81
    8282        deinit_canvas(canvas);
    8383        free(canvas);
     
    9393{
    9494        canvas_t *canvas = (canvas_t *) widget;
    95        
     95
    9696        widget_modify(widget, hpos, vpos, canvas->width, canvas->height);
    9797        paint_internal(widget);
     
    107107{
    108108        canvas_t *canvas = (canvas_t *) widget;
    109        
     109
    110110        sig_send(&canvas->keyboard_event, &event);
    111111}
     
    115115        canvas_t *canvas = (canvas_t *) widget;
    116116        pos_event_t tevent;
    117        
     117
    118118        tevent = event;
    119119        tevent.hpos -= widget->hpos;
    120120        tevent.vpos -= widget->vpos;
    121        
     121
    122122        sig_send(&canvas->position_event, &tevent);
    123123}
     
    127127{
    128128        widget_init(&canvas->widget, parent, data);
    129        
     129
    130130        canvas->widget.width = width;
    131131        canvas->widget.height = height;
    132        
     132
    133133        canvas->widget.width_min = width;
    134134        canvas->widget.height_min = height;
     
    137137        canvas->widget.width_max = width;
    138138        canvas->widget.height_max = height;
    139        
     139
    140140        canvas->widget.destroy = canvas_destroy;
    141141        canvas->widget.reconfigure = canvas_reconfigure;
     
    144144        canvas->widget.handle_keyboard_event = canvas_handle_keyboard_event;
    145145        canvas->widget.handle_position_event = canvas_handle_position_event;
    146        
     146
    147147        canvas->width = width;
    148148        canvas->height = height;
    149149        canvas->surface = surface;
    150        
     150
    151151        return true;
    152152}
     
    156156        if (surface != NULL)
    157157                canvas->surface = surface;
    158        
     158
    159159        canvas_repaint(&canvas->widget);
    160160        return true;
     
    167167        if (!canvas)
    168168                return NULL;
    169        
     169
    170170        if (init_canvas(canvas, parent, data, width, height, surface))
    171171                return canvas;
    172        
     172
    173173        free(canvas);
    174174        return NULL;
  • uspace/lib/gui/common.c

    r3061bc1 ra35b458  
    6363                        pixel_t pixel = (cross_texture[offset] & (1 << (x % 8))) ?
    6464                            highlight : shadow;
    65                        
     65
    6666                        if (visible)
    6767                                surface_put_pixel(surface, hpos + x, vpos + y, pixel);
     
    7777        drawctx_transfer(drawctx, hpos, vpos, width - 1, 1);
    7878        drawctx_transfer(drawctx, hpos, vpos + 1, 1, height - 2);
    79        
     79
    8080        source_set_color(source, shadow);
    8181        drawctx_transfer(drawctx, hpos, vpos + height - 1, width, 1);
  • uspace/lib/gui/connection.c

    r3061bc1 ra35b458  
    200200                if (data != NULL)
    201201                        data_copy = malloc(data_size);
    202                
     202
    203203                if (data_copy != NULL)
    204204                        memcpy(data_copy, data, data_size);
    205                
     205
    206206                window_event_t *event =
    207207                    (window_event_t *) malloc(sizeof(window_event_t));
    208                
     208
    209209                if (event) {
    210210                        link_initialize(&event->link);
  • uspace/lib/gui/grid.c

    r3061bc1 ra35b458  
    5151{
    5252        grid_t *grid = (grid_t *) widget;
    53        
     53
    5454        surface_t *surface = window_claim(grid->widget.window);
    5555        if (!surface) {
     
    5757                return;
    5858        }
    59        
     59
    6060        // FIXME: Replace with (accelerated) rectangle fill
    6161        for (sysarg_t y = widget->vpos; y < widget->vpos + widget->height; y++) {
     
    6363                        surface_put_pixel(surface, x, y, grid->background);
    6464        }
    65        
     65
    6666        window_yield(grid->widget.window);
    6767}
     
    7171        if ((col < grid->cols) && (row < grid->rows))
    7272                return grid->layout + (row * grid->cols + col);
    73        
     73
    7474        return NULL;
    7575}
     
    8282                        if (cell) {
    8383                                widget_t *widget = cell->widget;
    84                                
     84
    8585                                if ((widget) && (hpos >= widget->hpos) &&
    8686                                    (vpos >= widget->vpos) &&
     
    9191                }
    9292        }
    93        
     93
    9494        return NULL;
    9595}
     
    104104{
    105105        grid_t *grid = (grid_t *) widget;
    106        
     106
    107107        deinit_grid(grid);
    108108        free(grid);
     
    118118{
    119119        assert(run > 0);
    120        
     120
    121121        sysarg_t dim_min_part = dim_min / run;
    122122        sysarg_t dim_min_rem = dim_min % run;
    123        
     123
    124124        sysarg_t dim_max_part = dim_max / run;
    125125        sysarg_t dim_max_rem = dim_max % run;
    126        
     126
    127127        for (size_t i = 0; i < run; i++) {
    128128                sysarg_t dim_min_cur = dim_min_part;
    129129                sysarg_t dim_max_cur = dim_max_part;
    130                
     130
    131131                if (i == run - 1) {
    132132                        dim_min_cur += dim_min_rem;
    133133                        dim_max_cur += dim_max_rem;
    134134                }
    135                
     135
    136136                /*
    137137                 * We want the strongest constraint
     
    140140                if (cons[i].min < dim_min_cur)
    141141                        cons[i].min = dim_min_cur;
    142                
     142
    143143                /*
    144144                 * The comparison is correct, we want
     
    155155        /* Initial solution */
    156156        sysarg_t cur_sum = 0;
    157        
     157
    158158        for (size_t i = 0; i < run; i++) {
    159159                cons[i].val = cons[i].min;
    160160                cur_sum += cons[i].val;
    161161        }
    162        
     162
    163163        /* Iterative improvement */
    164164        while (cur_sum < sum) {
     
    166166                if (delta == 0)
    167167                        break;
    168                
     168
    169169                cur_sum = 0;
    170                
     170
    171171                for (size_t i = 0; i < run; i++) {
    172172                        if (cons[i].val + delta < cons[i].max)
    173173                                cons[i].val += delta;
    174                        
     174
    175175                        cur_sum += cons[i].val;
    176176                }
     
    182182{
    183183        grid_t *grid = (grid_t *) widget;
    184        
     184
    185185        widget_modify(widget, hpos, vpos, width, height);
    186186        paint_internal(widget);
    187        
     187
    188188        /* Compute column widths */
    189189        constraints_t *widths =
     
    193193                for (size_t c = 0; c < grid->cols; c++) {
    194194                        widths[c].min = 0;
    195                        
     195
    196196                        for (size_t r = 0; r < grid->rows; r++) {
    197197                                grid_cell_t *cell = grid_cell_at(grid, c, r);
    198198                                if (!cell)
    199199                                        continue;
    200                                
     200
    201201                                widget_t *widget = cell->widget;
    202202                                if (widget)
     
    205205                        }
    206206                }
    207                
     207
    208208                solve_constraints(widths, grid->cols, width);
    209209        }
    210        
     210
    211211        /* Compute row heights */
    212212        constraints_t *heights =
     
    216216                for (size_t r = 0; r < grid->rows; r++) {
    217217                        heights[r].min = 0;
    218                        
     218
    219219                        for (size_t c = 0; c < grid->cols; c++) {
    220220                                grid_cell_t *cell = grid_cell_at(grid, c, r);
    221221                                if (!cell)
    222222                                        continue;
    223                                
     223
    224224                                widget_t *widget = cell->widget;
    225225                                if (widget) {
     
    229229                        }
    230230                }
    231                
     231
    232232                solve_constraints(heights, grid->rows, height);
    233233        }
    234        
     234
    235235        /* Rearrange widgets */
    236236        if ((widths) && (heights)) {
    237237                sysarg_t cur_vpos = vpos;
    238                
     238
    239239                for (size_t r = 0; r < grid->rows; r++) {
    240240                        sysarg_t cur_hpos = hpos;
    241                        
     241
    242242                        for (size_t c = 0; c < grid->cols; c++) {
    243243                                grid_cell_t *cell = grid_cell_at(grid, c, r);
    244244                                if (!cell)
    245245                                        continue;
    246                                
     246
    247247                                widget_t *widget = cell->widget;
    248248                                if (widget) {
    249249                                        sysarg_t cur_width = 0;
    250250                                        sysarg_t cur_height = 0;
    251                                        
     251
    252252                                        for (size_t cd = 0; cd < cell->cols; cd++)
    253253                                                cur_width += widths[c + cd].val;
    254                                        
     254
    255255                                        for (size_t rd = 0; rd < cell->rows; rd++)
    256256                                                cur_height += heights[r + rd].val;
    257                                        
     257
    258258                                        if ((cur_width > 0) && (cur_height > 0)) {
    259259                                                sysarg_t wwidth = cur_width;
    260260                                                sysarg_t wheight = cur_height;
    261                                                
     261
    262262                                                /*
    263263                                                 * Make sure the widget is respects its
    264264                                                 * maximal constrains.
    265265                                                 */
    266                                                
     266
    267267                                                if ((widget->width_max > 0) &&
    268268                                                    (wwidth > widget->width_max))
    269269                                                        wwidth = widget->width_max;
    270                                                
     270
    271271                                                if ((widget->height_max > 0) &&
    272272                                                    (wheight > widget->height_max))
    273273                                                        wheight = widget->height_max;
    274                                                
     274
    275275                                                widget->rearrange(widget, cur_hpos, cur_vpos,
    276276                                                    wwidth, wheight);
    277277                                        }
    278                                        
    279                                        
     278
     279
    280280                                }
    281                                
     281
    282282                                cur_hpos += widths[c].val;
    283283                        }
    284                        
     284
    285285                        cur_vpos += heights[r].val;
    286286                }
    287287        }
    288        
     288
    289289        if (widths)
    290290                free(widths);
    291        
     291
    292292        if (heights)
    293293                free(heights);
     
    297297{
    298298        paint_internal(widget);
    299        
     299
    300300        list_foreach(widget->children, link, widget_t, child) {
    301301                child->repaint(child);
    302302        }
    303        
     303
    304304        window_damage(widget->window);
    305305}
     
    313313{
    314314        grid_t *grid = (grid_t *) widget;
    315        
     315
    316316        grid_cell_t *cell = grid_coords_at(grid, event.hpos, event.vpos);
    317317        if ((cell) && (cell->widget))
     
    325325            (row + rows > grid->rows))
    326326                return false;
    327        
     327
    328328        grid_cell_t *cell = grid_cell_at(grid, col, row);
    329329        if (!cell)
    330330                return false;
    331        
     331
    332332        /*
    333333         * Check whether the cell is not occupied by an
     
    336336        if ((!cell->widget) && (cell->cols > 0) && (cell->rows > 0))
    337337                return false;
    338        
     338
    339339        widget->parent = (widget_t *) grid;
    340        
     340
    341341        list_append(&widget->link, &grid->widget.children);
    342342        widget->window = grid->widget.window;
    343        
     343
    344344        /* Mark cells in layout */
    345345        for (size_t r = row; r < row + rows; r++) {
     
    359359                }
    360360        }
    361        
     361
    362362        return true;
    363363}
     
    368368        if ((cols == 0) || (rows == 0))
    369369                return false;
    370        
     370
    371371        grid->layout =
    372372            (grid_cell_t *) calloc(cols * rows, sizeof(grid_cell_t));
    373373        if (!grid->layout)
    374374                return false;
    375        
     375
    376376        memset(grid->layout, 0, cols * rows * sizeof(grid_cell_t));
    377        
     377
    378378        widget_init(&grid->widget, parent, data);
    379        
     379
    380380        grid->widget.destroy = grid_destroy;
    381381        grid->widget.reconfigure = grid_reconfigure;
     
    384384        grid->widget.handle_keyboard_event = grid_handle_keyboard_event;
    385385        grid->widget.handle_position_event = grid_handle_position_event;
    386        
     386
    387387        grid->add = grid_add;
    388388        grid->background = background;
    389389        grid->cols = cols;
    390390        grid->rows = rows;
    391        
     391
    392392        return true;
    393393}
     
    399399        if (!grid)
    400400                return NULL;
    401        
     401
    402402        if (init_grid(grid, parent, data, cols, rows, background))
    403403                return grid;
    404        
     404
    405405        free(grid);
    406406        return NULL;
  • uspace/lib/gui/label.c

    r3061bc1 ra35b458  
    5050        if (!surface)
    5151                window_yield(lbl->widget.window);
    52        
     52
    5353        drawctx_t drawctx;
    5454        drawctx_init(&drawctx, surface);
    55        
     55
    5656        drawctx_set_source(&drawctx, &lbl->background);
    5757        drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width,
    5858            widget->height);
    59        
     59
    6060        sysarg_t cpt_width;
    6161        sysarg_t cpt_height;
    6262        font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height);
    63        
     63
    6464        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
    6565                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
    6666                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
    67                
     67
    6868                drawctx_set_source(&drawctx, &lbl->text);
    6969                drawctx_set_font(&drawctx, lbl->font);
    70                
     70
    7171                if (lbl->caption)
    7272                        drawctx_print(&drawctx, lbl->caption, x, y);
    7373        }
    74        
     74
    7575        window_yield(lbl->widget.window);
    7676}
     
    8080        if (data != NULL) {
    8181                label_t *lbl = (label_t *) widget;
    82                
     82
    8383                const char *new_caption = (const char *) data;
    8484                lbl->caption = str_dup(new_caption);
    85                
     85
    8686                sysarg_t cpt_width;
    8787                sysarg_t cpt_height;
    8888                font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height);
    89                
     89
    9090                lbl->widget.width_min = cpt_width + 4;
    9191                lbl->widget.height_min = cpt_height + 4;
    9292                lbl->widget.width_ideal = lbl->widget.width_min;
    9393                lbl->widget.height_ideal = lbl->widget.height_min;
    94                
     94
    9595                window_refresh(lbl->widget.window);
    9696        }
     
    107107{
    108108        label_t *lbl = (label_t *) widget;
    109        
     109
    110110        deinit_label(lbl);
    111111        free(lbl);
     
    144144{
    145145        widget_init(&lbl->widget, parent, data);
    146        
     146
    147147        lbl->widget.destroy = label_destroy;
    148148        lbl->widget.reconfigure = label_reconfigure;
     
    151151        lbl->widget.handle_keyboard_event = label_handle_keyboard_event;
    152152        lbl->widget.handle_position_event = label_handle_position_event;
    153        
     153
    154154        source_init(&lbl->background);
    155155        source_set_color(&lbl->background, background);
    156        
     156
    157157        source_init(&lbl->text);
    158158        source_set_color(&lbl->text, text);
    159        
     159
    160160        if (caption == NULL)
    161161                lbl->caption = NULL;
    162162        else
    163163                lbl->caption = str_dup(caption);
    164        
     164
    165165        errno_t rc = embedded_font_create(&lbl->font, points);
    166166        if (rc != EOK) {
     
    169169                return false;
    170170        }
    171        
     171
    172172        sysarg_t cpt_width;
    173173        sysarg_t cpt_height;
    174174        font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height);
    175        
     175
    176176        lbl->widget.width_min = cpt_width + 4;
    177177        lbl->widget.height_min = cpt_height + 4;
    178178        lbl->widget.width_ideal = lbl->widget.width_min;
    179179        lbl->widget.height_ideal = lbl->widget.height_min;
    180        
     180
    181181        lbl->rewrite = on_rewrite;
    182        
     182
    183183        return true;
    184184}
     
    190190        if (!lbl)
    191191                return NULL;
    192        
     192
    193193        if (init_label(lbl, parent, data, caption, points, background, text))
    194194                return lbl;
    195        
     195
    196196        free(lbl);
    197197        return NULL;
  • uspace/lib/gui/minimal.c

    r3061bc1 ra35b458  
    6666                }
    6767        }
    68        
     68
    6969        window_yield(min->widget.window);
    7070}
  • uspace/lib/gui/terminal.c

    r3061bc1 ra35b458  
    118118        [COLOR_YELLOW]      = PIXEL(255, 240, 240, 0),
    119119        [COLOR_WHITE]       = PIXEL(255, 240, 240, 240),
    120        
     120
    121121        [COLOR_BLACK + 8]   = PIXEL(255, 0, 0, 0),
    122122        [COLOR_BLUE + 8]    = PIXEL(255, 0, 0, 255),
     
    170170        charfield_t *field =
    171171            chargrid_charfield_at(term->backbuf, col, row);
    172        
     172
    173173        bool inverted = chargrid_cursor_at(term->backbuf, col, row);
    174        
     174
    175175        sysarg_t bx = sx + (col * FONT_WIDTH);
    176176        sysarg_t by = sy + (row * FONT_SCANLINES);
    177        
     177
    178178        pixel_t bgcolor = 0;
    179179        pixel_t fgcolor = 0;
    180        
     180
    181181        if (inverted)
    182182                attrs_rgb(field->attrs, &fgcolor, &bgcolor);
    183183        else
    184184                attrs_rgb(field->attrs, &bgcolor, &fgcolor);
    185        
     185
    186186        // FIXME: Glyph type should be actually uint32_t
    187187        //        for full UTF-32 coverage.
    188        
     188
    189189        uint16_t glyph = fb_font_glyph(field->ch, NULL);
    190        
     190
    191191        for (unsigned int y = 0; y < FONT_SCANLINES; y++) {
    192192                pixel_t *dst = pixelmap_pixel_at(
     
    207207{
    208208        sysarg_t top_row = chargrid_get_top_row(term->frontbuf);
    209        
     209
    210210        if (term->top_row == top_row)
    211211                return false;
    212        
     212
    213213        term->top_row = top_row;
    214        
     214
    215215        for (sysarg_t row = 0; row < term->rows; row++) {
    216216                for (sysarg_t col = 0; col < term->cols; col++) {
     
    220220                            chargrid_charfield_at(term->backbuf, col, row);
    221221                        bool update = false;
    222                        
     222
    223223                        if (front_field->ch != back_field->ch) {
    224224                                back_field->ch = front_field->ch;
    225225                                update = true;
    226226                        }
    227                        
     227
    228228                        if (!attrs_same(front_field->attrs, back_field->attrs)) {
    229229                                back_field->attrs = front_field->attrs;
    230230                                update = true;
    231231                        }
    232                        
     232
    233233                        front_field->flags &= ~CHAR_FLAG_DIRTY;
    234                        
     234
    235235                        if (update)
    236236                                term_update_char(term, surface, sx, sy, col, row);
    237237                }
    238238        }
    239        
     239
    240240        return true;
    241241}
     
    245245{
    246246        bool damage = false;
    247        
     247
    248248        sysarg_t front_col;
    249249        sysarg_t front_row;
    250250        chargrid_get_cursor(term->frontbuf, &front_col, &front_row);
    251        
     251
    252252        sysarg_t back_col;
    253253        sysarg_t back_row;
    254254        chargrid_get_cursor(term->backbuf, &back_col, &back_row);
    255        
     255
    256256        bool front_visibility =
    257257            chargrid_get_cursor_visibility(term->frontbuf) &&
     
    259259        bool back_visibility =
    260260            chargrid_get_cursor_visibility(term->backbuf);
    261        
     261
    262262        if (front_visibility != back_visibility) {
    263263                chargrid_set_cursor_visibility(term->backbuf,
     
    266266                damage = true;
    267267        }
    268        
     268
    269269        if ((front_col != back_col) || (front_row != back_row)) {
    270270                chargrid_set_cursor(term->backbuf, front_col, front_row);
     
    273273                damage = true;
    274274        }
    275        
     275
    276276        return damage;
    277277}
     
    280280{
    281281        fibril_mutex_lock(&term->mtx);
    282        
     282
    283283        surface_t *surface = window_claim(term->widget.window);
    284284        if (!surface) {
     
    287287                return;
    288288        }
    289        
     289
    290290        bool damage = false;
    291291        sysarg_t sx = term->widget.hpos;
    292292        sysarg_t sy = term->widget.vpos;
    293        
     293
    294294        if (term_update_scroll(term, surface, sx, sy)) {
    295295                damage = true;
     
    302302                                    chargrid_charfield_at(term->backbuf, x, y);
    303303                                bool update = false;
    304                                
     304
    305305                                if ((front_field->flags & CHAR_FLAG_DIRTY) ==
    306306                                    CHAR_FLAG_DIRTY) {
     
    309309                                                update = true;
    310310                                        }
    311                                        
     311
    312312                                        if (!attrs_same(front_field->attrs,
    313313                                            back_field->attrs)) {
     
    315315                                                update = true;
    316316                                        }
    317                                        
     317
    318318                                        front_field->flags &= ~CHAR_FLAG_DIRTY;
    319319                                }
    320                                
     320
    321321                                if (update) {
    322322                                        term_update_char(term, surface, sx, sy, x, y);
     
    326326                }
    327327        }
    328        
     328
    329329        if (term_update_cursor(term, surface, sx, sy))
    330330                damage = true;
    331        
     331
    332332        window_yield(term->widget.window);
    333        
     333
    334334        if (damage)
    335335                window_damage(term->widget.window);
    336        
     336
    337337        fibril_mutex_unlock(&term->mtx);
    338338}
     
    341341{
    342342        fibril_mutex_lock(&term->mtx);
    343        
     343
    344344        surface_t *surface = window_claim(term->widget.window);
    345345        if (!surface) {
     
    348348                return;
    349349        }
    350        
     350
    351351        sysarg_t sx = term->widget.hpos;
    352352        sysarg_t sy = term->widget.vpos;
    353        
     353
    354354        if (!term_update_scroll(term, surface, sx, sy)) {
    355355                for (sysarg_t y = 0; y < term->rows; y++) {
     
    359359                                charfield_t *back_field =
    360360                                    chargrid_charfield_at(term->backbuf, x, y);
    361                                
     361
    362362                                back_field->ch = front_field->ch;
    363363                                back_field->attrs = front_field->attrs;
    364364                                front_field->flags &= ~CHAR_FLAG_DIRTY;
    365                                
     365
    366366                                term_update_char(term, surface, sx, sy, x, y);
    367367                        }
    368368                }
    369369        }
    370        
     370
    371371        term_update_cursor(term, surface, sx, sy);
    372        
     372
    373373        window_yield(term->widget.window);
    374374        window_damage(term->widget.window);
    375        
     375
    376376        fibril_mutex_unlock(&term->mtx);
    377377}
     
    392392        uint8_t *bbuf = buf;
    393393        size_t pos = 0;
    394        
     394
    395395        /*
    396396         * Read input from keyboard and copy it to the buffer.
     
    403403                        bbuf[pos] = term->char_remains[0];
    404404                        pos++;
    405                        
     405
    406406                        /* Unshift the array. */
    407407                        for (size_t i = 1; i < term->char_remains_len; i++)
    408408                                term->char_remains[i - 1] = term->char_remains[i];
    409                        
     409
    410410                        term->char_remains_len--;
    411411                }
    412                
     412
    413413                /* Still not enough? Then get another key from the queue. */
    414414                if (pos < size) {
    415415                        link_t *link = prodcons_consume(&term->input_pc);
    416416                        cons_event_t *event = list_get_instance(link, cons_event_t, link);
    417                        
     417
    418418                        /* Accept key presses of printable chars only. */
    419419                        if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS &&
     
    423423                                        0
    424424                                };
    425                                
     425
    426426                                wstr_to_str(term->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp);
    427427                                term->char_remains_len = str_size(term->char_remains);
    428428                        }
    429                        
     429
    430430                        free(event);
    431431                }
    432432        }
    433        
     433
    434434        *nread = size;
    435435        return EOK;
     
    439439{
    440440        sysarg_t updated = 0;
    441        
    442         fibril_mutex_lock(&term->mtx);
    443        
     441
     442        fibril_mutex_lock(&term->mtx);
     443
    444444        switch (ch) {
    445445        case '\n':
     
    457457                updated = chargrid_putchar(term->frontbuf, ch, true);
    458458        }
    459        
    460         fibril_mutex_unlock(&term->mtx);
    461        
     459
     460        fibril_mutex_unlock(&term->mtx);
     461
    462462        if (updated > 1)
    463463                term_update(term);
     
    467467{
    468468        terminal_t *term = srv_to_terminal(srv);
    469        
     469
    470470        size_t off = 0;
    471471        while (off < size)
    472472                term_write_char(term, str_decode(data, &off, size));
    473        
     473
    474474        *nwritten = size;
    475475        return EOK;
     
    479479{
    480480        terminal_t *term = srv_to_terminal(srv);
    481        
     481
    482482        term_update(term);
    483483}
     
    486486{
    487487        terminal_t *term = srv_to_terminal(srv);
    488        
     488
    489489        fibril_mutex_lock(&term->mtx);
    490490        chargrid_clear(term->frontbuf);
    491491        fibril_mutex_unlock(&term->mtx);
    492        
     492
    493493        term_update(term);
    494494}
     
    497497{
    498498        terminal_t *term = srv_to_terminal(srv);
    499        
     499
    500500        fibril_mutex_lock(&term->mtx);
    501501        chargrid_set_cursor(term->frontbuf, col, row);
    502502        fibril_mutex_unlock(&term->mtx);
    503        
     503
    504504        term_update(term);
    505505}
     
    508508{
    509509        terminal_t *term = srv_to_terminal(srv);
    510        
     510
    511511        fibril_mutex_lock(&term->mtx);
    512512        chargrid_get_cursor(term->frontbuf, col, row);
    513513        fibril_mutex_unlock(&term->mtx);
    514        
     514
    515515        return EOK;
    516516}
     
    519519{
    520520        terminal_t *term = srv_to_terminal(srv);
    521        
     521
    522522        fibril_mutex_lock(&term->mtx);
    523523        *cols = term->cols;
    524524        *rows = term->rows;
    525525        fibril_mutex_unlock(&term->mtx);
    526        
     526
    527527        return EOK;
    528528}
     
    532532        (void) srv;
    533533        *caps = TERM_CAPS;
    534        
     534
    535535        return EOK;
    536536}
     
    539539{
    540540        terminal_t *term = srv_to_terminal(srv);
    541        
     541
    542542        fibril_mutex_lock(&term->mtx);
    543543        chargrid_set_style(term->frontbuf, style);
     
    549549{
    550550        terminal_t *term = srv_to_terminal(srv);
    551        
     551
    552552        fibril_mutex_lock(&term->mtx);
    553553        chargrid_set_color(term->frontbuf, bgcolor, fgcolor, attr);
     
    559559{
    560560        terminal_t *term = srv_to_terminal(srv);
    561        
     561
    562562        fibril_mutex_lock(&term->mtx);
    563563        chargrid_set_rgb_color(term->frontbuf, bgcolor, fgcolor);
     
    568568{
    569569        terminal_t *term = srv_to_terminal(srv);
    570        
     570
    571571        fibril_mutex_lock(&term->mtx);
    572572        chargrid_set_cursor_visibility(term->frontbuf, visible);
    573573        fibril_mutex_unlock(&term->mtx);
    574        
     574
    575575        term_update(term);
    576576}
     
    581581        link_t *link = prodcons_consume(&term->input_pc);
    582582        cons_event_t *ev = list_get_instance(link, cons_event_t, link);
    583        
     583
    584584        *event = *ev;
    585585        free(ev);
     
    591591        list_remove(&term->link);
    592592        widget_deinit(&term->widget);
    593        
     593
    594594        if (term->frontbuf)
    595595                chargrid_destroy(term->frontbuf);
    596        
     596
    597597        if (term->backbuf)
    598598                chargrid_destroy(term->backbuf);
     
    602602{
    603603        terminal_t *term = (terminal_t *) widget;
    604        
     604
    605605        deinit_terminal(term);
    606606        free(term);
     
    616616{
    617617        terminal_t *term = (terminal_t *) widget;
    618        
     618
    619619        widget_modify(widget, hpos, vpos, width, height);
    620620        widget->width_ideal = width;
    621621        widget->height_ideal = height;
    622        
     622
    623623        term_damage(term);
    624624}
     
    627627{
    628628        terminal_t *term = (terminal_t *) widget;
    629        
     629
    630630        term_damage(term);
    631631}
     
    638638        if (event == NULL)
    639639                return;
    640        
     640
    641641        *event = *ev;
    642642        link_initialize(&event->link);
    643        
     643
    644644        prodcons_produce(&term->input_pc, &event->link);
    645645}
     
    651651        terminal_t *term = (terminal_t *) widget;
    652652        cons_event_t event;
    653        
     653
    654654        event.type = CEV_KEY;
    655655        event.ev.key = kbd_event;
    656        
     656
    657657        terminal_queue_cons_event(term, &event);
    658658}
     
    680680{
    681681        terminal_t *term = NULL;
    682        
     682
    683683        list_foreach(terms, link, terminal_t, cur) {
    684684                if (cur->dsid == (service_id_t) IPC_GET_ARG2(*icall)) {
     
    687687                }
    688688        }
    689        
     689
    690690        if (term == NULL) {
    691691                async_answer_0(iid, ENOENT);
    692692                return;
    693693        }
    694        
     694
    695695        if (atomic_postinc(&term->refcnt) == 0)
    696696                chargrid_set_cursor_visibility(term->frontbuf, true);
    697        
     697
    698698        con_conn(iid, icall, &term->srvs);
    699699}
     
    703703{
    704704        widget_init(&term->widget, parent, data);
    705        
     705
    706706        link_initialize(&term->link);
    707707        fibril_mutex_initialize(&term->mtx);
    708708        atomic_set(&term->refcnt, 0);
    709        
     709
    710710        prodcons_initialize(&term->input_pc);
    711711        term->char_remains_len = 0;
    712        
     712
    713713        term->widget.width = width;
    714714        term->widget.height = height;
    715715        term->widget.width_ideal = width;
    716716        term->widget.height_ideal = height;
    717        
     717
    718718        term->widget.destroy = terminal_destroy;
    719719        term->widget.reconfigure = terminal_reconfigure;
     
    722722        term->widget.handle_keyboard_event = terminal_handle_keyboard_event;
    723723        term->widget.handle_position_event = terminal_handle_position_event;
    724        
     724
    725725        term->cols = width / FONT_WIDTH;
    726726        term->rows = height / FONT_SCANLINES;
    727        
     727
    728728        term->frontbuf = NULL;
    729729        term->backbuf = NULL;
    730        
     730
    731731        term->frontbuf = chargrid_create(term->cols, term->rows,
    732732            CHARGRID_FLAG_NONE);
     
    735735                return false;
    736736        }
    737        
     737
    738738        term->backbuf = chargrid_create(term->cols, term->rows,
    739739            CHARGRID_FLAG_NONE);
     
    742742                return false;
    743743        }
    744        
     744
    745745        chargrid_clear(term->frontbuf);
    746746        chargrid_clear(term->backbuf);
    747747        term->top_row = 0;
    748        
     748
    749749        async_set_fallback_port_handler(term_connection, NULL);
    750750        con_srvs_init(&term->srvs);
    751751        term->srvs.ops = &con_ops;
    752752        term->srvs.sarg = term;
    753        
     753
    754754        errno_t rc = loc_server_register(NAME);
    755755        if (rc != EOK) {
     
    757757                return false;
    758758        }
    759        
     759
    760760        char vc[LOC_NAME_MAXLEN + 1];
    761761        snprintf(vc, LOC_NAME_MAXLEN, "%s/%" PRIu64, NAMESPACE,
    762762            task_get_id());
    763        
     763
    764764        rc = loc_service_register(vc, &term->dsid);
    765765        if (rc != EOK) {
     
    767767                return false;
    768768        }
    769        
     769
    770770        list_append(&term->link, &terms);
    771771        getterm(vc, "/app/bdsh");
    772        
     772
    773773        return true;
    774774}
     
    780780        if (!term)
    781781                return NULL;
    782        
     782
    783783        bool ret = init_terminal(term, parent, data, width, height);
    784784        if (!ret) {
     
    786786                return NULL;
    787787        }
    788        
     788
    789789        return term;
    790790}
  • uspace/lib/gui/terminal.h

    r3061bc1 ra35b458  
    5252typedef struct terminal {
    5353        widget_t widget;
    54        
     54
    5555        fibril_mutex_t mtx;
    5656        link_t link;
    5757        atomic_t refcnt;
    58        
     58
    5959        prodcons_t input_pc;
    6060        char char_remains[UTF8_CHAR_BUFFER_SIZE];
    6161        size_t char_remains_len;
    62        
     62
    6363        sysarg_t cols;
    6464        sysarg_t rows;
     
    6666        chargrid_t *backbuf;
    6767        sysarg_t top_row;
    68        
     68
    6969        service_id_t dsid;
    7070        con_srvs_t srvs;
  • uspace/lib/gui/widget.c

    r3061bc1 ra35b458  
    4141        link_initialize(&widget->link);
    4242        list_initialize(&widget->children);
    43        
     43
    4444        if (parent) {
    4545                widget->parent = parent;
     
    5050                widget->window = NULL;
    5151        }
    52        
     52
    5353        widget->data = data;
    54        
     54
    5555        widget->hpos = 0;
    5656        widget->vpos = 0;
    5757        widget->width = 0;
    5858        widget->height = 0;
    59        
     59
    6060        widget->width_min = 0;
    6161        widget->height_min = 0;
  • uspace/lib/gui/widget.h

    r3061bc1 ra35b458  
    5656        window_t *window;  /**< Window into which this widget belongs. */
    5757        const void *data;  /**< Custom client data. */
    58        
     58
    5959        sysarg_t hpos; /**< Horizontal position in window coordinates. */
    6060        sysarg_t vpos; /**< Vertical position in window coordinates. */
    6161        sysarg_t width;
    6262        sysarg_t height;
    63        
     63
    6464        sysarg_t width_min;
    6565        sysarg_t height_min;
  • uspace/lib/gui/window.c

    r3061bc1 ra35b458  
    8989        if (!surface)
    9090                window_yield(widget->window);
    91        
     91
    9292        source_t source;
    9393        source_init(&source);
    94        
     94
    9595        drawctx_t drawctx;
    9696        drawctx_init(&drawctx, surface);
    9797        drawctx_set_source(&drawctx, &source);
    98        
     98
    9999        /* Window border outer bevel */
    100        
     100
    101101        draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,
    102102            widget->width, widget->height, color_highlight, color_shadow);
    103        
     103
    104104        /* Window border surface */
    105        
     105
    106106        source_set_color(&source, color_surface);
    107107        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     
    113113        drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,
    114114            widget->vpos + 1, 2, widget->height - 4);
    115        
     115
    116116        /* Window border inner bevel */
    117        
     117
    118118        draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
    119119            widget->width - 6, widget->height - 6, color_shadow,
    120120            color_highlight);
    121        
     121
    122122        /* Header bevel */
    123        
     123
    124124        sysarg_t header_hpos = widget->hpos + border_thickness;
    125125        sysarg_t header_vpos = widget->vpos + border_thickness;
    126126        sysarg_t header_width = widget->width - 2 * border_thickness -
    127127            close_thickness;
    128        
     128
    129129        draw_bevel(&drawctx, &source, header_hpos, header_vpos,
    130130            header_width, header_height, widget->window->is_focused ?
     
    132132            widget->window->is_focused ?
    133133            color_header_focus_shadow : color_header_unfocus_shadow);
    134        
     134
    135135        /* Header surface */
    136        
     136
    137137        source_set_color(&source, widget->window->is_focused ?
    138138            color_header_focus_surface : color_header_unfocus_surface);
    139139        drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,
    140140            header_width - 2, header_height - 2);
    141        
     141
    142142        /* Close button bevel */
    143        
     143
    144144        sysarg_t close_hpos = widget->hpos + widget->width -
    145145            border_thickness - close_thickness;
    146146        sysarg_t close_vpos = widget->vpos + border_thickness;
    147        
     147
    148148        draw_bevel(&drawctx, &source, close_hpos, close_vpos,
    149149            close_thickness, close_thickness, color_highlight, color_shadow);
    150        
     150
    151151        /* Close button surface */
    152        
     152
    153153        source_set_color(&source, color_surface);
    154154        drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,
    155155            close_thickness - 2, close_thickness - 2);
    156        
     156
    157157        /* Close button icon */
    158        
     158
    159159        draw_icon_cross(surface, close_hpos + 3, close_vpos + 3,
    160160            color_highlight, color_shadow);
    161        
     161
    162162        /* Window caption */
    163        
     163
    164164        font_t *font;
    165165        errno_t rc = embedded_font_create(&font, 16);
     
    168168                return;
    169169        }
    170        
     170
    171171        drawctx_set_font(&drawctx, font);
    172172        source_set_color(&source, widget->window->is_focused ?
    173173            color_caption_focus : color_caption_unfocus);
    174        
     174
    175175        sysarg_t cpt_width;
    176176        sysarg_t cpt_height;
    177177        font_get_box(font, widget->window->caption, &cpt_width, &cpt_height);
    178        
     178
    179179        bool draw_title =
    180180            (widget->width >= 2 * border_thickness + 2 * bevel_thickness +
     
    184184                sysarg_t cpt_y = ((header_height - cpt_height) / 2) +
    185185                    widget->vpos + border_thickness;
    186                
     186
    187187                if (widget->window->caption)
    188188                        drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y);
    189189        }
    190        
     190
    191191        font_release(font);
    192192        window_yield(widget->window);
     
    375375                return;
    376376        }
    377        
     377
    378378        if (height < 2 * border_thickness + header_height) {
    379379                win_damage(win->osess, 0, 0, 0, 0);
    380380                return;
    381381        }
    382        
     382
    383383        /* Allocate resources for new surface. */
    384384        surface_t *new_surface = surface_create(width, height, NULL,
     
    386386        if (!new_surface)
    387387                return;
    388        
     388
    389389        /* Switch new and old surface. */
    390390        fibril_mutex_lock(&win->guard);
     
    392392        win->surface = new_surface;
    393393        fibril_mutex_unlock(&win->guard);
    394        
     394
    395395        /*
    396396         * Let all widgets in the tree alter their position and size.
     
    398398         */
    399399        win->root.rearrange(&win->root, 0, 0, width, height);
    400        
     400
    401401        fibril_mutex_lock(&win->guard);
    402402        surface_reset_damaged_region(win->surface);
    403403        fibril_mutex_unlock(&win->guard);
    404        
     404
    405405        /* Inform compositor about new surface. */
    406406        errno_t rc = win_resize(win->osess, offset_x, offset_y, width, height,
    407407            placement_flags, surface_direct_access(new_surface));
    408        
     408
    409409        if (rc != EOK) {
    410410                /* Rollback to old surface. Reverse all changes. */
    411                
     411
    412412                sysarg_t old_width = 0;
    413413                sysarg_t old_height = 0;
    414414                if (old_surface)
    415415                        surface_get_resolution(old_surface, &old_width, &old_height);
    416                
     416
    417417                fibril_mutex_lock(&win->guard);
    418418                new_surface = win->surface;
    419419                win->surface = old_surface;
    420420                fibril_mutex_unlock(&win->guard);
    421                
     421
    422422                win->root.rearrange(&win->root, 0, 0, old_width, old_height);
    423                
     423
    424424                if (win->surface) {
    425425                        fibril_mutex_lock(&win->guard);
     
    427427                        fibril_mutex_unlock(&win->guard);
    428428                }
    429                
     429
    430430                surface_destroy(new_surface);
    431431        } else {
     
    569569        while (true) {
    570570                window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
    571                
     571
    572572                if (event) {
    573573                        rc = win_get_event(win->isess, event);
     
    598598        if (!win)
    599599                return NULL;
    600        
     600
    601601        win->is_main = flags & WINDOW_MAIN;
    602602        win->is_decorated = flags & WINDOW_DECORATED;
     
    604604        prodcons_initialize(&win->events);
    605605        fibril_mutex_initialize(&win->guard);
    606        
     606
    607607        widget_init(&win->root, NULL, data);
    608608        win->root.window = win;
     
    616616        win->focus = NULL;
    617617        win->surface = NULL;
    618        
     618
    619619        service_id_t reg_dsid;
    620620        errno_t rc = loc_service_get_id(winreg, &reg_dsid, 0);
     
    623623                return NULL;
    624624        }
    625        
     625
    626626        async_sess_t *reg_sess =
    627627            loc_service_connect(reg_dsid, INTERFACE_COMPOSITOR, 0);
     
    630630                return NULL;
    631631        }
    632        
     632
    633633        service_id_t in_dsid;
    634634        service_id_t out_dsid;
     
    639639                return NULL;
    640640        }
    641        
     641
    642642        win->osess = loc_service_connect(out_dsid, INTERFACE_COMPOSITOR, 0);
    643643        if (win->osess == NULL) {
     
    645645                return NULL;
    646646        }
    647        
     647
    648648        win->isess = loc_service_connect(in_dsid, INTERFACE_COMPOSITOR, 0);
    649649        if (win->isess == NULL) {
     
    652652                return NULL;
    653653        }
    654        
     654
    655655        if (caption == NULL)
    656656                win->caption = NULL;
    657657        else
    658658                win->caption = str_dup(caption);
    659        
     659
    660660        return win;
    661661}
     
    680680{
    681681        char *cap;
    682        
     682
    683683        if (caption == NULL) {
    684684                win->caption = NULL;
     
    690690                win->caption = cap;
    691691        }
    692        
     692
    693693        win->is_focused = false;
    694694        handle_refresh(win);
    695        
     695
    696696        return EOK;
    697697}
Note: See TracChangeset for help on using the changeset viewer.