Changeset a58bc8b in mainline for uspace/srv/hid/console/console.c


Ignore:
Timestamp:
2012-05-24T14:22:21Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a33706e
Parents:
67435b1
Message:

Console does not send special keys on its VFS interface

Also, multi-byte characters are correctly splitted and their
remainder is sent during next request.

File:
1 edited

Legend:

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

    r67435b1 ra58bc8b  
    7676} console_state_t;
    7777
     78#define UTF8_CHAR_BUFFER_SIZE (STR_BOUNDS(1) + 1)
     79
    7880typedef struct {
    7981        atomic_t refcnt;           /**< Connection reference count */
    8082        prodcons_t input_pc;       /**< Incoming keyboard events */
     83        char char_remains[UTF8_CHAR_BUFFER_SIZE]; /**< Not yet sent bytes of last char event. */
     84        size_t char_remains_len;   /**< Number of not yet sent bytes. */
    8185       
    8286        fibril_mutex_t mtx;        /**< Lock protecting mutable fields */
     
    613617       
    614618        size_t pos = 0;
     619
     620        /*
     621         * Read input from keyboard and copy it to the buffer.
     622         * We need to handle situation when wchar is split by 2 following
     623         * reads.
     624         */
    615625        while (pos < size) {
    616                 link_t *link = prodcons_consume(&cons->input_pc);
    617                 kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
    618                
    619                 if (event->type == KEY_PRESS) {
    620                         buf[pos] = event->c;
     626                /* Copy to the buffer remaining characters. */
     627                while ((pos < size) && (cons->char_remains_len > 0)) {
     628                        buf[pos] = cons->char_remains[0];
    621629                        pos++;
    622                 }
    623                
    624                 free(event);
     630                        /* Unshift the array. */
     631                        for (size_t i = 1; i < cons->char_remains_len; i++) {
     632                                cons->char_remains[i - 1] = cons->char_remains[i];
     633                        }
     634                        cons->char_remains_len--;
     635                }
     636                /* Still not enough? Then get another key from the queue. */
     637                if (pos < size) {
     638                        link_t *link = prodcons_consume(&cons->input_pc);
     639                        kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
     640
     641                        /* Accept key presses of printable chars only. */
     642                        if ((event->type == KEY_PRESS) && (event->c != 0)) {
     643                                wchar_t tmp[2] = { event->c, 0 };
     644                                wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp);
     645                                cons->char_remains_len = str_size(cons->char_remains);
     646                        }
     647
     648                        free(event);
     649                }
    625650        }
    626651       
     
    930955                fibril_mutex_initialize(&consoles[i].mtx);
    931956                prodcons_initialize(&consoles[i].input_pc);
     957                consoles[i].char_remains_len = 0;
    932958               
    933959                if (graphics_state == GRAPHICS_FULL) {
Note: See TracChangeset for help on using the changeset viewer.