Changeset b3c185b6 in mainline for uspace/srv/hid/display/display.c
- Timestamp:
- 2019-11-04T14:05:35Z (4 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/display.c
r22faaf2 rb3c185b6 39 39 #include <io/log.h> 40 40 #include <stdlib.h> 41 #include "client.h" 42 #include "window.h" 41 43 #include "display.h" 42 #include "window.h"43 44 44 45 static errno_t disp_window_create(void *, sysarg_t *); 45 46 static errno_t disp_window_destroy(void *, sysarg_t); 47 static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *); 46 48 47 49 display_ops_t display_srv_ops = { 48 50 .window_create = disp_window_create, 49 .window_destroy = disp_window_destroy 51 .window_destroy = disp_window_destroy, 52 .get_event = disp_get_event 50 53 }; 51 54 … … 53 56 { 54 57 errno_t rc; 55 ds_ display_t *disp = (ds_display_t *) arg;58 ds_client_t *client = (ds_client_t *) arg; 56 59 ds_window_t *wnd; 57 60 58 61 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()"); 59 62 60 rc = ds_window_create( disp, &wnd);63 rc = ds_window_create(client, &wnd); 61 64 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc); 62 65 if (rc != EOK) … … 75 78 static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id) 76 79 { 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); 81 84 if (wnd == NULL) 82 85 return ENOENT; 83 86 84 87 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()"); 85 ds_ display_remove_window(wnd);88 ds_client_remove_window(wnd); 86 89 ds_window_delete(wnd); 90 return EOK; 91 } 92 93 static 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; 87 107 return EOK; 88 108 } … … 102 122 return ENOMEM; 103 123 104 list_initialize(&disp->windows); 124 list_initialize(&disp->clients); 125 disp->gc = gc; 105 126 disp->next_wnd_id = 1; 106 disp->gc = gc;107 127 *rdisp = disp; 108 128 return EOK; … … 115 135 void ds_display_destroy(ds_display_t *disp) 116 136 { 117 assert(list_empty(&disp-> windows));137 assert(list_empty(&disp->clients)); 118 138 free(disp); 119 139 } 120 140 121 /** Add windowto display.141 /** Add client to display. 122 142 * 123 143 * @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 */ 146 void 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 */ 159 void 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. 150 166 * 151 167 * @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 */ 170 ds_client_t *ds_display_first_client(ds_display_t *disp) 171 { 172 link_t *link = list_first(&disp->clients); 177 173 178 174 if (link == NULL) 179 175 return NULL; 180 176 181 return list_get_instance(link, ds_ window_t, lwindows);182 } 183 184 /** Get next windowin display.185 * 186 * @param wnd Current window187 * @return Next windowor @c NULL if there is none188 */ 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 */ 185 ds_client_t *ds_display_next_client(ds_client_t *client) 186 { 187 link_t *link = list_next(&client->lclients, &client->display->clients); 192 188 193 189 if (link == NULL) 194 190 return NULL; 195 191 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> 205 ds_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 228 errno_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); 197 244 } 198 245
Note:
See TracChangeset
for help on using the changeset viewer.