Changeset 7cc30e9 in mainline for uspace/srv/hid/display


Ignore:
Timestamp:
2022-10-24T17:50:46Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
913add60
Parents:
7a05d924
Message:

Display server needs to store window caption

Even though it does not use it itself, it needs to provide it to
window managers (e.g. Task bar). We need to be able to set caption
for a new window and to change it for an existing window.

Location:
uspace/srv/hid/display
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/dsops.c

    r7a05d924 r7cc30e9  
    5757static errno_t disp_window_unmaximize(void *, sysarg_t);
    5858static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
     59static errno_t disp_window_set_caption(void *, sysarg_t, const char *);
    5960static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
    6061static errno_t disp_get_info(void *, display_info_t *);
     
    7273        .window_unmaximize = disp_window_unmaximize,
    7374        .window_set_cursor = disp_window_set_cursor,
     75        .window_set_caption = disp_window_set_caption,
    7476        .get_event = disp_get_event,
    7577        .get_info = disp_get_info
     
    306308}
    307309
     310static errno_t disp_window_set_caption(void *arg, sysarg_t wnd_id,
     311    const char *caption)
     312{
     313        ds_client_t *client = (ds_client_t *) arg;
     314        ds_window_t *wnd;
     315        errno_t rc;
     316
     317        ds_display_lock(client->display);
     318
     319        wnd = ds_client_find_window(client, wnd_id);
     320        if (wnd == NULL) {
     321                ds_display_unlock(client->display);
     322                return ENOENT;
     323        }
     324
     325        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_caption()");
     326        rc = ds_window_set_caption(wnd, caption);
     327        ds_display_unlock(client->display);
     328        return rc;
     329}
     330
    308331static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
    309332    display_wnd_ev_t *event)
  • uspace/srv/hid/display/test/window.c

    r7a05d924 r7cc30e9  
    851851}
    852852
     853/** Test ds_window_set_caption() */
     854PCUT_TEST(window_set_caption)
     855{
     856        gfx_context_t *gc;
     857        ds_display_t *disp;
     858        ds_client_t *client;
     859        ds_seat_t *seat;
     860        ds_window_t *wnd;
     861        display_wnd_params_t params;
     862        errno_t rc;
     863
     864        rc = gfx_context_new(&dummy_ops, NULL, &gc);
     865        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     866
     867        rc = ds_display_create(gc, df_none, &disp);
     868        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     869
     870        rc = ds_client_create(disp, NULL, NULL, &client);
     871        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     872
     873        rc = ds_seat_create(disp, &seat);
     874        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     875
     876        display_wnd_params_init(&params);
     877        params.rect.p0.x = params.rect.p0.y = 0;
     878        params.rect.p1.x = params.rect.p1.y = 1;
     879
     880        rc = ds_window_create(client, &params, &wnd);
     881        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     882
     883        PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
     884
     885        rc = ds_window_set_caption(wnd, "Hello");
     886        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     887        PCUT_ASSERT_INT_EQUALS(0, str_cmp("Hello", wnd->caption));
     888
     889        ds_window_destroy(wnd);
     890        ds_seat_destroy(seat);
     891        ds_client_destroy(client);
     892        ds_display_destroy(disp);
     893}
     894
    853895static errno_t dummy_set_color(void *arg, gfx_color_t *color)
    854896{
  • uspace/srv/hid/display/types/display/window.h

    r7a05d924 r7cc30e9  
    105105        /** Window resize type (if state is dsw_resizing) */
    106106        display_wnd_rsztype_t rsztype;
     107        /** Window caption */
     108        char *caption;
    107109} ds_window_t;
    108110
  • uspace/srv/hid/display/window.c

    r7a05d924 r7cc30e9  
    4444#include <memgfx/memgc.h>
    4545#include <stdlib.h>
     46#include <str.h>
    4647#include "client.h"
    4748#include "display.h"
     
    8182        wnd = calloc(1, sizeof(ds_window_t));
    8283        if (wnd == NULL) {
     84                rc = ENOMEM;
     85                goto error;
     86        }
     87
     88        wnd->caption = str_dup(params->caption);
     89        if (wnd->caption == NULL) {
    8390                rc = ENOMEM;
    8491                goto error;
     
    152159                if (wnd->bitmap != NULL)
    153160                        gfx_bitmap_destroy(wnd->bitmap);
     161                if (wnd->caption != NULL)
     162                        free(wnd->caption);
    154163                free(wnd);
    155164        }
     
    176185                gfx_bitmap_destroy(wnd->bitmap);
    177186
     187        free(wnd->caption);
    178188        free(wnd);
    179189
     
    902912 *
    903913 * @param wnd Window
     914 * @param cursor New cursor
    904915 * @return EOK on success, EINVAL if @a cursor is invalid
    905916 */
     
    915926}
    916927
     928/** Set window caption.
     929 *
     930 * @param wnd Window
     931 * @param caption New caption
     932 *
     933 * @return EOK on success, EINVAL if @a cursor is invalid
     934 */
     935errno_t ds_window_set_caption(ds_window_t *wnd, const char *caption)
     936{
     937        char *dcaption;
     938
     939        dcaption = str_dup(caption);
     940        if (dcaption == NULL)
     941                return ENOMEM;
     942
     943        free(wnd->caption);
     944        wnd->caption = dcaption;
     945
     946        return EOK;
     947}
     948
    917949/** Window memory GC invalidate callback.
    918950 *
  • uspace/srv/hid/display/window.h

    r7a05d924 r7cc30e9  
    7373    gfx_rect_t *);
    7474extern errno_t ds_window_set_cursor(ds_window_t *, display_stock_cursor_t);
     75extern errno_t ds_window_set_caption(ds_window_t *, const char *);
    7576
    7677#endif
  • uspace/srv/hid/display/wmops.c

    r7a05d924 r7cc30e9  
    9898    wndmgt_window_info_t **rinfo)
    9999{
    100 
    101 /*      ds_client_t *client = (ds_client_t *) arg;
     100        ds_display_t *disp = (ds_display_t *)arg;
    102101        ds_window_t *wnd;
    103 
    104         ds_display_lock(client->display);
    105 
    106         wnd = ds_client_find_window(client, wnd_id);
    107         if (wnd == NULL) {
    108                 ds_display_unlock(client->display);
    109                 return ENOENT;
    110         }
    111 
    112         log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_pos()");
    113         ds_window_get_pos(wnd, pos);
    114         ds_display_unlock(client->display);
    115         return EOK;*/
    116102        wndmgt_window_info_t *info;
    117103
    118104        log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_info()");
     105
     106        wnd = ds_display_find_window(disp, wnd_id);
     107        if (wnd == NULL)
     108                return ENOENT;
    119109
    120110        info = calloc(1, sizeof(wndmgt_window_info_t));
     
    122112                return ENOMEM;
    123113
    124         info->caption = str_dup("Hello");
     114        info->caption = str_dup(wnd->caption);
    125115        if (info->caption == NULL) {
    126116                free(info);
Note: See TracChangeset for help on using the changeset viewer.