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


Ignore:
Timestamp:
2024-10-13T08:23:40Z (8 weeks ago)
Author:
GitHub <noreply@…>
Children:
0472cf17
Parents:
2a0c827c (diff), b3b79981 (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.
git-author:
boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
git-committer:
GitHub <noreply@…> (2024-10-13 08:23:40)
Message:

Merge branch 'HelenOS:master' into topic/packet-capture

File:
1 edited

Legend:

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

    r2a0c827c rebb1489  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <gfx/color.h>
    3939#include <gfx/render.h>
     40#include <sif.h>
     41#include <stdio.h>
    4042#include <stdlib.h>
    4143#include <str.h>
     
    117119        free(seat->name);
    118120        free(seat);
     121}
     122
     123/** Load seat from SIF node.
     124 *
     125 * @param display Display
     126 * @param snode Seat node from which to load the seat
     127 * @param rseat Place to store pointer to the newly loaded seat
     128 *
     129 * @return EOK on success or an error code
     130 */
     131errno_t ds_seat_load(ds_display_t *display, sif_node_t *snode,
     132    ds_seat_t **rseat)
     133{
     134        const char *sid;
     135        const char *name;
     136        char *endptr;
     137        unsigned long id;
     138        errno_t rc;
     139
     140        sid = sif_node_get_attr(snode, "id");
     141        if (sid == NULL)
     142                return EIO;
     143
     144        name = sif_node_get_attr(snode, "name");
     145        if (name == NULL)
     146                return EIO;
     147
     148        id = strtoul(sid, &endptr, 10);
     149        if (*endptr != '\0')
     150                return EIO;
     151
     152        rc = ds_seat_create(display, name, rseat);
     153        if (rc != EOK)
     154                return EIO;
     155
     156        (*rseat)->id = id;
     157        return EOK;
     158}
     159
     160/** Save seat to SIF node.
     161 *
     162 * @param seat Seat
     163 * @param snode Seat node into which the seat should be saved
     164 *
     165 * @return EOK on success or an error code
     166 */
     167errno_t ds_seat_save(ds_seat_t *seat, sif_node_t *snode)
     168{
     169        char *sid;
     170        errno_t rc;
     171        int rv;
     172
     173        rv = asprintf(&sid, "%lu", (unsigned long)seat->id);
     174        if (rv < 0) {
     175                rc = ENOMEM;
     176                return rc;
     177        }
     178
     179        rc = sif_node_set_attr(snode, "id", sid);
     180        if (rc != EOK) {
     181                free(sid);
     182                return rc;
     183        }
     184
     185        free(sid);
     186
     187        rc = sif_node_set_attr(snode, "name", seat->name);
     188        if (rc != EOK)
     189                return rc;
     190
     191        return EOK;
    119192}
    120193
     
    510583errno_t ds_seat_post_pos_event(ds_seat_t *seat, pos_event_t *event)
    511584{
    512         ds_window_t *wnd;
     585        ds_window_t *pwindow;
     586        ds_window_t *cwindow;
    513587        errno_t rc;
    514588
    515         wnd = ds_display_window_by_pos(seat->display, &seat->pntpos);
    516 
    517         /* Deliver event to popup window. */
    518         if (seat->popup != NULL && event->type != POS_PRESS) {
    519                 rc = ds_window_post_pos_event(seat->popup, event);
    520                 if (rc != EOK)
    521                         return rc;
    522         }
    523 
    524         if (seat->focus != wnd && seat->focus != NULL) {
    525                 rc = ds_window_post_pos_event(seat->focus, event);
    526                 if (rc != EOK)
    527                         return rc;
    528 
    529                 /* Only deliver release events to the focused window */
    530                 if (event->type == POS_RELEASE)
    531                         return EOK;
    532         }
    533 
    534         if (wnd != NULL) {
     589        /* Window under pointer */
     590        pwindow = ds_display_window_by_pos(seat->display, &seat->pntpos);
     591
     592        /* Current window: popup or focused */
     593        cwindow = seat->popup;
     594        if (cwindow == NULL)
     595                cwindow = seat->focus;
     596
     597        /*
     598         * Deliver move and release event to current window if different
     599         * from pwindow
     600         */
     601        if (event->type != POS_PRESS && cwindow != NULL &&
     602            cwindow != pwindow) {
     603                rc = ds_window_post_pos_event(cwindow, event);
     604                if (rc != EOK)
     605                        return rc;
     606        }
     607
     608        if (pwindow != NULL) {
    535609                /* Moving over a window */
    536                 ds_seat_set_client_cursor(seat, wnd->cursor);
    537 
    538                 /*
    539                  * Only deliver event if we didn't already deliver it
    540                  * to the same window above.
    541                  */
    542                 if (wnd != seat->popup || event->type == POS_PRESS) {
    543                         rc = ds_window_post_pos_event(wnd, event);
    544                         if (rc != EOK)
    545                                 return rc;
    546                 }
     610                ds_seat_set_client_cursor(seat, pwindow->cursor);
     611
     612                rc = ds_window_post_pos_event(pwindow, event);
     613                if (rc != EOK)
     614                        return rc;
    547615        } else {
    548616                /* Not over a window */
    549                 ds_seat_set_client_cursor(seat, seat->display->cursor[dcurs_arrow]);
     617                ds_seat_set_client_cursor(seat,
     618                    seat->display->cursor[dcurs_arrow]);
    550619        }
    551620
    552621        /* Click outside popup window */
    553         if (event->type == POS_PRESS && wnd != seat->popup) {
     622        if (event->type == POS_PRESS && pwindow != seat->popup) {
    554623                /* Close popup window */
    555624                ds_seat_set_popup(seat, NULL);
Note: See TracChangeset for help on using the changeset viewer.