Changeset 4fbdc3d in mainline
- Timestamp:
- 2019-12-11T16:58:30Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4d9c807
- Parents:
- 5bded44
- Location:
- uspace/srv/hid/display
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/display.c
r5bded44 r4fbdc3d 267 267 * @param event Event 268 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; 269 errno_t ds_display_post_ptd_event(ds_display_t *display, ptd_event_t *event) 270 { 273 271 ds_seat_t *seat; 274 272 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; 273 // TODO Determine which seat the event belongs to 274 seat = ds_display_first_seat(display); 275 printf("ds_display_post_ptd_event: seat=%p\n", seat); 276 if (seat == NULL) 277 return EOK; 278 279 return ds_seat_post_ptd_event(seat, event); 293 280 } 294 281 … … 408 395 ddev = ds_display_first_ddev(display); 409 396 if (ddev == NULL) 410 abort();397 return NULL; 411 398 412 399 return ddev->gc; -
uspace/srv/hid/display/display.h
r5bded44 r4fbdc3d 40 40 #include <gfx/context.h> 41 41 #include <io/kbd_event.h> 42 #include <io/pos_event.h>43 42 #include "types/display/client.h" 44 43 #include "types/display/ddev.h" 45 44 #include "types/display/display.h" 45 #include "types/display/ptd_event.h" 46 46 #include "types/display/seat.h" 47 47 … … 59 59 extern ds_window_t *ds_display_next_window(ds_window_t *); 60 60 extern errno_t ds_display_post_kbd_event(ds_display_t *, kbd_event_t *); 61 extern errno_t ds_display_post_p os_event(ds_display_t *, pos_event_t *);61 extern errno_t ds_display_post_ptd_event(ds_display_t *, ptd_event_t *); 62 62 extern void ds_display_add_seat(ds_display_t *, ds_seat_t *); 63 63 extern void ds_display_remove_seat(ds_seat_t *); -
uspace/srv/hid/display/input.c
r5bded44 r4fbdc3d 85 85 static errno_t ds_input_ev_move(input_t *input, int dx, int dy) 86 86 { 87 return EOK; 87 ds_display_t *disp = (ds_display_t *) input->user; 88 ptd_event_t event; 89 90 printf("ds_input_ev_move\n"); 91 event.type = PTD_MOVE; 92 event.dmove.x = dx; 93 event.dmove.y = dy; 94 95 return ds_display_post_ptd_event(disp, &event); 88 96 } 89 97 … … 91 99 unsigned max_x, unsigned max_y) 92 100 { 101 printf("ds_input_ev_abs_move x=%u y=%u mx=%u my=%u\n", 102 x, y, max_x, max_y); 93 103 return EOK; 94 104 } … … 96 106 static errno_t ds_input_ev_button(input_t *input, int bnum, int bpress) 97 107 { 98 return EOK; 108 ds_display_t *disp = (ds_display_t *) input->user; 109 ptd_event_t event; 110 111 printf("ds_input_ev_abs_button\n"); 112 event.type = bpress ? PTD_PRESS : PTD_RELEASE; 113 event.btn_num = bnum; 114 event.dmove.x = 0; 115 event.dmove.y = 0; 116 117 return ds_display_post_ptd_event(disp, &event); 99 118 } 100 119 -
uspace/srv/hid/display/seat.c
r5bded44 r4fbdc3d 36 36 #include <adt/list.h> 37 37 #include <errno.h> 38 #include <gfx/color.h> 39 #include <gfx/render.h> 38 40 #include <stdlib.h> 39 41 #include "client.h" … … 57 59 58 60 ds_display_add_seat(display, seat); 61 seat->pntpos.x = 10; 62 seat->pntpos.y = 10; 59 63 60 64 *rseat = seat; … … 72 76 } 73 77 78 /** Set seat focus to a window. 79 * 80 * @param seat Seat 81 * @param wnd Window to focus 82 */ 74 83 void ds_seat_set_focus(ds_seat_t *seat, ds_window_t *wnd) 75 84 { … … 77 86 } 78 87 88 /** Evacuate focus from window. 89 * 90 * If seat's focus is @a wnd, it will be set to a different window. 91 * 92 * @param seat Seat 93 * @param wnd Window to evacuate focus from 94 */ 79 95 void ds_seat_evac_focus(ds_seat_t *seat, ds_window_t *wnd) 80 96 { … … 119 135 } 120 136 137 /** Draw cross at seat pointer position. 138 * 139 * @param seat Seat 140 * @param len Cross length 141 * @param w Cross extra width 142 * @param br Brightness (0 to 65535) 143 * 144 * @return EOK on success or an error code 145 */ 146 static errno_t ds_seat_draw_cross(ds_seat_t *seat, gfx_coord_t len, 147 gfx_coord_t w, uint16_t br) 148 { 149 gfx_color_t *color = NULL; 150 gfx_context_t *gc; 151 gfx_rect_t rect, r0; 152 errno_t rc; 153 154 gc = ds_display_get_gc(seat->display); 155 if (gc == NULL) 156 return EOK; 157 158 rc = gfx_color_new_rgb_i16(br, br, br, &color); 159 if (rc != EOK) 160 goto error; 161 162 rc = gfx_set_color(gc, color); 163 if (rc != EOK) 164 goto error; 165 166 r0.p0.x = -len; 167 r0.p0.y = -w; 168 r0.p1.x = +len + 1; 169 r0.p1.y = +w + 1; 170 gfx_rect_translate(&seat->pntpos, &r0, &rect); 171 172 rc = gfx_fill_rect(gc, &rect); 173 if (rc != EOK) 174 goto error; 175 176 r0.p0.x = -w; 177 r0.p0.y = -len; 178 r0.p1.x = +w + 1; 179 r0.p1.y = +len + 1; 180 gfx_rect_translate(&seat->pntpos, &r0, &rect); 181 182 rc = gfx_fill_rect(gc, &rect); 183 if (rc != EOK) 184 goto error; 185 186 gfx_color_delete(color); 187 return EOK; 188 error: 189 if (color != NULL) 190 gfx_color_delete(color); 191 return rc; 192 } 193 194 /** Draw or clear seat pointer 195 * 196 * @param seat Seat 197 * @param shown @c true to display pointer, @c false to clear it 198 * 199 * @return EOK on success or an error code 200 */ 201 static errno_t ds_seat_draw_pointer(ds_seat_t *seat, bool shown) 202 { 203 errno_t rc; 204 205 rc = ds_seat_draw_cross(seat, 8, 1, 0); 206 if (rc != EOK) 207 return rc; 208 209 rc = ds_seat_draw_cross(seat, 8, 0, shown ? 65535 : 0); 210 if (rc != EOK) 211 return rc; 212 213 return EOK; 214 } 215 216 /** Post pointing device event to the seat 217 * 218 * @param seat Seat 219 * @param event Event 220 * 221 * @return EOK on success or an error code 222 */ 223 #include <stdio.h> 224 errno_t ds_seat_post_ptd_event(ds_seat_t *seat, ptd_event_t *event) 225 { 226 ds_window_t *wnd; 227 gfx_coord2_t npos; 228 229 printf("ds_seat_post_ptd_event\n"); 230 /* Focus window on button press */ 231 if (event->type == PTD_PRESS) { 232 printf("PTD_PRESS\n"); 233 wnd = ds_display_window_by_pos(seat->display, &seat->pntpos); 234 if (wnd != NULL) { 235 printf("set focus\n"); 236 ds_seat_set_focus(seat, wnd); 237 return EOK; 238 } 239 } 240 241 if (event->type == PTD_MOVE) { 242 printf("PTD_MOVE\n"); 243 gfx_coord2_add(&seat->pntpos, &event->dmove, &npos); 244 if (npos.x < 10) 245 npos.x = 10; 246 if (npos.y < 10) 247 npos.y = 10; 248 if (npos.x > 1024 - 10) 249 npos.x = 1024 - 10; 250 if (npos.y > 768 - 10) 251 npos.y = 768 - 10; 252 253 printf("clear pointer\n"); 254 (void) ds_seat_draw_pointer(seat, false); 255 seat->pntpos = npos; 256 printf("draw pointer\n"); 257 (void) ds_seat_draw_pointer(seat, true); 258 } 259 260 return EOK; 261 } 262 121 263 /** @} 122 264 */ -
uspace/srv/hid/display/seat.h
r5bded44 r4fbdc3d 41 41 #include "types/display/display.h" 42 42 #include "types/display/seat.h" 43 #include "types/display/ptd_event.h" 43 44 #include "types/display/window.h" 44 45 … … 48 49 extern void ds_seat_evac_focus(ds_seat_t *, ds_window_t *); 49 50 extern errno_t ds_seat_post_kbd_event(ds_seat_t *, kbd_event_t *); 51 extern errno_t ds_seat_post_ptd_event(ds_seat_t *, ptd_event_t *); 50 52 51 53 #endif -
uspace/srv/hid/display/test/display.c
r5bded44 r4fbdc3d 309 309 } 310 310 311 /** Test ds_display_post_p os_event() with click on window switches focus311 /** Test ds_display_post_ptd_event() with click on window switches focus 312 312 */ 313 PCUT_TEST(display_post_p os_event_wnd_switch)313 PCUT_TEST(display_post_ptd_event_wnd_switch) 314 314 { 315 315 ds_display_t *disp; … … 317 317 ds_client_t *client; 318 318 ds_window_t *w0, *w1; 319 p os_event_t event;319 ptd_event_t event; 320 320 bool called_cb = false; 321 321 errno_t rc; … … 342 342 w1->dpos.y = 400; 343 343 344 PCUT_ASSERT_FALSE(called_cb); 345 344 346 ds_seat_set_focus(seat, w0); 345 347 346 event.type = POS_PRESS; 348 event.type = PTD_MOVE; 349 event.dmove.x = 400; 350 event.dmove.y = 400; 351 rc = ds_display_post_ptd_event(disp, &event); 352 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 353 PCUT_ASSERT_FALSE(called_cb); 354 355 event.type = PTD_PRESS; 347 356 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); 357 rc = ds_display_post_ptd_event(disp, &event); 354 358 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 355 359 PCUT_ASSERT_FALSE(called_cb); … … 357 361 PCUT_ASSERT_EQUALS(w1, seat->focus); 358 362 359 event.hpos = 10; 360 event.vpos = 10; 361 rc = ds_display_post_pos_event(disp, &event); 363 event.type = PTD_MOVE; 364 event.dmove.x = -400; 365 event.dmove.y = -400; 366 rc = ds_display_post_ptd_event(disp, &event); 367 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 368 PCUT_ASSERT_FALSE(called_cb); 369 370 event.type = PTD_PRESS; 371 event.btn_num = 1; 372 rc = ds_display_post_ptd_event(disp, &event); 362 373 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 363 374 PCUT_ASSERT_FALSE(called_cb); -
uspace/srv/hid/display/types/display/seat.h
r5bded44 r4fbdc3d 38 38 39 39 #include <adt/list.h> 40 #include <gfx/coord.h> 40 41 41 42 /** Display server seat */ … … 47 48 /** Window this seat is focused on */ 48 49 struct ds_window *focus; 50 /** Pointer position */ 51 gfx_coord2_t pntpos; 49 52 } ds_seat_t; 50 53
Note:
See TracChangeset
for help on using the changeset viewer.