00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <l4/l4con/l4con.h>
00016 #include <l4/log/l4log.h>
00017 #include <l4/thread/thread.h>
00018 #include <l4/util/thread.h>
00019 #include <l4/util/l4_macros.h>
00020 #include <l4/input/libinput.h>
00021
00022 #include "stream-client.h"
00023
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026
00027 #include "config.h"
00028 #include "ev.h"
00029 #include "main.h"
00030 #include "vc.h"
00031
00032 int nomouse;
00033 int noshift;
00034
00035 static void
00036 send_event_client(struct l4input *ev)
00037 {
00038 int loop, resend;
00039 stream_io_input_event_t stream_event = { .type = ev->type,
00040 .code = ev->code,
00041 .value = ev->value };
00042
00043 for (loop=0, resend=1; resend && loop<10; loop++)
00044 {
00045 CORBA_Environment env = dice_default_environment;
00046
00047 l4lock_lock(&want_vc_lock);
00048 if ((vc_mode & CON_IN) && !l4_is_nil_id(ev_partner_l4id))
00049 {
00050 env.timeout = EVENT_TIMEOUT;
00051 stream_io_push_send(&ev_partner_l4id, &stream_event, &env);
00052 if (DICE_HAS_EXCEPTION(&env) &&
00053 DICE_EXCEPTION_MAJOR(&env) == CORBA_SYSTEM_EXCEPTION &&
00054 DICE_EXCEPTION_MINOR(&env) == CORBA_DICE_EXCEPTION_IPC_ERROR)
00055 {
00056 switch (DICE_IPC_ERROR(&env))
00057 {
00058 case L4_IPC_ENOT_EXISTENT:
00059
00060 LOG("Target thread "l4util_idfmt" dead",
00061 l4util_idstr(ev_partner_l4id));
00062 want_vc = -2;
00063 break;
00064 case L4_IPC_SETIMEOUT:
00065 case L4_IPC_SECANCELED:
00066
00067 break;
00068 case L4_IPC_RETIMEOUT:
00069 case L4_IPC_RECANCELED:
00070
00071 resend = 0;
00072 break;
00073 default:
00074
00075 LOG("Error %d sending event to "l4util_idfmt,
00076 DICE_IPC_ERROR(&env), l4util_idstr(ev_partner_l4id));
00077 want_vc = -2;
00078 break;
00079 }
00080 }
00081 else
00082 resend = 0;
00083
00084
00085 if (resend)
00086 l4_sleep(50);
00087 }
00088 l4lock_unlock(&want_vc_lock);
00089 }
00090 }
00091
00092
00093 static void
00094 handle_event(struct l4input *ev)
00095 {
00096 static int altgr_down;
00097 static int shift_down;
00098 static struct l4input special_ev = { .type = 0xff };
00099
00100 if (ev->type == EV_KEY)
00101 {
00102 l4_umword_t keycode = ev->code;
00103 l4_umword_t down = ev->value;
00104 l4_umword_t special_down = 0;
00105
00106 if (nomouse && keycode >= BTN_MOUSE && keycode < BTN_TASK)
00107 return;
00108
00109 if (keycode == KEY_RIGHTALT)
00110 altgr_down = special_down = down;
00111 else if (!noshift
00112 && (keycode == KEY_LEFTSHIFT || keycode == KEY_RIGHTSHIFT))
00113 shift_down = special_down = down;
00114
00115 if (special_down)
00116 {
00117
00118
00119 special_ev = *ev;
00120 return;
00121 }
00122
00123 if (down && (altgr_down || shift_down))
00124 {
00125
00126 if (keycode >= KEY_F1 && keycode <= KEY_F10)
00127 {
00128 request_vc(keycode - KEY_F1 + 1);
00129 special_ev.type = 0xff;
00130 return;
00131 }
00132 if (keycode == KEY_LEFT)
00133 {
00134 request_vc_delta(-1);
00135 special_ev.type = 0xff;
00136 return;
00137 }
00138 if (keycode == KEY_RIGHT)
00139 {
00140 request_vc_delta(1);
00141 special_ev.type = 0xff;
00142 return;
00143 }
00144 if (keycode == KEY_F11 && altgr_down)
00145 {
00146
00147 vc_brightness_contrast(shift_down ? -100 : 100, 0);
00148 special_ev.type = 0xff;
00149 return;
00150 }
00151 if (keycode == KEY_F12 && altgr_down)
00152 {
00153
00154 vc_brightness_contrast(0, shift_down ? -100 : 100);
00155 special_ev.type = 0xff;
00156 return;
00157 }
00158 if (keycode == KEY_PAUSE && altgr_down)
00159 {
00160 cpu_load_history = 1-cpu_load_history;
00161 return;
00162 }
00163 #ifndef L4BID_RELEASE_MODE
00164 if (keycode == KEY_SYSRQ && altgr_down)
00165 {
00166
00167 enter_kdebug("AltGr + SysRq");
00168 special_ev.type = 0xff;
00169 return;
00170 }
00171 #endif
00172 }
00173
00174
00175 if (special_ev.type != 0xff)
00176 {
00177 send_event_client(&special_ev);
00178 special_ev.type = 0xff;
00179 }
00180 }
00181 else if (ev->type == EV_REL || ev->type == EV_ABS)
00182 {
00183
00184 if (nomouse)
00185 return;
00186 }
00187 else if (ev->type == EV_MSC)
00188 {
00189
00190 return;
00191 }
00192 else
00193 {
00194 printf("handle_event: Unknown event type %d\n", ev->type);
00195 return;
00196 }
00197
00198 send_event_client(ev);
00199 }
00200
00201
00202
00203 void
00204 ev_init()
00205 {
00206 l4input_init(254, handle_event);
00207 }