Changeset 34aad53d in mainline for uspace/lib


Ignore:
Timestamp:
2024-04-07T09:45:45Z (18 months ago)
Author:
Nataliia Korop <n.corop08@…>
Children:
c37c24c
Parents:
e4cc266 (diff), 522eecf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge master to topic/packet-capture

Location:
uspace/lib
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/congfx/src/console.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    9191        uint8_t attr;
    9292
    93         if ((clr >> 24) == 0) {
     93        if ((clr >> 24) == 0xff) {
    9494                /* RGB (no text) */
    9595                ch->ch = 0;
    9696                ch->flags = CHAR_FLAG_DIRTY;
    9797                ch->attrs.type = CHAR_ATTR_RGB;
    98                 ch->attrs.val.rgb.fgcolor = clr ^ 0xffffff;
     98                ch->attrs.val.rgb.fgcolor = clr;
    9999                ch->attrs.val.rgb.bgcolor = clr;
    100100        } else {
  • uspace/lib/gfx/src/color.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6464        color->g = g;
    6565        color->b = b;
     66        color->attr = 0xff;
    6667
    6768        *rcolor = color;
  • uspace/lib/meson.build

    re4cc266 r34aad53d  
    3333        'c',
    3434        'math',
     35        'console',
    3536        'display',
     37        'input',
     38        'output',
    3639        'pixconv',
    3740        'posix',
  • uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h

    re4cc266 r34aad53d  
    4242#include <types/tbarcfg/tbarcfg.h>
    4343
     44#define TBARCFG_NOTIFY_DEFAULT "tbarcfg-notif"
     45
    4446extern errno_t tbarcfg_create(const char *, tbarcfg_t **);
    4547extern errno_t tbarcfg_open(const char *, tbarcfg_t **);
     
    6365extern errno_t smenu_entry_move_up(smenu_entry_t *);
    6466extern errno_t smenu_entry_move_down(smenu_entry_t *);
     67extern errno_t tbarcfg_listener_create(const char *, void (*)(void *),
     68    void *, tbarcfg_listener_t **);
     69extern void tbarcfg_listener_destroy(tbarcfg_listener_t *);
     70extern errno_t tbarcfg_notify(const char *);
    6571
    6672#endif
  • uspace/lib/tbarcfg/include/types/tbarcfg/tbarcfg.h

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343typedef struct smenu_entry smenu_entry_t;
    4444
     45struct tbarcfg_listener;
     46typedef struct tbarcfg_listener tbarcfg_listener_t;
     47
    4548#endif
    4649
  • uspace/lib/tbarcfg/private/tbarcfg.h

    re4cc266 r34aad53d  
    7171};
    7272
     73/** Taskbar configuration listener */
     74typedef struct tbarcfg_listener {
     75        /** Notification callback */
     76        void (*cb)(void *);
     77        /** Callback argument */
     78        void *arg;
     79} tbarcfg_listener_t;
     80
    7381extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *,
    7482    const char *, bool, smenu_entry_t **);
  • uspace/lib/tbarcfg/src/tbarcfg.c

    re4cc266 r34aad53d  
    3434 */
    3535
     36#include <async.h>
    3637#include <errno.h>
    3738#include <sif.h>
     39#include <ipc/tbarcfg.h>
     40#include <loc.h>
     41#include <task.h>
    3842#include <tbarcfg/tbarcfg.h>
     43#include <stdio.h>
    3944#include <stdlib.h>
    4045#include <str.h>
    4146#include "../private/tbarcfg.h"
     47
     48static void tbarcfg_notify_conn(ipc_call_t *, void *);
    4249
    4350/** Create taskbar configuration.
     
    784791}
    785792
     793/** Create taskbar configuration listener.
     794 *
     795 * Listens for taskbar configuration change notifications.
     796 *
     797 * @param nchan Notification channel (TBARCFG_NOTIFY_DEFAULT)
     798 * @param rlst Place to store pointer to new listener
     799 * @return EOK on success or an error code
     800 */
     801errno_t tbarcfg_listener_create(const char *nchan, void (*cb)(void *),
     802    void *arg, tbarcfg_listener_t **rlst)
     803{
     804        tbarcfg_listener_t *lst;
     805        service_id_t svcid = 0;
     806        loc_srv_t *srv = NULL;
     807        task_id_t taskid;
     808        char *svcname = NULL;
     809        category_id_t catid;
     810        port_id_t port;
     811        int rv;
     812        errno_t rc;
     813
     814        lst = calloc(1, sizeof(tbarcfg_listener_t));
     815        if (lst == NULL)
     816                return ENOMEM;
     817
     818        lst->cb = cb;
     819        lst->arg = arg;
     820
     821        rc = async_create_port(INTERFACE_TBARCFG_NOTIFY,
     822            tbarcfg_notify_conn, (void *)lst, &port);
     823        if (rc != EOK)
     824                goto error;
     825
     826        rc = loc_server_register("tbarcfg-listener", &srv);
     827        if (rc != EOK)
     828                goto error;
     829
     830        taskid = task_get_id();
     831
     832        rv = asprintf(&svcname, "tbarcfg/%u", (unsigned)taskid);
     833        if (rv < 0) {
     834                rc = ENOMEM;
     835                goto error;
     836        }
     837
     838        rc = loc_service_register(srv, svcname, &svcid);
     839        if (rc != EOK)
     840                goto error;
     841
     842        rc = loc_category_get_id(nchan, &catid, 0);
     843        if (rc != EOK)
     844                goto error;
     845
     846        rc = loc_service_add_to_cat(srv, svcid, catid);
     847        if (rc != EOK)
     848                goto error;
     849
     850        *rlst = lst;
     851        return EOK;
     852error:
     853        if (svcid != 0)
     854                loc_service_unregister(srv, svcid);
     855        if (srv != NULL)
     856                loc_server_unregister(srv);
     857        if (svcname != NULL)
     858                free(svcname);
     859        return rc;
     860}
     861
     862/** Destroy taskbar configuration listener.
     863 *
     864 * @param lst Listener
     865 */
     866void tbarcfg_listener_destroy(tbarcfg_listener_t *lst)
     867{
     868        free(lst);
     869}
     870
     871/** Send taskbar configuration notification to a particular service ID.
     872 *
     873 * @param svcid Service ID
     874 * @return EOK on success or an error code
     875 */
     876static errno_t tbarcfg_notify_svc(service_id_t svcid)
     877{
     878        async_sess_t *sess;
     879        async_exch_t *exch;
     880        errno_t rc;
     881
     882        sess = loc_service_connect(svcid, INTERFACE_TBARCFG_NOTIFY, 0);
     883        if (sess == NULL)
     884                return EIO;
     885
     886        exch = async_exchange_begin(sess);
     887        rc = async_req_0_0(exch, TBARCFG_NOTIFY_NOTIFY);
     888        if (rc != EOK) {
     889                async_exchange_end(exch);
     890                async_hangup(sess);
     891                return rc;
     892        }
     893
     894        async_exchange_end(exch);
     895        async_hangup(sess);
     896        return EOK;
     897}
     898
     899/** Send taskbar configuration change notification.
     900 *
     901 * @param nchan Notification channel (TBARCFG_NOTIFY_DEFAULT)
     902 */
     903errno_t tbarcfg_notify(const char *nchan)
     904{
     905        errno_t rc;
     906        category_id_t catid;
     907        service_id_t *svcs = NULL;
     908        size_t count, i;
     909
     910        rc = loc_category_get_id(nchan, &catid, 0);
     911        if (rc != EOK)
     912                return rc;
     913
     914        rc = loc_category_get_svcs(catid, &svcs, &count);
     915        if (rc != EOK)
     916                return rc;
     917
     918        for (i = 0; i < count; i++) {
     919                rc = tbarcfg_notify_svc(svcs[i]);
     920                if (rc != EOK)
     921                        goto error;
     922        }
     923
     924        free(svcs);
     925        return EOK;
     926error:
     927        free(svcs);
     928        return rc;
     929}
     930
     931/** Taskbar configuration connection handler.
     932 *
     933 * @param icall Initial call
     934 * @param arg Argument (tbarcfg_listener_t *)
     935 */
     936static void tbarcfg_notify_conn(ipc_call_t *icall, void *arg)
     937{
     938        tbarcfg_listener_t *lst = (tbarcfg_listener_t *)arg;
     939
     940        /* Accept the connection */
     941        async_accept_0(icall);
     942
     943        while (true) {
     944                ipc_call_t call;
     945                async_get_call(&call);
     946                sysarg_t method = ipc_get_imethod(&call);
     947
     948                if (!method) {
     949                        /* The other side has hung up */
     950                        async_answer_0(&call, EOK);
     951                        return;
     952                }
     953
     954                switch (method) {
     955                case TBARCFG_NOTIFY_NOTIFY:
     956                        lst->cb(lst->arg);
     957                        async_answer_0(&call, EOK);
     958                        break;
     959                default:
     960                        async_answer_0(&call, EINVAL);
     961                }
     962        }
     963}
     964
    786965/** @}
    787966 */
  • uspace/lib/tbarcfg/test/tbarcfg.c

    re4cc266 r34aad53d  
    3030#include <pcut/pcut.h>
    3131#include <tbarcfg/tbarcfg.h>
     32#include <stdbool.h>
    3233#include <stdio.h>
    3334
     
    3536
    3637PCUT_TEST_SUITE(tbarcfg);
     38
     39typedef struct {
     40        bool notified;
     41} tbarcfg_test_resp_t;
     42
     43static void test_cb(void *);
    3744
    3845/** Creating, opening and closing taskbar configuration */
     
    554561}
    555562
     563/** Notifications can be delivered from tbarcfg_notify() to a listener. */
     564PCUT_TEST(notify)
     565{
     566        errno_t rc;
     567        tbarcfg_listener_t *lst;
     568        tbarcfg_test_resp_t test_resp;
     569
     570        test_resp.notified = false;
     571
     572        printf("create listener resp=%p\n", (void *)&test_resp);
     573        rc = tbarcfg_listener_create(TBARCFG_NOTIFY_DEFAULT,
     574            test_cb, &test_resp, &lst);
     575        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     576
     577        rc = tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
     578        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     579
     580        PCUT_ASSERT_TRUE(test_resp.notified);
     581        tbarcfg_listener_destroy(lst);
     582}
     583
     584static void test_cb(void *arg)
     585{
     586        tbarcfg_test_resp_t *resp = (tbarcfg_test_resp_t *)arg;
     587
     588        printf("test_cb: executing resp=%p\n", (void *)resp);
     589        resp->notified = true;
     590}
     591
    556592PCUT_EXPORT(tbarcfg);
  • uspace/lib/ui/include/ui/menu.h

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5959extern ui_evclaim_t ui_menu_pos_event(ui_menu_t *, gfx_coord2_t *,
    6060    pos_event_t *);
     61extern sysarg_t ui_menu_get_idev_id(ui_menu_t *);
    6162
    6263#endif
  • uspace/lib/ui/include/ui/popup.h

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5454extern ui_resource_t *ui_popup_get_res(ui_popup_t *);
    5555extern gfx_context_t *ui_popup_get_gc(ui_popup_t *);
     56extern sysarg_t ui_popup_get_idev_id(ui_popup_t *);
    5657
    5758#endif
  • uspace/lib/ui/include/ui/wdecor.h

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4444#include <types/ui/event.h>
    4545#include <types/ui/resource.h>
     46#include <types/ui/ui.h>
    4647#include <types/ui/wdecor.h>
    4748
     
    5859extern ui_evclaim_t ui_wdecor_kbd_event(ui_wdecor_t *, kbd_event_t *);
    5960extern ui_evclaim_t ui_wdecor_pos_event(ui_wdecor_t *, pos_event_t *);
    60 extern void ui_wdecor_rect_from_app(ui_wdecor_style_t, gfx_rect_t *,
     61extern void ui_wdecor_rect_from_app(ui_t *, ui_wdecor_style_t, gfx_rect_t *,
    6162    gfx_rect_t *);
    6263extern void ui_wdecor_app_from_rect(ui_wdecor_style_t, gfx_rect_t *,
  • uspace/lib/ui/private/menu.h

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7070        /** Callback argument */
    7171        void *arg;
     72        /** ID of device that activated entry */
     73        sysarg_t idev_id;
    7274};
    7375
  • uspace/lib/ui/private/popup.h

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5858        /** Placement rectangle */
    5959        gfx_rect_t place;
     60        /** ID of device that sent input event */
     61        sysarg_t idev_id;
    6062};
    6163
  • uspace/lib/ui/src/menu.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    578578        ui_menu_t *menu = (ui_menu_t *)arg;
    579579
     580        menu->idev_id = ui_popup_get_idev_id(menu->popup);
    580581        ui_menu_kbd_event(menu, event);
    581582}
     
    592593        gfx_coord2_t spos;
    593594
     595        menu->idev_id = ui_popup_get_idev_id(menu->popup);
     596
    594597        spos.x = 0;
    595598        spos.y = 0;
     
    641644}
    642645
     646/** Get ID of last device that input event.
     647 *
     648 * @param menu Menu
     649 * @return Input device ID
     650 */
     651sysarg_t ui_menu_get_idev_id(ui_menu_t *menu)
     652{
     653        return menu->idev_id;
     654}
     655
    643656/** @}
    644657 */
  • uspace/lib/ui/src/menuentry.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    145145                return;
    146146
     147        mentry->menu->total_h -= ui_menu_entry_height(mentry);
     148        /* NOTE: max_caption_w/max_shortcut_w not updated (speed) */
     149
    147150        list_remove(&mentry->lentries);
     151
     152        /*
     153         * If we emptied the menu, reset accumulated dims so they
     154         * can be correctly calculated when (if) the menu is
     155         * re-populated.
     156         */
     157        if (list_empty(&mentry->menu->entries)) {
     158                mentry->menu->total_h = 0;
     159                mentry->menu->max_caption_w = 0;
     160                mentry->menu->max_shortcut_w = 0;
     161        }
     162
    148163        free(mentry->caption);
    149164        free(mentry);
  • uspace/lib/ui/src/popup.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    190190}
    191191
     192/** Get ID of device that sent the last position event.
     193 *
     194 * @param popup Popup window
     195 * @return Input device ID
     196 */
     197sysarg_t ui_popup_get_idev_id(ui_popup_t *popup)
     198{
     199        return popup->idev_id;
     200}
     201
    192202/** Handle close event in popup window.
    193203 *
     
    214224        ui_popup_t *popup = (ui_popup_t *)arg;
    215225
     226        /* Remember ID of device that sent the last event */
     227        popup->idev_id = event->kbd_id;
     228
    216229        if (popup->cb != NULL && popup->cb->kbd != NULL)
    217230                popup->cb->kbd(popup, popup->arg, event);
     
    229242        ui_popup_t *popup = (ui_popup_t *)arg;
    230243
     244        /* Remember ID of device that sent the last event */
     245        popup->idev_id = event->pos_id;
     246
    231247        if (popup->cb != NULL && popup->cb->pos != NULL)
    232248                popup->cb->pos(popup, popup->arg, event);
  • uspace/lib/ui/src/wdecor.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4545#include <ui/paint.h>
    4646#include <ui/pbutton.h>
     47#include <ui/ui.h>
    4748#include <ui/wdecor.h>
    4849#include "../private/resource.h"
     
    9495        /** Window resizing edge height */
    9596        wdecor_edge_h = 4,
     97        /** Window resizing edge witdth */
     98        wdecor_edge_w_text = 1,
     99        /** Window resizing edge height */
     100        wdecor_edge_h_text = 1,
    96101        /** Title bar height */
    97102        wdecor_tbar_h = 22,
     
    860865 * and its decoration.
    861866 *
     867 * @param ui UI
    862868 * @param style Decoration style
    863869 * @param app Application area rectangle
    864870 * @param rect Place to store (outer) window decoration rectangle
    865871 */
    866 void ui_wdecor_rect_from_app(ui_wdecor_style_t style, gfx_rect_t *app,
    867     gfx_rect_t *rect)
    868 {
     872void ui_wdecor_rect_from_app(ui_t *ui, ui_wdecor_style_t style,
     873    gfx_rect_t *app, gfx_rect_t *rect)
     874{
     875        bool textmode;
     876        gfx_coord_t edge_w, edge_h;
    869877        *rect = *app;
    870878
     879        textmode = ui_is_textmode(ui);
     880        if (textmode) {
     881                edge_w = wdecor_edge_w_text;
     882                edge_h = wdecor_edge_h_text;
     883        } else {
     884                edge_w = wdecor_edge_w;
     885                edge_h = wdecor_edge_h;
     886        }
     887
    871888        if ((style & ui_wds_frame) != 0) {
    872                 rect->p0.x -= wdecor_edge_w;
    873                 rect->p0.y -= wdecor_edge_h;
    874                 rect->p1.x += wdecor_edge_w;
    875                 rect->p1.y += wdecor_edge_h;
    876         }
    877 
    878         if ((style & ui_wds_titlebar) != 0)
    879                 rect->p0.y -= 22;
     889                rect->p0.x -= edge_w;
     890                rect->p0.y -= edge_h;
     891                rect->p1.x += edge_w;
     892                rect->p1.y += edge_h;
     893        }
     894
     895        if ((style & ui_wds_titlebar) != 0 && !textmode)
     896                rect->p0.y -= wdecor_tbar_h;
    880897}
    881898
  • uspace/lib/ui/test/wdecor.c

    re4cc266 r34aad53d  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434#include <ui/pbutton.h>
    3535#include <ui/resource.h>
     36#include <ui/ui.h>
    3637#include <ui/wdecor.h>
    3738#include "../private/wdecor.h"
     
    13221323PCUT_TEST(rect_from_app)
    13231324{
     1325        errno_t rc;
     1326        ui_t *ui = NULL;
    13241327        gfx_rect_t arect;
    13251328        gfx_rect_t rect;
     1329
     1330        rc = ui_create_disp(NULL, &ui);
     1331        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    13261332
    13271333        arect.p0.x = 14;
     
    13301336        arect.p1.y = 196;
    13311337
    1332         ui_wdecor_rect_from_app(ui_wds_none, &arect, &rect);
     1338        ui_wdecor_rect_from_app(ui, ui_wds_none, &arect, &rect);
    13331339
    13341340        PCUT_ASSERT_INT_EQUALS(14, rect.p0.x);
     
    13371343        PCUT_ASSERT_INT_EQUALS(196, rect.p1.y);
    13381344
    1339         ui_wdecor_rect_from_app(ui_wds_frame, &arect, &rect);
     1345        ui_wdecor_rect_from_app(ui, ui_wds_frame, &arect, &rect);
    13401346
    13411347        PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
     
    13441350        PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
    13451351
    1346         ui_wdecor_rect_from_app(ui_wds_decorated, &arect, &rect);
     1352        ui_wdecor_rect_from_app(ui, ui_wds_decorated, &arect, &rect);
    13471353
    13481354        PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
     
    13511357        PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
    13521358
     1359        ui_destroy(ui);
    13531360}
    13541361
  • uspace/lib/usbhid/src/hidparser.c

    re4cc266 r34aad53d  
    225225        /* Than we take the higher bits from the LSB */
    226226        const unsigned bit_offset = item->offset % 8;
    227         const int lsb_bits = min(bits, 8);
     227        const int lsb_bits = min((unsigned)bits, 8 - bit_offset);
    228228
    229229        value |= (*data >> bit_offset) & BIT_RRANGE(uint8_t, lsb_bits);
Note: See TracChangeset for help on using the changeset viewer.