]> Zhao Yanbai Git Server - minix.git/commitdiff
Added possibility to inject input events to tty
authorDirk Vogt <dirk@minix3.org>
Wed, 17 Nov 2010 14:53:07 +0000 (14:53 +0000)
committerDirk Vogt <dirk@minix3.org>
Wed, 17 Nov 2010 14:53:07 +0000 (14:53 +0000)
M    include/Makefile
A    include/minix/input.h
M    include/minix/com.h
M    drivers/tty/keyboard.c
M    drivers/tty/tty.c
M    drivers/tty/tty.h
M    include/minix/syslib.h
M    lib/libsys/Makefile
A    lib/libsys/input.c

drivers/tty/keyboard.c
drivers/tty/tty.c
drivers/tty/tty.h
include/Makefile
include/minix/com.h
include/minix/input.h [new file with mode: 0644]
include/minix/syslib.h
lib/libsys/Makefile
lib/libsys/input.c [new file with mode: 0644]

index 5c039203ad20de3ae588e721f8712c5a76b7f585..9b9d9e4112416fa14e2af16b61706065a339b414 100644 (file)
@@ -17,6 +17,7 @@
 #include <machine/archtypes.h>
 #include <minix/callnr.h>
 #include <minix/com.h>
+#include <minix/input.h>
 #include <minix/keymap.h>
 #include "tty.h"
 #include "kernel/const.h"
@@ -74,6 +75,12 @@ PRIVATE int aux_irq_hook_id = -1;
 
 #define CONSOLE                   0    /* line number for console */
 #define KB_IN_BYTES      32    /* size of keyboard input buffer */
+
+PRIVATE char injbuf[KB_IN_BYTES];
+PRIVATE char *injhead = injbuf;
+PRIVATE char *injtail = injbuf;
+PRIVATE int injcount;
+
 PRIVATE char ibuf[KB_IN_BYTES];        /* input buffer */
 PRIVATE char *ihead = ibuf;    /* next free spot in input buffer */
 PRIVATE char *itail = ibuf;    /* scan code to return to TTY */
@@ -558,6 +565,31 @@ message *m_ptr;
   }
 }
 
+
+PUBLIC void do_kb_inject(message *msg)
+{
+       unsigned char scode;
+       /* only handle keyboard events */
+       if (msg->INPUT_TYPE == INPUT_EV_KEY) {
+               scode = msg->INPUT_CODE;
+               
+               /* is it a KEY RELEASE? */
+               if (msg->INPUT_VALUE == 0) {
+                       scode |= KEY_RELEASE;   
+               }
+
+               if (injcount < KB_IN_BYTES) {
+                       *injhead++ = scode;
+                       if (injhead == injbuf + KB_IN_BYTES) injhead = injbuf;
+                       injcount++;
+                       tty_table[ccurrent].tty_events = 1;
+                       if (tty_table[ccurrent].tty_select_ops & SEL_RD) {
+                               select_retry(&tty_table[ccurrent]);
+                       }
+               }
+       }
+}
+
 /*===========================================================================*
  *                             kb_read                                      *
  *===========================================================================*/
@@ -569,23 +601,33 @@ int try;
   char buf[7], *p, suffix;
   int scode;
   unsigned ch;
-
-  tp = &tty_table[ccurrent];           /* always use the current console */
+  
+  /* always use the current console */
+  tp = &tty_table[ccurrent];
 
   if (try) {
        if (icount > 0) return 1;
        return 0;
   }
 
