Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/compositor/compositor.c

    r5a6cc679 ra35b458  
    177177        if (!p)
    178178                return NULL;
    179        
     179
    180180        link_initialize(&p->link);
    181181        p->pos.x = coord_origin;
     
    189189        p->state = 0;
    190190        cursor_init(&p->cursor, CURSOR_DECODER_EMBEDDED, NULL);
    191        
     191
    192192        /* Ghost window for transformation animation. */
    193193        transform_identity(&p->ghost.transform);
     
    202202        p->accum_ghost.x = 0;
    203203        p->accum_ghost.y = 0;
    204        
     204
    205205        return p;
    206206}
     
    219219        if (!win)
    220220                return NULL;
    221        
     221
    222222        link_initialize(&win->link);
    223223        atomic_set(&win->ref_cnt, 0);
     
    232232        win->opacity = 255;
    233233        win->surface = NULL;
    234        
     234
    235235        return win;
    236236}
     
    244244                        free(event);
    245245                }
    246                
     246
    247247                if (win->surface)
    248248                        surface_destroy(win->surface);
    249                
     249
    250250                free(win);
    251251        }
     
    259259        transform_invert(&win_trans);
    260260        transform_apply_affine(&win_trans, &x, &y);
    261        
     261
    262262        /*
    263263         * Since client coordinate origin is (0, 0), it is necessary to check
     
    268268        if ((x < 0) || (y < 0))
    269269                return false;
    270        
     270
    271271        (*x_out) = (sysarg_t) (x + 0.5);
    272272        (*y_out) = (sysarg_t) (y + 0.5);
    273        
     273
    274274        if (((*x_out) >= x_lim) || ((*y_out) >= y_lim))
    275275                return false;
    276        
     276
    277277        return true;
    278278}
     
    284284        double y = y_in;
    285285        transform_apply_affine(&win_trans, &x, &y);
    286        
     286
    287287        /*
    288288         * It is assumed that compositor coordinate origin is chosen in such way,
     
    300300                sysarg_t x[4];
    301301                sysarg_t y[4];
    302                
     302
    303303                comp_coord_from_client(x_in, y_in, win_trans, &x[0], &y[0]);
    304304                comp_coord_from_client(x_in + w_in - 1, y_in, win_trans, &x[1], &y[1]);
    305305                comp_coord_from_client(x_in + w_in - 1, y_in + h_in - 1, win_trans, &x[2], &y[2]);
    306306                comp_coord_from_client(x_in, y_in + h_in - 1, win_trans, &x[3], &y[3]);
    307                
     307
    308308                (*x_out) = x[0];
    309309                (*y_out) = y[0];
    310310                (*w_out) = x[0];
    311311                (*h_out) = y[0];
    312                
     312
    313313                for (unsigned int i = 1; i < 4; ++i) {
    314314                        (*x_out) = (x[i] < (*x_out)) ? x[i] : (*x_out);
     
    317317                        (*h_out) = (y[i] > (*h_out)) ? y[i] : (*h_out);
    318318                }
    319                
     319
    320320                (*w_out) = (*w_out) - (*x_out) + 1;
    321321                (*h_out) = (*h_out) - (*y_out) + 1;
     
    331331{
    332332        fibril_mutex_lock(&viewport_list_mtx);
    333        
     333
    334334        sysarg_t x_res = coord_origin;
    335335        sysarg_t y_res = coord_origin;
    336336        sysarg_t w_res = 0;
    337337        sysarg_t h_res = 0;
    338        
     338
    339339        if (!list_empty(&viewport_list)) {
    340340                viewport_t *vp = (viewport_t *) list_first(&viewport_list);
     
    343343                surface_get_resolution(vp->surface, &w_res, &h_res);
    344344        }
    345        
     345
    346346        list_foreach(viewport_list, link, viewport_t, vp) {
    347347                sysarg_t w_vp, h_vp;
     
    351351                    &x_res, &y_res, &w_res, &h_res);
    352352        }
    353        
     353
    354354        viewport_bound_rect.x = x_res;
    355355        viewport_bound_rect.y = y_res;
    356356        viewport_bound_rect.w = w_res;
    357357        viewport_bound_rect.h = h_res;
    358        
     358
    359359        fibril_mutex_unlock(&viewport_list_mtx);
    360360}
     
    363363{
    364364        comp_update_viewport_bound_rect();
    365        
     365
    366366        fibril_mutex_lock(&pointer_list_mtx);
    367        
     367
    368368        list_foreach(pointer_list, link, pointer_t, ptr) {
    369369                ptr->pos.x = ptr->pos.x > viewport_bound_rect.x ? ptr->pos.x : viewport_bound_rect.x;
     
    374374                    ptr->pos.y : viewport_bound_rect.y + viewport_bound_rect.h;
    375375        }
    376        
     376
    377377        fibril_mutex_unlock(&pointer_list_mtx);
    378378}
     
    585585                }
    586586        }
    587        
     587
    588588        fibril_mutex_unlock(&viewport_list_mtx);
    589589}
     
    601601                return;
    602602        }
    603        
     603
    604604        errno_t rc = async_data_read_finalize(callid, event, len);
    605605        if (rc != EOK) {
     
    608608                return;
    609609        }
    610        
     610
    611611        async_answer_0(iid, EOK);
    612612        free(event);
     
    638638        sysarg_t pos_id = IPC_GET_ARG1(*icall);
    639639        sysarg_t grab_flags = IPC_GET_ARG2(*icall);
    640        
     640
    641641        /*
    642642         * Filter out resize grab flags if the window
     
    669669        transform_identity(&translate);
    670670        transform_translate(&translate, win->dx, win->dy);
    671        
     671
    672672        transform_t scale;
    673673        transform_identity(&scale);
    674674        if ((win->fx != 1) || (win->fy != 1))
    675675                transform_scale(&scale, win->fx, win->fy);
    676        
     676
    677677        transform_t rotate;
    678678        transform_identity(&rotate);
    679679        if (win->angle != 0)
    680680                transform_rotate(&rotate, win->angle);
    681        
     681
    682682        transform_t transform;
    683683        transform_t temp;
     
    689689        temp = transform;
    690690        transform_product(&transform, &temp, &scale);
    691        
     691
    692692        win->transform = transform;
    693693}
     
    698698        size_t size;
    699699        unsigned int flags;
    700        
     700
    701701        /* Start sharing resized window with client. */
    702702        if (!async_share_out_receive(&callid, &size, &flags)) {
     
    704704                return;
    705705        }
    706        
     706
    707707        void *new_cell_storage;
    708708        errno_t rc = async_share_out_finalize(callid, &new_cell_storage);
     
    711711                return;
    712712        }
    713        
     713
    714714        /* Create new surface for the resized window. */
    715715        surface_t *new_surface = surface_create(IPC_GET_ARG3(*icall),
     
    720720                return;
    721721        }
    722        
     722
    723723        sysarg_t offset_x = IPC_GET_ARG1(*icall);
    724724        sysarg_t offset_y = IPC_GET_ARG2(*icall);
    725725        window_placement_flags_t placement_flags =
    726726            (window_placement_flags_t) IPC_GET_ARG5(*icall);
    727        
     727
    728728        comp_update_viewport_bound_rect();
    729        
     729
    730730        /* Switch new surface with old surface and calculate damage. */
    731731        fibril_mutex_lock(&window_list_mtx);
    732        
     732
    733733        sysarg_t old_width = 0;
    734734        sysarg_t old_height = 0;
    735        
     735
    736736        if (win->surface) {
    737737                surface_get_resolution(win->surface, &old_width, &old_height);
    738738                surface_destroy(win->surface);
    739739        }
    740        
     740
    741741        win->surface = new_surface;
    742        
     742
    743743        sysarg_t new_width = 0;
    744744        sysarg_t new_height = 0;
    745745        surface_get_resolution(win->surface, &new_width, &new_height);
    746        
     746
    747747        if (placement_flags & WINDOW_PLACEMENT_CENTER_X)
    748748                win->dx = viewport_bound_rect.x + viewport_bound_rect.w / 2 -
    749749                    new_width / 2;
    750        
     750
    751751        if (placement_flags & WINDOW_PLACEMENT_CENTER_Y)
    752752                win->dy = viewport_bound_rect.y + viewport_bound_rect.h / 2 -
    753753                    new_height / 2;
    754        
     754
    755755        if (placement_flags & WINDOW_PLACEMENT_LEFT)
    756756                win->dx = viewport_bound_rect.x;
    757        
     757
    758758        if (placement_flags & WINDOW_PLACEMENT_TOP)
    759759                win->dy = viewport_bound_rect.y;
    760        
     760
    761761        if (placement_flags & WINDOW_PLACEMENT_RIGHT)
    762762                win->dx = viewport_bound_rect.x + viewport_bound_rect.w -
    763763                    new_width;
    764        
     764
    765765        if (placement_flags & WINDOW_PLACEMENT_BOTTOM)
    766766                win->dy = viewport_bound_rect.y + viewport_bound_rect.h -
    767767                    new_height;
    768        
     768
    769769        if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_X)
    770770                win->dx = coord_origin + offset_x;
    771        
     771
    772772        if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_Y)
    773773                win->dy = coord_origin + offset_y;
    774        
     774
    775775        /* Transform the window and calculate damage. */
    776776        sysarg_t x1;
     
    778778        sysarg_t width1;
    779779        sysarg_t height1;
    780        
     780
    781781        comp_coord_bounding_rect(0, 0, old_width, old_height, win->transform,
    782782            &x1, &y1, &width1, &height1);
    783        
     783
    784784        comp_recalc_transform(win);
    785        
     785
    786786        sysarg_t x2;
    787787        sysarg_t y2;
    788788        sysarg_t width2;
    789789        sysarg_t height2;
    790        
     790
    791791        comp_coord_bounding_rect(0, 0, new_width, new_height, win->transform,
    792792            &x2, &y2, &width2, &height2);
    793        
     793
    794794        sysarg_t x;
    795795        sysarg_t y;
    796796        sysarg_t width;
    797797        sysarg_t height;
    798        
     798
    799799        rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
    800800            &x, &y, &width, &height);
    801        
     801
    802802        fibril_mutex_unlock(&window_list_mtx);
    803        
     803
    804804        comp_damage(x, y, width, height);
    805        
     805
    806806        async_answer_0(iid, EOK);
    807807}
     
    810810{
    811811        fibril_mutex_lock(&window_list_mtx);
    812        
     812
    813813        list_foreach(window_list, link, window_t, window) {
    814814                if (window == target) {
     
    818818                }
    819819        }
    820        
     820
    821821        fibril_mutex_unlock(&window_list_mtx);
    822822        free(event);
     
    826826{
    827827        fibril_mutex_lock(&window_list_mtx);
    828        
     828
    829829        window_t *win = (window_t *) list_first(&window_list);
    830830        if (win)
     
    832832        else
    833833                free(event);
    834        
     834
    835835        fibril_mutex_unlock(&window_list_mtx);
    836836}
     
    914914                                return;
    915915                        }
    916                        
     916
    917917                        win->flags = IPC_GET_ARG1(call);
    918918
     
    950950                                event_unfocus->type = ET_WINDOW_UNFOCUS;
    951951                        }
    952                        
     952
    953953                        async_answer_2(callid, EOK, win->in_dsid, win->out_dsid);
    954954                        fibril_mutex_unlock(&window_list_mtx);
    955                        
     955
    956956                        if (event_unfocus && win_unfocus) {
    957957                                comp_post_event_win(event_unfocus, win_unfocus);
     
    11021102        loc_service_unregister(winreg_id);
    11031103        input_disconnect();
    1104        
     1104
    11051105        /* Close all clients and their windows. */
    11061106        fibril_mutex_lock(&window_list_mtx);
     
    11141114        }
    11151115        fibril_mutex_unlock(&window_list_mtx);
    1116        
     1116
    11171117        async_answer_0(iid, EOK);
    1118        
     1118
    11191119        /* All fibrils of the compositor will terminate soon. */
    11201120}
     
    11251125        /* Release viewport resources. */
    11261126        fibril_mutex_lock(&viewport_list_mtx);
    1127        
     1127
    11281128        list_remove(&vp->link);
    11291129        viewport_destroy(vp);
    1130        
     1130
    11311131        fibril_mutex_unlock(&viewport_list_mtx);
    1132        
     1132
    11331133        async_answer_0(iid, EOK);
    1134        
     1134
    11351135        comp_restrict_pointers();
    11361136        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
     
    11871187
    11881188        async_exch_t *exch = async_exchange_begin(sess);
    1189        
     1189
    11901190        port_id_t port;
    11911191        rc = async_create_callback_port(exch, INTERFACE_VISUALIZER_CB, 0, 0,
    11921192            vsl_notifications, NULL, &port);
    1193        
     1193
    11941194        async_exchange_end(exch);
    11951195
     
    12651265        if (claimed)
    12661266                visualizer_yield(vp->sess);
    1267        
     1267
    12681268        if (vp->sess != NULL)
    12691269                async_hangup(vp->sess);
    1270        
     1270
    12711271        free(vp);
    12721272        free(vsl_name);
     
    12951295                double cx = 0;
    12961296                double cy = 0;
    1297                
     1297
    12981298                if (pointer->grab_flags & GF_MOVE_X)
    12991299                        cx = 1;
    1300                
     1300
    13011301                if (pointer->grab_flags & GF_MOVE_Y)
    13021302                        cy = 1;
    1303                
     1303
    13041304                if (((scale) || (resize)) && (win->angle != 0)) {
    13051305                        transform_t rotate;
    13061306                        transform_identity(&rotate);
    1307                        
     1307
    13081308                        transform_rotate(&rotate, win->angle);
    13091309                        transform_apply_linear(&rotate, &cx, &cy);
    13101310                }
    1311                
     1311
    13121312                cx = (cx < 0) ? (-1 * cx) : cx;
    13131313                cy = (cy < 0) ? (-1 * cy) : cy;
    1314                
     1314
    13151315                win->dx += (cx * dx);
    13161316                win->dy += (cy * dy);
     
    14681468                rect3->w = w_u - w_i - x_i + x_u + 1;
    14691469                rect3->h = h_u;
    1470                
     1470
    14711471                rect4->x = x_u;
    14721472                rect4->y = y_i + h_i - 1;
     
    14811481{
    14821482        /* XXX TODO Use absolute coordinates directly */
    1483        
     1483
    14841484        pointer_t *pointer = input_pointer(input);
    1485        
     1485
    14861486        sysarg_t width, height;
    1487        
     1487
    14881488        fibril_mutex_lock(&viewport_list_mtx);
    14891489        if (list_empty(&viewport_list)) {
     
    15011501        pos_in_viewport.x = x * width / max_x;
    15021502        pos_in_viewport.y = y * height / max_y;
    1503        
     1503
    15041504        /* Calculate offset from pointer */
    15051505        fibril_mutex_lock(&pointer_list_mtx);
     
    15081508        delta.y = (vp_pos.y + pos_in_viewport.y) - pointer->pos.y;
    15091509        fibril_mutex_unlock(&pointer_list_mtx);
    1510        
     1510
    15111511        return comp_mouse_move(input, delta.x, delta.y);
    15121512}
     
    15151515{
    15161516        pointer_t *pointer = input_pointer(input);
    1517        
     1517
    15181518        comp_update_viewport_bound_rect();
    1519        
     1519
    15201520        /* Update pointer position. */
    15211521        fibril_mutex_lock(&pointer_list_mtx);
    1522        
     1522
    15231523        desktop_point_t old_pos = pointer->pos;
    1524        
     1524
    15251525        sysarg_t cursor_width;
    15261526        sysarg_t cursor_height;
    15271527        surface_get_resolution(pointer->cursor.states[pointer->state],
    15281528             &cursor_width, &cursor_height);
    1529        
     1529
    15301530        if (pointer->pos.x + dx < viewport_bound_rect.x)
    15311531                dx = -1 * (pointer->pos.x - viewport_bound_rect.x);
    1532        
     1532
    15331533        if (pointer->pos.y + dy < viewport_bound_rect.y)
    15341534                dy = -1 * (pointer->pos.y - viewport_bound_rect.y);
    1535        
     1535
    15361536        if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w)
    15371537                dx = (viewport_bound_rect.x + viewport_bound_rect.w - pointer->pos.x);
    1538        
     1538
    15391539        if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h)
    15401540                dy = (viewport_bound_rect.y + viewport_bound_rect.h - pointer->pos.y);
    1541        
     1541
    15421542        pointer->pos.x += dx;
    15431543        pointer->pos.y += dy;
     
    15451545        comp_damage(old_pos.x, old_pos.y, cursor_width, cursor_height);
    15461546        comp_damage(old_pos.x + dx, old_pos.y + dy, cursor_width, cursor_height);
    1547        
     1547
    15481548        fibril_mutex_lock(&window_list_mtx);
    15491549        fibril_mutex_lock(&pointer_list_mtx);
     
    16631663        sysarg_t dmg_width = 0;
    16641664        sysarg_t dmg_height = 0;
    1665        
     1665
    16661666#if ANIMATE_WINDOW_TRANSFORMS == 0
    16671667        desktop_rect_t dmg_rect1, dmg_rect2, dmg_rect3, dmg_rect4;
     
    17381738                                link_initialize(&event_top->link);
    17391739                                event_top->type = ET_WINDOW_RESIZE;
    1740                                
     1740
    17411741                                event_top->data.resize.offset_x = 0;
    17421742                                event_top->data.resize.offset_y = 0;
    1743                                
     1743
    17441744                                int dx = (int) (((double) width) * (scale_back_x - 1.0));
    17451745                                int dy = (int) (((double) height) * (scale_back_y - 1.0));
    1746                                
     1746
    17471747                                if (pointer->grab_flags & GF_RESIZE_X)
    17481748                                        event_top->data.resize.width =
     
    17501750                                else
    17511751                                        event_top->data.resize.width = width;
    1752                                
     1752
    17531753                                if (pointer->grab_flags & GF_RESIZE_Y)
    17541754                                        event_top->data.resize.height =
     
    17561756                                else
    17571757                                        event_top->data.resize.height = height;
    1758                                
     1758
    17591759                                event_top->data.resize.placement_flags =
    17601760                                    WINDOW_PLACEMENT_ANY;
     
    17641764
    17651765                } else if (within_client && (pointer->grab_flags == GF_EMPTY) && (top == win)) {
    1766                        
     1766
    17671767                        /* Notify top-level window about mouse release. */
    17681768                        event_top = (window_event_t *) malloc(sizeof(window_event_t));
     
    17771777                        }
    17781778                        pointer->grab_flags = GF_EMPTY;
    1779                        
     1779
    17801780                } else {
    17811781                        pointer->grab_flags = GF_EMPTY;
     
    18131813        active = true;
    18141814        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    1815        
     1815
    18161816        return EOK;
    18171817}
     
    19101910                                return ENOMEM;
    19111911                        }
    1912                        
     1912
    19131913                        sysarg_t width, height;
    19141914                        surface_get_resolution(win->surface, &width, &height);
    1915                        
     1915
    19161916                        link_initialize(&event->link);
    19171917                        event->type = ET_WINDOW_RESIZE;
    1918                        
     1918
    19191919                        event->data.resize.offset_x = 0;
    19201920                        event->data.resize.offset_y = 0;
    1921                        
     1921
    19221922                        switch (key) {
    19231923                        case KC_T:
     
    19421942                                break;
    19431943                        }
    1944                        
     1944
    19451945                        event->data.resize.placement_flags = WINDOW_PLACEMENT_ANY;
    1946                        
     1946
    19471947                        fibril_mutex_unlock(&window_list_mtx);
    19481948                        comp_post_event_top(event);
     
    20752075                                break;
    20762076                        }
    2077                        
     2077
    20782078                        sysarg_t x = vp->pos.x;
    20792079                        sysarg_t y = vp->pos.y;
     
    21962196{
    21972197        fibril_mutex_lock(&discovery_mtx);
    2198        
     2198
    21992199        /* Create viewports and connect them to visualizers. */
    22002200        category_id_t cat_id;
     
    22022202        if (rc != EOK)
    22032203                goto ret;
    2204        
     2204
    22052205        service_id_t *svcs;
    22062206        size_t svcs_cnt = 0;
     
    22082208        if (rc != EOK)
    22092209                goto ret;
    2210        
     2210
    22112211        fibril_mutex_lock(&viewport_list_mtx);
    22122212        for (size_t i = 0; i < svcs_cnt; ++i) {
     
    22182218                        }
    22192219                }
    2220                
     2220
    22212221                if (exists)
    22222222                        continue;
    2223                
     2223
    22242224                viewport_t *vp = viewport_create(svcs[i]);
    22252225                if (vp != NULL)
     
    22272227        }
    22282228        fibril_mutex_unlock(&viewport_list_mtx);
    2229        
     2229
    22302230        if (!list_empty(&viewport_list))
    22312231                input_activate(input);
    2232        
     2232
    22332233ret:
    22342234        fibril_mutex_unlock(&discovery_mtx);
     
    22442244        /* Coordinates of the central pixel. */
    22452245        coord_origin = UINT32_MAX / 4;
    2246        
     2246
    22472247        /* Color of the viewport background. Must be opaque. */
    22482248        bg_color = PIXEL(255, 69, 51, 103);
    2249        
     2249
    22502250        /* Register compositor server. */
    22512251        async_set_fallback_port_handler(client_connection, NULL);
    2252        
     2252
    22532253        errno_t rc = loc_server_register(NAME);
    22542254        if (rc != EOK) {
     
    22562256                return -1;
    22572257        }
    2258        
     2258
    22592259        server_name = name;
    2260        
     2260
    22612261        char svc[LOC_NAME_MAXLEN + 1];
    22622262        snprintf(svc, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, server_name);
    2263        
     2263
    22642264        service_id_t service_id;
    22652265        rc = loc_service_register(svc, &service_id);
     
    22682268                return rc;
    22692269        }
    2270        
     2270
    22712271        /* Prepare window registrator (entrypoint for clients). */
    22722272        char winreg[LOC_NAME_MAXLEN + 1];
     
    22762276                return -1;
    22772277        }
    2278        
     2278
    22792279        /* Establish input bidirectional connection. */
    22802280        rc = input_connect(input_svc);
     
    22832283                return rc;
    22842284        }
    2285        
     2285
    22862286        rc = loc_register_cat_change_cb(category_change_cb);
    22872287        if (rc != EOK) {
     
    22902290                return rc;
    22912291        }
    2292        
     2292
    22932293        discover_viewports();
    2294        
     2294
    22952295        comp_restrict_pointers();
    22962296        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    2297        
     2297
    22982298        return EOK;
    22992299}
     
    23102310                return 1;
    23112311        }
    2312        
     2312
    23132313        printf("%s: HelenOS Compositor server\n", NAME);
    2314        
     2314
    23152315        errno_t rc = compositor_srv_init(argv[1], argv[2]);
    23162316        if (rc != EOK)
    23172317                return rc;
    2318        
     2318
    23192319        printf("%s: Accepting connections\n", NAME);
    23202320        task_retval(0);
    23212321        async_manager();
    2322        
     2322
    23232323        /* Never reached */
    23242324        return 0;
Note: See TracChangeset for help on using the changeset viewer.