2 * \file l4con/server/src/ev.c
3 * \brief mouse, keyboard, etc event stuff
6 * \author Christian Helmuth <ch12@os.inf.tu-dresden.de>
7 * Frank Mehnert <fm3@os.inf.tu-dresden.de> */
9 * (c) 2008-2009 Author(s)
10 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
17 /* (c) 2003 'Technische Universitaet Dresden'
18 * This file is part of the con package, which is distributed under
19 * the terms of the GNU General Public License 2. Please see the
20 * COPYING file for details. */
22 #include <l4/l4con/l4con.h>
23 #include <l4/util/l4_macros.h>
24 #include <l4/input/libinput.h>
25 #include <l4/sys/kdebug.h>
26 #include <l4/sys/factory.h>
27 #include <l4/sys/icu.h>
28 #include <l4/re/env.h>
29 #include <l4/re/c/event_buffer.h>
30 #include <l4/re/c/util/cap_alloc.h>
31 #include <l4/re/c/util/video/goos_fb.h>
33 #include <pthread-l4.h>
43 int nomouse, noshift, gen_abs_events;
44 int cur_abs_pos_x, cur_abs_pos_y;
45 static l4_cap_idx_t ev_ds, ev_irq;
46 static l4re_event_buffer_consumer_t ev_buf;
48 /** brief Key event handling -> distribution and switch */
50 handle_event(struct l4input *ev)
52 static int altgr_down;
53 static int shift_down;
54 static struct l4input special_ev = { .type = 0xff };
56 if (ev->type == EV_KEY)
58 l4_umword_t keycode = ev->code;
59 l4_umword_t down = ev->value;
60 l4_umword_t special_down = 0;
62 if (nomouse && keycode >= BTN_MOUSE && keycode < BTN_TASK)
65 if (keycode == KEY_RIGHTALT)
66 altgr_down = special_down = down;
68 && (keycode == KEY_LEFTSHIFT || keycode == KEY_RIGHTSHIFT))
69 shift_down = special_down = down;
73 /* Defer sending of the special key until we know if we handle
74 * the next key completely in the server */
79 if (down && (altgr_down || shift_down))
81 /* virtual console switching */
82 if (keycode >= KEY_F1 && keycode <= KEY_F10)
84 request_vc(keycode - KEY_F1 + 1);
85 special_ev.type = 0xff;
88 if (keycode == KEY_LEFT)
91 special_ev.type = 0xff;
94 if (keycode == KEY_RIGHT)
97 special_ev.type = 0xff;
100 if (keycode == KEY_F11 && altgr_down)
102 /* F11/Shift F11: increase/decrase brightness */
103 vc_brightness_contrast(shift_down ? -100 : 100, 0);
104 special_ev.type = 0xff;
107 if (keycode == KEY_F12 && altgr_down)
109 /* F12/Shift F12: increase/decrase contrast */
110 vc_brightness_contrast(0, shift_down ? -100 : 100);
111 special_ev.type = 0xff;
114 if (keycode == KEY_PAUSE && altgr_down)
116 cpu_load_history = 1-cpu_load_history;
119 #ifndef L4BID_RELEASE_MODE
120 if (keycode == KEY_SYSRQ && altgr_down)
122 /* Magic SysReq -> enter_kdebug() */
123 enter_kdebug("AltGr + SysRq");
124 special_ev.type = 0xff;
130 /* No special key, send deferred key event */
131 if (special_ev.type != 0xff)
133 send_event_client(vc[fg_vc], &special_ev);
134 special_ev.type = 0xff;
137 else if (ev->type == EV_REL || ev->type == EV_ABS)
143 if (gen_abs_events && ev->type == EV_REL)
145 // for now we treat gen_abs_events to replace the relative events
149 cur_abs_pos_x += ev->value;
150 if (cur_abs_pos_x < 0)
152 else if ((unsigned)cur_abs_pos_x >= vc[fg_vc]->client_xres)
153 cur_abs_pos_x = vc[fg_vc]->client_xres;
154 ev->value = cur_abs_pos_x;
156 else if (ev->code == 1)
158 cur_abs_pos_y += ev->value;
159 if (cur_abs_pos_y < 0)
161 else if ((unsigned)cur_abs_pos_y >= vc[fg_vc]->client_yres)
162 cur_abs_pos_y = vc[fg_vc]->client_yres;
163 ev->value = cur_abs_pos_y;
167 else if (ev->type == EV_MSC)
172 else if (ev->type == EV_SYN)
178 printf("handle_event: Unknown event type %d\n", ev->type);
182 send_event_client(vc[fg_vc], ev);
185 static void *ev_thread(void *d)
188 l4re_event_buffer_consumer_process(&ev_buf, ev_irq,
189 pthread_getl4cap(pthread_self()),
190 (void (*)(l4re_event_t *))handle_event);
194 #define Panic(a...) do { fprintf(stderr, a); exit(1); } while (0)
196 /** \brief event driver initialization
203 if (l4_is_invalid_cap(ev_ds = l4re_util_cap_alloc()))
204 Panic("Cap alloc failed");
206 if (l4_is_invalid_cap(ev_irq = l4re_util_cap_alloc()))
207 Panic("Cap alloc failed");
209 if (l4_error(l4_factory_create_irq(l4re_env()->factory, ev_irq)))
210 Panic("IRQ create failed");
212 if (l4_error(l4_icu_bind(l4re_util_video_goos_fb_goos(&goosfb), 0, ev_irq))
213 || l4re_event_get(l4re_util_video_goos_fb_goos(&goosfb), ev_ds)
214 || l4re_event_buffer_attach(&ev_buf, ev_ds, l4re_env()->rm))
216 // failed, try to start the hw driver
217 l4re_util_cap_free_um(ev_ds);
218 l4re_util_cap_free_um(ev_irq);
220 printf("Using l4input\n");
221 l4input_init(254, handle_event);
225 printf("Using l4re-console event pass-through\n");
227 if (pthread_create(&t, NULL, ev_thread, NULL))
228 Panic("Thread creation failed\n");