Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    r5d1ff11 r68a552f  
    6363typedef struct {
    6464        atomic_flag refcnt;      /**< Connection reference count */
    65         prodcons_t input_pc;  /**< Incoming console events */
     65        prodcons_t input_pc;  /**< Incoming keyboard events */
    6666
    6767        /**
     
    9999static sysarg_t cols;
    100100static 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;
    111101
    112102/** Array of data for virtual consoles */
     
    176166};
    177167
    178 static void pointer_draw(void);
    179 static void pointer_undraw(void);
    180 
    181168static console_t *srv_to_console(con_srv_t *srv)
    182169{
     
    244231
    245232        fibril_mutex_lock(&switch_mtx);
    246         pointer_undraw();
    247233
    248234        if (cons == active_console) {
     
    253239        active_console = cons;
    254240
    255         pointer_draw();
    256241        fibril_mutex_unlock(&switch_mtx);
    257242
    258243        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 with
    280          * 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                 else
    296                         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 Console
    322  * @param ev Console event
    323  */
    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);
    336244}
    337245
     
    356264    keymod_t mods, char32_t c)
    357265{
    358         cons_event_t event;
    359 
    360266        if ((key >= KC_F1) && (key <= KC_F1 + CONSOLE_COUNT) &&
    361267            ((mods & KM_CTRL) == 0)) {
     
    363269        } else {
    364270                /* 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;
    413288}
    414289
    415290static errno_t input_ev_move(input_t *input, int dx, int dy)
    416291{
    417         pointer_update(pointer_x + dx, pointer_y + dy);
    418292        return EOK;
    419293}
     
    422296    unsigned max_x, unsigned max_y)
    423297{
    424         pointer_update(mouse_scale_x * cols * x / max_x, mouse_scale_y * rows * y / max_y);
    425298        return EOK;
    426299}
     
    428301static errno_t input_ev_button(input_t *input, int bnum, int bpress)
    429302{
    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);
    439303        return EOK;
    440304}
     
    446310
    447311        fibril_mutex_lock(&cons->mtx);
    448         pointer_undraw();
    449312
    450313        switch (ch) {
     
    464327        }
    465328
    466         pointer_draw();
    467329        fibril_mutex_unlock(&cons->mtx);
    468330
     
    474336{
    475337        fibril_mutex_lock(&cons->mtx);
    476         pointer_undraw();
    477338        chargrid_set_cursor_visibility(cons->frontbuf, visible);
    478         pointer_draw();
    479339        fibril_mutex_unlock(&cons->mtx);
    480340
     
    519379                if (pos < size) {
    520380                        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);
    523382
    524383                        /* 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 };
    528386                                wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp);
    529387                                cons->char_remains_len = str_size(cons->char_remains);
     
    562420
    563421        fibril_mutex_lock(&cons->mtx);
    564         pointer_undraw();
    565422        chargrid_clear(cons->frontbuf);
    566         pointer_draw();
    567423        fibril_mutex_unlock(&cons->mtx);
    568424
     
    575431
    576432        fibril_mutex_lock(&cons->mtx);
    577         pointer_undraw();
    578433        chargrid_set_cursor(cons->frontbuf, col, row);
    579         pointer_draw();
    580434        fibril_mutex_unlock(&cons->mtx);
    581435
     
    657511        console_t *cons = srv_to_console(srv);
    658512        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);
    663519        return EOK;
    664520}
     
    765621        /* Update front buffer from user buffer */
    766622
    767         pointer_undraw();
    768 
    769623        for (row = r0; row < r1; row++) {
    770624                for (col = c0; col < c1; col++) {
     
    774628        }
    775629
    776         pointer_draw();
    777630        fibril_mutex_unlock(&cons->mtx);
    778631
Note: See TracChangeset for help on using the changeset viewer.