[broadway] Add initial keyboard event support

This commit is contained in:
Alexander Larsson 2010-11-25 21:57:31 +01:00
parent 4aac045a30
commit 80f332308f
2 changed files with 72 additions and 1 deletions

View File

@ -293,6 +293,21 @@ function on_mouse_up (ev) {
send_input ("B", [get_surface_id(ev), ev.pageX, ev.pageY, ev.button, ev.timeStamp])
}
var last_key_down = 0;
function on_key_down (ev) {
var key_code = ev.keyCode;
if (key_code != last_key_down) {
send_input ("k", [key_code, ev.timeStamp]);
last_key_down = key_code;
}
}
function on_key_up (ev) {
var key_code = ev.keyCode;
send_input ("K", [key_code, ev.timeStamp]);
last_key_down = 0;
}
function cancel_event(ev)
{
ev = ev ? ev : window.event;
@ -350,6 +365,8 @@ function connect()
document.onmousemove = on_mouse_move;
document.onmousedown = on_mouse_down;
document.onmouseup = on_mouse_up;
document.onkeydown = on_key_down;
document.onkeyup = on_key_up;
if (document.addEventListener) {
document.addEventListener('DOMMouseScroll', on_mouse_wheel, false);

View File

@ -96,7 +96,7 @@ _gdk_events_got_input (GdkDisplay *display,
GdkScreen *screen;
GdkWindow *root, *window;
char *p;
int x, y, button, id;
int x, y, button, id, dir,key;
guint64 time;
GdkEvent *event = NULL;
char cmd;
@ -226,6 +226,60 @@ _gdk_events_got_input (GdkDisplay *display,
_gdk_windowing_got_event (display, node, event, 0);
}
break;
case 's':
id = strtol(p, &p, 10);
p++; /* Skip , */
x = strtol(p, &p, 10);
p++; /* Skip , */
y = strtol(p, &p, 10);
p++; /* Skip , */
dir = strtol(p, &p, 10);
p++; /* Skip , */
time = strtol(p, &p, 10);
display_broadway->last_x = x;
display_broadway->last_y = y;
window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (id));
if (window)
{
event = gdk_event_new (GDK_SCROLL);
event->scroll.window = g_object_ref (window);
event->scroll.time = time;
event->scroll.x = x - GDK_WINDOW_OBJECT (window)->x;
event->scroll.y = y - GDK_WINDOW_OBJECT (window)->y;
event->scroll.x_root = x;
event->scroll.y_root = y;
event->scroll.direction = dir == 0 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN;
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
}
break;
case 'k':
case 'K':
key = strtol(p, &p, 10);
p++; /* Skip , */
time = strtol(p, &p, 10);
window = display_broadway->mouse_in_toplevel;
if (window)
{
event = gdk_event_new (cmd == 'k' ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
event->key.window = g_object_ref (window);
event->key.time = time;
event->key.keyval = key;
event->key.length = 0;
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
}
break;
default:
g_print ("Unknown input command %s\n", message);