source: mainline/uspace/srv/hid/display/display.c@ 38e5f36c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 38e5f36c was 38e5f36c, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Move implementation of display ops to a separate module

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2019 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup display
30 * @{
31 */
32/**
33 * @file Display server display
34 */
35
36#include <errno.h>
37#include <gfx/context.h>
38#include <io/log.h>
39#include <stdlib.h>
40#include "client.h"
41#include "window.h"
42#include "display.h"
43
44/** Create display.
45 *
46 * @param gc Graphics context for displaying output
47 * @param rdisp Place to store pointer to new display.
48 * @return EOK on success, ENOMEM if out of memory
49 */
50errno_t ds_display_create(gfx_context_t *gc, ds_display_t **rdisp)
51{
52 ds_display_t *disp;
53
54 disp = calloc(1, sizeof(ds_display_t));
55 if (disp == NULL)
56 return ENOMEM;
57
58 list_initialize(&disp->clients);
59 disp->gc = gc;
60 disp->next_wnd_id = 1;
61 *rdisp = disp;
62 return EOK;
63}
64
65/** Destroy display.
66 *
67 * @param disp Display
68 */
69void ds_display_destroy(ds_display_t *disp)
70{
71 assert(list_empty(&disp->clients));
72 free(disp);
73}
74
75/** Add client to display.
76 *
77 * @param disp Display
78 * @param client client
79 */
80void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
81{
82 assert(client->display == NULL);
83 assert(!link_used(&client->lclients));
84
85 client->display = disp;
86 list_append(&client->lclients, &disp->clients);
87}
88
89/** Remove client from display.
90 *
91 * @param client client
92 */
93void ds_display_remove_client(ds_client_t *client)
94{
95 list_remove(&client->lclients);
96 client->display = NULL;
97}
98
99/** Get first client in display.
100 *
101 * @param disp Display
102 * @return First client or @c NULL if there is none
103 */
104ds_client_t *ds_display_first_client(ds_display_t *disp)
105{
106 link_t *link = list_first(&disp->clients);
107
108 if (link == NULL)
109 return NULL;
110
111 return list_get_instance(link, ds_client_t, lclients);
112}
113
114/** Get next client in display.
115 *
116 * @param client Current client
117 * @return Next client or @c NULL if there is none
118 */
119ds_client_t *ds_display_next_client(ds_client_t *client)
120{
121 link_t *link = list_next(&client->lclients, &client->display->clients);
122
123 if (link == NULL)
124 return NULL;
125
126 return list_get_instance(link, ds_client_t, lclients);
127}
128
129/** Find window in all clients by ID.
130 *
131 * XXX This is just a hack needed to match GC connection to a window,
132 * as we don't have a good safe way to pass the GC endpoint to our client
133 * on demand.
134 *
135 * @param display Display
136 * @param id Window ID
137 */
138#include <stdio.h>
139ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id)
140{
141 ds_client_t *client;
142 ds_window_t *wnd;
143
144 printf("ds_display_find_window: id=0x%x\n", (unsigned) id);
145
146 client = ds_display_first_client(display);
147 while (client != NULL) {
148 printf("ds_display_find_window: client=%p\n", client);
149 wnd = ds_client_find_window(client, id);
150 if (wnd != NULL) {
151 printf("ds_display_find_window: found wnd=%p id=0x%x\n",
152 wnd, (unsigned) wnd->id);
153 return wnd;
154 }
155 client = ds_display_next_client(client);
156 }
157
158 printf("ds_display_find_window: not found\n");
159 return NULL;
160}
161
162errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
163{
164 ds_client_t *client;
165 ds_window_t *wnd;
166
167 // XXX Correctly determine destination window
168
169 client = ds_display_first_client(display);
170 if (client == NULL)
171 return EOK;
172
173 wnd = ds_client_first_window(client);
174 if (wnd == NULL)
175 return EOK;
176
177 return ds_client_post_kbd_event(client, wnd, event);
178}
179
180/** @}
181 */
Note: See TracBrowser for help on using the repository browser.