Changeset 4fbdc3d in mainline for uspace/srv/hid/display/seat.c


Ignore:
Timestamp:
2019-12-11T16:58:30Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4d9c807
Parents:
5bded44
Message:

Movement events from input server, display pointer, focus by click again

File:
1 edited

Legend:

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

    r5bded44 r4fbdc3d  
    3636#include <adt/list.h>
    3737#include <errno.h>
     38#include <gfx/color.h>
     39#include <gfx/render.h>
    3840#include <stdlib.h>
    3941#include "client.h"
     
    5759
    5860        ds_display_add_seat(display, seat);
     61        seat->pntpos.x = 10;
     62        seat->pntpos.y = 10;
    5963
    6064        *rseat = seat;
     
    7276}
    7377
     78/** Set seat focus to a window.
     79 *
     80 * @param seat Seat
     81 * @param wnd Window to focus
     82 */
    7483void ds_seat_set_focus(ds_seat_t *seat, ds_window_t *wnd)
    7584{
     
    7786}
    7887
     88/** Evacuate focus from window.
     89 *
     90 * If seat's focus is @a wnd, it will be set to a different window.
     91 *
     92 * @param seat Seat
     93 * @param wnd Window to evacuate focus from
     94 */
    7995void ds_seat_evac_focus(ds_seat_t *seat, ds_window_t *wnd)
    8096{
     
    119135}
    120136
     137/** Draw cross at seat pointer position.
     138 *
     139 * @param seat Seat
     140 * @param len Cross length
     141 * @param w Cross extra width
     142 * @param br Brightness (0 to 65535)
     143 *
     144 * @return EOK on success or an error code
     145 */
     146static errno_t ds_seat_draw_cross(ds_seat_t *seat, gfx_coord_t len,
     147    gfx_coord_t w, uint16_t br)
     148{
     149        gfx_color_t *color = NULL;
     150        gfx_context_t *gc;
     151        gfx_rect_t rect, r0;
     152        errno_t rc;
     153
     154        gc = ds_display_get_gc(seat->display);
     155        if (gc == NULL)
     156                return EOK;
     157
     158        rc = gfx_color_new_rgb_i16(br, br, br, &color);
     159        if (rc != EOK)
     160                goto error;
     161
     162        rc = gfx_set_color(gc, color);
     163        if (rc != EOK)
     164                goto error;
     165
     166        r0.p0.x = -len;
     167        r0.p0.y = -w;
     168        r0.p1.x = +len + 1;
     169        r0.p1.y = +w + 1;
     170        gfx_rect_translate(&seat->pntpos, &r0, &rect);
     171
     172        rc = gfx_fill_rect(gc, &rect);
     173        if (rc != EOK)
     174                goto error;
     175
     176        r0.p0.x = -w;
     177        r0.p0.y = -len;
     178        r0.p1.x = +w + 1;
     179        r0.p1.y = +len + 1;
     180        gfx_rect_translate(&seat->pntpos, &r0, &rect);
     181
     182        rc = gfx_fill_rect(gc, &rect);
     183        if (rc != EOK)
     184                goto error;
     185
     186        gfx_color_delete(color);
     187        return EOK;
     188error:
     189        if (color != NULL)
     190                gfx_color_delete(color);
     191        return rc;
     192}
     193
     194/** Draw or clear seat pointer
     195 *
     196 * @param seat Seat
     197 * @param shown @c true to display pointer, @c false to clear it
     198 *
     199 * @return EOK on success or an error code
     200 */
     201static errno_t ds_seat_draw_pointer(ds_seat_t *seat, bool shown)
     202{
     203        errno_t rc;
     204
     205        rc = ds_seat_draw_cross(seat, 8, 1, 0);
     206        if (rc != EOK)
     207                return rc;
     208
     209        rc = ds_seat_draw_cross(seat, 8, 0, shown ? 65535 : 0);
     210        if (rc != EOK)
     211                return rc;
     212
     213        return EOK;
     214}
     215
     216/** Post pointing device event to the seat
     217 *
     218 * @param seat Seat
     219 * @param event Event
     220 *
     221 * @return EOK on success or an error code
     222 */
     223#include <stdio.h>
     224errno_t ds_seat_post_ptd_event(ds_seat_t *seat, ptd_event_t *event)
     225{
     226        ds_window_t *wnd;
     227        gfx_coord2_t npos;
     228
     229        printf("ds_seat_post_ptd_event\n");
     230        /* Focus window on button press */
     231        if (event->type == PTD_PRESS) {
     232                printf("PTD_PRESS\n");
     233                wnd = ds_display_window_by_pos(seat->display, &seat->pntpos);
     234                if (wnd != NULL) {
     235                        printf("set focus\n");
     236                        ds_seat_set_focus(seat, wnd);
     237                        return EOK;
     238                }
     239        }
     240
     241        if (event->type == PTD_MOVE) {
     242                printf("PTD_MOVE\n");
     243                gfx_coord2_add(&seat->pntpos, &event->dmove, &npos);
     244                if (npos.x < 10)
     245                        npos.x = 10;
     246                if (npos.y < 10)
     247                        npos.y = 10;
     248                if (npos.x > 1024 - 10)
     249                        npos.x = 1024 - 10;
     250                if (npos.y > 768 - 10)
     251                        npos.y = 768 - 10;
     252
     253                printf("clear pointer\n");
     254                (void) ds_seat_draw_pointer(seat, false);
     255                seat->pntpos = npos;
     256                printf("draw pointer\n");
     257                (void) ds_seat_draw_pointer(seat, true);
     258        }
     259
     260        return EOK;
     261}
     262
    121263/** @}
    122264 */
Note: See TracChangeset for help on using the changeset viewer.