Changeset 338d0935 in mainline for uspace/srv/hid/display
- Timestamp:
- 2020-03-02T11:22:01Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2e104e
- Parents:
- 7bb45e3
- git-author:
- Jiri Svoboda <jiri@…> (2020-02-01 11:18:50)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-03-02 11:22:01)
- Location:
- uspace/srv/hid/display
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/client.c
r7bb45e3 r338d0935 203 203 } 204 204 205 /** Post focusevent to the client's message queue.206 * 207 * @param client Client 208 * @param ewindow Window that the message is targetted to 209 * 210 * @return EOK on success or an error code 211 */ 212 errno_t ds_client_post_ focus_event(ds_client_t *client, ds_window_t *ewindow)213 { 214 ds_window_ev_t *wevent; 215 216 wevent = calloc(1, sizeof(ds_window_ev_t)); 217 if (wevent == NULL) 218 return ENOMEM; 219 220 wevent->window = ewindow; 221 wevent->event.etype = wev_ focus;205 /** Post close event to the client's message queue. 206 * 207 * @param client Client 208 * @param ewindow Window that the message is targetted to 209 * 210 * @return EOK on success or an error code 211 */ 212 errno_t ds_client_post_close_event(ds_client_t *client, ds_window_t *ewindow) 213 { 214 ds_window_ev_t *wevent; 215 216 wevent = calloc(1, sizeof(ds_window_ev_t)); 217 if (wevent == NULL) 218 return ENOMEM; 219 220 wevent->window = ewindow; 221 wevent->event.etype = wev_close; 222 222 list_append(&wevent->levents, &client->events); 223 223 … … 230 230 } 231 231 232 /** Post focus event to the client's message queue. 233 * 234 * @param client Client 235 * @param ewindow Window that the message is targetted to 236 * 237 * @return EOK on success or an error code 238 */ 239 errno_t ds_client_post_focus_event(ds_client_t *client, ds_window_t *ewindow) 240 { 241 ds_window_ev_t *wevent; 242 243 wevent = calloc(1, sizeof(ds_window_ev_t)); 244 if (wevent == NULL) 245 return ENOMEM; 246 247 wevent->window = ewindow; 248 wevent->event.etype = wev_focus; 249 list_append(&wevent->levents, &client->events); 250 251 /* Notify the client */ 252 // TODO Do not send more than once until client drains the queue 253 if (client->cb != NULL && client->cb->ev_pending != NULL) 254 client->cb->ev_pending(client->cb_arg); 255 256 return EOK; 257 } 258 232 259 /** Post keyboard event to the client's message queue. 233 260 * -
uspace/srv/hid/display/client.h
r7bb45e3 r338d0935 53 53 extern errno_t ds_client_get_event(ds_client_t *, ds_window_t **, 54 54 display_wnd_ev_t *); 55 extern errno_t ds_client_post_close_event(ds_client_t *, ds_window_t *); 55 56 extern errno_t ds_client_post_focus_event(ds_client_t *, ds_window_t *); 56 57 extern errno_t ds_client_post_kbd_event(ds_client_t *, ds_window_t *, -
uspace/srv/hid/display/seat.c
r7bb45e3 r338d0935 137 137 return EOK; 138 138 139 return ds_ client_post_kbd_event(dwindow->client,dwindow, event);139 return ds_window_post_kbd_event(dwindow, event); 140 140 } 141 141 -
uspace/srv/hid/display/test/client.c
r7bb45e3 r338d0935 163 163 } 164 164 165 /** Test ds_client_get_event(), ds_client_post_close_event(). */ 166 PCUT_TEST(client_get_post_close_event) 167 { 168 ds_display_t *disp; 169 ds_client_t *client; 170 ds_window_t *wnd; 171 display_wnd_params_t params; 172 ds_window_t *rwindow; 173 display_wnd_ev_t revent; 174 bool called_cb = NULL; 175 errno_t rc; 176 177 rc = ds_display_create(NULL, &disp); 178 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 179 180 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 183 display_wnd_params_init(¶ms); 184 params.rect.p0.x = params.rect.p0.y = 0; 185 params.rect.p1.x = params.rect.p1.y = 1; 186 187 rc = ds_window_create(client, ¶ms, &wnd); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 190 PCUT_ASSERT_FALSE(called_cb); 191 192 rc = ds_client_get_event(client, &rwindow, &revent); 193 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 194 195 rc = ds_client_post_close_event(client, wnd); 196 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 197 PCUT_ASSERT_TRUE(called_cb); 198 199 rc = ds_client_get_event(client, &rwindow, &revent); 200 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 201 PCUT_ASSERT_EQUALS(wnd, rwindow); 202 PCUT_ASSERT_EQUALS(wev_close, revent.etype); 203 204 rc = ds_client_get_event(client, &rwindow, &revent); 205 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 206 207 ds_window_destroy(wnd); 208 ds_client_destroy(client); 209 ds_display_destroy(disp); 210 } 211 165 212 /** Test ds_client_get_event(), ds_client_post_focus_event(). */ 166 213 PCUT_TEST(client_get_post_focus_event) -
uspace/srv/hid/display/test/window.c
r7bb45e3 r338d0935 124 124 } 125 125 126 /** Test ds_window_post_kbd_event() with Alt-F4 sends close event */ 127 PCUT_TEST(window_post_kbd_event_alt_f4) 128 { 129 gfx_context_t *gc; 130 ds_display_t *disp; 131 ds_client_t *client; 132 ds_window_t *wnd; 133 ds_window_t *rwindow; 134 display_wnd_ev_t revent; 135 display_wnd_params_t params; 136 kbd_event_t event; 137 errno_t rc; 138 139 rc = gfx_context_new(&dummy_ops, NULL, &gc); 140 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 141 142 rc = ds_display_create(gc, &disp); 143 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 144 145 rc = ds_client_create(disp, NULL, NULL, &client); 146 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 147 148 display_wnd_params_init(¶ms); 149 params.rect.p0.x = params.rect.p0.y = 0; 150 params.rect.p1.x = params.rect.p1.y = 1; 151 152 rc = ds_window_create(client, ¶ms, &wnd); 153 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 154 155 event.type = KEY_PRESS; 156 event.mods = KM_ALT; 157 event.key = KC_F4; 158 rc = ds_window_post_kbd_event(wnd, &event); 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 161 rc = ds_client_get_event(client, &rwindow, &revent); 162 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 163 PCUT_ASSERT_EQUALS(wnd, rwindow); 164 PCUT_ASSERT_EQUALS(wev_close, revent.etype); 165 166 rc = ds_client_get_event(client, &rwindow, &revent); 167 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 168 169 ds_window_destroy(wnd); 170 ds_client_destroy(client); 171 ds_display_destroy(disp); 172 } 173 126 174 /** Test ds_window_post_pos_event() */ 127 175 PCUT_TEST(window_post_pos_event) -
uspace/srv/hid/display/window.c
r7bb45e3 r338d0935 529 529 } 530 530 531 /** Post keyboard event to window. 532 * 533 * @param wnd Window 534 * @param event Event 535 * 536 * @return EOK on success or an error code 537 */ 538 errno_t ds_window_post_kbd_event(ds_window_t *wnd, kbd_event_t *event) 539 { 540 bool alt_or_shift; 541 542 alt_or_shift = event->mods & (KM_SHIFT | KM_ALT); 543 544 if (event->type == KEY_PRESS && alt_or_shift && event->key == KC_F4) { 545 /* On Alt-F4 or Shift-F4 send close event to the window */ 546 ds_client_post_close_event(wnd->client, wnd); 547 return EOK; 548 } 549 550 return ds_client_post_kbd_event(wnd->client, wnd, event); 551 } 552 531 553 /** Post position event to window. 532 554 * -
uspace/srv/hid/display/window.h
r7bb45e3 r338d0935 54 54 extern gfx_context_t *ds_window_get_ctx(ds_window_t *); 55 55 extern errno_t ds_window_paint(ds_window_t *, gfx_rect_t *); 56 extern errno_t ds_window_post_kbd_event(ds_window_t *, kbd_event_t *); 56 57 extern errno_t ds_window_post_pos_event(ds_window_t *, pos_event_t *); 57 58 extern errno_t ds_window_post_focus_event(ds_window_t *);
Note:
See TracChangeset
for help on using the changeset viewer.