Changeset 24cf391a in mainline
- Timestamp:
- 2019-12-03T10:59:47Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 973efd36
- Parents:
- 79949f3
- git-author:
- Jiri Svoboda <jiri@…> (2019-11-02 18:59:43)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-12-03 10:59:47)
- Location:
- uspace/srv/hid/display
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/display.c
r79949f3 r24cf391a 164 164 } 165 165 166 /** Find window by display position. 167 * 168 * @param display Display 169 * @param pos Display position 170 */ 171 ds_window_t *ds_display_window_by_pos(ds_display_t *display, gfx_coord2_t *pos) 172 { 173 ds_window_t *wnd; 174 175 wnd = ds_display_first_window(display); 176 while (wnd != NULL) { 177 // XXX Need to know window dimensions 178 if (pos->x >= wnd->dpos.x && pos->y >= wnd->dpos.y && 179 pos->x <= wnd->dpos.x + 100 && pos->y <= wnd->dpos.y + 100) { 180 return wnd; 181 } 182 183 wnd = ds_display_next_window(wnd); 184 } 185 186 return NULL; 187 } 188 166 189 /** Add window to display. 167 190 * … … 239 262 } 240 263 264 /** Post position event to a display. 265 * 266 * @param display Display 267 * @param event Event 268 */ 269 errno_t ds_display_post_pos_event(ds_display_t *display, pos_event_t *event) 270 { 271 gfx_coord2_t pos; 272 ds_window_t *wnd; 273 ds_seat_t *seat; 274 275 /* Focus window on button press */ 276 if (event->type == POS_PRESS) { 277 printf("Button press\n"); 278 pos.x = event->hpos; 279 pos.y = event->vpos; 280 281 wnd = ds_display_window_by_pos(display, &pos); 282 if (wnd != NULL) { 283 seat = ds_display_first_seat(display); 284 if (seat == NULL) 285 return EOK; 286 287 ds_seat_set_focus(seat, wnd); 288 return EOK; 289 } 290 } 291 292 return EOK; 293 } 294 241 295 /** Add seat to display. 242 296 * -
uspace/srv/hid/display/display.h
r79949f3 r24cf391a 40 40 #include <gfx/context.h> 41 41 #include <io/kbd_event.h> 42 #include <io/pos_event.h> 42 43 #include "types/display/client.h" 43 44 #include "types/display/display.h" … … 51 52 extern ds_client_t *ds_display_next_client(ds_client_t *); 52 53 extern ds_window_t *ds_display_find_window(ds_display_t *, ds_wnd_id_t); 54 extern ds_window_t *ds_display_window_by_pos(ds_display_t *, gfx_coord2_t *); 53 55 extern void ds_display_add_window(ds_display_t *, ds_window_t *); 54 56 extern void ds_display_remove_window(ds_window_t *); … … 56 58 extern ds_window_t *ds_display_next_window(ds_window_t *); 57 59 extern errno_t ds_display_post_kbd_event(ds_display_t *, kbd_event_t *); 60 extern errno_t ds_display_post_pos_event(ds_display_t *, pos_event_t *); 58 61 extern void ds_display_add_seat(ds_display_t *, ds_seat_t *); 59 62 extern void ds_display_remove_seat(ds_seat_t *); -
uspace/srv/hid/display/main.c
r79949f3 r24cf391a 40 40 #include <str_error.h> 41 41 #include <io/log.h> 42 #include <io/kbd_event.h> 43 #include <io/pos_event.h> 42 44 #include <ipc/services.h> 43 45 #include <ipcgfx/server.h> … … 64 66 ds_display_t *disp = (ds_display_t *) arg; 65 67 66 printf("display_kbd_event\n");67 68 ds_display_post_kbd_event(disp, event); 69 } 70 71 static void display_pos_event(void *arg, pos_event_t *event) 72 { 73 ds_display_t *disp = (ds_display_t *) arg; 74 75 ds_display_post_pos_event(disp, event); 68 76 } 69 77 … … 93 101 goto error; 94 102 95 rc = output_init(display_kbd_event, (void *) disp, &gc); 103 rc = output_init(display_kbd_event, (void *) disp, 104 display_pos_event, (void *) disp, &gc); 96 105 if (rc != EOK) 97 106 goto error; -
uspace/srv/hid/display/output.c
r79949f3 r24cf391a 37 37 #include <gfx/context.h> 38 38 #include <guigfx/canvas.h> 39 #include <io/kbd_event.h> 40 #include <io/pos_event.h> 39 41 #include <stdio.h> 40 42 #include <stdlib.h> … … 44 46 static void (*kbd_ev_handler)(void *, kbd_event_t *); 45 47 static void *kbd_ev_arg; 48 static void (*pos_ev_handler)(void *, pos_event_t *); 49 static void *pos_ev_arg; 46 50 47 51 static void on_keyboard_event(widget_t *widget, void *data) … … 51 55 } 52 56 57 static void on_position_event(widget_t *widget, void *data) 58 { 59 pos_ev_handler(pos_ev_arg, (pos_event_t *) data); 60 } 61 53 62 errno_t output_init(void (*kbd_event_handler)(void *, kbd_event_t *), 54 void *arg, gfx_context_t **rgc) 63 void *karg, void (*pos_event_handler)(void *, pos_event_t *), 64 void *parg, gfx_context_t **rgc) 55 65 { 56 66 canvas_gc_t *cgc = NULL; … … 64 74 printf("Init canvas..\n"); 65 75 kbd_ev_handler = kbd_event_handler; 66 kbd_ev_arg = arg; 76 kbd_ev_arg = karg; 77 78 pos_ev_handler = pos_event_handler; 79 pos_ev_arg = parg; 67 80 68 81 window = window_open("comp:0/winreg", NULL, … … 96 109 97 110 sig_connect(&canvas->keyboard_event, NULL, on_keyboard_event); 111 sig_connect(&canvas->position_event, NULL, on_position_event); 98 112 99 113 window_resize(window, 0, 0, vw + 10, vh + 30, WINDOW_PLACEMENT_ANY); -
uspace/srv/hid/display/output.h
r79949f3 r24cf391a 38 38 39 39 #include <gfx/context.h> 40 #include <io/kbd_event.h> 41 #include <io/pos_event.h> 40 42 41 43 extern errno_t output_init(void (*)(void *, kbd_event_t *), void *, 44 void (*)(void *, pos_event_t *), void *, 42 45 gfx_context_t **); 43 46 -
uspace/srv/hid/display/test/display.c
r79949f3 r24cf391a 140 140 } 141 141 142 /** Test ds_display_window_by_pos(). */ 143 PCUT_TEST(display_window_by_pos) 144 { 145 ds_display_t *disp; 146 ds_client_t *client; 147 ds_window_t *w0; 148 ds_window_t *w1; 149 ds_window_t *wnd; 150 gfx_coord2_t pos; 151 errno_t rc; 152 153 rc = ds_display_create(NULL, &disp); 154 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 155 156 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 159 rc = ds_window_create(client, &w0); 160 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 161 162 rc = ds_window_create(client, &w1); 163 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 164 165 w0->dpos.x = 10; 166 w0->dpos.y = 10; 167 168 w1->dpos.x = 400; 169 w1->dpos.y = 400; 170 171 pos.x = 10; 172 pos.y = 10; 173 wnd = ds_display_window_by_pos(disp, &pos); 174 PCUT_ASSERT_EQUALS(w0, wnd); 175 176 pos.x = 400; 177 pos.y = 400; 178 wnd = ds_display_window_by_pos(disp, &pos); 179 PCUT_ASSERT_EQUALS(w1, wnd); 180 181 ds_window_destroy(w0); 182 ds_window_destroy(w1); 183 ds_client_destroy(client); 184 ds_display_destroy(disp); 185 } 186 142 187 /** Basic seat operation. */ 143 188 PCUT_TEST(display_seat) … … 164 209 } 165 210 166 /** Test ds_display_post_kbd_event(). */ 211 /** Test ds_display_post_kbd_event() delivers event to client callback. 212 */ 167 213 PCUT_TEST(display_post_kbd_event) 168 214 { … … 172 218 ds_window_t *wnd; 173 219 kbd_event_t event; 174 bool called_cb = NULL;220 bool called_cb = false; 175 221 errno_t rc; 176 222 … … 206 252 } 207 253 254 /** Test ds_display_post_kbd_event() with Alt-Tab switches focus. 255 */ 256 PCUT_TEST(display_post_kbd_event_alt_tab) 257 { 258 ds_display_t *disp; 259 ds_seat_t *seat; 260 ds_client_t *client; 261 ds_window_t *w0, *w1; 262 kbd_event_t event; 263 bool called_cb = false; 264 errno_t rc; 265 266 rc = ds_display_create(NULL, &disp); 267 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 268 269 rc = ds_seat_create(disp, &seat); 270 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 271 272 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client); 273 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 274 275 rc = ds_window_create(client, &w0); 276 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 277 278 rc = ds_window_create(client, &w1); 279 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 280 281 ds_seat_set_focus(seat, w0); 282 283 event.type = KEY_PRESS; 284 event.key = KC_TAB; 285 event.mods = KM_ALT; 286 event.c = L'\0'; 287 288 PCUT_ASSERT_FALSE(called_cb); 289 290 rc = ds_display_post_kbd_event(disp, &event); 291 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 292 PCUT_ASSERT_FALSE(called_cb); 293 294 /* Next window should be focused */ 295 PCUT_ASSERT_EQUALS(w1, seat->focus); 296 297 rc = ds_display_post_kbd_event(disp, &event); 298 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 299 PCUT_ASSERT_FALSE(called_cb); 300 301 /* Focus should be back to the first window */ 302 PCUT_ASSERT_EQUALS(w0, seat->focus); 303 304 ds_window_destroy(w0); 305 ds_window_destroy(w1); 306 ds_client_destroy(client); 307 ds_seat_destroy(seat); 308 ds_display_destroy(disp); 309 } 310 311 /** Test ds_display_post_pos_event() with click on window switches focus 312 */ 313 PCUT_TEST(display_post_pos_event_wnd_switch) 314 { 315 ds_display_t *disp; 316 ds_seat_t *seat; 317 ds_client_t *client; 318 ds_window_t *w0, *w1; 319 pos_event_t event; 320 bool called_cb = false; 321 errno_t rc; 322 323 rc = ds_display_create(NULL, &disp); 324 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 325 326 rc = ds_seat_create(disp, &seat); 327 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 328 329 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client); 330 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 331 332 rc = ds_window_create(client, &w0); 333 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 334 335 rc = ds_window_create(client, &w1); 336 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 337 338 w0->dpos.x = 10; 339 w0->dpos.y = 10; 340 341 w1->dpos.x = 400; 342 w1->dpos.y = 400; 343 344 ds_seat_set_focus(seat, w0); 345 346 event.type = POS_PRESS; 347 event.btn_num = 1; 348 349 PCUT_ASSERT_FALSE(called_cb); 350 351 event.hpos = 400; 352 event.vpos = 400; 353 rc = ds_display_post_pos_event(disp, &event); 354 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 355 PCUT_ASSERT_FALSE(called_cb); 356 357 PCUT_ASSERT_EQUALS(w1, seat->focus); 358 359 event.hpos = 10; 360 event.vpos = 10; 361 rc = ds_display_post_pos_event(disp, &event); 362 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 363 PCUT_ASSERT_FALSE(called_cb); 364 365 PCUT_ASSERT_EQUALS(w0, seat->focus); 366 367 ds_window_destroy(w0); 368 ds_window_destroy(w1); 369 ds_client_destroy(client); 370 ds_seat_destroy(seat); 371 ds_display_destroy(disp); 372 } 373 208 374 PCUT_EXPORT(display);
Note:
See TracChangeset
for help on using the changeset viewer.