Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/clui/tinput.c

    ra2bdcf87 r6d5e378  
    4040#include <errno.h>
    4141#include <assert.h>
    42 #include <stdbool.h>
     42#include <bool.h>
    4343#include <tinput.h>
    4444
    4545#define LIN_TO_COL(ti, lpos) ((lpos) % ((ti)->con_cols))
    4646#define LIN_TO_ROW(ti, lpos) ((lpos) / ((ti)->con_cols))
    47 #define LIN_POS(ti, col, row) ((col) + (row) * (ti)->con_cols)
    4847
    4948/** Seek direction */
     
    105104static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad)
    106105{
    107         wchar_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(wchar_t));
    108         if (!dbuf)
    109                 return;
     106        wchar_t dbuf[INPUT_MAX_SIZE + 1];
    110107       
    111108        size_t sa;
     
    149146       
    150147        console_flush(ti->console);
    151 
    152         free(dbuf);
    153148}
    154149
     
    381376        }
    382377       
    383         tinput_post_seek(ti, shift_held);
    384 }
    385 
    386 static void tinput_seek_scrpos(tinput_t *ti, int col, int line, bool shift_held)
    387 {
    388         unsigned lpos;
    389         tinput_pre_seek(ti, shift_held);
    390 
    391         lpos = LIN_POS(ti, col, line);
    392 
    393         if (lpos > ti->text_coord)
    394                 ti->pos = lpos -  ti->text_coord;
    395         else
    396                 ti->pos = 0;
    397         if (ti->pos > ti->nc)
    398                 ti->pos = ti->nc;
    399 
    400378        tinput_post_seek(ti, shift_held);
    401379}
     
    805783}
    806784
    807 /** Handle key press event. */
    808 static void tinput_key_press(tinput_t *ti, kbd_event_t *kev)
    809 {
    810         if (kev->key == KC_LSHIFT)
    811                 ti->lshift_held = true;
    812         if (kev->key == KC_RSHIFT)
    813                 ti->rshift_held = true;
    814 
    815         if (((kev->mods & KM_CTRL) != 0) &&
    816             ((kev->mods & (KM_ALT | KM_SHIFT)) == 0))
    817                 tinput_key_ctrl(ti, kev);
    818        
    819         if (((kev->mods & KM_SHIFT) != 0) &&
    820             ((kev->mods & (KM_CTRL | KM_ALT)) == 0))
    821                 tinput_key_shift(ti, kev);
    822        
    823         if (((kev->mods & KM_CTRL) != 0) &&
    824             ((kev->mods & KM_SHIFT) != 0) &&
    825             ((kev->mods & KM_ALT) == 0))
    826                 tinput_key_ctrl_shift(ti, kev);
    827        
    828         if ((kev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)
    829                 tinput_key_unmod(ti, kev);
    830        
    831         if (kev->c >= ' ') {
    832                 tinput_sel_delete(ti);
    833                 tinput_insert_char(ti, kev->c);
    834         }
    835 }
    836 
    837 /** Handle key release event. */
    838 static void tinput_key_release(tinput_t *ti, kbd_event_t *kev)
    839 {
    840         if (kev->key == KC_LSHIFT)
    841                 ti->lshift_held = false;
    842         if (kev->key == KC_RSHIFT)
    843                 ti->rshift_held = false;
    844 }
    845 
    846 /** Position event */
    847 static void tinput_pos(tinput_t *ti, pos_event_t *ev)
    848 {
    849         if (ev->type == POS_PRESS) {
    850                 tinput_seek_scrpos(ti, ev->hpos, ev->vpos,
    851                     ti->lshift_held || ti->rshift_held);
    852         }
    853 }
    854 
    855785/** Read in one line of input.
    856786 *
     
    882812                console_flush(ti->console);
    883813               
    884                 cons_event_t ev;
    885                 if (!console_get_event(ti->console, &ev))
     814                kbd_event_t ev;
     815                if (!console_get_kbd_event(ti->console, &ev))
    886816                        return EIO;
    887817               
    888                 switch (ev.type) {
    889                 case CEV_KEY:
    890                         if (ev.ev.key.type == KEY_PRESS)
    891                                 tinput_key_press(ti, &ev.ev.key);
    892                         else
    893                                 tinput_key_release(ti, &ev.ev.key);
    894                         break;
    895                 case CEV_POS:
    896                         tinput_pos(ti, &ev.ev.pos);
    897                         break;
     818                if (ev.type != KEY_PRESS)
     819                        continue;
     820               
     821                if (((ev.mods & KM_CTRL) != 0) &&
     822                    ((ev.mods & (KM_ALT | KM_SHIFT)) == 0))
     823                        tinput_key_ctrl(ti, &ev);
     824               
     825                if (((ev.mods & KM_SHIFT) != 0) &&
     826                    ((ev.mods & (KM_CTRL | KM_ALT)) == 0))
     827                        tinput_key_shift(ti, &ev);
     828               
     829                if (((ev.mods & KM_CTRL) != 0) &&
     830                    ((ev.mods & KM_SHIFT) != 0) &&
     831                    ((ev.mods & KM_ALT) == 0))
     832                        tinput_key_ctrl_shift(ti, &ev);
     833               
     834                if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)
     835                        tinput_key_unmod(ti, &ev);
     836               
     837                if (ev.c >= ' ') {
     838                        tinput_sel_delete(ti);
     839                        tinput_insert_char(ti, ev.c);
    898840                }
    899841        }
Note: See TracChangeset for help on using the changeset viewer.