mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 18:11:05 -05:00
2007-06-18 Matthew Allum <mallum@openedhand.com>
* clutter/sdl/clutter-event-sdl.c: Seemingly fix SDL Event source. Add some very basic SDL keysym translation. (Thanks to Thomas Van Machelen for initial translation code) * tests/test-events.c: Dump some info on keysyms pressed.
This commit is contained in:
parent
339b22ded9
commit
1494a017c3
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2007-06-18 Matthew Allum <mallum@openedhand.com>
|
||||||
|
|
||||||
|
* clutter/sdl/clutter-event-sdl.c:
|
||||||
|
Seemingly fix SDL Event source.
|
||||||
|
Add some very basic SDL keysym translation.
|
||||||
|
(Thanks to Thomas Van Machelen for initial translation code)
|
||||||
|
|
||||||
|
* tests/test-events.c:
|
||||||
|
Dump some info on keysyms pressed.
|
||||||
|
|
||||||
2007-06-16 Emmanuele Bassi <ebassi@openedhand.com>
|
2007-06-16 Emmanuele Bassi <ebassi@openedhand.com>
|
||||||
|
|
||||||
* clutter/clutter-actor.h:
|
* clutter/clutter-actor.h:
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "../clutter-private.h"
|
#include "../clutter-private.h"
|
||||||
#include "../clutter-debug.h"
|
#include "../clutter-debug.h"
|
||||||
#include "../clutter-main.h"
|
#include "../clutter-main.h"
|
||||||
|
#include "../clutter-keysyms.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -109,18 +110,83 @@ static gboolean
|
|||||||
clutter_event_prepare (GSource *source,
|
clutter_event_prepare (GSource *source,
|
||||||
gint *timeout)
|
gint *timeout)
|
||||||
{
|
{
|
||||||
return FALSE;
|
SDL_Event events;
|
||||||
|
int num_events;
|
||||||
|
|
||||||
|
num_events = SDL_PeepEvents(&events, 1, SDL_PEEKEVENT, SDL_ALLEVENTS);
|
||||||
|
|
||||||
|
if (num_events == 1)
|
||||||
|
{
|
||||||
|
*timeout = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num_events == -1)
|
||||||
|
g_warning("Error polling SDL: %s", SDL_GetError());
|
||||||
|
|
||||||
|
*timeout = 50;
|
||||||
|
|
||||||
|
return clutter_events_pending ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
clutter_event_check (GSource *source)
|
clutter_event_check (GSource *source)
|
||||||
{
|
{
|
||||||
SDL_Event events;
|
SDL_Event events;
|
||||||
|
int num_events;
|
||||||
|
|
||||||
/* Pump SDL */
|
/* Pump SDL */
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
|
|
||||||
return SDL_PeepEvents(&events, 1, SDL_PEEKEVENT, SDL_ALLEVENTS);
|
num_events = SDL_PeepEvents(&events, 1, SDL_PEEKEVENT, SDL_ALLEVENTS);
|
||||||
|
|
||||||
|
if (num_events == -1)
|
||||||
|
g_warning("Error polling SDL: %s", SDL_GetError());
|
||||||
|
|
||||||
|
return (num_events == 1 || clutter_events_pending ());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
key_event_translate (ClutterEvent *event,
|
||||||
|
SDL_Event *sdl_event)
|
||||||
|
{
|
||||||
|
event->key.time = 0;
|
||||||
|
|
||||||
|
/* FIXME: This is just a quick hack to make SDL keys roughly work.
|
||||||
|
* Fixing it properly is left as a exercise to someone who enjoys
|
||||||
|
* battleing the SDL API.
|
||||||
|
*
|
||||||
|
* We probably need to use sdl_event->key.keysym.unicode to do lookups
|
||||||
|
* and I have no idea how to get shifted keysyms. It looks quite easy
|
||||||
|
* if you drop into xlib but that then avoids the whole point of using
|
||||||
|
* SDL in the first place (More portability than just GLX)
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch(sdl_event->key.keysym.sym)
|
||||||
|
{
|
||||||
|
case SDLK_UP: event->key.keyval = CLUTTER_Up; break;
|
||||||
|
case SDLK_DOWN: event->key.keyval = CLUTTER_Down; break;
|
||||||
|
case SDLK_LEFT: event->key.keyval = CLUTTER_Left; break;
|
||||||
|
case SDLK_RIGHT: event->key.keyval = CLUTTER_Right; break;
|
||||||
|
case SDLK_HOME: event->key.keyval = CLUTTER_Home; break;
|
||||||
|
case SDLK_END: event->key.keyval = CLUTTER_End; break;
|
||||||
|
case SDLK_PAGEUP: event->key.keyval = CLUTTER_Page_Up; break;
|
||||||
|
case SDLK_PAGEDOWN: event->key.keyval = CLUTTER_Page_Down; break;
|
||||||
|
case SDLK_BACKSPACE: event->key.keyval = CLUTTER_BackSpace; break;
|
||||||
|
case SDLK_DELETE: event->key.keyval = CLUTTER_Delete; break;
|
||||||
|
default:
|
||||||
|
event->key.keyval = sdl_event->key.keysym.sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
event->key.hardware_keycode = sdl_event->key.keysym.scancode;
|
||||||
|
|
||||||
|
if (sdl_event->key.keysym.mod & KMOD_CTRL)
|
||||||
|
event->key.modifier_state
|
||||||
|
= event->key.modifier_state & CLUTTER_CONTROL_MASK;
|
||||||
|
|
||||||
|
if (sdl_event->key.keysym.mod & KMOD_SHIFT)
|
||||||
|
event->key.modifier_state
|
||||||
|
= event->key.modifier_state & CLUTTER_SHIFT_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -128,13 +194,21 @@ event_translate (ClutterBackend *backend,
|
|||||||
ClutterEvent *event,
|
ClutterEvent *event,
|
||||||
SDL_Event *sdl_event)
|
SDL_Event *sdl_event)
|
||||||
{
|
{
|
||||||
/* FIXME: Complete */
|
|
||||||
gboolean res;
|
gboolean res;
|
||||||
|
|
||||||
res = TRUE;
|
res = TRUE;
|
||||||
|
|
||||||
switch (sdl_event->type)
|
switch (sdl_event->type)
|
||||||
{
|
{
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
event->type = CLUTTER_KEY_PRESS;
|
||||||
|
key_event_translate (event, sdl_event);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_KEYUP:
|
||||||
|
event->type = CLUTTER_KEY_RELEASE;
|
||||||
|
key_event_translate (event, sdl_event);
|
||||||
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
switch (sdl_event->button.button)
|
switch (sdl_event->button.button)
|
||||||
|
@ -5,13 +5,22 @@ input_cb (ClutterStage *stage,
|
|||||||
ClutterEvent *event,
|
ClutterEvent *event,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
|
gchar keybuf[9];
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
case CLUTTER_KEY_PRESS:
|
case CLUTTER_KEY_PRESS:
|
||||||
printf("- KEY PRESS\n");
|
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval),
|
||||||
|
keybuf);
|
||||||
|
keybuf[len] = '\0';
|
||||||
|
printf("- KEY PRESS '%s'\n", keybuf);
|
||||||
break;
|
break;
|
||||||
case CLUTTER_KEY_RELEASE:
|
case CLUTTER_KEY_RELEASE:
|
||||||
printf("- KEY RELEASE\n");
|
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval),
|
||||||
|
keybuf);
|
||||||
|
keybuf[len] = '\0';
|
||||||
|
printf("- KEY RELEASE '%s'\n");
|
||||||
break;
|
break;
|
||||||
case CLUTTER_MOTION:
|
case CLUTTER_MOTION:
|
||||||
printf("- MOTION\n");
|
printf("- MOTION\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user