-  while (icount > 0) {
-       scode = *itail++;                       /* take one key scan code */
-       if (itail == ibuf + KB_IN_BYTES) itail = ibuf;
-       icount--;
+  while (icount > 0 || injcount > 0) {
+         if (injcount > 0) { 
+                 /* take one key scan code */
+                 scode = *injtail++;
+                 if (injtail == injbuf + KB_IN_BYTES) injtail = injbuf;
+                 injcount--;
+         } else {
+                 /* take one key scan code */
+                 scode = *itail++;                     
+                 if (itail == ibuf + KB_IN_BYTES) itail = ibuf;
+                 icount--;
+         }
 
        /* Function keys are being used for debug dumps (if enabled). */
        if (debug_fkeys && func_key(scode)) continue;
 
        /* Perform make/break processing. */
+
        ch = make_break(scode);
 
        if (ch <= 0xFF) {
index 6f3b6d9bbd1f0a08bf62ee3055ae8b5a7b66dfde..3a44d3571defa69b3f5b096347ec4a592a9c2b48 100644 (file)
@@ -232,6 +232,9 @@ PUBLIC int main(void)
        case FKEY_CONTROL:              /* (un)register a fkey observer */
                do_fkey_ctl(&tty_mess);
                continue;
+       case INPUT_EVENT:
+               do_kb_inject(&tty_mess);
+               continue;
        default:                        /* should be a driver request */
                ;                       /* do nothing; end switch */
        }
index ff9329ffad54a974ad93eb7a1228530ae7044e86..5a04570b245bd7e5bd448a2c42b2df66f56b651d 100644 (file)
@@ -180,6 +180,7 @@ _PROTOTYPE( int kbd_loadmap, (message *m, int safe)                 );
 _PROTOTYPE( void do_fkey_ctl, (message *m)                             );
 _PROTOTYPE( void kbd_interrupt, (message *m)                           );
 _PROTOTYPE( void do_kbd, (message *m)                                  );
+_PROTOTYPE( void do_kb_inject, (message *m)             );
 _PROTOTYPE( void do_kbdaux, (message *m)                               );
 _PROTOTYPE( int kbd_status, (message *m_ptr)                           );
 
index 37a8ca72b975261e169b9903a2d58a801c8660bf..4741da49733c65905667d421eeed31ee3280528d 100644 (file)
@@ -29,7 +29,7 @@ INCS+=        minix/a.out.h minix/bitmap.h minix/callnr.h minix/cdrom.h \
        minix/sysutil.h minix/timers.h minix/tty.h minix/type.h minix/types.h \
        minix/u64.h minix/vfsif.h minix/vm.h minix/vtreefs.h minix/gcov.h  \
        minix/compiler.h minix/compiler-ack.h minix/sha2.h minix/sha1.h minix/md5.h \
-       minix/audio_fw.h minix/hash.h
+       minix/audio_fw.h minix/hash.h minix/input.h
 INCS+= net/hton.h net/if.h net/ioctl.h net/netlib.h
 INCS+= net/gen/arp_io.h net/gen/dhcp.h net/gen/ether.h \
        net/gen/eth_hdr.h net/gen/eth_io.h net/gen/icmp.h \
index dc3d48a0003c3e7a9d7f79877f7516ac34c1bee7..756f73a67f08164813f1edb6e1731dc8d63b90af 100644 (file)
@@ -22,6 +22,7 @@
  *    0xE00 -  0xEFF   Common system messages (e.g. system signals)
  *    0xF00 -  0xFFF    Scheduling messages
  *   0x1000 - 0x10FF   Notify messages
+ *   0x1300 - 0x13FF    TTY Input
  *
  * Zero and negative values are widely used for OK and error responses.
  */
 /* SCHEDULING_INHERIT is like SCHEDULING_START, but without _QUANTUM field */
 #define SCHEDULING_INHERIT     (SCHEDULING_BASE+5)
 
+/*===========================================================================*
+ *              TTY INPUT INJECTION                                          *
+ *===========================================================================*/
+
+#define INPUT_BASE 0x1300
+
+#define INPUT_EVENT      (INPUT_BASE + 0)
+
+#      define INPUT_TYPE        m4_l1
+#      define INPUT_CODE        m4_l2
+#      define INPUT_VALUE       m4_l3
+
 #endif
 
 /* _MINIX_COM_H */
diff --git a/include/minix/input.h b/include/minix/input.h
new file mode 100644 (file)
index 0000000..65d3ed5
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _MINIX_INPUT_H
+#define _MINIX_INPUT_H
+
+#define INPUT_EV_KEY 0x1
+#define INPUT_EV_REL 0x2
+#define INPUT_EV_ABS 0x3
+
+#endif
index f47d82b7e39a14cfde3029bc5ca57d46c8a45b1d..3353d3401e6d0d8d219fb0763679b605bad57d74 100644 (file)
@@ -268,5 +268,8 @@ _PROTOTYPE( int sys_profbuf, (void *ctl_ptr, void *mem_ptr)            );
 _PROTOTYPE( int sys_getmcontext, (endpoint_t proc, mcontext_t *mcp)    );
 _PROTOTYPE( int sys_setmcontext, (endpoint_t proc, mcontext_t *mcp)    );
 
+/* input */
+_PROTOTYPE( int tty_input_inject, (int type, int code, int val) );
+
 #endif /* _SYSLIB_H */
 
index f2475d135033079696c4de7a9276d2f198f7811e..0d8413b986038f6c3fa4ab42dd65ae8861b2c45e 100644 (file)
@@ -5,8 +5,24 @@ LIB=           sys
 SRCS=  \
        alloc_util.c \
        assert.c \
+       asynsend.c \
+       ds.c    \
+       env_get_prm.c \
+       env_panic.c \
+       env_parse.c \
+       env_prefix.c \
+       fkey_ctl.c \
+       gcov.c \
+       get_randomness.c \
+       getidle.c \
        getsysinfo.c \
+       getuptime.c \
+       getuptime2.c \
+       input.c \
        kernel_call.c \
+       kprintf.c \
+       kputc.c \
+       kputs.c \
        panic.c \
        pci_attr_r16.c \
        pci_attr_r32.c \
@@ -27,6 +43,8 @@ SRCS=  \
        pci_reserve.c \
        pci_set_acl.c \
        pci_slot_name.c \
+       profile.c \
+       profile_extern.c \
        safecopies.c \
        sched_start.c \
        sched_stop.c \
@@ -36,9 +54,11 @@ SRCS=  \
        sef_liveupdate.c \
        sef_ping.c \
        sef_signal.c \
+       ser_putc.c \
+       spin.c \
+       stacktrace.c \
        sys_abort.c \
        sys_clear.c \
-       sys_mcontext.c \
        sys_cprof.c \
        sys_endsig.c \
        sys_eniop.c \
@@ -47,37 +67,38 @@ SRCS=  \
        sys_fork.c \
        sys_getinfo.c \
        sys_getsig.c \
+       sys_hz.c \
        sys_in.c \
        sys_int86.c \
        sys_irqctl.c \
        sys_kill.c \
+       sys_mcontext.c \
        sys_memset.c \
        sys_newmap.c \
        sys_out.c \
        sys_physcopy.c \
+       sys_privctl.c \
+       sys_profbuf.c \
        sys_readbios.c \
        sys_runctl.c \
-       sys_update.c \
        sys_safecopy.c \
        sys_safemap.c \
-       sys_sysctl.c \
-       sys_vsafecopy.c \
-       sys_profbuf.c \
+       sys_schedctl.c \
+       sys_schedule.c \
        sys_sdevio.c \
        sys_segctl.c \
        sys_setalarm.c \
+       sys_setgrant.c \
        sys_sigreturn.c \
        sys_sigsend.c \
-       sys_privctl.c \
-       sys_setgrant.c \
        sys_sprof.c \
+       sys_statectl.c \
        sys_stime.c \
-        sys_schedule.c \
-        sys_schedctl.c \
-        sys_statectl.c \
+       sys_sysctl.c \
        sys_times.c \
        sys_trace.c \
        sys_umap.c \
+       sys_update.c \
        sys_vinb.c \
        sys_vinl.c \
        sys_vinw.c \
@@ -86,44 +107,24 @@ SRCS=  \
        sys_voutb.c \
        sys_voutl.c \
        sys_voutw.c \
+       sys_vsafecopy.c \
        sys_vtimer.c \
        taskcall.c \
-       ds.c    \
+       tickdelay.c \
+       timers.c \
+       timing.c \
+       tsc_util.c \
        vm_brk.c \
        vm_exec_newmem.c \
        vm_exit.c \
-       vm_notify_sig.c \
        vm_fork.c \
        vm_info.c \
        vm_map_phys.c \
-       vm_umap.c \
+       vm_notify_sig.c \
        vm_push_sig.c \
+       vm_umap.c \
        vm_yield_get_block.c \
-       asynsend.c \
-       kprintf.c \
-       kputc.c \
-       kputs.c \
-       tickdelay.c \
-       get_randomness.c \
-       getidle.c \
-       getuptime.c \
-       getuptime2.c \
-       env_get_prm.c \
-       env_parse.c \
-       env_panic.c \
-       env_prefix.c \
-       fkey_ctl.c \
-       tsc_util.c \
-       ser_putc.c \
-       stacktrace.c \
-       sys_hz.c \
-       timing.c \
-       profile_extern.c \
-       profile.c \
        vprintf.c \
-       timers.c \
-       spin.c \
-       gcov.c
 
 CPPFLAGS.sched_start.c+=       -I${MINIXSRCDIR}
 
diff --git a/lib/libsys/input.c b/lib/libsys/input.c
new file mode 100644 (file)
index 0000000..6143d24
--- /dev/null
@@ -0,0 +1,17 @@
+#include "syslib.h"
+#include <minix/sysutil.h>
+/*****************************************************************************
+ *             tty_inject_event                                              *
+ *****************************************************************************/
+PUBLIC int tty_inject_event(type, code, val)
+int type;
+int code;
+int val;
+{
+       message msg;
+       msg.INPUT_TYPE  = type;
+       msg.INPUT_CODE  = code;
+       msg.INPUT_VALUE = val;
+
+       return send(TTY_PROC_NR, &msg);
+}