Ignore:
File:
1 edited

Legend:

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

    r3b98311 r071fefec  
    5858
    5959#include <event.h>
    60 #include <device/graph_dev.h>
     60#include <graph_iface.h>
    6161#include <io/keycode.h>
    6262#include <io/mode.h>
     
    7272#include <codec/tga.h>
    7373
    74 #include "images.h"
    7574#include "compositor.h"
    7675
     
    143142static LIST_INITIALIZE(viewport_list);
    144143
     144static FIBRIL_MUTEX_INITIALIZE(discovery_mtx);
     145
    145146/** Input server proxy */
    146147static input_t *input;
     
    160161static void input_disconnect(void);
    161162
    162 
    163163static pointer_t *input_pointer(input_t *input)
    164164{
     
    166166}
    167167
    168 static pointer_t *pointer_create()
     168static pointer_t *pointer_create(void)
    169169{
    170170        pointer_t *p = (pointer_t *) malloc(sizeof(pointer_t));
    171         if (!p) {
     171        if (!p)
    172172                return NULL;
    173         }
    174 
     173       
    175174        link_initialize(&p->link);
    176175        p->pos.x = coord_origin;
     
    184183        p->state = 0;
    185184        cursor_init(&p->cursor, CURSOR_DECODER_EMBEDDED, NULL);
    186 
     185       
    187186        /* Ghost window for transformation animation. */
    188187        transform_identity(&p->ghost.transform);
     
    197196        p->accum_ghost.x = 0;
    198197        p->accum_ghost.y = 0;
    199 
     198       
    200199        return p;
    201200}
     
    209208}
    210209
    211 static window_t *window_create(sysarg_t x_offset, sysarg_t y_offset)
     210static window_t *window_create(void)
    212211{
    213212        window_t *win = (window_t *) malloc(sizeof(window_t));
    214         if (!win) {
     213        if (!win)
    215214                return NULL;
    216         }
    217 
     215       
    218216        link_initialize(&win->link);
    219217        atomic_set(&win->ref_cnt, 0);
    220218        prodcons_initialize(&win->queue);
    221219        transform_identity(&win->transform);
    222         transform_translate(&win->transform,
    223             coord_origin + x_offset, coord_origin + y_offset);
    224         win->dx = coord_origin + x_offset;
    225         win->dy = coord_origin + y_offset;
     220        transform_translate(&win->transform, coord_origin, coord_origin);
     221        win->dx = coord_origin;
     222        win->dy = coord_origin;
    226223        win->fx = 1;
    227224        win->fy = 1;
     
    229226        win->opacity = 255;
    230227        win->surface = NULL;
    231 
     228       
    232229        return win;
    233230}
     
    292289    sysarg_t *x_out, sysarg_t *y_out, sysarg_t *w_out, sysarg_t *h_out)
    293290{
    294         if (w_in > 0 && h_in > 0) {
     291        if ((w_in > 0) && (h_in > 0)) {
    295292                sysarg_t x[4];
    296293                sysarg_t y[4];
     294               
    297295                comp_coord_from_client(x_in, y_in, win_trans, &x[0], &y[0]);
    298296                comp_coord_from_client(x_in + w_in - 1, y_in, win_trans, &x[1], &y[1]);
    299297                comp_coord_from_client(x_in + w_in - 1, y_in + h_in - 1, win_trans, &x[2], &y[2]);
    300298                comp_coord_from_client(x_in, y_in + h_in - 1, win_trans, &x[3], &y[3]);
     299               
    301300                (*x_out) = x[0];
    302301                (*y_out) = y[0];
    303302                (*w_out) = x[0];
    304303                (*h_out) = y[0];
    305                 for (int i = 1; i < 4; ++i) {
     304               
     305                for (unsigned int i = 1; i < 4; ++i) {
    306306                        (*x_out) = (x[i] < (*x_out)) ? x[i] : (*x_out);
    307307                        (*y_out) = (y[i] < (*y_out)) ? y[i] : (*y_out);
     
    309309                        (*h_out) = (y[i] > (*h_out)) ? y[i] : (*h_out);
    310310                }
     311               
    311312                (*w_out) = (*w_out) - (*x_out) + 1;
    312313                (*h_out) = (*h_out) - (*y_out) + 1;
     
    319320}
    320321
    321 static void comp_restrict_pointers(void)
     322static void comp_update_viewport_bound_rect(void)
    322323{
    323324        fibril_mutex_lock(&viewport_list_mtx);
    324 
     325       
    325326        sysarg_t x_res = coord_origin;
    326327        sysarg_t y_res = coord_origin;
    327328        sysarg_t w_res = 0;
    328329        sysarg_t h_res = 0;
    329 
     330       
    330331        if (!list_empty(&viewport_list)) {
    331332                viewport_t *vp = (viewport_t *) list_first(&viewport_list);
     
    334335                surface_get_resolution(vp->surface, &w_res, &h_res);
    335336        }
    336 
    337         list_foreach(viewport_list, link) {
    338                 viewport_t *vp = list_get_instance(link, viewport_t, link);
     337       
     338        list_foreach(viewport_list, link, viewport_t, vp) {
    339339                sysarg_t w_vp, h_vp;
    340340                surface_get_resolution(vp->surface, &w_vp, &h_vp);
    341                 rectangle_union(
    342                     x_res, y_res, w_res, h_res,
     341                rectangle_union(x_res, y_res, w_res, h_res,
    343342                    vp->pos.x, vp->pos.y, w_vp, h_vp,
    344343                    &x_res, &y_res, &w_res, &h_res);
    345344        }
    346 
     345       
    347346        viewport_bound_rect.x = x_res;
    348347        viewport_bound_rect.y = y_res;
    349348        viewport_bound_rect.w = w_res;
    350349        viewport_bound_rect.h = h_res;
    351 
     350       
    352351        fibril_mutex_unlock(&viewport_list_mtx);
    353 
     352}
     353
     354static void comp_restrict_pointers(void)
     355{
     356        comp_update_viewport_bound_rect();
     357       
    354358        fibril_mutex_lock(&pointer_list_mtx);
    355 
    356         list_foreach(pointer_list, link) {
    357                 pointer_t *ptr = list_get_instance(link, pointer_t, link);
     359       
     360        list_foreach(pointer_list, link, pointer_t, ptr) {
    358361                ptr->pos.x = ptr->pos.x > viewport_bound_rect.x ? ptr->pos.x : viewport_bound_rect.x;
    359362                ptr->pos.y = ptr->pos.y > viewport_bound_rect.y ? ptr->pos.y : viewport_bound_rect.y;
     
    363366                    ptr->pos.y : viewport_bound_rect.y + viewport_bound_rect.h;
    364367        }
    365 
     368       
    366369        fibril_mutex_unlock(&pointer_list_mtx);
    367370}
     
    374377        fibril_mutex_lock(&pointer_list_mtx);
    375378
    376         list_foreach(viewport_list, link) {
    377 
     379        list_foreach(viewport_list, link, viewport_t, vp) {
    378380                /* Determine what part of the viewport must be updated. */
    379                 viewport_t *vp = list_get_instance(link, viewport_t, link);
    380381                sysarg_t x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp;
    381382                surface_get_resolution(vp->surface, &w_dmg_vp, &h_dmg_vp);
     
    446447                        }
    447448
    448                         list_foreach(pointer_list, link) {
    449 
    450                                 pointer_t *ptr = list_get_instance(link, pointer_t, link);
     449                        list_foreach(pointer_list, link, pointer_t, ptr) {
    451450                                if (ptr->ghost.surface) {
    452451
     
    522521                        }
    523522
    524                         list_foreach(pointer_list, link) {
     523                        list_foreach(pointer_list, link, pointer_t, ptr) {
    525524
    526525                                /* Determine what part of the pointer intersects with the
    527526                                 * updated area of the current viewport. */
    528                                 pointer_t *ptr = list_get_instance(link, pointer_t, link);
    529527                                sysarg_t x_dmg_ptr, y_dmg_ptr, w_dmg_ptr, h_dmg_ptr;
    530528                                surface_t *sf_ptr = ptr->cursor.states[ptr->state];
     
    569567
    570568        /* Notify visualizers about updated regions. */
    571         list_foreach(viewport_list, link) {
    572                 viewport_t *vp = list_get_instance(link, viewport_t, link);
     569        list_foreach(viewport_list, link, viewport_t, vp) {
    573570                sysarg_t x_dmg_vp, y_dmg_vp, w_dmg_vp, h_dmg_vp;
    574571                surface_get_damaged_region(vp->surface, &x_dmg_vp, &y_dmg_vp, &w_dmg_vp, &h_dmg_vp);
     
    631628
    632629        fibril_mutex_lock(&pointer_list_mtx);
    633         list_foreach(pointer_list, link) {
    634                 pointer_t *pointer = list_get_instance(link, pointer_t, link);
     630        list_foreach(pointer_list, link, pointer_t, pointer) {
    635631                if (pointer->id == pos_id) {
    636632                        pointer->grab_flags = pointer->pressed ? grab_flags : GF_EMPTY;
     
    649645}
    650646
     647static void comp_recalc_transform(window_t *win)
     648{
     649        transform_t translate;
     650        transform_identity(&translate);
     651        transform_translate(&translate, win->dx, win->dy);
     652       
     653        transform_t scale;
     654        transform_identity(&scale);
     655        if ((win->fx != 1) || (win->fy != 1))
     656                transform_scale(&scale, win->fx, win->fy);
     657       
     658        transform_t rotate;
     659        transform_identity(&rotate);
     660        if (win->angle != 0)
     661                transform_rotate(&rotate, win->angle);
     662       
     663        transform_t transform;
     664        transform_t temp;
     665        transform_identity(&transform);
     666        temp = transform;
     667        transform_product(&transform, &temp, &translate);
     668        temp = transform;
     669        transform_product(&transform, &temp, &rotate);
     670        temp = transform;
     671        transform_product(&transform, &temp, &scale);
     672       
     673        win->transform = transform;
     674}
     675
    651676static void comp_window_resize(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
    652677{
    653         int rc;
    654 
    655678        ipc_callid_t callid;
    656679        size_t size;
    657680        unsigned int flags;
    658 
     681       
    659682        /* Start sharing resized window with client. */
    660683        if (!async_share_out_receive(&callid, &size, &flags)) {
     
    662685                return;
    663686        }
     687       
    664688        void *new_cell_storage;
    665         rc = async_share_out_finalize(callid, &new_cell_storage);
     689        int rc = async_share_out_finalize(callid, &new_cell_storage);
    666690        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    667691                async_answer_0(iid, ENOMEM);
    668692                return;
    669693        }
    670 
     694       
    671695        /* Create new surface for the resized window. */
    672         surface_t *new_surface = surface_create(
    673             IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    674             new_cell_storage, SURFACE_FLAG_SHARED);
     696        surface_t *new_surface = surface_create(IPC_GET_ARG3(*icall),
     697            IPC_GET_ARG4(*icall), new_cell_storage, SURFACE_FLAG_SHARED);
    675698        if (!new_surface) {
    676699                as_area_destroy(new_cell_storage);
     
    678701                return;
    679702        }
    680 
     703       
     704        sysarg_t offset_x = IPC_GET_ARG1(*icall);
     705        sysarg_t offset_y = IPC_GET_ARG2(*icall);
     706        window_placement_flags_t placement_flags =
     707            (window_placement_flags_t) IPC_GET_ARG5(*icall);
     708       
     709        comp_update_viewport_bound_rect();
     710       
    681711        /* Switch new surface with old surface and calculate damage. */
    682712        fibril_mutex_lock(&window_list_mtx);
    683 
     713       
    684714        sysarg_t old_width = 0;
    685715        sysarg_t old_height = 0;
     716       
    686717        if (win->surface) {
    687718                surface_get_resolution(win->surface, &old_width, &old_height);
    688719                surface_destroy(win->surface);
    689720        }
    690 
     721       
    691722        win->surface = new_surface;
    692 
     723       
    693724        sysarg_t new_width = 0;
    694725        sysarg_t new_height = 0;
    695726        surface_get_resolution(win->surface, &new_width, &new_height);
    696 
    697         sysarg_t x, y;
    698         sysarg_t width = old_width > new_width ? old_width : new_width;
    699         sysarg_t height = old_height > new_height ? old_height : new_height;
    700         comp_coord_bounding_rect(0, 0, width, height, win->transform, &x, &y, &width, &height);
    701 
     727       
     728        if (placement_flags & WINDOW_PLACEMENT_CENTER_X)
     729                win->dx = viewport_bound_rect.x + viewport_bound_rect.w / 2 -
     730                    new_width / 2;
     731       
     732        if (placement_flags & WINDOW_PLACEMENT_CENTER_Y)
     733                win->dy = viewport_bound_rect.y + viewport_bound_rect.h / 2 -
     734                    new_height / 2;
     735       
     736        if (placement_flags & WINDOW_PLACEMENT_LEFT)
     737                win->dx = viewport_bound_rect.x;
     738       
     739        if (placement_flags & WINDOW_PLACEMENT_TOP)
     740                win->dy = viewport_bound_rect.y;
     741       
     742        if (placement_flags & WINDOW_PLACEMENT_RIGHT)
     743                win->dx = viewport_bound_rect.x + viewport_bound_rect.w -
     744                    new_width;
     745       
     746        if (placement_flags & WINDOW_PLACEMENT_BOTTOM)
     747                win->dy = viewport_bound_rect.y + viewport_bound_rect.h -
     748                    new_height;
     749       
     750        if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_X)
     751                win->dx = coord_origin + offset_x;
     752       
     753        if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_Y)
     754                win->dy = coord_origin + offset_y;
     755       
     756        /* Transform the window and calculate damage. */
     757        sysarg_t x1;
     758        sysarg_t y1;
     759        sysarg_t width1;
     760        sysarg_t height1;
     761       
     762        comp_coord_bounding_rect(0, 0, old_width, old_height, win->transform,
     763            &x1, &y1, &width1, &height1);
     764       
     765        comp_recalc_transform(win);
     766       
     767        sysarg_t x2;
     768        sysarg_t y2;
     769        sysarg_t width2;
     770        sysarg_t height2;
     771       
     772        comp_coord_bounding_rect(0, 0, new_width, new_height, win->transform,
     773            &x2, &y2, &width2, &height2);
     774       
     775        sysarg_t x;
     776        sysarg_t y;
     777        sysarg_t width;
     778        sysarg_t height;
     779       
     780        rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
     781            &x, &y, &width, &height);
     782       
    702783        fibril_mutex_unlock(&window_list_mtx);
    703 
     784       
    704785        comp_damage(x, y, width, height);
    705 
     786       
    706787        async_answer_0(iid, EOK);
    707788}
     
    710791{
    711792        fibril_mutex_lock(&window_list_mtx);
    712         window_t *window = NULL;
    713         list_foreach(window_list, link) {
    714                 window = list_get_instance(link, window_t, link);
     793       
     794        list_foreach(window_list, link, window_t, window) {
    715795                if (window == target) {
    716796                        prodcons_produce(&window->queue, &event->link);
    717                 }
    718         }
    719         if (!window) {
     797                        fibril_mutex_unlock(&window_list_mtx);
     798                        return;
     799                }
     800        }
     801       
     802        fibril_mutex_unlock(&window_list_mtx);
     803        free(event);
     804}
     805
     806static void comp_post_event_top(window_event_t *event)
     807{
     808        fibril_mutex_lock(&window_list_mtx);
     809       
     810        window_t *win = (window_t *) list_first(&window_list);
     811        if (win)
     812                prodcons_produce(&win->queue, &event->link);
     813        else
    720814                free(event);
    721         }
    722         fibril_mutex_unlock(&window_list_mtx);
    723 }
    724 
    725 static void comp_post_event_top(window_event_t *event)
    726 {
    727         fibril_mutex_lock(&window_list_mtx);
    728         window_t *win = (window_t *) list_first(&window_list);
    729         if (win) {
    730                 prodcons_produce(&win->queue, &event->link);
    731         } else {
    732                 free(event);
    733         }
     815       
    734816        fibril_mutex_unlock(&window_list_mtx);
    735817}
     
    808890                        fibril_mutex_lock(&window_list_mtx);
    809891
    810                         window_t *win = window_create(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
     892                        window_t *win = window_create();
    811893                        if (!win) {
    812894                                async_answer_2(callid, ENOMEM, 0, 0);
     
    863945        window_t *win = NULL;
    864946        fibril_mutex_lock(&window_list_mtx);
    865         list_foreach(window_list, link) {
    866                 window_t *cur = list_get_instance(link, window_t, link);
     947        list_foreach(window_list, link, window_t, cur) {
    867948                if (cur->in_dsid == service_id || cur->out_dsid == service_id) {
    868949                        win = cur;
     
    10071088                /* Close all clients and their windows. */
    10081089                fibril_mutex_lock(&window_list_mtx);
    1009                 list_foreach(window_list, link) {
    1010                         window_t *win = list_get_instance(link, window_t, link);
     1090                list_foreach(window_list, link, window_t, win) {
    10111091                        window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
    10121092                        if (event) {
     
    10341114        viewport_t *vp = NULL;
    10351115        fibril_mutex_lock(&viewport_list_mtx);
    1036         list_foreach(viewport_list, link) {
    1037                 viewport_t *cur = list_get_instance(link, viewport_t, link);
     1116        list_foreach(viewport_list, link, viewport_t, cur) {
    10381117                if (cur->dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
    10391118                        vp = cur;
     
    11831262}
    11841263
    1185 static void comp_recalc_transform(window_t *win)
    1186 {
    1187         transform_t translate;
    1188         transform_identity(&translate);
    1189         transform_translate(&translate, win->dx, win->dy);
    1190 
    1191         transform_t scale;
    1192         transform_identity(&scale);
    1193         if (win->fx != 1 || win->fy != 1) {
    1194                 transform_scale(&scale, win->fx, win->fy);
    1195         }
    1196 
    1197         transform_t rotate;
    1198         transform_identity(&rotate);
    1199         if (win->angle != 0) {
    1200                 transform_rotate(&rotate, win->angle);
    1201         }
    1202 
    1203         transform_t transform;
    1204         transform_t temp;
    1205         transform_identity(&transform);
    1206         temp = transform;
    1207         transform_multiply(&transform, &temp, &translate);
    1208         temp = transform;
    1209         transform_multiply(&transform, &temp, &rotate);
    1210         temp = transform;
    1211         transform_multiply(&transform, &temp, &scale);
    1212        
    1213 
    1214         win->transform = transform;
    1215 }
    1216 
    12171264static void comp_window_animate(pointer_t *pointer, window_t *win,
    12181265    sysarg_t *dmg_x, sysarg_t *dmg_y, sysarg_t *dmg_width, sysarg_t *dmg_height)
     
    12361283                double cx = 0;
    12371284                double cy = 0;
    1238                 if (pointer->grab_flags & GF_MOVE_X) {
     1285               
     1286                if (pointer->grab_flags & GF_MOVE_X)
    12391287                        cx = 1;
    1240                 }
    1241                 if (pointer->grab_flags & GF_MOVE_Y) {
     1288               
     1289                if (pointer->grab_flags & GF_MOVE_Y)
    12421290                        cy = 1;
    1243                 }
    1244 
    1245                 if ((scale || resize) && (win->angle != 0)) {
     1291               
     1292                if (((scale) || (resize)) && (win->angle != 0)) {
    12461293                        transform_t rotate;
    12471294                        transform_identity(&rotate);
     1295                       
    12481296                        transform_rotate(&rotate, win->angle);
    12491297                        transform_apply_linear(&rotate, &cx, &cy);
    12501298                }
    12511299               
    1252                 cx = (cx < 0) ? (-1 * cx) : cx; 
     1300                cx = (cx < 0) ? (-1 * cx) : cx;
    12531301                cy = (cy < 0) ? (-1 * cy) : cy;
    1254 
     1302               
    12551303                win->dx += (cx * dx);
    12561304                win->dy += (cy * dy);
    12571305        }
    12581306
    1259         if (scale || resize) {
     1307        if ((scale) || (resize)) {
    12601308                double _dx = dx;
    12611309                double _dy = dy;
     
    12731321                        if (fx > 0) {
    12741322#if ANIMATE_WINDOW_TRANSFORMS == 0
    1275                                 if (scale) win->fx *= fx;
     1323                                if (scale)
     1324                                        win->fx *= fx;
    12761325#endif
    12771326#if ANIMATE_WINDOW_TRANSFORMS == 1
     
    14541503{
    14551504        pointer_t *pointer = input_pointer(input);
    1456 
     1505       
     1506        comp_update_viewport_bound_rect();
     1507       
    14571508        /* Update pointer position. */
    14581509        fibril_mutex_lock(&pointer_list_mtx);
     1510       
    14591511        desktop_point_t old_pos = pointer->pos;
     1512       
    14601513        sysarg_t cursor_width;
    14611514        sysarg_t cursor_height;
    1462         surface_get_resolution(pointer->cursor.states[pointer->state], 
     1515        surface_get_resolution(pointer->cursor.states[pointer->state],
    14631516             &cursor_width, &cursor_height);
    1464         if (pointer->pos.x + dx < viewport_bound_rect.x) {
     1517       
     1518        if (pointer->pos.x + dx < viewport_bound_rect.x)
    14651519                dx = -1 * (pointer->pos.x - viewport_bound_rect.x);
    1466         }
    1467         if (pointer->pos.y + dy < viewport_bound_rect.y) {
     1520       
     1521        if (pointer->pos.y + dy < viewport_bound_rect.y)
    14681522                dy = -1 * (pointer->pos.y - viewport_bound_rect.y);
    1469         }
    1470         if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w) {
     1523       
     1524        if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w)
    14711525                dx = (viewport_bound_rect.x + viewport_bound_rect.w - pointer->pos.x);
    1472         }
    1473         if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h) {
     1526       
     1527        if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h)
    14741528                dy = (viewport_bound_rect.y + viewport_bound_rect.h - pointer->pos.y);
    1475         }
     1529       
    14761530        pointer->pos.x += dx;
    14771531        pointer->pos.y += dy;
     
    14791533        comp_damage(old_pos.x, old_pos.y, cursor_width, cursor_height);
    14801534        comp_damage(old_pos.x + dx, old_pos.y + dy, cursor_width, cursor_height);
    1481 
     1535       
    14821536        fibril_mutex_lock(&window_list_mtx);
    14831537        fibril_mutex_lock(&pointer_list_mtx);
     
    15711625
    15721626        /* Determine the window which the mouse click belongs to. */
    1573         list_foreach(window_list, link) {
    1574                 win = list_get_instance(link, window_t, link);
     1627        list_foreach(window_list, link, window_t, cw) {
     1628                win = cw;
    15751629                if (win->surface) {
    15761630                        surface_get_resolution(win->surface, &width, &height);
     
    16401694
    16411695#if ANIMATE_WINDOW_TRANSFORMS == 0
    1642                 sysarg_t pre_x = 0; 
     1696                sysarg_t pre_x = 0;
    16431697                sysarg_t pre_y = 0;
    16441698                sysarg_t pre_width = 0;
     
    16721726                                link_initialize(&event_top->link);
    16731727                                event_top->type = ET_WINDOW_RESIZE;
    1674 
     1728                               
     1729                                event_top->data.resize.offset_x = 0;
     1730                                event_top->data.resize.offset_y = 0;
     1731                               
    16751732                                int dx = (int) (((double) width) * (scale_back_x - 1.0));
    16761733                                int dy = (int) (((double) height) * (scale_back_y - 1.0));
    1677 
    1678                                 if (pointer->grab_flags & GF_RESIZE_X) {
    1679                                         event_top->data.rsz.width =
    1680                                                 ((((int) width) + dx) >= 0) ? (width + dx) : 0;
    1681                                 } else {
    1682                                         event_top->data.rsz.width = width;
    1683                                 }
    1684 
    1685                                 if (pointer->grab_flags & GF_RESIZE_Y) {
    1686                                         event_top->data.rsz.height =
    1687                                                 ((((int) height) + dy) >= 0) ? (height + dy) : 0;
    1688                                 } else {
    1689                                         event_top->data.rsz.height = height;
    1690                                 }
     1734                               
     1735                                if (pointer->grab_flags & GF_RESIZE_X)
     1736                                        event_top->data.resize.width =
     1737                                            ((((int) width) + dx) >= 0) ? (width + dx) : 0;
     1738                                else
     1739                                        event_top->data.resize.width = width;
     1740                               
     1741                                if (pointer->grab_flags & GF_RESIZE_Y)
     1742                                        event_top->data.resize.height =
     1743                                            ((((int) height) + dy) >= 0) ? (height + dy) : 0;
     1744                                else
     1745                                        event_top->data.resize.height = height;
     1746                               
     1747                                event_top->data.resize.placement_flags =
     1748                                    WINDOW_PLACEMENT_ANY;
    16911749                        }
    16921750
     
    17561814            key == KC_O || key == KC_P);
    17571815        bool kconsole_switch = (mods & KM_ALT) && (key == KC_M);
    1758         bool compositor_test = (mods & KM_ALT) && (key == KC_H);
    17591816
    17601817        bool filter = (type == KEY_RELEASE) && (win_transform || win_resize ||
    17611818            win_opacity || win_close || win_switch || viewport_move ||
    1762             viewport_change || kconsole_switch || compositor_test);
     1819            viewport_change || kconsole_switch);
    17631820
    17641821        if (filter) {
     
    17821839                                break;
    17831840                        case KC_Q:
    1784                                 win->angle += (PI / 2);
     1841                                win->angle += 0.1;
    17851842                                break;
    17861843                        case KC_E:
    1787                                 win->angle += -(PI / 2);
     1844                                win->angle -= 0.1;
    17881845                                break;
    17891846                        case KC_R:
     
    18261883                                return ENOMEM;
    18271884                        }
    1828 
     1885                       
    18291886                        sysarg_t width, height;
    18301887                        surface_get_resolution(win->surface, &width, &height);
    1831 
     1888                       
    18321889                        link_initialize(&event->link);
    18331890                        event->type = ET_WINDOW_RESIZE;
    1834 
     1891                       
     1892                        event->data.resize.offset_x = 0;
     1893                        event->data.resize.offset_y = 0;
     1894                       
    18351895                        switch (key) {
    18361896                        case KC_T:
    1837                                 event->data.rsz.width = width;
    1838                                 event->data.rsz.height = (height >= 20) ? height - 20 : 0;
     1897                                event->data.resize.width = width;
     1898                                event->data.resize.height = (height >= 20) ? height - 20 : 0;
    18391899                                break;
    18401900                        case KC_G:
    1841                                 event->data.rsz.width = width;
    1842                                 event->data.rsz.height = height + 20;
     1901                                event->data.resize.width = width;
     1902                                event->data.resize.height = height + 20;
    18431903                                break;
    18441904                        case KC_B:
    1845                                 event->data.rsz.width = (width >= 20) ? width - 20 : 0;;
    1846                                 event->data.rsz.height = height;
     1905                                event->data.resize.width = (width >= 20) ? width - 20 : 0;;
     1906                                event->data.resize.height = height;
    18471907                                break;
    18481908                        case KC_N:
    1849                                 event->data.rsz.width = width + 20;
    1850                                 event->data.rsz.height = height;
     1909                                event->data.resize.width = width + 20;
     1910                                event->data.resize.height = height;
    18511911                                break;
    18521912                        default:
    1853                                 event->data.rsz.width = 0;
    1854                                 event->data.rsz.height = 0;
    1855                                 break;
    1856                         }
    1857 
     1913                                event->data.resize.width = 0;
     1914                                event->data.resize.height = 0;
     1915                                break;
     1916                        }
     1917                       
     1918                        event->data.resize.placement_flags = WINDOW_PLACEMENT_ANY;
     1919                       
    18581920                        fibril_mutex_unlock(&window_list_mtx);
    18591921                        comp_post_event_top(event);
     
    20242086        } else if (kconsole_switch) {
    20252087                __SYSCALL0(SYS_DEBUG_ACTIVATE_CONSOLE);
    2026         } else if (compositor_test) {
    2027                 fibril_mutex_lock(&window_list_mtx);
    2028 
    2029                 window_t *red_win = window_create(0, 0);
    2030                 red_win->surface = surface_create(250, 150, NULL, 0);
    2031                 pixel_t red_pix = PIXEL(255, 240, 0, 0);
    2032                 for (sysarg_t y = 0; y <  150; ++y) {
    2033                         for (sysarg_t x = 0; x < 250; ++x) {
    2034                                 surface_put_pixel(red_win->surface, x, y, red_pix);
    2035                         }
    2036                 }
    2037                 list_prepend(&red_win->link, &window_list);
    2038 
    2039                 window_t *blue_win = window_create(0, 0);
    2040                 blue_win->surface = surface_create(200, 100, NULL, 0);
    2041                 pixel_t blue_pix = PIXEL(255, 0, 0, 240);
    2042                 for (sysarg_t y = 0; y <  100; ++y) {
    2043                         for (sysarg_t x = 0; x < 200; ++x) {
    2044                                 surface_put_pixel(blue_win->surface, x, y, blue_pix);
    2045                         }
    2046                 }
    2047                 list_prepend(&blue_win->link, &window_list);
    2048                
    2049                 window_t *nameic_win = window_create(0, 0);
    2050                 nameic_win->surface = decode_tga((void *) nameic_tga, nameic_tga_size, 0);
    2051                 list_prepend(&nameic_win->link, &window_list);
    2052 
    2053                 fibril_mutex_unlock(&window_list_mtx);
    2054                 comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    20552088        } else {
    20562089                window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
     
    21262159}
    21272160
     2161static int discover_viewports(void)
     2162{
     2163        /* Create viewports and connect them to visualizers. */
     2164        category_id_t cat_id;
     2165        int rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING);
     2166        if (rc != EOK) {
     2167                printf("%s: Failed to get visualizer category.\n", NAME);
     2168                return -1;
     2169        }
     2170       
     2171        service_id_t *svcs;
     2172        size_t svcs_cnt = 0;
     2173        rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt);
     2174        if (rc != EOK || svcs_cnt == 0) {
     2175                printf("%s: Failed to get visualizer category services.\n", NAME);
     2176                return -1;
     2177        }
     2178
     2179        fibril_mutex_lock(&viewport_list_mtx); 
     2180        for (size_t i = 0; i < svcs_cnt; ++i) {
     2181                bool exists = false;
     2182                list_foreach(viewport_list, link, viewport_t, vp) {
     2183                        if (vp->dsid == svcs[i]) {
     2184                                exists = true;
     2185                                break;
     2186                        }
     2187                }
     2188               
     2189                if (exists)
     2190                        continue;
     2191               
     2192                char *svc_name;
     2193                rc = loc_service_get_name(svcs[i], &svc_name);
     2194                if (rc == EOK) {
     2195                        viewport_t *vp = viewport_create(svc_name);
     2196                        if (vp != NULL) {
     2197                                list_append(&vp->link, &viewport_list);
     2198                        }
     2199                }
     2200        }
     2201        fibril_mutex_unlock(&viewport_list_mtx);
     2202       
     2203        /* TODO damage only newly added viewports */
     2204        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
     2205        return EOK;
     2206}
     2207
     2208static void category_change_cb(void)
     2209{
     2210        fibril_mutex_lock(&discovery_mtx);
     2211        discover_viewports();
     2212        fibril_mutex_unlock(&discovery_mtx);
     2213}
     2214
    21282215static int compositor_srv_init(char *input_svc, char *name)
    21292216{
     
    21322219       
    21332220        /* Color of the viewport background. Must be opaque. */
    2134         bg_color = PIXEL(255, 75, 70, 75);
     2221        bg_color = PIXEL(255, 69, 51, 103);
    21352222       
    21362223        /* Register compositor server. */
     
    21722259        /* Establish input bidirectional connection. */
    21732260        rc = input_connect(input_svc);
    2174         if (rc != EOK)
     2261        if (rc != EOK) {
     2262                printf("%s: Failed to connect to input service.\n", NAME);
    21752263                return rc;
    2176 
    2177         /* Create viewports and connect them to visualizers. */
    2178         category_id_t cat_id;
    2179         rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING);
     2264        }
     2265
     2266        rc = loc_register_cat_change_cb(category_change_cb);
     2267        if (rc != EOK) {
     2268                printf("%s: Failed to register category change callback\n", NAME);
     2269                input_disconnect();
     2270                return rc;
     2271        }       
     2272
     2273        rc = discover_viewports();
    21802274        if (rc != EOK) {
    21812275                input_disconnect();
    2182                 return -1;
    2183         }
    2184        
    2185         service_id_t *svcs;
    2186         size_t svcs_cnt = 0;
    2187         rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt);
    2188         if (rc != EOK || svcs_cnt == 0) {
     2276                return rc;
     2277        }
     2278       
     2279        if (list_empty(&viewport_list)) {
     2280                printf("%s: Failed to get viewports.\n", NAME);
    21892281                input_disconnect();
    21902282                return -1;
    21912283        }
    2192        
    2193         for (size_t i = 0; i < svcs_cnt; ++i) {
    2194                 char *svc_name;
    2195                 rc = loc_service_get_name(svcs[i], &svc_name);
    2196                 if (rc == EOK) {
    2197                         viewport_t *vp = viewport_create(svc_name);
    2198                         if (vp != NULL) {
    2199                                 list_append(&vp->link, &viewport_list);
    2200                         }
    2201                 }
    2202         }
    2203        
    2204         if (list_empty(&viewport_list)) {
    2205                 input_disconnect();
    2206                 return -1;
    2207         }
    22082284
    22092285        comp_restrict_pointers();
    22102286        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
     2287       
    22112288       
    22122289        return EOK;
Note: See TracChangeset for help on using the changeset viewer.