Changeset aeb3037 in mainline


Ignore:
Timestamp:
2020-03-18T17:27:18Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0680854
Parents:
1a1271d
git-author:
Jiri Svoboda <jiri@…> (2020-03-18 16:57:15)
git-committer:
Jiri Svoboda <jiri@…> (2020-03-18 17:27:18)
Message:

Allow getting display dimensions

Can be used to position special windows such as panels, or to help
emulate libgui's window placement policy. To support multi-monitor
setups we would rather need to be able to query individual monitors.
But let's keep things simple for now.

Location:
uspace
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/display/include/disp_srv.h

    r1a1271d raeb3037  
    4141#include "display/wndparams.h"
    4242#include "types/display/event.h"
     43#include "types/display/info.h"
    4344#include "types/display/wndresize.h"
    4445
     
    6061        errno_t (*window_resize)(void *, sysarg_t, gfx_coord2_t *, gfx_rect_t *);
    6162        errno_t (*get_event)(void *, sysarg_t *, display_wnd_ev_t *);
     63        errno_t (*get_info)(void *, display_info_t *);
    6264};
    6365
  • uspace/lib/display/include/display.h

    r1a1271d raeb3037  
    4343#include "display/wndresize.h"
    4444#include "types/display.h"
     45#include "types/display/info.h"
    4546
    4647extern errno_t display_open(const char *, display_t **);
    4748extern void display_close(display_t *);
     49extern errno_t display_get_info(display_t *, display_info_t *);
     50
    4851extern errno_t display_window_create(display_t *, display_wnd_params_t *,
    4952    display_wnd_cb_t *, void *, display_window_t **);
  • uspace/lib/display/include/ipc/display.h

    r1a1271d raeb3037  
    4545        DISPLAY_WINDOW_RESIZE,
    4646        DISPLAY_WINDOW_RESIZE_REQ,
    47         DISPLAY_GET_EVENT
     47        DISPLAY_GET_EVENT,
     48        DISPLAY_GET_INFO
    4849} display_request_t;
    4950
  • uspace/lib/display/src/disp_srv.c

    r1a1271d raeb3037  
    3737#include <disp_srv.h>
    3838#include <display/event.h>
     39#include <display/info.h>
    3940#include <display/wndresize.h>
    4041#include <errno.h>
     
    268269}
    269270
     271static void display_get_info_srv(display_srv_t *srv, ipc_call_t *icall)
     272{
     273        display_info_t info;
     274        ipc_call_t call;
     275        size_t size;
     276        errno_t rc;
     277
     278        if (srv->ops->get_info == NULL) {
     279                async_answer_0(icall, ENOTSUP);
     280                return;
     281        }
     282
     283        /* Transfer information */
     284        if (!async_data_read_receive(&call, &size)) {
     285                async_answer_0(icall, EREFUSED);
     286                return;
     287        }
     288
     289        if (size != sizeof(info)) {
     290                async_answer_0(icall, EREFUSED);
     291                async_answer_0(&call, EREFUSED);
     292                return;
     293        }
     294
     295        rc = srv->ops->get_info(srv->arg, &info);
     296        if (rc != EOK) {
     297                async_answer_0(icall, rc);
     298                async_answer_0(&call, rc);
     299                return;
     300        }
     301
     302        rc = async_data_read_finalize(&call, &info, sizeof(info));
     303        if (rc != EOK) {
     304                async_answer_0(icall, rc);
     305                async_answer_0(&call, rc);
     306                return;
     307        }
     308
     309        async_answer_0(icall, EOK);
     310}
     311
    270312void display_conn(ipc_call_t *icall, display_srv_t *srv)
    271313{
     
    306348                case DISPLAY_GET_EVENT:
    307349                        display_get_event_srv(srv, &call);
     350                        break;
     351                case DISPLAY_GET_INFO:
     352                        display_get_info_srv(srv, &call);
    308353                        break;
    309354                default:
  • uspace/lib/display/src/display.c

    r1a1271d raeb3037  
    385385 *
    386386 * @param display Display
    387  * @param rwindow Place to store pointe to window that received event
     387 * @param rwindow Place to store pointer to window that received event
    388388 * @param event Place to store event
    389389 * @return EOK on success or an error code
     
    418418
    419419        *rwindow = window;
     420        return EOK;
     421}
     422
     423/** Get display information.
     424 *
     425 * @param display Display
     426 * @param info Place to store display information
     427 * @return EOK on success or an error code
     428 */
     429errno_t display_get_info(display_t *display, display_info_t *info)
     430{
     431        async_exch_t *exch;
     432        ipc_call_t answer;
     433        aid_t req;
     434        errno_t rc;
     435
     436        exch = async_exchange_begin(display->sess);
     437        req = async_send_0(exch, DISPLAY_GET_INFO, &answer);
     438        rc = async_data_read_start(exch, info, sizeof(*info));
     439        async_exchange_end(exch);
     440        if (rc != EOK) {
     441                async_forget(req);
     442                return rc;
     443        }
     444
     445        async_wait_for(req, &rc);
     446        if (rc != EOK)
     447                return rc;
     448
    420449        return EOK;
    421450}
  • uspace/lib/display/test/display.c

    r1a1271d raeb3037  
    6262    gfx_rect_t *);
    6363static errno_t test_get_event(void *, sysarg_t *, display_wnd_ev_t *);
     64static errno_t test_get_info(void *, display_info_t *);
    6465
    6566static errno_t test_gc_set_color(void *, gfx_color_t *);
     
    7172        .window_resize_req = test_window_resize_req,
    7273        .window_resize = test_window_resize,
    73         .get_event = test_get_event
     74        .get_event = test_get_event,
     75        .get_info = test_get_info
    7476};
    7577
     
    116118
    117119        bool get_event_called;
     120
     121        bool get_info_called;
     122        gfx_rect_t get_info_rect;
     123
    118124        bool set_color_called;
    119125        bool close_event_called;
     
    831837
    832838        /* Verify that the event was delivered correctly */
    833         PCUT_ASSERT_EQUALS(resp.event.etype,
     839        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    834840            resp.revent.etype);
    835841
     
    896902
    897903        /* Verify that the event was delivered correctly */
    898         PCUT_ASSERT_EQUALS(resp.event.etype,
     904        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    899905            resp.revent.etype);
    900906
     
    965971
    966972        /* Verify that the event was delivered correctly */
    967         PCUT_ASSERT_EQUALS(resp.event.etype,
     973        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    968974            resp.revent.etype);
    969         PCUT_ASSERT_EQUALS(resp.event.ev.kbd.type,
     975        PCUT_ASSERT_INT_EQUALS(resp.event.ev.kbd.type,
    970976            resp.revent.ev.kbd.type);
    971         PCUT_ASSERT_EQUALS(resp.event.ev.kbd.key,
     977        PCUT_ASSERT_INT_EQUALS(resp.event.ev.kbd.key,
    972978            resp.revent.ev.kbd.key);
    973         PCUT_ASSERT_EQUALS(resp.event.ev.kbd.mods,
     979        PCUT_ASSERT_INT_EQUALS(resp.event.ev.kbd.mods,
    974980            resp.revent.ev.kbd.mods);
    975         PCUT_ASSERT_EQUALS(resp.event.ev.kbd.c,
     981        PCUT_ASSERT_INT_EQUALS(resp.event.ev.kbd.c,
    976982            resp.revent.ev.kbd.c);
    977983
     
    10421048
    10431049        /* Verify that the event was delivered correctly */
    1044         PCUT_ASSERT_EQUALS(resp.event.etype,
     1050        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    10451051            resp.revent.etype);
    1046         PCUT_ASSERT_EQUALS(resp.event.ev.pos.type,
     1052        PCUT_ASSERT_INT_EQUALS(resp.event.ev.pos.type,
    10471053            resp.revent.ev.pos.type);
    1048         PCUT_ASSERT_EQUALS(resp.event.ev.pos.btn_num,
     1054        PCUT_ASSERT_INT_EQUALS(resp.event.ev.pos.btn_num,
    10491055            resp.revent.ev.pos.btn_num);
    1050         PCUT_ASSERT_EQUALS(resp.event.ev.pos.hpos,
     1056        PCUT_ASSERT_INT_EQUALS(resp.event.ev.pos.hpos,
    10511057            resp.revent.ev.pos.hpos);
    1052         PCUT_ASSERT_EQUALS(resp.event.ev.pos.vpos,
     1058        PCUT_ASSERT_INT_EQUALS(resp.event.ev.pos.vpos,
    10531059            resp.revent.ev.pos.vpos);
    10541060
     
    11021108        resp.event.etype = wev_unfocus;
    11031109        resp.wnd_id = wnd->id;
    1104         resp.focus_event_called = false;
     1110        resp.unfocus_event_called = false;
    11051111        fibril_mutex_initialize(&resp.event_lock);
    11061112        fibril_condvar_initialize(&resp.event_cv);
     
    11151121
    11161122        /* Verify that the event was delivered correctly */
    1117         PCUT_ASSERT_EQUALS(resp.event.etype,
     1123        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    11181124            resp.revent.etype);
    11191125
     
    11231129        display_close(disp);
    11241130
     1131        rc = loc_service_unregister(sid);
     1132        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1133}
     1134
     1135/** display_get_info() with server returning failure response works. */
     1136PCUT_TEST(get_info_failure)
     1137{
     1138        errno_t rc;
     1139        service_id_t sid;
     1140        display_t *disp = NULL;
     1141        display_info_t info;
     1142        test_response_t resp;
     1143
     1144        async_set_fallback_port_handler(test_display_conn, &resp);
     1145
     1146        // FIXME This causes this test to be non-reentrant!
     1147        rc = loc_server_register(test_display_server);
     1148        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1149
     1150        rc = loc_service_register(test_display_svc, &sid);
     1151        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1152
     1153        rc = display_open(test_display_svc, &disp);
     1154        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1155        PCUT_ASSERT_NOT_NULL(disp);
     1156
     1157        resp.rc = ENOMEM;
     1158        resp.get_info_called = false;
     1159
     1160        rc = display_get_info(disp, &info);
     1161        PCUT_ASSERT_TRUE(resp.get_info_called);
     1162        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
     1163
     1164        display_close(disp);
     1165        rc = loc_service_unregister(sid);
     1166        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1167}
     1168
     1169/** display_get_info() with server returning success response works. */
     1170PCUT_TEST(get_info_success)
     1171{
     1172        errno_t rc;
     1173        service_id_t sid;
     1174        display_t *disp = NULL;
     1175        display_info_t info;
     1176        test_response_t resp;
     1177
     1178        async_set_fallback_port_handler(test_display_conn, &resp);
     1179
     1180        // FIXME This causes this test to be non-reentrant!
     1181        rc = loc_server_register(test_display_server);
     1182        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1183
     1184        rc = loc_service_register(test_display_svc, &sid);
     1185        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1186
     1187        rc = display_open(test_display_svc, &disp);
     1188        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1189        PCUT_ASSERT_NOT_NULL(disp);
     1190
     1191        resp.rc = EOK;
     1192        resp.get_info_called = false;
     1193        resp.get_info_rect.p0.x = 10;
     1194        resp.get_info_rect.p0.y = 11;
     1195        resp.get_info_rect.p1.x = 20;
     1196        resp.get_info_rect.p1.y = 21;
     1197
     1198        rc = display_get_info(disp, &info);
     1199        PCUT_ASSERT_TRUE(resp.get_info_called);
     1200        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
     1201        PCUT_ASSERT_INT_EQUALS(resp.get_info_rect.p0.x, info.rect.p0.x);
     1202        PCUT_ASSERT_INT_EQUALS(resp.get_info_rect.p0.y, info.rect.p0.y);
     1203        PCUT_ASSERT_INT_EQUALS(resp.get_info_rect.p1.x, info.rect.p1.x);
     1204        PCUT_ASSERT_INT_EQUALS(resp.get_info_rect.p1.y, info.rect.p1.y);
     1205
     1206        display_close(disp);
    11251207        rc = loc_service_unregister(sid);
    11261208        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     
    12941376}
    12951377
    1296 static errno_t test_get_event(void *arg, sysarg_t *wnd_id, display_wnd_ev_t *event)
     1378static errno_t test_get_event(void *arg, sysarg_t *wnd_id,
     1379    display_wnd_ev_t *event)
    12971380{
    12981381        test_response_t *resp = (test_response_t *) arg;
     
    13091392}
    13101393
     1394static errno_t test_get_info(void *arg, display_info_t *info)
     1395{
     1396        test_response_t *resp = (test_response_t *) arg;
     1397
     1398        resp->get_info_called = true;
     1399        info->rect = resp->get_info_rect;
     1400
     1401        return resp->rc;
     1402}
     1403
    13111404static errno_t test_gc_set_color(void *arg, gfx_color_t *color)
    13121405{
  • uspace/srv/hid/display/display.c

    r1a1271d raeb3037  
    8484        gfx_color_delete(disp->bg_color);
    8585        free(disp);
     86}
     87
     88/** Get display information.
     89 *
     90 * @param disp Display
     91 */
     92void ds_display_get_info(ds_display_t *disp, display_info_t *info)
     93{
     94        info->rect = disp->rect;
    8695}
    8796
  • uspace/srv/hid/display/display.h

    r1a1271d raeb3037  
    3737#define DISPLAY_H
    3838
     39#include <display/info.h>
    3940#include <errno.h>
    4041#include <gfx/context.h>
     
    4950extern errno_t ds_display_create(gfx_context_t *, ds_display_t **);
    5051extern void ds_display_destroy(ds_display_t *);
     52extern void ds_display_get_info(ds_display_t *, display_info_t *);
    5153extern void ds_display_add_client(ds_display_t *, ds_client_t *);
    5254extern void ds_display_remove_client(ds_client_t *);
  • uspace/srv/hid/display/dsops.c

    r1a1271d raeb3037  
    5252    gfx_rect_t *);
    5353static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
     54static errno_t disp_get_info(void *, display_info_t *);
    5455
    5556display_ops_t display_srv_ops = {
     
    5960        .window_resize_req = disp_window_resize_req,
    6061        .window_resize = disp_window_resize,
    61         .get_event = disp_get_event
     62        .get_event = disp_get_event,
     63        .get_info = disp_get_info
    6264};
    6365
     
    168170}
    169171
     172static errno_t disp_get_info(void *arg, display_info_t *info)
     173{
     174        ds_client_t *client = (ds_client_t *) arg;
     175
     176        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_get_info()");
     177
     178        ds_display_get_info(client->display, info);
     179        return EOK;
     180}
     181
    170182/** @}
    171183 */
Note: See TracChangeset for help on using the changeset viewer.