Changeset b3c185b6 in mainline for uspace/srv/hid/display/display.c


Ignore:
Timestamp:
2019-11-04T14:05:35Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
be15256
Parents:
22faaf2
git-author:
Jiri Svoboda <jiri@…> (2019-10-03 18:05:09)
git-committer:
Jiri Svoboda <jiri@…> (2019-11-04 14:05:35)
Message:

Window event delivery mechanism

File:
1 edited

Legend:

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

    r22faaf2 rb3c185b6  
    3939#include <io/log.h>
    4040#include <stdlib.h>
     41#include "client.h"
     42#include "window.h"
    4143#include "display.h"
    42 #include "window.h"
    4344
    4445static errno_t disp_window_create(void *, sysarg_t *);
    4546static errno_t disp_window_destroy(void *, sysarg_t);
     47static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
    4648
    4749display_ops_t display_srv_ops = {
    4850        .window_create = disp_window_create,
    49         .window_destroy = disp_window_destroy
     51        .window_destroy = disp_window_destroy,
     52        .get_event = disp_get_event
    5053};
    5154
     
    5356{
    5457        errno_t rc;
    55         ds_display_t *disp = (ds_display_t *) arg;
     58        ds_client_t *client = (ds_client_t *) arg;
    5659        ds_window_t *wnd;
    5760
    5861        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
    5962
    60         rc = ds_window_create(disp, &wnd);
     63        rc = ds_window_create(client, &wnd);
    6164        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
    6265        if (rc != EOK)
     
    7578static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
    7679{
    77         ds_display_t *disp = (ds_display_t *) arg;
    78         ds_window_t *wnd;
    79 
    80         wnd = ds_display_find_window(disp, wnd_id);
     80        ds_client_t *client = (ds_client_t *) arg;
     81        ds_window_t *wnd;
     82
     83        wnd = ds_client_find_window(client, wnd_id);
    8184        if (wnd == NULL)
    8285                return ENOENT;
    8386
    8487        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
    85         ds_display_remove_window(wnd);
     88        ds_client_remove_window(wnd);
    8689        ds_window_delete(wnd);
     90        return EOK;
     91}
     92
     93static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
     94    display_wnd_ev_t *event)
     95{
     96        ds_client_t *client = (ds_client_t *) arg;
     97        ds_window_t *wnd;
     98        errno_t rc;
     99
     100        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()");
     101
     102        rc = ds_client_get_event(client, &wnd, event);
     103        if (rc != EOK)
     104                return rc;
     105
     106        *wnd_id = wnd->id;
    87107        return EOK;
    88108}
     
    102122                return ENOMEM;
    103123
    104         list_initialize(&disp->windows);
     124        list_initialize(&disp->clients);
     125        disp->gc = gc;
    105126        disp->next_wnd_id = 1;
    106         disp->gc = gc;
    107127        *rdisp = disp;
    108128        return EOK;
     
    115135void ds_display_destroy(ds_display_t *disp)
    116136{
    117         assert(list_empty(&disp->windows));
     137        assert(list_empty(&disp->clients));
    118138        free(disp);
    119139}
    120140
    121 /** Add window to display.
     141/** Add client to display.
    122142 *
    123143 * @param disp Display
    124  * @param wnd Window
    125  * @return EOK on success, ENOMEM if there are no free window identifiers
    126  */
    127 errno_t ds_display_add_window(ds_display_t *disp, ds_window_t *wnd)
    128 {
    129         assert(wnd->display == NULL);
    130         assert(!link_used(&wnd->lwindows));
    131 
    132         wnd->display = disp;
    133         wnd->id = disp->next_wnd_id++;
    134         list_append(&wnd->lwindows, &disp->windows);
    135 
    136         return EOK;
    137 }
    138 
    139 /** Remove window from display.
    140  *
    141  * @param wnd Window
    142  */
    143 void ds_display_remove_window(ds_window_t *wnd)
    144 {
    145         list_remove(&wnd->lwindows);
    146         wnd->display = NULL;
    147 }
    148 
    149 /** Find window by ID.
     144 * @param client client
     145 */
     146void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
     147{
     148        assert(client->display == NULL);
     149        assert(!link_used(&client->lclients));
     150
     151        client->display = disp;
     152        list_append(&client->lclients, &disp->clients);
     153}
     154
     155/** Remove client from display.
     156 *
     157 * @param client client
     158 */
     159void ds_display_remove_client(ds_client_t *client)
     160{
     161        list_remove(&client->lclients);
     162        client->display = NULL;
     163}
     164
     165/** Get first client in display.
    150166 *
    151167 * @param disp Display
    152  * @param id Window ID
    153  */
    154 ds_window_t *ds_display_find_window(ds_display_t *disp, ds_wnd_id_t id)
    155 {
    156         ds_window_t *wnd;
    157 
    158         // TODO Make this faster
    159         wnd = ds_display_first_window(disp);
    160         while (wnd != NULL) {
    161                 if (wnd->id == id)
    162                         return wnd;
    163                 wnd = ds_display_next_window(wnd);
    164         }
    165 
    166         return NULL;
    167 }
    168 
    169 /** Get first window in display.
    170  *
    171  * @param disp Display
    172  * @return First window or @c NULL if there is none
    173  */
    174 ds_window_t *ds_display_first_window(ds_display_t *disp)
    175 {
    176         link_t *link = list_first(&disp->windows);
     168 * @return First client or @c NULL if there is none
     169 */
     170ds_client_t *ds_display_first_client(ds_display_t *disp)
     171{
     172        link_t *link = list_first(&disp->clients);
    177173
    178174        if (link == NULL)
    179175                return NULL;
    180176
    181         return list_get_instance(link, ds_window_t, lwindows);
    182 }
    183 
    184 /** Get next window in display.
    185  *
    186  * @param wnd Current window
    187  * @return Next window or @c NULL if there is none
    188  */
    189 ds_window_t *ds_display_next_window(ds_window_t *wnd)
    190 {
    191         link_t *link = list_next(&wnd->lwindows, &wnd->display->windows);
     177        return list_get_instance(link, ds_client_t, lclients);
     178}
     179
     180/** Get next client in display.
     181 *
     182 * @param client Current client
     183 * @return Next client or @c NULL if there is none
     184 */
     185ds_client_t *ds_display_next_client(ds_client_t *client)
     186{
     187        link_t *link = list_next(&client->lclients, &client->display->clients);
    192188
    193189        if (link == NULL)
    194190                return NULL;
    195191
    196         return list_get_instance(link, ds_window_t, lwindows);
     192        return list_get_instance(link, ds_client_t, lclients);
     193}
     194
     195/** Find window in all clients by ID.
     196 *
     197 * XXX This is just a hack needed to match GC connection to a window,
     198 * as we don't have a good safe way to pass the GC endpoint to our client
     199 * on demand.
     200 *
     201 * @param display Display
     202 * @param id Window ID
     203 */
     204#include <stdio.h>
     205ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id)
     206{
     207        ds_client_t *client;
     208        ds_window_t *wnd;
     209
     210        printf("ds_display_find_window: id=0x%lx\n", id);
     211
     212        client = ds_display_first_client(display);
     213        while (client != NULL) {
     214                printf("ds_display_find_window: client=%p\n", client);
     215                wnd = ds_client_find_window(client, id);
     216                if (wnd != NULL) {
     217                        printf("ds_display_find_window: found wnd=%p id=0x%lx\n",
     218                            wnd, wnd->id);
     219                        return wnd;
     220                }
     221                client = ds_display_next_client(client);
     222        }
     223
     224        printf("ds_display_find_window: not found\n");
     225        return NULL;
     226}
     227
     228errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
     229{
     230        ds_client_t *client;
     231        ds_window_t *wnd;
     232
     233        // XXX Correctly determine destination window
     234
     235        client = ds_display_first_client(display);
     236        if (client == NULL)
     237                return EOK;
     238
     239        wnd = ds_client_first_window(client);
     240        if (wnd == NULL)
     241                return EOK;
     242
     243        return ds_client_post_kbd_event(client, wnd, event);
    197244}
    198245
Note: See TracChangeset for help on using the changeset viewer.