Re: [AD] Missing field in keyboard and mouse events |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: Coordination of admins/developers of the game programming library Allegro <alleg-developers@xxxxxxxxxx>
- Subject: Re: [AD] Missing field in keyboard and mouse events
- From: Elias Pschernig <elias@xxxxxxxxxx>
- Date: Tue, 12 Aug 2008 17:44:58 +0200
On Tue, 2008-08-12 at 13:34 +0200, Elias Pschernig wrote:
>
> Ok. I'll try and fill in the display field for all X11 events now then.
>
Patach attached.
Since I didn't want to mess with xwin.c, I also went ahead and tried to
work some more on getting rid of the old A4 system driver still running
in the background.
--
Elias Pschernig <elias@xxxxxxxxxx>
Index: src/xglx/xglx.h
===================================================================
--- src/xglx/xglx.h (revision 10344)
+++ src/xglx/xglx.h (working copy)
@@ -73,12 +73,13 @@
void _al_display_xglx_closebutton(ALLEGRO_DISPLAY *d, XEvent *xevent);
/* keyboard */
-void _al_xwin_keyboard_handler(XKeyEvent *event, bool dga2_hack);
+void _al_xwin_keyboard_handler(XKeyEvent *event, bool dga2_hack,
+ ALLEGRO_DISPLAY *display);
/* mouse */
-void _al_xwin_mouse_button_press_handler(int button);
-void _al_xwin_mouse_button_release_handler(int button);
-void _al_xwin_mouse_motion_notify_handler(int x, int y);
+void _al_xwin_mouse_button_press_handler(int button, ALLEGRO_DISPLAY *display);
+void _al_xwin_mouse_button_release_handler(int button, ALLEGRO_DISPLAY *d);
+void _al_xwin_mouse_motion_notify_handler(int x, int y, ALLEGRO_DISPLAY *d);
/* fullscreen */
int _al_xglx_get_num_display_modes(void);
Index: src/xglx/xsystem.c
===================================================================
--- src/xglx/xsystem.c (revision 10344)
+++ src/xglx/xsystem.c (working copy)
@@ -23,8 +23,8 @@
_al_mutex_lock(&s->lock);
- // FIXME: With many windows, it's bad to loop through them all,
- // maybe can come up with a better system here.
+ // With many windows, it's bad to loop through them all, but typically
+ // we have one or at most two or so.
for (i = 0; i < _al_vector_size(&s->system.displays); i++) {
ALLEGRO_DISPLAY_XGLX **dptr = _al_vector_ref(&s->system.displays, i);
d = *dptr;
@@ -35,20 +35,24 @@
switch (event.type) {
case KeyPress:
- _al_xwin_keyboard_handler(&event.xkey, false);
+ _al_xwin_keyboard_handler(&event.xkey, false,
+ &d->ogl_display.display);
break;
case KeyRelease:
- _al_xwin_keyboard_handler(&event.xkey, false);
+ _al_xwin_keyboard_handler(&event.xkey, false,
+ &d->ogl_display.display);
break;
case ButtonPress:
- _al_xwin_mouse_button_press_handler(event.xbutton.button);
+ _al_xwin_mouse_button_press_handler(event.xbutton.button,
+ &d->ogl_display.display);
break;
case ButtonRelease:
- _al_xwin_mouse_button_release_handler(event.xbutton.button);
+ _al_xwin_mouse_button_release_handler(event.xbutton.button,
+ &d->ogl_display.display);
break;
case MotionNotify:
_al_xwin_mouse_motion_notify_handler(
- event.xmotion.x, event.xmotion.y);
+ event.xmotion.x, event.xmotion.y, &d->ogl_display.display);
break;
case ConfigureNotify:
_al_display_xglx_configure(&d->ogl_display.display, &event);
@@ -78,6 +82,8 @@
_Xdebug = 1;
#endif
+ _al_unix_init_time();
+
_al_mutex_init(&s->lock);
_al_cond_init(&s->mapped);
_al_cond_init(&s->resized);
@@ -170,3 +176,50 @@
*add = _al_system_xglx_driver();
#endif
}
+
+// FIXME: Remove this, it's the *A4* system driver, only here as long as we still
+// need an A4 system driver running behinds our backs.
+static int _dummy_init(void) {return 0;}
+static void _dummy_exit(void) {}
+/* the main system driver for running under X-Windows */
+SYSTEM_DRIVER system_xwin =
+{
+ SYSTEM_XWINDOWS,
+ empty_string,
+ empty_string,
+ "X-Windows",
+ _dummy_init,
+ _dummy_exit,
+ _unix_get_executable_name,
+ _unix_find_resource,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* assert */
+ NULL, /* save_console_state */
+ NULL, /* restore_console_state */
+ NULL, /* create_bitmap */
+ NULL, /* created_bitmap */
+ NULL, /* create_sub_bitmap */
+ NULL, /* created_sub_bitmap */
+ NULL, /* destroy_bitmap */
+ NULL, /* read_hardware_palette */
+ NULL, /* set_palette_range */
+ NULL, /* get_vtable */
+ NULL,
+ NULL, /* display_switch_lock */
+ NULL,
+ NULL,
+ NULL,
+ _unix_yield_timeslice,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+#ifdef ALLEGRO_LINUX
+ NULL
+#else
+ NULL /* joystick_driver_list */
+#endif
+};
\ No newline at end of file
Index: src/mousenu.c
===================================================================
--- src/mousenu.c (revision 10344)
+++ src/mousenu.c (working copy)
@@ -25,6 +25,7 @@
#include "allegro5/internal/aintern.h"
#include "allegro5/internal/aintern_mouse.h"
#include "allegro5/internal/aintern_bitmap.h"
+#include "allegro5/internal/aintern_system.h"
@@ -55,6 +56,17 @@
if (new_mouse_driver)
return true;
+
+ //FIXME: seems A4/A5 driver list stuff doesn't quite agree right now
+ if (al_system_driver()->vt->get_mouse_driver) {
+ new_mouse_driver = al_system_driver()->vt->get_mouse_driver();
+ if (!new_mouse_driver->init_mouse()) {
+ new_mouse_driver = NULL;
+ return false;
+ }
+ _add_exit_func(al_uninstall_keyboard, "al_uninstall_mouse");
+ return true;
+ }
if (system_driver->mouse_drivers)
driver_list = system_driver->mouse_drivers();
Index: src/keybdnu.c
===================================================================
--- src/keybdnu.c (revision 10344)
+++ src/keybdnu.c (working copy)
@@ -25,6 +25,7 @@
#include "allegro5/internal/aintern.h"
#include "allegro5/internal/aintern_events.h"
#include "allegro5/internal/aintern_keyboard.h"
+#include "allegro5/internal/aintern_system.h"
@@ -95,6 +96,17 @@
if (new_keyboard_driver)
return true;
+ //FIXME: seems A4/A5 driver list stuff doesn't quite agree right now
+ if (al_system_driver()->vt->get_keyboard_driver) {
+ new_keyboard_driver = al_system_driver()->vt->get_keyboard_driver();
+ if (!new_keyboard_driver->init_keyboard()) {
+ new_keyboard_driver = NULL;
+ return false;
+ }
+ _add_exit_func(al_uninstall_keyboard, "al_uninstall_keyboard");
+ return true;
+ }
+
if (system_driver->keyboard_drivers)
driver_list = system_driver->keyboard_drivers();
else
Index: src/x/xmousenu.c
===================================================================
--- src/x/xmousenu.c (revision 10344)
+++ src/x/xmousenu.c (working copy)
@@ -23,7 +23,8 @@
#include "allegro5/allegro5.h"
#include "allegro5/internal/aintern.h"
#include "allegro5/internal/aintern_mouse.h"
-#include "xwin.h"
+//#include "xwin.h"
+#include "../xglx/xglx.h"
@@ -55,13 +56,14 @@
static bool xmouse_set_mouse_range(int x1, int y1, int x2, int y2);
static void xmouse_get_state(ALLEGRO_MSESTATE *ret_state);
-static void wheel_motion_handler(int dz);
+static void wheel_motion_handler(int dz, ALLEGRO_DISPLAY *display);
static int x_button_to_wheel(unsigned int x_button);
static unsigned int x_button_to_al_button(unsigned int x_button);
static void generate_mouse_event(unsigned int type,
int x, int y, int z,
int dx, int dy, int dz,
- unsigned int button);
+ unsigned int button,
+ ALLEGRO_DISPLAY *display);
@@ -101,7 +103,8 @@
*/
static bool xmouse_init(void)
{
- _al_xwin_enable_hardware_cursor(true);
+ //FIXME
+ //_al_xwin_enable_hardware_cursor(true);
memset(&the_mouse, 0, sizeof the_mouse);
@@ -149,12 +152,13 @@
{
int num_buttons;
unsigned char map[8];
+ ALLEGRO_SYSTEM_XGLX *system = (void *)al_system_driver();
ASSERT(xmouse_installed);
- XLOCK();
- num_buttons = XGetPointerMapping(_xwin.display, map, sizeof(map));
- XUNLOCK();
+ //XLOCK();
+ num_buttons = XGetPointerMapping(system->xdisplay, map, sizeof(map));
+ //XUNLOCK();
num_buttons = CLAMP(2, num_buttons, 3);
return num_buttons;
@@ -181,7 +185,8 @@
static bool xmouse_set_mouse_xy(int x, int y)
{
ASSERT(xmouse_installed);
-
+ //FIXME
+#if 0
if ((x < 0) || (y < 0) || (x >= _xwin.window_width) || (y >= _xwin.window_height))
return false;
@@ -191,7 +196,7 @@
_xwin.window_width, _xwin.window_height, x, y);
}
_al_event_source_unlock(&the_mouse.parent.es);
-
+#endif
return true;
}
@@ -219,7 +224,7 @@
ALLEGRO_EVENT_MOUSE_AXES,
the_mouse.state.x, the_mouse.state.y, the_mouse.state.z,
0, 0, dz,
- 0);
+ 0, NULL);
}
}
_al_event_source_unlock(&the_mouse.parent.es);
@@ -259,7 +264,8 @@
* Called by _xwin_process_event() for ButtonPress events received from the X
* server.
*/
-void _al_xwin_mouse_button_press_handler(unsigned int x_button)
+void _al_xwin_mouse_button_press_handler(int x_button,
+ ALLEGRO_DISPLAY *display)
{
int dz;
unsigned int al_button;
@@ -271,7 +277,7 @@
/* TODO secondary wheel support */
dz = x_button_to_wheel(x_button);
if (dz != 0) {
- wheel_motion_handler(dz);
+ wheel_motion_handler(dz, display);
return;
}
@@ -288,7 +294,7 @@
ALLEGRO_EVENT_MOUSE_BUTTON_DOWN,
the_mouse.state.x, the_mouse.state.y, the_mouse.state.z,
0, 0, 0,
- al_button);
+ al_button, display);
}
_al_event_source_unlock(&the_mouse.parent.es);
}
@@ -299,7 +305,7 @@
* Called by _al_xwin_mouse_button_press_handler() if the ButtonPress event
* received from the X server is actually for a mouse wheel movement.
*/
-static void wheel_motion_handler(int dz)
+static void wheel_motion_handler(int dz, ALLEGRO_DISPLAY *display)
{
_al_event_source_lock(&the_mouse.parent.es);
{
@@ -309,7 +315,7 @@
ALLEGRO_EVENT_MOUSE_AXES,
the_mouse.state.x, the_mouse.state.y, the_mouse.state.z,
0, 0, dz,
- 0);
+ 0, display);
}
_al_event_source_unlock(&the_mouse.parent.es);
}
@@ -320,7 +326,8 @@
* Called by _xwin_process_event() for ButtonRelease events received from the
* X server.
*/
-void _al_xwin_mouse_button_release_handler(unsigned int x_button)
+void _al_xwin_mouse_button_release_handler(int x_button,
+ ALLEGRO_DISPLAY *display)
{
int al_button;
@@ -339,7 +346,7 @@
ALLEGRO_EVENT_MOUSE_BUTTON_UP,
the_mouse.state.x, the_mouse.state.y, the_mouse.state.z,
0, 0, 0,
- al_button);
+ al_button, display);
}
_al_event_source_unlock(&the_mouse.parent.es);
}
@@ -350,7 +357,8 @@
* Called by _xwin_process_event() for MotionNotify events received from the X
* server.
*/
-void _al_xwin_mouse_motion_notify_handler(int x, int y)
+void _al_xwin_mouse_motion_notify_handler(int x, int y,
+ ALLEGRO_DISPLAY *display)
{
if (!xmouse_installed)
return;
@@ -366,7 +374,7 @@
ALLEGRO_EVENT_MOUSE_AXES,
the_mouse.state.x, the_mouse.state.y, the_mouse.state.z,
dx, dy, 0,
- 0);
+ 0, display);
}
_al_event_source_unlock(&the_mouse.parent.es);
}
@@ -380,7 +388,8 @@
*/
void _al_xwin_mouse_motion_notify_handler_dga2(int dx, int dy,
int min_x, int min_y,
- int max_x, int max_y)
+ int max_x, int max_y,
+ ALLEGRO_DISPLAY *display)
{
if (!xmouse_installed)
return;
@@ -397,7 +406,7 @@
ALLEGRO_EVENT_MOUSE_AXES,
the_mouse.state.x, the_mouse.state.y, the_mouse.state.z,
dx, dy, 0,
- 0);
+ 0, display);
}
_al_event_source_unlock(&the_mouse.parent.es);
}
@@ -449,7 +458,8 @@
static void generate_mouse_event(unsigned int type,
int x, int y, int z,
int dx, int dy, int dz,
- unsigned int button)
+ unsigned int button,
+ ALLEGRO_DISPLAY *display)
{
ALLEGRO_EVENT *event;
@@ -462,7 +472,7 @@
event->mouse.type = type;
event->mouse.timestamp = al_current_time();
- event->mouse.__display__dont_use_yet__ = NULL; /* TODO */
+ event->mouse.display = display;
event->mouse.x = x;
event->mouse.y = y;
event->mouse.z = z;
Index: src/x/xvtable.c
===================================================================
--- src/x/xvtable.c (revision 10344)
+++ src/x/xvtable.c (working copy)
@@ -20,6 +20,8 @@
#include "allegro5/platform/aintunix.h"
#include "xwin.h"
+#if 0
+
static GFX_VTABLE _xwin_vtable;
@@ -849,3 +851,5 @@
_xwin_in_gfx_call = 0;
_xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
}
+
+#endif
\ No newline at end of file
Index: src/x/xwin.c
===================================================================
--- src/x/xwin.c (revision 10344)
+++ src/x/xwin.c (working copy)
@@ -166,6 +166,7 @@
#define PREFIX_W "al-xwin WARNING: "
#define PREFIX_E "al-xwin ERROR: "
+#if 0
/* Forward declarations for private functions. */
static int _xwin_private_open_display(char *name);
@@ -2355,6 +2356,7 @@
}
+
/* _xwin_process_event: [bgman thread]
* Process (usually) one event. To handle key repeats sometimes two
* events are processed. Returns the number of events processed.
@@ -3048,3 +3050,5 @@
void (*_xwin_window_defaultor)(void) = &_xwin_private_set_window_defaults;
void (*_xwin_window_redrawer)(int, int, int, int) = &_xwin_private_redraw_window;
void (*_xwin_input_handler)(void) = 0;
+
+#endif
\ No newline at end of file
Index: src/x/xgfxdrv.c
===================================================================
--- src/x/xgfxdrv.c (revision 10344)
+++ src/x/xgfxdrv.c (working copy)
@@ -20,6 +20,7 @@
#include "allegro5/platform/aintunix.h"
#include "xwin.h"
+#if 0
static BITMAP *_xwin_gfxdrv_init(int w, int h, int vw, int vh, int color_depth);
static void _xwin_gfxdrv_exit(BITMAP *bmp);
@@ -149,3 +150,5 @@
{
return _xwin_create_screen(&gfx_xwin_fullscreen, w, h, vw, vh, color_depth, TRUE);
}
+
+#endif
\ No newline at end of file
Index: src/x/xkeyboard.c
===================================================================
--- src/x/xkeyboard.c (revision 10344)
+++ src/x/xkeyboard.c (working copy)
@@ -34,11 +34,13 @@
#include "allegro5/internal/aintern.h"
#include "allegro5/internal/aintern_events.h"
#include "allegro5/internal/aintern_keyboard.h"
-#include "xwin.h"
+//#include "xwin.h"
+#include "../xglx/xglx.h"
/*----------------------------------------------------------------------*/
-static void handle_key_press(int mycode, int unichar, unsigned int modifiers);
-static void handle_key_release(int mycode);
+static void handle_key_press(int mycode, int unichar, unsigned int modifiers,
+ ALLEGRO_DISPLAY *display);
+static void handle_key_release(int mycode, ALLEGRO_DISPLAY *display);
static int _key_shifts;
/*----------------------------------------------------------------------*/
@@ -58,6 +60,7 @@
static KeySym *keysyms = NULL;
static int main_pid; /* The pid to kill with ctrl-alt-del. */
static int pause_key = 0; /* Allegro's special pause key state. */
+static int keycode_to_scancode[256];
/* This table can be ammended to provide more reasonable defaults for
* mappings other than US/UK. They are used to map X11 KeySyms as found in
@@ -269,7 +272,7 @@
* press/release.
*/
if (event->state & modifier_flags[i][1])
- mask |= modifier_flags[i][0];
+ mask |= modifier_flags[i][0];
/* In case a modifier key itself was pressed, we now need to update
* the above state for Allegro, which wants the state after the
@@ -278,19 +281,19 @@
for (j = 0; j < xmodmap->max_keypermod; j++) {
if (event->keycode && event->keycode ==
xmodmap->modifiermap[i * xmodmap->max_keypermod + j]) {
- if (event->type == KeyPress) {
+ if (event->type == KeyPress) {
/* Modifier key pressed - toggle or set flag. */
- if (modifier_flags[i][2])
- mask ^= modifier_flags[i][0];
- else
- mask |= modifier_flags[i][0];
- }
+ if (modifier_flags[i][2])
+ mask ^= modifier_flags[i][0];
+ else
+ mask |= modifier_flags[i][0];
+ }
else if (event->type == KeyRelease) {
- /* Modifier key of non-toggle key released - remove flag. */
- if (!modifier_flags[i][2])
- mask &= ~modifier_flags[i][0];
- }
- }
+ /* Modifier key of non-toggle key released - remove flag. */
+ if (!modifier_flags[i][2])
+ mask &= ~modifier_flags[i][0];
+ }
+ }
}
}
_key_shifts = mask;
@@ -320,11 +323,11 @@
if (!modifier_flags[i][2])
_key_shifts &= ~modifier_flags[i][0];
}
- }
+ }
}
/* Hack: DGA keys seem to get reported wrong otherwise. */
if (_key_shifts & modifier_flags[i][0])
- event->state |= modifier_flags[i][1];
+ event->state |= modifier_flags[i][1];
}
}
@@ -340,23 +343,23 @@
for (j = 1; j < ALLEGRO_KEY_MAX; j++) {
if (!used[j]) {
- AL_CONST char *str;
- _xwin.keycode_to_scancode[i] = j;
- str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
- if (str)
- key_names[j] = str;
- else {
- key_names[j] = _al_keyboard_common_names[j];
- }
- used[j] = 1;
- break;
+ AL_CONST char *str;
+ keycode_to_scancode[i] = j;
+ str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
+ if (str)
+ key_names[j] = str;
+ else {
+ key_names[j] = _al_keyboard_common_names[j];
+ }
+ used[j] = 1;
+ break;
}
}
if (j == ALLEGRO_KEY_MAX) {
TRACE (PREFIX_E "You have more keys reported by X than Allegro's "
- "maximum of %i keys. Please send a bug report.\n", ALLEGRO_KEY_MAX);
- _xwin.keycode_to_scancode[i] = 0;
+ "maximum of %i keys. Please send a bug report.\n", ALLEGRO_KEY_MAX);
+ keycode_to_scancode[i] = 0;
}
TRACE(PREFIX_I "Key %i missing:", i);
@@ -364,9 +367,9 @@
char *sym_str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode) + j]);
TRACE(" %s", sym_str ? sym_str : "NULL");
}
- TRACE(" - assigned to %i.\n", _xwin.keycode_to_scancode[i]);
+ TRACE(" - assigned to %i.\n", keycode_to_scancode[i]);
- return _xwin.keycode_to_scancode[i];
+ return keycode_to_scancode[i];
}
@@ -374,14 +377,15 @@
/* _al_xwin_keyboard_handler:
* Keyboard "interrupt" handler.
*/
-void _al_xwin_keyboard_handler(XKeyEvent *event, bool dga2_hack)
+void _al_xwin_keyboard_handler(XKeyEvent *event, bool dga2_hack,
+ ALLEGRO_DISPLAY *display)
{
int keycode;
if (!xkeyboard_installed)
return;
- keycode = _xwin.keycode_to_scancode[event->keycode];
+ keycode = keycode_to_scancode[event->keycode];
if (keycode == -1)
keycode = find_unknown_key_assignment(event->keycode);
@@ -412,42 +416,42 @@
#if defined (ALLEGRO_XWINDOWS_WITH_XIM) && defined(X_HAVE_UTF8_STRING)
if (xic) {
- len = Xutf8LookupString(xic, event, buffer, sizeof buffer, NULL, NULL);
+ len = Xutf8LookupString(xic, event, buffer, sizeof buffer, NULL, NULL);
}
else
#endif
{
/* XLookupString is supposed to only use ASCII. */
- len = XLookupString(event, buffer, sizeof buffer, NULL, NULL);
+ len = XLookupString(event, buffer, sizeof buffer, NULL, NULL);
}
buffer[len] = '\0';
uconvert(buffer, U_UTF8, buffer2, U_UNICODE, sizeof buffer2);
unicode = *(unsigned short *)buffer2;
#ifdef ALLEGRO_XWINDOWS_WITH_XIM
- r = XFilterEvent((XEvent *)event, _xwin.window);
+ r = XFilterEvent((XEvent *)event, display->window);
#endif
if (keycode || unicode) {
- /* If we have a keycode, we want it to go to Allegro immediately, so the
- * key[] array is updated, and the user callbacks are called. OTOH, a key
- * should not be added to the keyboard buffer (parameter -1) if it was
+ /* If we have a keycode, we want it to go to Allegro immediately, so the
+ * key[] array is updated, and the user callbacks are called. OTOH, a key
+ * should not be added to the keyboard buffer (parameter -1) if it was
* filtered out as a compose key, or if it is a modifier key.
- */
- if (r || keycode >= ALLEGRO_KEY_MODIFIERS)
- unicode = -1;
- else {
- /* Historically, Allegro expects to get only the scancode when Alt is
- * held down.
- */
- if (_key_shifts & ALLEGRO_KEYMOD_ALT)
- unicode = 0;
+ */
+ if (r || keycode >= ALLEGRO_KEY_MODIFIERS)
+ unicode = -1;
+ else {
+ /* Historically, Allegro expects to get only the scancode when Alt is
+ * held down.
+ */
+ if (_key_shifts & ALLEGRO_KEYMOD_ALT)
+ unicode = 0;
}
- handle_key_press(keycode, unicode, _key_shifts);
+ handle_key_press(keycode, unicode, _key_shifts, display);
}
}
else { /* Key release. */
- handle_key_release(keycode);
+ handle_key_release(keycode, display);
}
}
@@ -466,8 +470,8 @@
int i;
for (i = 0; i < ALLEGRO_KEY_MAX; i++) {
- if (key[i])
- handle_key_release(i);
+ if (key[i])
+ handle_key_release(i, display);
}
}
#endif
@@ -486,7 +490,7 @@
for (i = 0; i < n; i++) {
if (translation_table[i].keysym == sym)
- return translation_table[i].allegro_key;
+ return translation_table[i].allegro_key;
}
return 0;
}
@@ -519,22 +523,23 @@
* KeySyms to ALLEGRO_KEY_* codes.
*/
-static void private_get_keyboard_mapping(void)
+static void _al_xwin_get_keyboard_mapping(void)
{
int i;
int count;
int missing = 0;
+ ALLEGRO_SYSTEM_XGLX *system = (void *)al_system_driver();
memset(used, 0, sizeof used);
- memset(_xwin.keycode_to_scancode, 0, sizeof _xwin.keycode_to_scancode);
+ memset(keycode_to_scancode, 0, sizeof keycode_to_scancode);
- XDisplayKeycodes(_xwin.display, &min_keycode, &max_keycode);
+ XDisplayKeycodes(system->xdisplay, &min_keycode, &max_keycode);
count = 1 + max_keycode - min_keycode;
if (keysyms) {
XFree(keysyms);
}
- keysyms = XGetKeyboardMapping(_xwin.display, min_keycode,
+ keysyms = XGetKeyboardMapping(system->xdisplay, min_keycode,
count, &sym_per_key);
TRACE (PREFIX_I "%i keys, %i symbols per key.\n", count, sym_per_key);
@@ -555,56 +560,56 @@
/* Hack for French keyboards, to correctly map ALLEGRO_KEY_0 to ALLEGRO_KEY_9. */
if (sym2 >= XK_0 && sym2 <= XK_9) {
- allegro_key = find_allegro_key(sym2);
+ allegro_key = find_allegro_key(sym2);
}
if (!allegro_key) {
- if (sym != NoSymbol) {
- allegro_key = find_allegro_key(sym);
+ if (sym != NoSymbol) {
+ allegro_key = find_allegro_key(sym);
- if (allegro_key == 0) {
- missing++;
- TRACE (" defering.\n");
- }
- }
- else {
- /* No KeySym for this key - ignore it. */
- _xwin.keycode_to_scancode[i] = -1;
- TRACE (" not assigned.\n");
- }
+ if (allegro_key == 0) {
+ missing++;
+ TRACE (" defering.\n");
+ }
+ }
+ else {
+ /* No KeySym for this key - ignore it. */
+ keycode_to_scancode[i] = -1;
+ TRACE (" not assigned.\n");
+ }
}
if (allegro_key) {
- if (used[allegro_key]) {
- TRACE(" *double*");
- }
- _xwin.keycode_to_scancode[i] = allegro_key;
- key_names[allegro_key] =
- XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
- used[allegro_key] = 1;
- TRACE(" assigned to %i.\n", allegro_key);
+ if (used[allegro_key]) {
+ TRACE(" *double*");
+ }
+ keycode_to_scancode[i] = allegro_key;
+ key_names[allegro_key] =
+ XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
+ used[allegro_key] = 1;
+ TRACE(" assigned to %i.\n", allegro_key);
}
}
if (missing) {
/* The keys still not assigned are just assigned arbitrarily now. */
for (i = min_keycode; i <= max_keycode; i++) {
- if (_xwin.keycode_to_scancode[i] == 0) {
- find_unknown_key_assignment(i);
- }
+ if (keycode_to_scancode[i] == 0) {
+ find_unknown_key_assignment(i);
+ }
}
}
if (xmodmap)
XFreeModifiermap(xmodmap);
- xmodmap = XGetModifierMapping(_xwin.display);
+ xmodmap = XGetModifierMapping(system->xdisplay);
for (i = 0; i < 8; i++) {
int j;
TRACE (PREFIX_I "Modifier %d:", i + 1);
for (j = 0; j < xmodmap->max_keypermod; j++) {
- KeySym sym = XKeycodeToKeysym(_xwin.display,
- xmodmap->modifiermap[i * xmodmap->max_keypermod + j], 0);
+ KeySym sym = XKeycodeToKeysym(system->xdisplay,
+ xmodmap->modifiermap[i * xmodmap->max_keypermod + j], 0);
char *sym_str = XKeysymToString(sym);
TRACE(" %s", sym_str ? sym_str : "NULL");
}
@@ -625,51 +630,45 @@
option_format = uconvert_ascii("keycode%d", tmp2);
for (i = min_keycode; i <= max_keycode; i++) {
- int scancode;
+ int scancode;
- uszprintf(option, sizeof(option), option_format, i);
- scancode = get_config_int(section, option, -1);
- if (scancode > 0) {
- _xwin.keycode_to_scancode[i] = scancode;
- TRACE(PREFIX_I "User override: KeySym %i assigned to %i.\n", i, scancode);
- }
+ uszprintf(option, sizeof(option), option_format, i);
+ scancode = get_config_int(section, option, -1);
+ if (scancode > 0) {
+ keycode_to_scancode[i] = scancode;
+ TRACE(PREFIX_I "User override: KeySym %i assigned to %i.\n", i, scancode);
+ }
}
}
}
-void _al_xwin_get_keyboard_mapping(void)
-{
- XLOCK();
- private_get_keyboard_mapping();
- XUNLOCK();
-}
-
/* x_set_leds:
* Update the keyboard LEDs.
*/
static void x_set_leds(int leds)
{
XKeyboardControl values;
+ ALLEGRO_SYSTEM_XGLX *system = (void *)al_system_driver();
ASSERT(xkeyboard_installed);
- XLOCK();
+ //XLOCK();
values.led = 1;
values.led_mode = leds & ALLEGRO_KEYMOD_NUMLOCK ? LedModeOn : LedModeOff;
- XChangeKeyboardControl(_xwin.display, KBLed | KBLedMode, &values);
+ XChangeKeyboardControl(system->xdisplay, KBLed | KBLedMode, &values);
values.led = 2;
values.led_mode = leds & ALLEGRO_KEYMOD_CAPSLOCK ? LedModeOn : LedModeOff;
- XChangeKeyboardControl(_xwin.display, KBLed | KBLedMode, &values);
+ XChangeKeyboardControl(system->xdisplay, KBLed | KBLedMode, &values);
values.led = 3;
values.led_mode = leds & ALLEGRO_KEYMOD_SCROLLLOCK ? LedModeOn : LedModeOff;
- XChangeKeyboardControl(_xwin.display, KBLed | KBLedMode, &values);
+ XChangeKeyboardControl(system->xdisplay, KBLed | KBLedMode, &values);
- XUNLOCK();
+ //XUNLOCK();
}
@@ -684,6 +683,7 @@
XIMStyle xim_style = 0;
char *imvalret;
int i;
+ ALLEGRO_SYSTEM_XGLX *system = (void *)al_system_driver();
#endif
if (xkeyboard_installed)
@@ -693,7 +693,7 @@
memcpy(key_names, _al_keyboard_common_names, sizeof key_names);
- XLOCK ();
+ //XLOCK ();
#ifdef ALLEGRO_XWINDOWS_WITH_XIM
/* TODO: is this needed?
@@ -706,7 +706,7 @@
TRACE(PREFIX_W "XSetLocaleModifiers failed.\n");
}
*/
- xim = XOpenIM (_xwin.display, NULL, NULL, NULL);
+ xim = XOpenIM (system->xdisplay, NULL, NULL, NULL);
if (xim == NULL) {
TRACE(PREFIX_W "XOpenIM failed.\n");
}
@@ -714,42 +714,42 @@
if (xim) {
imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
if (imvalret != NULL || xim_styles == NULL) {
- TRACE(PREFIX_W "Input method doesn't support any styles.\n");
+ TRACE(PREFIX_W "Input method doesn't support any styles.\n");
}
if (xim_styles) {
- xim_style = 0;
- for (i = 0; i < xim_styles->count_styles; i++) {
- if (xim_styles->supported_styles[i] ==
- (XIMPreeditNothing | XIMStatusNothing)) {
- xim_style = xim_styles->supported_styles[i];
- break;
- }
- }
+ xim_style = 0;
+ for (i = 0; i < xim_styles->count_styles; i++) {
+ if (xim_styles->supported_styles[i] ==
+ (XIMPreeditNothing | XIMStatusNothing)) {
+ xim_style = xim_styles->supported_styles[i];
+ break;
+ }
+ }
- if (xim_style == 0) {
- TRACE (PREFIX_W "Input method doesn't support the style we support.\n");
- }
- XFree(xim_styles);
+ if (xim_style == 0) {
+ TRACE (PREFIX_W "Input method doesn't support the style we support.\n");
+ }
+ XFree(xim_styles);
}
}
if (xim && xim_style) {
xic = XCreateIC(xim,
- XNInputStyle, xim_style,
- XNClientWindow, _xwin.window,
- XNFocusWindow, _xwin.window,
- NULL);
+ XNInputStyle, xim_style,
+ XNClientWindow, system->xwindow,
+ XNFocusWindow, system->xwindow,
+ NULL);
if (xic == NULL) {
- TRACE (PREFIX_W "XCreateIC failed.\n");
+ TRACE (PREFIX_W "XCreateIC failed.\n");
}
}
#endif
- private_get_keyboard_mapping();
+ _al_xwin_get_keyboard_mapping();
- XUNLOCK();
+ //XUNLOCK();
xkeyboard_installed = 1;
@@ -767,7 +767,7 @@
return;
xkeyboard_installed = 0;
- XLOCK();
+ //XLOCK();
#ifdef ALLEGRO_XWINDOWS_WITH_XIM
@@ -793,7 +793,7 @@
keysyms = NULL;
}
- XUNLOCK();
+ //XUNLOCK();
}
@@ -942,7 +942,8 @@
*/
static int last_press_code = -1;
-static void handle_key_press(int mycode, int unichar, unsigned int modifiers)
+static void handle_key_press(int mycode, int unichar, unsigned int modifiers,
+ ALLEGRO_DISPLAY *display)
{
bool is_repeat;
ALLEGRO_EVENT *event;
@@ -963,7 +964,7 @@
{
event->keyboard.type = type;
event->keyboard.timestamp = al_current_time();
- event->keyboard.__display__dont_use_yet__ = NULL; /* TODO */
+ event->keyboard.display = display;
event->keyboard.keycode = mycode;
event->keyboard.unichar = unichar;
event->keyboard.modifiers = modifiers;
@@ -979,7 +980,7 @@
&& (modifiers & (ALLEGRO_KEYMOD_ALT | ALLEGRO_KEYMOD_ALTGR)))
{
TRACE(PREFIX_W "Three finger combo detected. SIGTERMing "
- "pid %d\n", main_pid);
+ "pid %d\n", main_pid);
kill(main_pid, SIGTERM);
}
}
@@ -990,7 +991,7 @@
* Hook for the X event dispatcher to handle key releases.
* The caller must lock the X-display.
*/
-static void handle_key_release(int mycode)
+static void handle_key_release(int mycode, ALLEGRO_DISPLAY *display)
{
ALLEGRO_EVENT *event;
@@ -1008,7 +1009,7 @@
{
event->keyboard.type = ALLEGRO_EVENT_KEY_UP;
event->keyboard.timestamp = al_current_time();
- event->keyboard.__display__dont_use_yet__ = NULL; /* TODO */
+ event->keyboard.display = display;
event->keyboard.keycode = mycode;
event->keyboard.unichar = 0;
event->keyboard.modifiers = 0;
Index: src/x/xwin.h
===================================================================
--- src/x/xwin.h (revision 10344)
+++ src/x/xwin.h (working copy)
@@ -75,17 +75,22 @@
AL_FUNC(void, _xwin_unlock, (BITMAP *bmp));
/* Defined in xkeyboard.c. */
-AL_FUNC(void, _al_xwin_keyboard_handler, (XKeyEvent *event, bool dga2_hack));
+AL_FUNC(void, _al_xwin_keyboard_handler, (XKeyEvent *event, bool dga2_hack,
+ ALLEGRO_DISPLAY *display));
AL_FUNC(void, _al_xwin_get_keyboard_mapping, (void));
AL_FUNC(void, _al_xwin_keyboard_focus_handler, (XFocusChangeEvent *event));
/* Defined in xmousenu.c */
-AL_FUNC(void, _al_xwin_mouse_button_press_handler, (unsigned int x_button));
-AL_FUNC(void, _al_xwin_mouse_button_release_handler, (unsigned int x_button));
-AL_FUNC(void, _al_xwin_mouse_motion_notify_handler, (int x, int y));
+AL_FUNC(void, _al_xwin_mouse_button_press_handler, (unsigned int x_button,
+ ALLEGRO_DISPLAY *display));
+AL_FUNC(void, _al_xwin_mouse_button_release_handler, (unsigned int x_button,
+ ALLEGRO_DISPLAY *display));
+AL_FUNC(void, _al_xwin_mouse_motion_notify_handler, (int x, int y,
+ ALLEGRO_DISPLAY *display));
AL_FUNC(void, _al_xwin_mouse_motion_notify_handler_dga2, (int dx, int dy,
int min_x, int min_y,
- int max_x, int max_y));
+ int max_x, int max_y,
+ ALLEGRO_DISPLAY *display));
#endif /* !__bma_xwin_h */
Index: src/x/xsystem.c
===================================================================
--- src/x/xsystem.c (revision 10344)
+++ src/x/xsystem.c (working copy)
@@ -28,8 +28,8 @@
#include <sys/wait.h>
#include <unistd.h>
+#if 0
-
static int _xwin_sysdrv_init(void);
static void _xwin_sysdrv_exit(void);
static void _xwin_sysdrv_set_window_title(AL_CONST char *name);
@@ -437,3 +437,4 @@
mode->bpp = 8;
}
+#endif
\ No newline at end of file
Index: include/allegro5/events.h
===================================================================
--- include/allegro5/events.h (revision 10344)
+++ include/allegro5/events.h (working copy)
@@ -175,6 +175,7 @@
{
_AL_EVENT_HEADER(struct ALLEGRO_KEYBOARD);
struct ALLEGRO_DISPLAY *__display__dont_use_yet__;
+ struct ALLEGRO_DISPLAY *display; /* the window the key was pressed in */
int keycode; /* the physical key pressed */
unsigned int unichar; /* unicode character */
unsigned int modifiers; /* bitfield */
@@ -189,9 +190,11 @@
/* (x, y) Primary mouse position */
/* (z) Mouse wheel position (1D 'wheel'), or, */
/* (w, z) Mouse wheel position (2D 'ball') */
+ /* (display) Window the event originate from */
int x, y, z, w;
int dx, dy, dz, dw;
unsigned int button;
+ struct ALLEGRO_DISPLAY *display;
} ALLEGRO_MOUSE_EVENT;