Changes in uspace/srv/hid/console/console.c [5d1ff11:68a552f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r5d1ff11 r68a552f 63 63 typedef struct { 64 64 atomic_flag refcnt; /**< Connection reference count */ 65 prodcons_t input_pc; /**< Incoming consoleevents */65 prodcons_t input_pc; /**< Incoming keyboard events */ 66 66 67 67 /** … … 99 99 static sysarg_t cols; 100 100 static sysarg_t rows; 101 102 /** Mouse pointer X coordinate */103 static int pointer_x;104 /** Mouse pointer Y coordinate */105 static int pointer_y;106 /** Character under mouse cursor */107 static charfield_t pointer_bg;108 109 static int mouse_scale_x = 4;110 static int mouse_scale_y = 8;111 101 112 102 /** Array of data for virtual consoles */ … … 176 166 }; 177 167 178 static void pointer_draw(void);179 static void pointer_undraw(void);180 181 168 static console_t *srv_to_console(con_srv_t *srv) 182 169 { … … 244 231 245 232 fibril_mutex_lock(&switch_mtx); 246 pointer_undraw();247 233 248 234 if (cons == active_console) { … … 253 239 active_console = cons; 254 240 255 pointer_draw();256 241 fibril_mutex_unlock(&switch_mtx); 257 242 258 243 cons_damage(cons); 259 }260 261 /** Draw mouse pointer. */262 static void pointer_draw(void)263 {264 charfield_t *ch;265 int col, row;266 267 /* Downscale coordinates to text resolution */268 col = pointer_x / mouse_scale_x;269 row = pointer_y / mouse_scale_y;270 271 /* Make sure they are in range */272 if (col < 0 || row < 0 || col >= (int)cols || row >= (int)rows)273 return;274 275 ch = chargrid_charfield_at(active_console->frontbuf, col, row);276 277 /*278 * Store background attributes for undrawing the pointer.279 * This is necessary as styles cannot be inverted with280 * round trip (unlike RGB or INDEX)281 */282 pointer_bg = *ch;283 284 /* In general the color should be a one's complement of the background */285 if (ch->attrs.type == CHAR_ATTR_INDEX) {286 ch->attrs.val.index.bgcolor ^= 0xf;287 ch->attrs.val.index.fgcolor ^= 0xf;288 } else if (ch->attrs.type == CHAR_ATTR_RGB) {289 ch->attrs.val.rgb.fgcolor ^= 0xffffff;290 ch->attrs.val.rgb.bgcolor ^= 0xffffff;291 } else if (ch->attrs.type == CHAR_ATTR_STYLE) {292 /* Don't have a proper inverse for each style */293 if (ch->attrs.val.style == STYLE_INVERTED)294 ch->attrs.val.style = STYLE_NORMAL;295 else296 ch->attrs.val.style = STYLE_INVERTED;297 }298 299 /* Make sure the cell gets updated */300 ch->flags |= CHAR_FLAG_DIRTY;301 }302 303 /** Undraw mouse pointer. */304 static void pointer_undraw(void)305 {306 charfield_t *ch;307 int col, row;308 309 col = pointer_x / mouse_scale_x;310 row = pointer_y / mouse_scale_y;311 if (col < 0 || row < 0 || col >= (int)cols || row >= (int)rows)312 return;313 314 ch = chargrid_charfield_at(active_console->frontbuf, col, row);315 *ch = pointer_bg;316 ch->flags |= CHAR_FLAG_DIRTY;317 }318 319 /** Queue console event.320 *321 * @param cons Console322 * @param ev Console event323 */324 static void console_queue_cons_event(console_t *cons, cons_event_t *ev)325 {326 /* Got key press/release event */327 cons_event_t *event =328 (cons_event_t *) malloc(sizeof(cons_event_t));329 if (event == NULL)330 return;331 332 *event = *ev;333 link_initialize(&event->link);334 335 prodcons_produce(&cons->input_pc, &event->link);336 244 } 337 245 … … 356 264 keymod_t mods, char32_t c) 357 265 { 358 cons_event_t event;359 360 266 if ((key >= KC_F1) && (key <= KC_F1 + CONSOLE_COUNT) && 361 267 ((mods & KM_CTRL) == 0)) { … … 363 269 } else { 364 270 /* Got key press/release event */ 365 event.type = CEV_KEY; 366 367 event.ev.key.type = type; 368 event.ev.key.key = key; 369 event.ev.key.mods = mods; 370 event.ev.key.c = c; 371 372 console_queue_cons_event(active_console, &event); 373 } 374 375 return EOK; 376 } 377 378 /** Update pointer position. 379 * 380 * @param new_x New X coordinate (in pixels) 381 * @param new_y New Y coordinate (in pixels) 382 */ 383 static void pointer_update(int new_x, int new_y) 384 { 385 bool upd_pointer; 386 387 /* Make sure coordinates are in range */ 388 389 if (new_x < 0) 390 new_x = 0; 391 if (new_x >= (int)cols * mouse_scale_x) 392 new_x = cols * mouse_scale_x - 1; 393 if (new_y < 0) 394 new_y = 0; 395 if (new_y >= (int)rows * mouse_scale_y) 396 new_y = rows * mouse_scale_y - 1; 397 398 /* Determine if pointer moved to a different character cell */ 399 upd_pointer = (new_x / mouse_scale_x != pointer_x / mouse_scale_x) || 400 (new_y / mouse_scale_y != pointer_y / mouse_scale_y); 401 402 if (upd_pointer) 403 pointer_undraw(); 404 405 /* Store new pointer position */ 406 pointer_x = new_x; 407 pointer_y = new_y; 408 409 if (upd_pointer) { 410 pointer_draw(); 411 cons_update(active_console); 412 } 271 kbd_event_t *event = 272 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 273 if (event == NULL) { 274 return ENOMEM; 275 } 276 277 link_initialize(&event->link); 278 event->type = type; 279 event->key = key; 280 event->mods = mods; 281 event->c = c; 282 283 prodcons_produce(&active_console->input_pc, 284 &event->link); 285 } 286 287 return EOK; 413 288 } 414 289 415 290 static errno_t input_ev_move(input_t *input, int dx, int dy) 416 291 { 417 pointer_update(pointer_x + dx, pointer_y + dy);418 292 return EOK; 419 293 } … … 422 296 unsigned max_x, unsigned max_y) 423 297 { 424 pointer_update(mouse_scale_x * cols * x / max_x, mouse_scale_y * rows * y / max_y);425 298 return EOK; 426 299 } … … 428 301 static errno_t input_ev_button(input_t *input, int bnum, int bpress) 429 302 { 430 cons_event_t event;431 432 event.type = CEV_POS;433 event.ev.pos.type = bpress ? POS_PRESS : POS_RELEASE;434 event.ev.pos.btn_num = bnum;435 event.ev.pos.hpos = pointer_x / mouse_scale_x;436 event.ev.pos.vpos = pointer_y / mouse_scale_y;437 438 console_queue_cons_event(active_console, &event);439 303 return EOK; 440 304 } … … 446 310 447 311 fibril_mutex_lock(&cons->mtx); 448 pointer_undraw();449 312 450 313 switch (ch) { … … 464 327 } 465 328 466 pointer_draw();467 329 fibril_mutex_unlock(&cons->mtx); 468 330 … … 474 336 { 475 337 fibril_mutex_lock(&cons->mtx); 476 pointer_undraw();477 338 chargrid_set_cursor_visibility(cons->frontbuf, visible); 478 pointer_draw();479 339 fibril_mutex_unlock(&cons->mtx); 480 340 … … 519 379 if (pos < size) { 520 380 link_t *link = prodcons_consume(&cons->input_pc); 521 cons_event_t *event = list_get_instance(link, 522 cons_event_t, link); 381 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 523 382 524 383 /* Accept key presses of printable chars only. */ 525 if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS && 526 (event->ev.key.c != 0)) { 527 char32_t tmp[2] = { event->ev.key.c, 0 }; 384 if ((event->type == KEY_PRESS) && (event->c != 0)) { 385 char32_t tmp[2] = { event->c, 0 }; 528 386 wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp); 529 387 cons->char_remains_len = str_size(cons->char_remains); … … 562 420 563 421 fibril_mutex_lock(&cons->mtx); 564 pointer_undraw();565 422 chargrid_clear(cons->frontbuf); 566 pointer_draw();567 423 fibril_mutex_unlock(&cons->mtx); 568 424 … … 575 431 576 432 fibril_mutex_lock(&cons->mtx); 577 pointer_undraw();578 433 chargrid_set_cursor(cons->frontbuf, col, row); 579 pointer_draw();580 434 fibril_mutex_unlock(&cons->mtx); 581 435 … … 657 511 console_t *cons = srv_to_console(srv); 658 512 link_t *link = prodcons_consume(&cons->input_pc); 659 cons_event_t *cevent = list_get_instance(link, cons_event_t, link); 660 661 *event = *cevent; 662 free(cevent); 513 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 514 515 event->type = CEV_KEY; 516 event->ev.key = *kevent; 517 518 free(kevent); 663 519 return EOK; 664 520 } … … 765 621 /* Update front buffer from user buffer */ 766 622 767 pointer_undraw();768 769 623 for (row = r0; row < r1; row++) { 770 624 for (col = c0; col < c1; col++) { … … 774 628 } 775 629 776 pointer_draw();777 630 fibril_mutex_unlock(&cons->mtx); 778 631
Note:
See TracChangeset
for help on using the changeset viewer.